ec-av1-syntax: streams test reads ec_testkit bitstreams fixtures and ffprobe; missing fixtures fail instead of skipping
Browse files at this commit92bd1ce2e0450bb314f796fea5511a1dfaed6e8fParent: 6f9d2803 changed files +13 -39
Cargo.lockmodified+1 -0
| @@ -384,6 +384,7 @@ name = "ec-av1-syntax" | ||
| 384 | 384 | version = "0.1.0" |
| 385 | 385 | dependencies = [ |
| 386 | 386 | "ec-core", |
| 387 | + "ec-testkit", | |
| 387 | 388 | ] |
| 388 | 389 | |
| 389 | 390 | [[package]] |
crates/ec-av1-syntax/Cargo.tomlmodified+3 -0
| @@ -8,3 +8,6 @@ authors.workspace = true | ||
| 8 | 8 | |
| 9 | 9 | [dependencies] |
| 10 | 10 | ec-core.workspace = true |
| 11 | + | |
| 12 | +[dev-dependencies] | |
| 13 | +ec-testkit.workspace = true |
crates/ec-av1-syntax/tests/streams.rsmodified+9 -39
| @@ -1,19 +1,13 @@ | ||
| 1 | 1 | //! Every AV1 fixture stream parsed end to end, field-compared against ffprobe. |
| 2 | 2 | //! |
| 3 | 3 | //! `scripts/gen-bitstream-fixtures.sh` remuxes the container fixtures to IVF and |
| 4 | -//! encodes the branch cases (4:4:4, monochrome, tiles, hidden ALTREF). Fixtures | |
| 5 | -//! are gitignored, so a checkout without them skips rather than fails. | |
| 4 | +//! encodes the branch cases (4:4:4, monochrome, tiles, hidden ALTREF). | |
| 6 | 5 | |
| 7 | 6 | use std::path::{Path, PathBuf}; |
| 8 | -use std::process::Command; | |
| 9 | 7 | |
| 10 | 8 | use ec_av1_syntax::{Av1Parser, FrameType, ObuKind}; |
| 11 | 9 | use ec_core::Error; |
| 12 | 10 | |
| 13 | -fn bitstreams() -> PathBuf { | |
| 14 | - Path::new(env!("CARGO_MANIFEST_DIR")).join("../../fixtures/bitstreams") | |
| 15 | -} | |
| 16 | - | |
| 17 | 11 | /// The IVF frames of a file — for AV1, each is one temporal unit. |
| 18 | 12 | fn ivf_frames(data: &[u8]) -> Vec<&[u8]> { |
| 19 | 13 | let mut out = Vec::new(); |
| @@ -31,7 +25,7 @@ fn ivf_frames(data: &[u8]) -> Vec<&[u8]> { | ||
| 31 | 25 | } |
| 32 | 26 | |
| 33 | 27 | fn ffprobe(path: &Path, entries: &str) -> Vec<String> { |
| 34 | - let out = Command::new("ffprobe") | |
| 28 | + let out = ec_testkit::ffprobe() | |
| 35 | 29 | .args(["-v", "error", "-select_streams", "v:0", "-show_entries"]) |
| 36 | 30 | .arg(entries) |
| 37 | 31 | .args(["-of", "csv=p=0"]) |
| @@ -89,19 +83,13 @@ fn pix_fmt_geometry(pix_fmt: &str) -> (u8, bool, u8, u8) { | ||
| 89 | 83 | } |
| 90 | 84 | |
| 91 | 85 | fn fixtures() -> Vec<PathBuf> { |
| 92 | - let Ok(entries) = std::fs::read_dir(bitstreams()) else { | |
| 93 | - return Vec::new(); | |
| 94 | - }; | |
| 95 | - let mut files: Vec<PathBuf> = entries | |
| 96 | - .filter_map(|e| e.ok().map(|e| e.path())) | |
| 86 | + ec_testkit::fixtures("bitstreams", "ivf") | |
| 87 | + .into_iter() | |
| 97 | 88 | .filter(|p| { |
| 98 | - p.extension().is_some_and(|e| e == "ivf") | |
| 99 | - && p.file_name() | |
| 100 | - .is_some_and(|n| n.to_string_lossy().starts_with("av1-")) | |
| 89 | + p.file_name() | |
| 90 | + .is_some_and(|n| n.to_string_lossy().starts_with("av1-")) | |
| 101 | 91 | }) |
| 102 | - .collect(); | |
| 103 | - files.sort(); | |
| 104 | - files | |
| 92 | + .collect() | |
| 105 | 93 | } |
| 106 | 94 | |
| 107 | 95 | /// One pass over a stream: what the parser saw. |
| @@ -117,14 +105,7 @@ struct Tally { | ||
| 117 | 105 | |
| 118 | 106 | #[test] |
| 119 | 107 | fn every_fixture_matches_ffprobe() { |
| 120 | - let files = fixtures(); | |
| 121 | - if files.is_empty() { | |
| 122 | - eprintln!( | |
| 123 | - "skipped: no fixtures/bitstreams/av1-*.ivf — run scripts/gen-bitstream-fixtures.sh" | |
| 124 | - ); | |
| 125 | - return; | |
| 126 | - } | |
| 127 | - for path in files { | |
| 108 | + for path in fixtures() { | |
| 128 | 109 | let name = path.file_name().unwrap().to_string_lossy().to_string(); |
| 129 | 110 | let (width, height, pix_fmt, profile) = probe_stream(&path); |
| 130 | 111 | let (bit_depth, mono, sx, sy) = pix_fmt_geometry(&pix_fmt); |
| @@ -236,11 +217,7 @@ fn every_fixture_matches_ffprobe() { | ||
| 236 | 217 | /// cannot prove. |
| 237 | 218 | #[test] |
| 238 | 219 | fn altref_fixture_has_hidden_frames_and_show_existing() { |
| 239 | - let path = bitstreams().join("av1-altref.ivf"); | |
| 240 | - if !path.exists() { | |
| 241 | - eprintln!("skipped: no av1-altref.ivf"); | |
| 242 | - return; | |
| 243 | - } | |
| 220 | + let path = ec_testkit::fixture("bitstreams/av1-altref.ivf"); | |
| 244 | 221 | let data = std::fs::read(&path).unwrap(); |
| 245 | 222 | let mut parser = Av1Parser::new(); |
| 246 | 223 | let (mut hidden, mut show_existing, mut showable) = (0usize, 0usize, 0usize); |
| @@ -287,13 +264,6 @@ fn fuzz_10k_mutations_never_panics() { | ||
| 287 | 264 | .collect::<Vec<_>>() |
| 288 | 265 | }) |
| 289 | 266 | .collect(); |
| 290 | - let seeds = if seeds.is_empty() { | |
| 291 | - vec![vec![ | |
| 292 | - 0x0au8, 0x0b, 0x00, 0x00, 0x00, 0x24, 0xcf, 0x7f, 0x0d, 0xbf, 0xff, 0x30, 0x08, | |
| 293 | - ]] | |
| 294 | - } else { | |
| 295 | - seeds | |
| 296 | - }; | |
| 297 | 267 | |
| 298 | 268 | let mut state = 0x9e37_79b9_7f4a_7c15u64; |
| 299 | 269 | let mut rng = move || { |