backplane-tracecheck 0.3.0__tar.gz → 0.4.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {backplane_tracecheck-0.3.0 → backplane_tracecheck-0.4.0}/CHANGELOG.md +35 -0
- {backplane_tracecheck-0.3.0 → backplane_tracecheck-0.4.0}/PKG-INFO +2 -2
- {backplane_tracecheck-0.3.0 → backplane_tracecheck-0.4.0}/README.md +1 -1
- {backplane_tracecheck-0.3.0 → backplane_tracecheck-0.4.0}/docs/CONTRACT_REFERENCE.md +3 -2
- backplane_tracecheck-0.4.0/examples/bad-index.mcap +0 -0
- {backplane_tracecheck-0.3.0 → backplane_tracecheck-0.4.0}/examples/expected.json +55 -0
- backplane_tracecheck-0.4.0/examples/indexless-rosbag2.mcap +0 -0
- backplane_tracecheck-0.4.0/src/tracecheck/__init__.py +1 -0
- {backplane_tracecheck-0.3.0 → backplane_tracecheck-0.4.0}/src/tracecheck/engine.py +53 -1
- {backplane_tracecheck-0.3.0 → backplane_tracecheck-0.4.0}/src/tracecheck/reader.py +136 -6
- {backplane_tracecheck-0.3.0 → backplane_tracecheck-0.4.0}/src/tracecheck/samples.py +66 -1
- backplane_tracecheck-0.4.0/tests/test_index.py +101 -0
- {backplane_tracecheck-0.3.0 → backplane_tracecheck-0.4.0}/web/src/app.js +2 -2
- {backplane_tracecheck-0.3.0 → backplane_tracecheck-0.4.0}/web/src/engine/engine.js +41 -3
- {backplane_tracecheck-0.3.0 → backplane_tracecheck-0.4.0}/web/src/engine/reader.js +134 -8
- backplane_tracecheck-0.3.0/src/tracecheck/__init__.py +0 -1
- {backplane_tracecheck-0.3.0 → backplane_tracecheck-0.4.0}/.gitignore +0 -0
- {backplane_tracecheck-0.3.0 → backplane_tracecheck-0.4.0}/LICENSE +0 -0
- {backplane_tracecheck-0.3.0 → backplane_tracecheck-0.4.0}/NOTICE +0 -0
- {backplane_tracecheck-0.3.0 → backplane_tracecheck-0.4.0}/docs/COVERED_LIST_TRACKER.md +0 -0
- {backplane_tracecheck-0.3.0 → backplane_tracecheck-0.4.0}/docs/FEEDBACK.md +0 -0
- {backplane_tracecheck-0.3.0 → backplane_tracecheck-0.4.0}/docs/THIRD_PARTY_NOTICES.md +0 -0
- {backplane_tracecheck-0.3.0 → backplane_tracecheck-0.4.0}/docs/licenses/lz4-LICENSE.txt +0 -0
- {backplane_tracecheck-0.3.0 → backplane_tracecheck-0.4.0}/docs/licenses/zstandard-LICENSE.txt +0 -0
- {backplane_tracecheck-0.3.0 → backplane_tracecheck-0.4.0}/examples/clean-lz4.mcap +0 -0
- {backplane_tracecheck-0.3.0 → backplane_tracecheck-0.4.0}/examples/clean-zstd.mcap +0 -0
- {backplane_tracecheck-0.3.0 → backplane_tracecheck-0.4.0}/examples/clean.mcap +0 -0
- {backplane_tracecheck-0.3.0 → backplane_tracecheck-0.4.0}/examples/demo-contract.json +0 -0
- {backplane_tracecheck-0.3.0 → backplane_tracecheck-0.4.0}/examples/faults.mcap +0 -0
- {backplane_tracecheck-0.3.0 → backplane_tracecheck-0.4.0}/examples/fleet-bag/fleet-bag_0.mcap +0 -0
- {backplane_tracecheck-0.3.0 → backplane_tracecheck-0.4.0}/examples/fleet-bag/fleet-bag_1.mcap +0 -0
- {backplane_tracecheck-0.3.0 → backplane_tracecheck-0.4.0}/examples/fleet-bag/fleet-bag_2.mcap +0 -0
- {backplane_tracecheck-0.3.0 → backplane_tracecheck-0.4.0}/examples/fleet-bag/metadata.yaml +0 -0
- {backplane_tracecheck-0.3.0 → backplane_tracecheck-0.4.0}/examples/fleet-bag-interrupted/fleet-bag-interrupted_0.mcap +0 -0
- {backplane_tracecheck-0.3.0 → backplane_tracecheck-0.4.0}/examples/fleet-bag-interrupted/fleet-bag-interrupted_1.mcap +0 -0
- {backplane_tracecheck-0.3.0 → backplane_tracecheck-0.4.0}/examples/fleet-bag-interrupted/fleet-bag-interrupted_2.mcap +0 -0
- {backplane_tracecheck-0.3.0 → backplane_tracecheck-0.4.0}/examples/fleet-contract.json +0 -0
- {backplane_tracecheck-0.3.0 → backplane_tracecheck-0.4.0}/examples/fleet-dropout-lz4.mcap +0 -0
- {backplane_tracecheck-0.3.0 → backplane_tracecheck-0.4.0}/examples/fleet-paused-zstd.mcap +0 -0
- {backplane_tracecheck-0.3.0 → backplane_tracecheck-0.4.0}/examples/fleet-zstd.mcap +0 -0
- {backplane_tracecheck-0.3.0 → backplane_tracecheck-0.4.0}/examples/interrupted-zstd.mcap +0 -0
- {backplane_tracecheck-0.3.0 → backplane_tracecheck-0.4.0}/examples/malformed.mcap +0 -0
- {backplane_tracecheck-0.3.0 → backplane_tracecheck-0.4.0}/examples/no-crc.mcap +0 -0
- {backplane_tracecheck-0.3.0 → backplane_tracecheck-0.4.0}/examples/truncated.mcap +0 -0
- {backplane_tracecheck-0.3.0 → backplane_tracecheck-0.4.0}/examples/unchunked.mcap +0 -0
- {backplane_tracecheck-0.3.0 → backplane_tracecheck-0.4.0}/examples/unsupported-codec.mcap +0 -0
- {backplane_tracecheck-0.3.0 → backplane_tracecheck-0.4.0}/pyproject.toml +0 -0
- {backplane_tracecheck-0.3.0 → backplane_tracecheck-0.4.0}/src/tracecheck/__main__.py +0 -0
- {backplane_tracecheck-0.3.0 → backplane_tracecheck-0.4.0}/src/tracecheck/bag.py +0 -0
- {backplane_tracecheck-0.3.0 → backplane_tracecheck-0.4.0}/src/tracecheck/contract.py +0 -0
- {backplane_tracecheck-0.3.0 → backplane_tracecheck-0.4.0}/src/tracecheck/events.py +0 -0
- {backplane_tracecheck-0.3.0 → backplane_tracecheck-0.4.0}/src/tracecheck/manifest.py +0 -0
- {backplane_tracecheck-0.3.0 → backplane_tracecheck-0.4.0}/src/tracecheck/report.py +0 -0
- {backplane_tracecheck-0.3.0 → backplane_tracecheck-0.4.0}/src/tracecheck/server.py +0 -0
- {backplane_tracecheck-0.3.0 → backplane_tracecheck-0.4.0}/src/tracecheck/ui.html +0 -0
- {backplane_tracecheck-0.3.0 → backplane_tracecheck-0.4.0}/tests/test_bag.py +0 -0
- {backplane_tracecheck-0.3.0 → backplane_tracecheck-0.4.0}/tests/test_checker.py +0 -0
- {backplane_tracecheck-0.3.0 → backplane_tracecheck-0.4.0}/tests/test_events.py +0 -0
- {backplane_tracecheck-0.3.0 → backplane_tracecheck-0.4.0}/tests/test_manifest.py +0 -0
- {backplane_tracecheck-0.3.0 → backplane_tracecheck-0.4.0}/tests/test_streaming.py +0 -0
- {backplane_tracecheck-0.3.0 → backplane_tracecheck-0.4.0}/tests/test_truncated.py +0 -0
- {backplane_tracecheck-0.3.0 → backplane_tracecheck-0.4.0}/web/src/app.css +0 -0
- {backplane_tracecheck-0.3.0 → backplane_tracecheck-0.4.0}/web/src/chrome.js +0 -0
- {backplane_tracecheck-0.3.0 → backplane_tracecheck-0.4.0}/web/src/engine/bag.js +0 -0
- {backplane_tracecheck-0.3.0 → backplane_tracecheck-0.4.0}/web/src/engine/contract.js +0 -0
- {backplane_tracecheck-0.3.0 → backplane_tracecheck-0.4.0}/web/src/engine/crc32.js +0 -0
- {backplane_tracecheck-0.3.0 → backplane_tracecheck-0.4.0}/web/src/engine/events.js +0 -0
- {backplane_tracecheck-0.3.0 → backplane_tracecheck-0.4.0}/web/src/engine/json.js +0 -0
- {backplane_tracecheck-0.3.0 → backplane_tracecheck-0.4.0}/web/src/engine/lz4.js +0 -0
- {backplane_tracecheck-0.3.0 → backplane_tracecheck-0.4.0}/web/src/engine/report.js +0 -0
- {backplane_tracecheck-0.3.0 → backplane_tracecheck-0.4.0}/web/src/engine/vendor/fzstd.js +0 -0
- {backplane_tracecheck-0.3.0 → backplane_tracecheck-0.4.0}/web/src/engine/worker.js +0 -0
- {backplane_tracecheck-0.3.0 → backplane_tracecheck-0.4.0}/web/src/feedback-schema.js +0 -0
- {backplane_tracecheck-0.3.0 → backplane_tracecheck-0.4.0}/web/src/feedback.js +0 -0
- {backplane_tracecheck-0.3.0 → backplane_tracecheck-0.4.0}/web/src/landing.css +0 -0
- {backplane_tracecheck-0.3.0 → backplane_tracecheck-0.4.0}/web/src/main.js +0 -0
- {backplane_tracecheck-0.3.0 → backplane_tracecheck-0.4.0}/web/src/style.css +0 -0
- {backplane_tracecheck-0.3.0 → backplane_tracecheck-0.4.0}/web/src/tracker-data.js +0 -0
- {backplane_tracecheck-0.3.0 → backplane_tracecheck-0.4.0}/web/src/tracker.css +0 -0
- {backplane_tracecheck-0.3.0 → backplane_tracecheck-0.4.0}/web/src/tracker.js +0 -0
|
@@ -6,6 +6,41 @@ All notable changes to this project are documented here. The format follows
|
|
|
6
6
|
|
|
7
7
|
## [Unreleased]
|
|
8
8
|
|
|
9
|
+
## [0.4.0] - 2026-11-03
|
|
10
|
+
|
|
11
|
+
### Added
|
|
12
|
+
- **Summary index agreement (C01, full scan).** Many tools jump through an MCAP file's summary indexes instead of
|
|
13
|
+
reading every record. C01 now checks that each Chunk, Attachment and Metadata index entry points to a record of that
|
|
14
|
+
type and length (for chunks, also compression, sizes and time range), that an index covers every record of its type,
|
|
15
|
+
and that the Statistics record matches the counts and times actually read. A disagreement **warns** and lists each
|
|
16
|
+
wrong entry or statistic; the records themselves are read directly, so the other checks are unaffected. Prompted by
|
|
17
|
+
MCAP TypeScript 2.4.0, which fixed attachment and metadata index offsets that could be wrong while messages were
|
|
18
|
+
buffered. Files with no indexes and no Statistics get a *skipped* (no conclusion) finding.
|
|
19
|
+
- `bad-index.mcap` synthetic example (intact records, wrong attachment and metadata index entries) and
|
|
20
|
+
`indexless-rosbag2.mcap` (no indexes, embedded `rosbag2` metadata; ROS 2's own reader has been reported to mis-read
|
|
21
|
+
such files, rosbag2 issue #2530).
|
|
22
|
+
- CI also runs the Python tests with `mcap` 1.6.
|
|
23
|
+
- **C08 largest backwards jump.** When record-order timestamps go backwards, the finding also reports
|
|
24
|
+
`largest_regression_ns` and the message pair where the largest jump happened, so small reordering jitter can be told
|
|
25
|
+
apart from a likely clock reset. Pass/fail is unchanged.
|
|
26
|
+
- Web app: "Wrong summary index" demo recording.
|
|
27
|
+
|
|
28
|
+
### Changed
|
|
29
|
+
- **Fast mode** falls back to a full scan, with a `fast_mode_fallback` reason, when the summary's metadata index does
|
|
30
|
+
not point to a Metadata record. Previously the scan stopped and the file was reported as unreadable.
|
|
31
|
+
- Web app: the result view shows the new C01 index facts and C08's largest backwards jump.
|
|
32
|
+
|
|
33
|
+
### Fixed
|
|
34
|
+
- Website: one small web font was embedded in the build as a `data:` URL, which the site's own security policy
|
|
35
|
+
(`font-src 'self'`) blocked. Fonts are now always served as files.
|
|
36
|
+
|
|
37
|
+
### Website
|
|
38
|
+
- FCC Covered List robot tracker: added Vulcan (DA 26-1130), Haystack and T-Robotics (DA 26-1154) on 2026-10-28, and
|
|
39
|
+
ARAPL, ATI Motors, Lightberry, SunScout, Swap Robotics and OMRON (DA 26-1181) on 2026-11-03. All 13 entries are checked
|
|
40
|
+
against Appendix B of DA 26-1181, the FCC's full list of robotic-device conditional approvals.
|
|
41
|
+
- Tracker page: a note explaining that waivers (for example DA 26-1146 for Intel) are not Covered List exemptions and are
|
|
42
|
+
not listed.
|
|
43
|
+
|
|
9
44
|
## [0.3.0] - 2026-10-20
|
|
10
45
|
|
|
11
46
|
### Added
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: backplane-tracecheck
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.4.0
|
|
4
4
|
Summary: Check robot recordings (MCAP) against an explicit, versioned recording contract.
|
|
5
5
|
Project-URL: Homepage, https://backplanerobotics.com
|
|
6
6
|
Project-URL: Source, https://github.com/backplane-robotics/backplane-tracecheck
|
|
@@ -127,7 +127,7 @@ Start minimal, then read the report's channel inventory to see the actual schema
|
|
|
127
127
|
|
|
128
128
|
| ID | Check |
|
|
129
129
|
|---|---|
|
|
130
|
-
| C01 | Readable bounded MCAP scan (with CRC verification where present) |
|
|
130
|
+
| C01 | Readable bounded MCAP scan (with CRC verification where present, and summary index agreement) |
|
|
131
131
|
| C02 | Required topics contain messages |
|
|
132
132
|
| C03 | Profile, schema and encoding |
|
|
133
133
|
| C04 | Required file metadata |
|
|
@@ -96,7 +96,7 @@ Start minimal, then read the report's channel inventory to see the actual schema
|
|
|
96
96
|
|
|
97
97
|
| ID | Check |
|
|
98
98
|
|---|---|
|
|
99
|
-
| C01 | Readable bounded MCAP scan (with CRC verification where present) |
|
|
99
|
+
| C01 | Readable bounded MCAP scan (with CRC verification where present, and summary index agreement) |
|
|
100
100
|
| C02 | Required topics contain messages |
|
|
101
101
|
| C03 | Profile, schema and encoding |
|
|
102
102
|
| C04 | Required file metadata |
|
|
@@ -26,7 +26,7 @@ Contracts are UTF-8 JSON objects up to 64 KiB. Keys are case-sensitive; duplicat
|
|
|
26
26
|
| `clock_confirmed` | Boolean, default false. All four timing checks skip unless true. User asserts the clock is interpretable for this requirement. |
|
|
27
27
|
| `min_rate_hz`, `max_rate_hz` | Optional inclusive bounds for observed average `(N−1)/(last−first)` after sorting. Not windowed rate or proof of session completeness. Use interval/gap checks too. On the `log_time` basis, if the recording contains rosbag2_dynamic_recorder pause or unsubscribe events, time covered by them is left out: the bounds are applied to `active_hz`, and the finding also reports `observed_hz` (whole span), `excluded_ns` and `excluded_by`. The events are the recorder's own account and are not verified. |
|
|
28
28
|
| `max_gap_ns` | Optional inclusive upper limit between adjacent **sorted** timestamps. Does not include leading/trailing gaps. On the `log_time` basis, a gap covered by a rosbag2_dynamic_recorder pause or unsubscribe event in the recording is listed under `explained_gaps` and does not fail, provided no uncovered part of the gap exceeds the limit. |
|
|
29
|
-
| `check_regression` | Boolean, default false. Strict decreases in **physical record order** fail; equal timestamps pass. |
|
|
29
|
+
| `check_regression` | Boolean, default false. Strict decreases in **physical record order** fail; equal timestamps pass. When there are regressions, the C08 finding also reports `largest_regression_ns` and the message pair where the largest backwards jump happened (`largest_regression`), to help tell small reordering jitter from a clock reset. |
|
|
30
30
|
| `sequence` | `disabled` (default) or `increment_mod32`. The latter asserts one unit-incrementing sequence source per channel, allowing wrap from 2^32−1 to 0; resets, duplicates and jumps fail. |
|
|
31
31
|
| `interval_ns` | Optional inclusive `[start,end]`, with start < end, on the selected clock. All recorded timestamps must be inside; first and last must reach the respective boundaries within tolerance. |
|
|
32
32
|
| `boundary_tolerance_ns` | Nonnegative integer, default 0; at most half the interval length. |
|
|
@@ -44,7 +44,8 @@ The JSON report embeds the complete contract and hashes its normalized UTF-8 JSO
|
|
|
44
44
|
- **Full scan** (default) streams the whole file. It computes the file SHA-256 and verifies every CRC that is present: the data-section CRC in the Data End record, each chunk's CRC of its uncompressed records, and the summary CRC in the footer. Attachment CRCs are not checked. Attachments and unknown record types are hashed but skipped.
|
|
45
45
|
- **CRC coverage rule.** C01 warns about missing CRCs only when the data-section CRC is absent **and** some message data is not covered by another CRC: a chunk without a CRC, or a message outside any chunk. Default ROS 2 recordings, with chunk CRCs but no data-section CRC, therefore pass. Set `missing_crc` to `"ignore"` to suppress the warning entirely.
|
|
46
46
|
- **Compression.** Chunks may be uncompressed, `zstd` or `lz4`. Decompressed output is capped at the chunk's declared uncompressed size. A mismatch, any other codec, or a chunk above the size limit fails C01.
|
|
47
|
-
- **
|
|
47
|
+
- **Summary index agreement** (full scan). Other tools often jump through the summary section's indexes instead of reading the whole file. C01 therefore checks that every Chunk, Attachment and Metadata index entry points to a record of that type and length (for chunks, also the compression, sizes and time range), that an index covers every record of its type, and that the Statistics record agrees with the counts and times actually read. A disagreement **warns**, listing each entry (`index`, `entry`, `offset`, `length`, `problem`) or statistic (`field`, `claimed`, `observed`); the records themselves were read directly, so the other checks are unaffected. A writer bug of this kind was fixed in MCAP TypeScript 2.4.0. A file with no indexes and no Statistics gets a *skipped* finding (no conclusion), not a failure. The finding reports `summary_index`, `index_entries_checked` and `summary_statistics`.
|
|
48
|
+
- **Fast mode** (`--fast` in the CLI, the toggle in the web app) reads only the header, footer and summary section (Statistics, Channel, Schema and indexed Metadata records) and checks the summary CRC. C01–C05 run on that information; C06–C10 skip because they need every timestamp. If the summary is missing or lacks Statistics, or its metadata index does not point to a Metadata record, the scan falls back to a full scan and records `fast_mode_fallback` in the report. In fast mode `source.sha256` is `null`.
|
|
48
49
|
- **Limits.** Defaults: 256 MiB per record, uncompressed chunk and summary section; 20 million tracked timestamps for sorted-gap checks; 10,000 schemas/channels/metadata records. Exceeding a limit fails C01 with an explanation, rather than exhausting memory. The CLI exposes `--max-chunk-mib`, `--max-record-mib`, `--max-tracked-messages` and `--timeout`. There is no overall file-size cap.
|
|
49
50
|
|
|
50
51
|
## ROS 2 bag folders (C11)
|
|
Binary file
|
|
@@ -163,6 +163,42 @@
|
|
|
163
163
|
"C10": "skipped"
|
|
164
164
|
}
|
|
165
165
|
},
|
|
166
|
+
{
|
|
167
|
+
"file": "bad-index.mcap",
|
|
168
|
+
"contract": "demo-contract.json",
|
|
169
|
+
"overall": "warn",
|
|
170
|
+
"scan_complete": true,
|
|
171
|
+
"checks": {
|
|
172
|
+
"C01": "warn",
|
|
173
|
+
"C02": "pass",
|
|
174
|
+
"C03": "pass",
|
|
175
|
+
"C04": "pass",
|
|
176
|
+
"C05": "pass",
|
|
177
|
+
"C06": "pass",
|
|
178
|
+
"C07": "pass",
|
|
179
|
+
"C08": "pass",
|
|
180
|
+
"C09": "pass",
|
|
181
|
+
"C10": "pass"
|
|
182
|
+
}
|
|
183
|
+
},
|
|
184
|
+
{
|
|
185
|
+
"file": "indexless-rosbag2.mcap",
|
|
186
|
+
"contract": "demo-contract.json",
|
|
187
|
+
"overall": "pass",
|
|
188
|
+
"scan_complete": true,
|
|
189
|
+
"checks": {
|
|
190
|
+
"C01": "pass",
|
|
191
|
+
"C02": "pass",
|
|
192
|
+
"C03": "pass",
|
|
193
|
+
"C04": "pass",
|
|
194
|
+
"C05": "pass",
|
|
195
|
+
"C06": "pass",
|
|
196
|
+
"C07": "pass",
|
|
197
|
+
"C08": "pass",
|
|
198
|
+
"C09": "pass",
|
|
199
|
+
"C10": "pass"
|
|
200
|
+
}
|
|
201
|
+
},
|
|
166
202
|
{
|
|
167
203
|
"file": "clean-zstd.mcap",
|
|
168
204
|
"contract": "demo-contract.json",
|
|
@@ -201,6 +237,25 @@
|
|
|
201
237
|
"C10": "skipped"
|
|
202
238
|
}
|
|
203
239
|
},
|
|
240
|
+
{
|
|
241
|
+
"file": "bad-index.mcap",
|
|
242
|
+
"contract": "demo-contract.json",
|
|
243
|
+
"fast": true,
|
|
244
|
+
"overall": "warn",
|
|
245
|
+
"scan_complete": true,
|
|
246
|
+
"checks": {
|
|
247
|
+
"C01": "warn",
|
|
248
|
+
"C02": "pass",
|
|
249
|
+
"C03": "pass",
|
|
250
|
+
"C04": "pass",
|
|
251
|
+
"C05": "pass",
|
|
252
|
+
"C06": "pass",
|
|
253
|
+
"C07": "pass",
|
|
254
|
+
"C08": "pass",
|
|
255
|
+
"C09": "pass",
|
|
256
|
+
"C10": "pass"
|
|
257
|
+
}
|
|
258
|
+
},
|
|
204
259
|
{
|
|
205
260
|
"file": "fleet-zstd.mcap",
|
|
206
261
|
"contract": "fleet-contract.json",
|
|
Binary file
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.4.0"
|
|
@@ -17,6 +17,7 @@ from . import events as rec_events
|
|
|
17
17
|
from .bag import META_LIMIT, META_NAME, plan as bag_plan
|
|
18
18
|
from .contract import validate
|
|
19
19
|
from .reader import (
|
|
20
|
+
INDEX_TARGET_LIMIT,
|
|
20
21
|
META_PAIRS_LIMIT,
|
|
21
22
|
META_VALUE_LIMIT,
|
|
22
23
|
TEXT_LIMIT,
|
|
@@ -68,6 +69,16 @@ FULL_DETAIL = ("Bounded scan completed. Data-section, chunk and summary CRCs che
|
|
|
68
69
|
"conformance validation.") # fmt: skip
|
|
69
70
|
FAST_DETAIL = ("Fast mode: header, footer and summary section read and summary CRC checked when present. The data "
|
|
70
71
|
"section was not scanned, so message-level corruption is not detected.") # fmt: skip
|
|
72
|
+
INDEX_OK = ("Summary index entries point to matching records, and the summary statistics agree with the records "
|
|
73
|
+
"read.") # fmt: skip
|
|
74
|
+
INDEX_STATS_ONLY = "The summary has no index entries; its statistics agree with the records read."
|
|
75
|
+
INDEX_INDEX_ONLY = "Summary index entries point to matching records. The summary has no statistics record."
|
|
76
|
+
INDEX_BAD = ("The summary index or statistics disagree with the records read. Every record was read directly, so "
|
|
77
|
+
"the other checks are not affected, but tools that rely on the index (for example to list metadata or "
|
|
78
|
+
"attachments, or to jump to a time) may show wrong or missing data. A writer bug of this kind was fixed "
|
|
79
|
+
"in MCAP TypeScript 2.4.0.") # fmt: skip
|
|
80
|
+
INDEX_NONE = "The file has no summary index or statistics to compare with the records."
|
|
81
|
+
INDEX_LIMIT = f"More than {INDEX_TARGET_LIMIT:,} indexed records; the summary index was not checked."
|
|
71
82
|
BAG_BY_NAME = "The .mcap files in the folder were checked in name order; message counts could not be compared."
|
|
72
83
|
BAG_NO_META = ("No metadata.yaml in the folder. rosbag2 writes it when a recording is closed, so a recorder that "
|
|
73
84
|
"stopped unexpectedly may leave none; it can also be left out when copying. " + BAG_BY_NAME) # fmt: skip
|
|
@@ -173,10 +184,31 @@ def _scanned(result: dict, r: ScanResult, missing: bool, ignore_crc: bool, findi
|
|
|
173
184
|
if r.mode == "full":
|
|
174
185
|
finding(1, status, FULL_DETAIL, unknown_records_skipped=r.unknown, missing_crc_policy=policy,
|
|
175
186
|
crc_coverage_complete=not missing, **extra) # fmt: skip
|
|
187
|
+
_index_finding(r.index, finding)
|
|
176
188
|
else:
|
|
177
189
|
finding(1, status, FAST_DETAIL, unknown_records_skipped=r.unknown, missing_crc_policy=policy, **extra)
|
|
178
190
|
|
|
179
191
|
|
|
192
|
+
def _index_finding(ix: dict | None, finding: Callable) -> None:
|
|
193
|
+
"""C01: do the summary indexes and statistics agree with the records a full scan read?"""
|
|
194
|
+
if ix is None:
|
|
195
|
+
return
|
|
196
|
+
facts = {"summary_index": ix["summary_index"], "index_entries_checked": ix["entries_checked"],
|
|
197
|
+
"summary_statistics": ix["statistics"]} # fmt: skip
|
|
198
|
+
if ix["limit_reached"]:
|
|
199
|
+
finding(1, "skipped", INDEX_LIMIT, **facts)
|
|
200
|
+
elif ix["issues"]:
|
|
201
|
+
finding(1, "warn", INDEX_BAD, evidence=ix["issues"], **facts)
|
|
202
|
+
elif ix["summary_index"] == "absent" and ix["statistics"] == "absent":
|
|
203
|
+
finding(1, "skipped", INDEX_NONE, **facts)
|
|
204
|
+
elif ix["summary_index"] == "absent":
|
|
205
|
+
finding(1, "pass", INDEX_STATS_ONLY, **facts)
|
|
206
|
+
elif ix["statistics"] == "absent":
|
|
207
|
+
finding(1, "pass", INDEX_INDEX_ONLY, **facts)
|
|
208
|
+
else:
|
|
209
|
+
finding(1, "pass", INDEX_OK, **facts)
|
|
210
|
+
|
|
211
|
+
|
|
180
212
|
def analyze_stream(
|
|
181
213
|
f: BinaryIO,
|
|
182
214
|
size: int,
|
|
@@ -357,9 +389,15 @@ def _evaluate(result: dict, c: dict, r: ScanResult, finding: Callable, first_fil
|
|
|
357
389
|
finding(7, "skipped", "Gap threshold absent or fewer than two messages.", **ctx)
|
|
358
390
|
if t.get("check_regression") and n >= 2:
|
|
359
391
|
bad = [{"previous": _msg(cid, a), "current": _msg(cid, b)} for a, b in tr.reg_bad]
|
|
392
|
+
# The largest backwards jump helps tell small reordering jitter from a clock reset.
|
|
393
|
+
worst = {}
|
|
394
|
+
if tr.reg_bad_n:
|
|
395
|
+
a, b = tr.reg_max_pair
|
|
396
|
+
worst = {"largest_regression_ns": tr.reg_max,
|
|
397
|
+
"largest_regression": {"previous": _msg(cid, a), "current": _msg(cid, b)}} # fmt: skip
|
|
360
398
|
finding(8, "fail" if tr.reg_bad_n else "pass",
|
|
361
399
|
"Strictly decreasing timestamps in physical record order; equal values allowed.",
|
|
362
|
-
bad, total=tr.reg_bad_n, time_basis=basis, **ctx) # fmt: skip
|
|
400
|
+
bad, total=tr.reg_bad_n, time_basis=basis, **ctx, **worst) # fmt: skip
|
|
363
401
|
else:
|
|
364
402
|
finding(8, "skipped", "Regression check disabled or fewer than two messages.", **ctx)
|
|
365
403
|
if "interval_ns" in t:
|
|
@@ -567,6 +605,8 @@ def _merge(results: list[ScanResult], ctx: BagContext) -> ScanResult:
|
|
|
567
605
|
counts[lid] = counts.get(lid, 0) + x.counts.get(cid, 0)
|
|
568
606
|
m.counts = counts
|
|
569
607
|
m.schemas, m.channels, m.tracks = ctx.schemas, ctx.channels, ctx.tracks
|
|
608
|
+
if first.mode == "full":
|
|
609
|
+
m.index = _merge_index([x.index for x in results], ctx.names)
|
|
570
610
|
infos = [x.recorder_events for x in results if x.recorder_events is not None]
|
|
571
611
|
if infos:
|
|
572
612
|
events = [e for x in results for e in x.events]
|
|
@@ -582,6 +622,18 @@ def _merge(results: list[ScanResult], ctx: BagContext) -> ScanResult:
|
|
|
582
622
|
return m
|
|
583
623
|
|
|
584
624
|
|
|
625
|
+
def _merge_index(parts: list[dict], names: list[str]) -> dict:
|
|
626
|
+
"""Combine the per-file summary index checks of a bag; each issue names its file."""
|
|
627
|
+
stats = [p["statistics"] for p in parts]
|
|
628
|
+
return {
|
|
629
|
+
"summary_index": "present" if any(p["summary_index"] == "present" for p in parts) else "absent",
|
|
630
|
+
"entries_checked": sum(p["entries_checked"] for p in parts),
|
|
631
|
+
"statistics": "differs" if "differs" in stats else stats[0] if len(set(stats)) == 1 else "mixed",
|
|
632
|
+
"issues": [{"file": name, **i} for name, p in zip(names, parts, strict=True) for i in p["issues"]],
|
|
633
|
+
"limit_reached": any(p["limit_reached"] for p in parts),
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
|
|
585
637
|
def _report_truncated_bag(result: dict, ctx: BagContext, results: list, r, f: dict, n_files: int, reason: str,
|
|
586
638
|
finding: Callable) -> None: # fmt: skip
|
|
587
639
|
"""Like _report_truncated, for a bag whose file ``f`` is cut off. Later files are not scanned."""
|
|
@@ -55,6 +55,12 @@ META_VALUE_LIMIT = 65536 # ROS 2 stores QoS YAML in channel metadata values
|
|
|
55
55
|
META_PAIRS_LIMIT = 100
|
|
56
56
|
FOOTER_RECORD_SIZE = 1 + 8 + 20
|
|
57
57
|
SUPPORTED_COMPRESSION = ("", "zstd", "lz4")
|
|
58
|
+
# Full scan: data-section Chunk/Attachment/Metadata records remembered for the summary index check.
|
|
59
|
+
INDEX_TARGET_LIMIT = 1_000_000
|
|
60
|
+
BAD_METADATA_INDEX = "summary metadata index does not point to a Metadata record (checked with a full scan instead)"
|
|
61
|
+
INDEX_KINDS = (("chunk", "Chunk"), ("attachment", "Attachment"), ("metadata", "Metadata"))
|
|
62
|
+
STAT_FIELDS = ("message_count", "schema_count", "channel_count", "attachment_count", "metadata_count", "chunk_count",
|
|
63
|
+
"message_start_time", "message_end_time") # fmt: skip
|
|
58
64
|
|
|
59
65
|
_U16 = struct.Struct("<H")
|
|
60
66
|
_U32 = struct.Struct("<I")
|
|
@@ -253,7 +259,7 @@ class Track:
|
|
|
253
259
|
|
|
254
260
|
__slots__ = (
|
|
255
261
|
"cid", "cfg", "ev", "count", "first", "last", "lo", "hi", "monotonic",
|
|
256
|
-
"seq_bad", "seq_bad_n", "reg_bad", "reg_bad_n", "gap_bad", "gap_bad_n",
|
|
262
|
+
"seq_bad", "seq_bad_n", "reg_bad", "reg_bad_n", "gap_bad", "gap_bad_n", "reg_max", "reg_max_pair",
|
|
257
263
|
"times", "ords", "loc_a", "loc_b", "files",
|
|
258
264
|
) # fmt: skip
|
|
259
265
|
|
|
@@ -268,6 +274,8 @@ class Track:
|
|
|
268
274
|
self.reg_bad: list = []
|
|
269
275
|
self.gap_bad: list = []
|
|
270
276
|
self.seq_bad_n = self.reg_bad_n = self.gap_bad_n = 0
|
|
277
|
+
self.reg_max = 0 # largest backwards jump, in ns, and the first message pair where it occurred
|
|
278
|
+
self.reg_max_pair: tuple | None = None
|
|
271
279
|
gap = cfg is not None and cfg.max_gap is not None
|
|
272
280
|
self.times = array("Q") if gap else None
|
|
273
281
|
self.ords = array("Q") if gap else None
|
|
@@ -295,6 +303,9 @@ class Track:
|
|
|
295
303
|
self.reg_bad_n += 1
|
|
296
304
|
if len(self.reg_bad) < self.ev:
|
|
297
305
|
self.reg_bad.append((prev, m))
|
|
306
|
+
if pt - t > self.reg_max:
|
|
307
|
+
self.reg_max = pt - t
|
|
308
|
+
self.reg_max_pair = (prev, m)
|
|
298
309
|
elif self.monotonic and cfg.max_gap is not None and t - pt > cfg.max_gap:
|
|
299
310
|
self.gap_bad_n += 1
|
|
300
311
|
if len(self.gap_bad) < self.ev:
|
|
@@ -371,6 +382,62 @@ class ScanResult:
|
|
|
371
382
|
# Full scan only. Recognised recorder event messages; None when the recording has none.
|
|
372
383
|
recorder_events: dict | None = None
|
|
373
384
|
events: list = field(default_factory=list) # (log_time, ordinal, kind, action, topic)
|
|
385
|
+
# Full scan only. Agreement of the summary indexes and statistics with the records read (see check_index).
|
|
386
|
+
index: dict | None = None
|
|
387
|
+
|
|
388
|
+
|
|
389
|
+
def check_index(targets: dict | None, entries: dict, statistics: dict | None, observed: dict) -> dict:
|
|
390
|
+
"""Compare the summary section's indexes and Statistics with what a full scan read.
|
|
391
|
+
|
|
392
|
+
``targets`` maps the file offset of each data-section Chunk, Attachment and Metadata record to
|
|
393
|
+
``(kind, record_length, details)``, or is None when there were too many to remember. ``entries`` maps
|
|
394
|
+
each kind to its index entries ``(offset, length, details)`` in summary order. ``observed`` holds the
|
|
395
|
+
counts and times the scan saw. Issues are listed in a fixed order so both implementations agree.
|
|
396
|
+
"""
|
|
397
|
+
issues: list[dict] = []
|
|
398
|
+
present = any(entries[k] for k, _ in INDEX_KINDS)
|
|
399
|
+
if targets is None:
|
|
400
|
+
return {"summary_index": "present" if present else "absent", "entries_checked": 0,
|
|
401
|
+
"statistics": "not checked", "issues": [], "limit_reached": True} # fmt: skip
|
|
402
|
+
checked = 0
|
|
403
|
+
an = lambda w: f"an {w}" if w[0] in "AEIOU" else f"a {w}" # noqa: E731
|
|
404
|
+
for kind, label in INDEX_KINDS:
|
|
405
|
+
actual = sum(1 for t in targets.values() if t[0] == kind)
|
|
406
|
+
for i, (offset, length, details) in enumerate(entries[kind]):
|
|
407
|
+
checked += 1
|
|
408
|
+
t = targets.get(offset)
|
|
409
|
+
row = {"index": kind, "entry": i, "offset": offset, "length": length}
|
|
410
|
+
if t is None:
|
|
411
|
+
problem = f"does not point to the start of {an(label)} record"
|
|
412
|
+
elif t[0] != kind:
|
|
413
|
+
problem = f"points to {an(dict(INDEX_KINDS)[t[0]])} record, not {an(label)} record"
|
|
414
|
+
elif t[1] != length:
|
|
415
|
+
problem = f"gives a length of {length} bytes; the {label} record there is {t[1]} bytes"
|
|
416
|
+
elif t[2] != details:
|
|
417
|
+
problem = f"describes the {label} record differently from the record itself"
|
|
418
|
+
else:
|
|
419
|
+
continue
|
|
420
|
+
issues.append(dict(row, problem=problem))
|
|
421
|
+
if entries[kind] and len(entries[kind]) != actual:
|
|
422
|
+
issues.append({"index": kind, "problem": f"indexes {len(entries[kind])} of the {actual} {label} records"})
|
|
423
|
+
stats_state = "absent"
|
|
424
|
+
if statistics is not None:
|
|
425
|
+
stats_state = "agrees"
|
|
426
|
+
has_messages = observed["message_count"] > 0
|
|
427
|
+
for k in STAT_FIELDS:
|
|
428
|
+
if k in ("message_start_time", "message_end_time") and not has_messages:
|
|
429
|
+
continue
|
|
430
|
+
if statistics[k] != observed[k]:
|
|
431
|
+
stats_state = "differs"
|
|
432
|
+
issues.append({"index": "statistics", "field": k, "claimed": statistics[k], "observed": observed[k]})
|
|
433
|
+
claimed, seen = statistics["channel_message_counts"], observed["channel_message_counts"]
|
|
434
|
+
for cid in sorted(set(claimed) | set(seen)):
|
|
435
|
+
if claimed.get(cid, 0) != seen.get(cid, 0):
|
|
436
|
+
stats_state = "differs"
|
|
437
|
+
issues.append({"index": "statistics", "field": "channel_message_counts", "channel_id": cid,
|
|
438
|
+
"claimed": claimed.get(cid, 0), "observed": seen.get(cid, 0)}) # fmt: skip
|
|
439
|
+
return {"summary_index": "present" if present else "absent", "entries_checked": checked,
|
|
440
|
+
"statistics": stats_state, "issues": issues, "limit_reached": False} # fmt: skip
|
|
374
441
|
|
|
375
442
|
|
|
376
443
|
class _Registry:
|
|
@@ -556,6 +623,29 @@ def scan_full(
|
|
|
556
623
|
summary_crc_start = None
|
|
557
624
|
t_lo = t_hi = None
|
|
558
625
|
event_kind: dict[int, str] = {} # channel id -> recognised recorder event type
|
|
626
|
+
# Summary index check (check_index): where the data records are, and what the summary says about them.
|
|
627
|
+
targets: dict[int, tuple] = {}
|
|
628
|
+
entries: dict[str, list] = {"chunk": [], "attachment": [], "metadata": []}
|
|
629
|
+
n_entries = 0
|
|
630
|
+
overflow = False
|
|
631
|
+
statistics: dict | None = None
|
|
632
|
+
cid_counts: dict[int, int] = {}
|
|
633
|
+
metadata_records = 0
|
|
634
|
+
|
|
635
|
+
def remember(offset: int, kind: str, length: int, details: str) -> None:
|
|
636
|
+
nonlocal overflow
|
|
637
|
+
if len(targets) >= INDEX_TARGET_LIMIT:
|
|
638
|
+
overflow = True
|
|
639
|
+
elif not overflow:
|
|
640
|
+
targets[offset] = (kind, length, details)
|
|
641
|
+
|
|
642
|
+
def add_entry(kind: str, offset: int, length: int, details: str) -> None:
|
|
643
|
+
nonlocal overflow, n_entries
|
|
644
|
+
n_entries += 1
|
|
645
|
+
if n_entries > INDEX_TARGET_LIMIT:
|
|
646
|
+
overflow = True
|
|
647
|
+
elif not overflow:
|
|
648
|
+
entries[kind].append((offset, length, details))
|
|
559
649
|
|
|
560
650
|
def on_event(kind: str, buf, body: int, end: int, log_t: int) -> None:
|
|
561
651
|
info = r.recorder_events
|
|
@@ -587,6 +677,7 @@ def scan_full(
|
|
|
587
677
|
stats["messages"] += 1
|
|
588
678
|
if stats["messages"] > limits.max_messages:
|
|
589
679
|
raise ScanError(f"message count exceeds {limits.max_messages}")
|
|
680
|
+
cid_counts[cid] = cid_counts.get(cid, 0) + 1
|
|
590
681
|
if t_lo is None or log_t < t_lo:
|
|
591
682
|
t_lo = log_t
|
|
592
683
|
if t_hi is None or log_t > t_hi:
|
|
@@ -666,10 +757,35 @@ def scan_full(
|
|
|
666
757
|
if src.pos != size:
|
|
667
758
|
raise ScanError("trailing bytes after footer magic")
|
|
668
759
|
break
|
|
760
|
+
if ended and op in (OP_CHUNK_INDEX, OP_ATTACHMENT_INDEX, OP_METADATA_INDEX, OP_STATISTICS):
|
|
761
|
+
if length > limits.max_record_bytes:
|
|
762
|
+
raise ScanError(f"record length exceeds {limits.max_record_bytes} byte limit")
|
|
763
|
+
c = _Cursor(src.read(length))
|
|
764
|
+
if op == OP_CHUNK_INDEX:
|
|
765
|
+
t0, t1, at, ln = c.u64(), c.u64(), c.u64(), c.u64()
|
|
766
|
+
c.take(c.u32()) # message index offsets
|
|
767
|
+
c.u64() # message index length
|
|
768
|
+
comp = c.string()
|
|
769
|
+
add_entry("chunk", at, ln, f"{comp}|{c.u64()}|{c.u64()}|{t0}|{t1}")
|
|
770
|
+
elif op == OP_ATTACHMENT_INDEX:
|
|
771
|
+
add_entry("attachment", c.u64(), c.u64(), "")
|
|
772
|
+
elif op == OP_METADATA_INDEX:
|
|
773
|
+
at, ln = c.u64(), c.u64()
|
|
774
|
+
add_entry("metadata", at, ln, c.string())
|
|
775
|
+
else:
|
|
776
|
+
statistics = {
|
|
777
|
+
"message_count": c.u64(), "schema_count": c.u16(), "channel_count": c.u32(),
|
|
778
|
+
"attachment_count": c.u32(), "metadata_count": c.u32(), "chunk_count": c.u32(),
|
|
779
|
+
"message_start_time": c.u64(), "message_end_time": c.u64(),
|
|
780
|
+
"channel_message_counts": c.u16_u64_map(),
|
|
781
|
+
} # fmt: skip
|
|
782
|
+
continue
|
|
669
783
|
if op not in (OP_HEADER, OP_SCHEMA, OP_CHANNEL, OP_MESSAGE, OP_CHUNK, OP_METADATA, OP_DATA_END):
|
|
670
784
|
src.skip(length)
|
|
671
785
|
if op == OP_ATTACHMENT:
|
|
672
786
|
stats["attachments_skipped"] += 1
|
|
787
|
+
if not ended:
|
|
788
|
+
remember(offset, "attachment", 9 + length, "")
|
|
673
789
|
elif op not in KNOWN_OPCODES:
|
|
674
790
|
r.unknown += 1
|
|
675
791
|
continue
|
|
@@ -692,6 +808,8 @@ def scan_full(
|
|
|
692
808
|
elif op == OP_METADATA:
|
|
693
809
|
if not ended:
|
|
694
810
|
reg.metadata(c, loc)
|
|
811
|
+
metadata_records += 1
|
|
812
|
+
remember(offset, "metadata", 9 + length, r.metadata[-1]["name"])
|
|
695
813
|
elif op == OP_DATA_END:
|
|
696
814
|
if ended:
|
|
697
815
|
raise ScanError("repeated DataEnd")
|
|
@@ -707,13 +825,14 @@ def scan_full(
|
|
|
707
825
|
if ended:
|
|
708
826
|
raise ScanError("chunk after DataEnd")
|
|
709
827
|
stats["chunks"] += 1
|
|
710
|
-
c.u64() # message_start_time
|
|
711
|
-
c.u64() # message_end_time
|
|
828
|
+
t0 = c.u64() # message_start_time
|
|
829
|
+
t1 = c.u64() # message_end_time
|
|
712
830
|
usize = c.u64()
|
|
713
831
|
ucrc = c.u32()
|
|
714
832
|
compression = c.string()
|
|
715
833
|
n = c.u64()
|
|
716
834
|
p = c.take(n)
|
|
835
|
+
remember(offset, "chunk", 9 + length, f"{compression}|{n}|{usize}|{t0}|{t1}")
|
|
717
836
|
if compression not in SUPPORTED_COMPRESSION:
|
|
718
837
|
raise ScanError(f"unsupported compression: {compression[:40]!r}")
|
|
719
838
|
if compression == "":
|
|
@@ -749,6 +868,13 @@ def scan_full(
|
|
|
749
868
|
r.sha256 = src.sha.hexdigest()
|
|
750
869
|
r.stats["seconds"] = round(time.monotonic() - started, 3)
|
|
751
870
|
r.log_time_range = None if t_lo is None else (t_lo, t_hi)
|
|
871
|
+
observed = {
|
|
872
|
+
"message_count": stats["messages"], "schema_count": len(r.schemas), "channel_count": len(r.channels),
|
|
873
|
+
"attachment_count": stats["attachments_skipped"], "metadata_count": metadata_records,
|
|
874
|
+
"chunk_count": stats["chunks"], "message_start_time": t_lo or 0, "message_end_time": t_hi or 0,
|
|
875
|
+
"channel_message_counts": cid_counts,
|
|
876
|
+
} # fmt: skip
|
|
877
|
+
r.index = check_index(None if overflow else targets, entries, statistics, observed)
|
|
752
878
|
if ctx is not None:
|
|
753
879
|
ctx.base += stats["messages"]
|
|
754
880
|
ctx.tracked = tracked
|
|
@@ -866,11 +992,15 @@ def scan_fast(f: BinaryIO, size: int, limits: Limits | None = None) -> ScanResul
|
|
|
866
992
|
return r
|
|
867
993
|
|
|
868
994
|
for offset, length in metadata_index:
|
|
869
|
-
|
|
870
|
-
|
|
995
|
+
# A wrong index is a property of the file worth reporting, not a reason to stop: fall back to a full scan,
|
|
996
|
+
# which reads every record and reports the index disagreement in C01.
|
|
997
|
+
if not 9 <= length <= limits.max_record_bytes or offset < header_end or offset + length > summary_start:
|
|
998
|
+
r.fast_fallback = BAD_METADATA_INDEX
|
|
999
|
+
return r
|
|
871
1000
|
rec = read_at(offset, length)
|
|
872
1001
|
if rec[0] != OP_METADATA or _U64.unpack_from(rec, 1)[0] != length - 9:
|
|
873
|
-
|
|
1002
|
+
r.fast_fallback = BAD_METADATA_INDEX
|
|
1003
|
+
return r
|
|
874
1004
|
reg.metadata(_Cursor(rec, 9), {"file_offset": offset})
|
|
875
1005
|
|
|
876
1006
|
r.counts = {cid: statistics["channel_message_counts"].get(cid, 0) for cid in r.channels}
|
|
@@ -2,9 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
import json
|
|
4
4
|
import struct
|
|
5
|
+
import zlib
|
|
5
6
|
from pathlib import Path
|
|
6
7
|
|
|
7
|
-
from mcap.writer import CompressionType, Writer
|
|
8
|
+
from mcap.writer import CompressionType, IndexType, Writer
|
|
8
9
|
|
|
9
10
|
DYNREC = 'rosbag2_dynamic_recorder_interfaces/msg/'
|
|
10
11
|
|
|
@@ -50,6 +51,66 @@ def write_sample(path, fault=False, chunked=True, compression=CompressionType.NO
|
|
|
50
51
|
w.finish()
|
|
51
52
|
|
|
52
53
|
|
|
54
|
+
def write_bad_index_sample(path):
|
|
55
|
+
"""A valid recording whose summary indexes point to the wrong places, as a buggy writer could produce.
|
|
56
|
+
|
|
57
|
+
Every record is intact; only the summary is wrong: the Metadata index entry points 20 bytes past the start of
|
|
58
|
+
its record, and the Attachment index entry points at the Metadata record. The summary CRC is recomputed, so
|
|
59
|
+
the file is otherwise well formed. Readers that trust the index would show wrong metadata and attachments.
|
|
60
|
+
"""
|
|
61
|
+
with Path(path).open('wb') as f:
|
|
62
|
+
w = Writer(f, compression=CompressionType.NONE, enable_crcs=True, enable_data_crcs=True)
|
|
63
|
+
w.start(profile='', library='backplane-tracecheck synthetic generator')
|
|
64
|
+
sid = w.register_schema('DemoPosition', 'jsonschema', b'{"type":"object"}')
|
|
65
|
+
cid = w.register_channel('/demo/position', 'json', sid)
|
|
66
|
+
w.add_metadata('session', {'software_version': 'demo-1'})
|
|
67
|
+
for i in range(11):
|
|
68
|
+
t = i * 100000000
|
|
69
|
+
w.add_message(cid, t, b'{"x":1,"synthetic":true}', t, sequence=i)
|
|
70
|
+
w.add_attachment(create_time=0, log_time=500000000, name='calibration.yaml', media_type='application/yaml',
|
|
71
|
+
data=b'synthetic: true\n')
|
|
72
|
+
w.finish()
|
|
73
|
+
data = bytearray(Path(path).read_bytes())
|
|
74
|
+
footer_at = len(data) - 8 - 29
|
|
75
|
+
summary_start = struct.unpack_from('<Q', data, footer_at + 9)[0]
|
|
76
|
+
meta_at = None
|
|
77
|
+
pos = summary_start
|
|
78
|
+
while pos < footer_at:
|
|
79
|
+
op, length = data[pos], struct.unpack_from('<Q', data, pos + 1)[0]
|
|
80
|
+
if op == 0x0D: # MetadataIndex: remember the true offset, then point 20 bytes past it
|
|
81
|
+
meta_at = struct.unpack_from('<Q', data, pos + 9)[0]
|
|
82
|
+
struct.pack_into('<Q', data, pos + 9, meta_at + 20)
|
|
83
|
+
pos += 9 + length
|
|
84
|
+
pos = summary_start
|
|
85
|
+
while pos < footer_at:
|
|
86
|
+
op, length = data[pos], struct.unpack_from('<Q', data, pos + 1)[0]
|
|
87
|
+
if op == 0x0A: # AttachmentIndex: point at the Metadata record instead
|
|
88
|
+
struct.pack_into('<Q', data, pos + 9, meta_at)
|
|
89
|
+
pos += 9 + length
|
|
90
|
+
struct.pack_into('<I', data, footer_at + 25, zlib.crc32(bytes(data[summary_start:footer_at + 25])))
|
|
91
|
+
Path(path).write_bytes(bytes(data))
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def write_indexless_rosbag2_sample(path):
|
|
95
|
+
"""No chunk, message, attachment or metadata indexes, with an embedded ``rosbag2`` Metadata record.
|
|
96
|
+
|
|
97
|
+
ROS 2's own MCAP reader has been reported to mis-read message 2 of such files (rosbag2 issue #2530); a full
|
|
98
|
+
scan reads the records directly and is not affected.
|
|
99
|
+
"""
|
|
100
|
+
with Path(path).open('wb') as f:
|
|
101
|
+
w = Writer(f, compression=CompressionType.ZSTD, index_types=IndexType.NONE, enable_crcs=True)
|
|
102
|
+
w.start(profile='', library='backplane-tracecheck synthetic generator')
|
|
103
|
+
sid = w.register_schema('DemoPosition', 'jsonschema', b'{"type":"object"}')
|
|
104
|
+
cid = w.register_channel('/demo/position', 'json', sid)
|
|
105
|
+
w.add_metadata('session', {'software_version': 'demo-1'})
|
|
106
|
+
w.add_metadata('rosbag2', {'serialized_metadata': 'rosbag2_bagfile_information:\n version: 9\n'
|
|
107
|
+
' storage_identifier: mcap\n message_count: 11\n'})
|
|
108
|
+
for i in range(11):
|
|
109
|
+
t = i * 100000000
|
|
110
|
+
w.add_message(cid, t, b'{"x":1,"synthetic":true}', t, sequence=i)
|
|
111
|
+
w.finish()
|
|
112
|
+
|
|
113
|
+
|
|
53
114
|
def _cdr_event(stamp_ns, *fields):
|
|
54
115
|
"""Little-endian plain CDR for a dynrec event: Time stamp, then uint8 (int) and string (str) fields."""
|
|
55
116
|
out = bytearray(b'\x00\x01\x00\x00')
|
|
@@ -201,6 +262,10 @@ def generate(dest):
|
|
|
201
262
|
p.write_bytes(p.read_bytes().replace(b'zstd', b'brot'))
|
|
202
263
|
(dest/'malformed.mcap').write_bytes(b'not an MCAP recording\x00')
|
|
203
264
|
(dest/'truncated.mcap').write_bytes((dest/'clean.mcap').read_bytes()[:-12])
|
|
265
|
+
# Intact records, wrong summary indexes (a writer bug of the kind fixed in MCAP TypeScript 2.4.0).
|
|
266
|
+
write_bad_index_sample(dest/'bad-index.mcap')
|
|
267
|
+
# No indexes at all, with embedded rosbag2 metadata: must read cleanly.
|
|
268
|
+
write_indexless_rosbag2_sample(dest/'indexless-rosbag2.mcap')
|
|
204
269
|
write_fleet_sample(dest/'fleet-zstd.mcap', seconds=20)
|
|
205
270
|
# Cut part-way through the message data, like a recorder that stopped mid-write: no summary, no footer.
|
|
206
271
|
fleet = (dest/'fleet-zstd.mcap').read_bytes()
|