Skip to content

Commit a60269d

Browse files
authored
Adds basic snapshots tests for MCAP binaries (#11175)
### Related - part of #10807 ### What Snapshot tests for the MCAP loader. Adds a basic protobuf-based MCAP and a detailed ROS2 MCAP by @gijs. <!-- Make sure the PR title and labels are set to maximize their usefulness for the CHANGELOG, and our `git log`. If you have noticed any breaking changes, include them in the migration guide. We track various metrics at <https://build.rerun.io>. For maintainers: * To run all checks from `main`, comment on the PR with `@rerun-bot full-check`. * To deploy documentation changes immediately after merging this PR, add the `deploy docs` label. For more details check the PR section on <https://github.com/rerun-io/rerun/blob/main/CONTRIBUTING.md>. -->
1 parent 843ad2a commit a60269d

10 files changed

+83
-1
lines changed

Cargo.lock

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3906,6 +3906,19 @@ version = "0.3.2"
39063906
source = "registry+https://github.com/rust-lang/crates.io-index"
39073907
checksum = "a8d1add55171497b4705a648c6b583acafb01d58050a51727785f0b2c8e0a2b2"
39083908

3909+
[[package]]
3910+
name = "globset"
3911+
version = "0.4.16"
3912+
source = "registry+https://github.com/rust-lang/crates.io-index"
3913+
checksum = "54a1028dfc5f5df5da8a56a73e6c153c9a9708ec57232470703592a3f18e49f5"
3914+
dependencies = [
3915+
"aho-corasick",
3916+
"bstr",
3917+
"log",
3918+
"regex-automata",
3919+
"regex-syntax",
3920+
]
3921+
39093922
[[package]]
39103923
name = "glow"
39113924
version = "0.16.0"
@@ -4663,12 +4676,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
46634676
checksum = "154934ea70c58054b556dd430b99a98c2a7ff5309ac9891597e339b5c28f4371"
46644677
dependencies = [
46654678
"console",
4679+
"globset",
46664680
"once_cell",
46674681
"pest",
46684682
"pest_derive",
46694683
"regex",
46704684
"serde",
46714685
"similar",
4686+
"walkdir",
46724687
]
46734688

46744689
[[package]]
@@ -7484,6 +7499,7 @@ dependencies = [
74847499
"crossbeam",
74857500
"image",
74867501
"indexmap 2.10.0",
7502+
"insta",
74877503
"itertools 0.14.0",
74887504
"mcap",
74897505
"memmap2 0.9.5",

crates/store/re_data_loader/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,4 @@ re_crash_handler.workspace = true
6060

6161
[dev-dependencies]
6262
re_log_encoding = { workspace = true, features = ["decoder", "encoder"] }
63+
insta = { workspace = true, features = ["glob"] }

crates/store/re_data_loader/src/loader_mcap.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ fn load_mcap_mmap(
181181
load_mcap(&mmap, settings, tx, selected_layers, raw_fallback_enabled)
182182
}
183183

184-
fn load_mcap(
184+
pub fn load_mcap(
185185
mcap: &[u8],
186186
settings: &DataLoaderSettings,
187187
tx: &Sender<LoadedData>,
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*.mcap filter=lfs diff=lfs merge=lfs -text
2+
*.snap filter=lfs diff=lfs merge=lfs -text
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:be192939c0eff121444e449127eae2d9b26892dcba138423362c0bdff55190e7
3+
size 1204
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:ce92c1dc857ef9f8c0f3823cb285b2ccd5e6601c85b3a0a6cf81623924b0c57e
3+
size 1468176
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
foo
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:0d754b1992f72daa7623c49ba4ce21ad7fe392f9e153e0a9958ed719271dd1e5
3+
size 17642
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:3fe309bc865899cacf618eb9a2c38ba16aa457bce7032b44defb44ef3161b1ed
3+
size 441989
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#[cfg(test)]
2+
mod tests {
3+
use re_chunk::{Chunk, ChunkId};
4+
use re_data_loader::{DataLoaderSettings, LoadedData, loader_mcap::load_mcap};
5+
use re_mcap::layers::SelectedLayers;
6+
7+
// Load an MCAP file into a list of chunks.
8+
fn load_mcap_chunks(path: &std::path::Path) -> Vec<Chunk> {
9+
println!("Loading MCAP file: {}", path.display());
10+
let mcap_data = std::fs::read(path).unwrap();
11+
let (tx, rx) = std::sync::mpsc::channel();
12+
let settings = DataLoaderSettings::recommended("test");
13+
load_mcap(&mcap_data, &settings, &tx, &SelectedLayers::All, false).unwrap();
14+
drop(tx);
15+
16+
// Collect chunks
17+
rx.iter()
18+
.filter_map(|res| {
19+
if let LoadedData::Chunk(_, _, chunk) = res {
20+
Some(chunk)
21+
} else {
22+
None
23+
}
24+
})
25+
.collect()
26+
}
27+
28+
// Compare chunks based on their debug representation.
29+
// Chunks are sorted by entity path and row ids are cleared to make comparison stable.
30+
fn assert_chunk_snapshot(mut chunks: Vec<Chunk>) {
31+
chunks.sort_by_key(|chunk| chunk.entity_path().to_string());
32+
let clean_chunks: Vec<Chunk> = chunks
33+
.into_iter()
34+
.map(|chunk| {
35+
chunk
36+
.with_id(ChunkId::from_u128(123_456_789_123_456_789_123_456_789))
37+
.zeroed()
38+
})
39+
.collect();
40+
insta::assert_debug_snapshot!(clean_chunks);
41+
}
42+
43+
#[test]
44+
fn test_mcap_loader() {
45+
insta::glob!("assets/*.mcap", |path| {
46+
let chunks = load_mcap_chunks(path);
47+
assert_chunk_snapshot(chunks);
48+
});
49+
}
50+
}

0 commit comments

Comments
 (0)