• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

SpiNNakerManchester / JavaSpiNNaker / 6233274834

19 Sep 2023 08:46AM UTC coverage: 36.409% (-0.6%) from 36.982%
6233274834

Pull #658

github

dkfellows
Merge branch 'master' into java-17
Pull Request #658: Update Java version to 17

1656 of 1656 new or added lines in 260 files covered. (100.0%)

8373 of 22997 relevant lines covered (36.41%)

0.36 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/SpiNNaker-front-end/src/main/java/uk/ac/manchester/spinnaker/front_end/DebuggingUtils.java
1
/*
2
 * Copyright (c) 2019-2022 The University of Manchester
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *     https://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
package uk.ac.manchester.spinnaker.front_end;
17

18
import static difflib.DiffUtils.diff;
19
import static uk.ac.manchester.spinnaker.utils.ByteBufferUtils.sliceUp;
20
import static java.util.stream.Collectors.toList;
21

22
import java.nio.ByteBuffer;
23
import java.util.List;
24

25
import org.slf4j.Logger;
26

27
import difflib.Chunk;
28
import uk.ac.manchester.spinnaker.utils.MathUtils;
29

30
/**
31
 * Utilities for debugging.
32
 */
33
public abstract class DebuggingUtils {
34
        private DebuggingUtils() {
35
        }
36

37
        /**
38
         * Compare two buffers and write a description of how they differ to the
39
         * given log (if they actually differ).
40
         *
41
         * @param original
42
         *            The data to compare against. The ground truth.
43
         * @param downloaded
44
         *            The data that is being checked for differences.
45
         * @param log
46
         *            Where to write messages on differences being found.
47
         */
48
        public static void compareBuffers(ByteBuffer original,
49
                        ByteBuffer downloaded, Logger log) {
50
                for (int i = 0; i < original.remaining(); i++) {
×
51
                        if (original.get(i) != downloaded.get(i)) {
×
52
                                log.error("downloaded buffer contents different");
×
53
                                for (var delta : diff(list(original), list(downloaded))
×
54
                                                .getDeltas()) {
×
55
                                        switch (delta.getType()) {
×
56
                                        case CHANGE -> {
57
                                                var changeFrom = delta.getOriginal();
×
58
                                                var changeTo = delta.getRevised();
×
59
                                                log.warn(
×
60
                                                                "swapped {} bytes (SCP) for {} (gather) "
61
                                                                                + "at {}->{}",
62
                                                                changeFrom.getLines().size(),
×
63
                                                                changeTo.getLines().size(),
×
64
                                                                changeFrom.getPosition(),
×
65
                                                                changeTo.getPosition());
×
66
                                                log.info("change {} -> {}", describeChunk(changeFrom),
×
67
                                                                describeChunk(changeTo));
×
68
                                        }
×
69
                                        case DELETE -> {
70
                                                var delete = delta.getOriginal();
×
71
                                                log.warn("gather deleted {} bytes at {}",
×
72
                                                                delete.getLines().size(), delete.getPosition());
×
73
                                                log.info("delete {}", describeChunk(delete));
×
74
                                        }
×
75
                                        default /* INSERT */ -> {
76
                                                var insert = delta.getRevised();
×
77
                                                log.warn("gather inserted {} bytes at {}",
×
78
                                                                insert.getLines().size(), insert.getPosition());
×
79
                                                log.info("insert {}", describeChunk(insert));
×
80
                                        }
81
                                        }
82
                                }
×
83
                                break;
×
84
                        }
85
                }
86
        }
×
87

88
        private static List<Byte> list(ByteBuffer buffer) {
89
                return sliceUp(buffer, 1).map(ByteBuffer::get).toList();
×
90
        }
91

92
        private static List<String> describeChunk(Chunk<Byte> chunk) {
93
                return chunk.getLines().stream().map(MathUtils::hexbyte)
×
94
                                .collect(toList());
×
95
        }
96
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc