diff --git a/Cargo.lock b/Cargo.lock index cc823cef..a717b119 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -491,6 +491,7 @@ dependencies = [ "ec-h264-syntax", "ec-matroska", "ec-mp4", + "ec-testkit", "tracking-allocator", "wide", ] @@ -510,6 +511,7 @@ dependencies = [ "bytemuck", "ec-core", "ec-h265-syntax", + "ec-testkit", "multiversion", "wide", ] @@ -519,6 +521,7 @@ name = "ec-h265-syntax" version = "0.1.0" dependencies = [ "ec-core", + "ec-testkit", ] [[package]] diff --git a/crates/ec-h264/Cargo.toml b/crates/ec-h264/Cargo.toml index fe06db93..62f5ba9c 100644 --- a/crates/ec-h264/Cargo.toml +++ b/crates/ec-h264/Cargo.toml @@ -18,6 +18,7 @@ ec-h264-syntax = { workspace = true } wide = { workspace = true } [dev-dependencies] +ec-testkit.workspace = true # The conformance harness walks Annex B itself to drive push_nal. ec-h264-syntax = { workspace = true } # ... and demuxes an MP4 directly where ffmpeg's own Annex B extraction of it diff --git a/crates/ec-h264/fuzz/seed.sh b/crates/ec-h264/fuzz/seed.sh index ce4de9ce..c4b19281 100755 --- a/crates/ec-h264/fuzz/seed.sh +++ b/crates/ec-h264/fuzz/seed.sh @@ -4,7 +4,7 @@ set -euo pipefail here=$(cd -- "$(dirname -- "$0")" && pwd) -src="$here/../../../fixtures/vectors/h264-jvt" +src="${EC_FIXTURES:-$here/../../../fixtures}/vectors/h264-jvt" dst="$here/corpus/decode_annexb" seeds=( @@ -19,7 +19,7 @@ mkdir -p "$dst" for rel in "${seeds[@]}"; do f="$src/$rel" if [ ! -f "$f" ]; then - echo "seed.sh: missing fixture $f (run scripts/link-fixtures.sh)" >&2 + echo "seed.sh: missing fixture $f (run scripts/fixtures.sh)" >&2 exit 1 fi cp -f "$f" "$dst/$(basename "$rel")" diff --git a/crates/ec-h264/tests/conformance.rs b/crates/ec-h264/tests/conformance.rs index 187f1594..11d0be48 100644 --- a/crates/ec-h264/tests/conformance.rs +++ b/crates/ec-h264/tests/conformance.rs @@ -1,7 +1,6 @@ //! JVT conformance: first IDR picture, bit-exact. //! -//! Fixture-gated like tools/oracle: fixtures/ is gitignored, so a checkout -//! without `scripts/fetch-vectors.sh` skips loudly instead of failing. +//! Fixtures come from `scripts/fixtures.sh`; a missing one fails. //! //! Oracles, in order of authority: //! 1. The reference decoder YUV that ships with each JVT vector (first @@ -18,7 +17,6 @@ use std::sync::Once; use tracking_allocator::{AllocationGroupId, AllocationRegistry, AllocationTracker, Allocator}; use std::cell::Cell; use std::path::{Path, PathBuf}; -use std::process::Command; use std::sync::atomic::{AtomicU64, Ordering}; use ec_core::registry::{CodecId, CodecParameters, Decoder as _}; @@ -76,38 +74,10 @@ fn install_counter() { // --------------------------------------------------------------------------- fn vectors_dir() -> PathBuf { - Path::new(env!("CARGO_MANIFEST_DIR")).join("../../fixtures/vectors/h264-jvt") + ec_testkit::fixture("vectors/h264-jvt") } -/// A gate that skips when its fixtures are absent reports GREEN having checked -/// nothing — the "gate skips on its own failure" class. The root `fixtures/` -/// directory is gitignored, so `git worktree add` hands every lane worktree a -/// tree without it and the whole conformance suite silently stops testing. -/// -/// `EC_REQUIRE_FIXTURES=1` turns the skip into a hard failure naming the exact -/// missing path and the command that produces it; unset (the default), the skip -/// is kept and now says what it skipped. Set it in every batch run. -fn require_fixtures(path: &Path, what: &str, generator: &str) -> bool { - if path.exists() { - return true; - } - assert!( - std::env::var_os("EC_REQUIRE_FIXTURES").is_none(), - "{what} missing at {} — this gate would prove nothing. A worktree has no \ - gitignored root `fixtures/`: run scripts/link-fixtures.sh, or generate \ - them with {generator}.", - path.display() - ); - eprintln!( - "SKIP {what} missing at {} — this gate proved nothing; run \ - scripts/link-fixtures.sh, or generate them with {generator} \ - (or set EC_REQUIRE_FIXTURES=1 to make this a failure).", - path.display() - ); - false -} - -/// Every vector directory `scripts/fetch-vectors.sh` has populated, in name +/// Every vector directory `scripts/fixtures.sh` has populated, in name /// order. /// /// A hand-written list would only ever record what passed on the day it was @@ -153,7 +123,7 @@ fn find_ref_yuv(dir: &Path) -> Option { } fn ffmpeg_first_frame(stream: &Path) -> Option> { - let out = Command::new("ffmpeg") + let out = ec_testkit::ffmpeg() .args(["-v", "error", "-i"]) .arg(stream) .args([ @@ -235,7 +205,7 @@ fn decode_all(bytes: &[u8]) -> Result>, Error> { /// Every frame ffmpeg decodes from `stream`, as raw I420. fn ffmpeg_all_frames(stream: &Path, frame_len: usize) -> Option>> { - let out = Command::new("ffmpeg") + let out = ec_testkit::ffmpeg() .args(["-v", "error", "-i"]) .arg(stream) .args(["-f", "rawvideo", "-pix_fmt", "yuv420p", "-"]) @@ -291,7 +261,7 @@ fn x264_encode_gop( stream.to_string_lossy().into_owned(), ]); let refs: Vec<&str> = args.iter().map(|s| s.as_str()).collect(); - run("ffmpeg", &refs).then_some(stream) + run(&refs).then_some(stream) } /// Decode `stream` both ways and report the first frame that differs. @@ -328,23 +298,13 @@ fn compare_sequence(stream: &Path) -> Result { #[test] fn jvt_cavlc_first_idr_bit_exact() { let base = vectors_dir(); - if !require_fixtures( - &base, - "the JVT conformance vectors", - "scripts/fetch-vectors.sh", - ) { - return; - } let mut passed = Vec::new(); let mut failed = Vec::new(); let mut refused = Vec::new(); for name in all_vectors(&base) { let name = name.as_str(); let dir = base.join(name); - let Some(stream) = find_stream(&dir) else { - eprintln!("SKIP {name}: no bitstream file"); - continue; - }; + let stream = find_stream(&dir).unwrap_or_else(|| panic!("{name}: no bitstream file")); let bytes = std::fs::read(&stream).unwrap(); match decode_first(&bytes) { Ok((ours, w, h)) => { @@ -436,13 +396,6 @@ fn jvt_cavlc_first_idr_bit_exact() { fn steady_state_decode_loop_zero_alloc() { install_counter(); let base = vectors_dir(); - if !require_fixtures( - &base, - "the JVT conformance vectors", - "scripts/fetch-vectors.sh", - ) { - return; - } // One stream per entropy coder, and one with B slices and multiple // reference frames so the decoded picture buffer really recycles pictures. for name in ["BA1_Sony_D", "CABA1_SVA_B", "CABA3_SVA_B"] { @@ -523,13 +476,6 @@ fn steady_state_decode_loop_zero_alloc() { #[test] fn ns_per_macroblock_measurement() { let base = vectors_dir(); - if !require_fixtures( - &base, - "the JVT conformance vectors", - "scripts/fetch-vectors.sh", - ) { - return; - } for name in [ "BA1_Sony_D", "CI_MW_D", @@ -610,13 +556,6 @@ fn perf_whole_sequence() { #[test] fn corrupt_streams_never_panic() { let base = vectors_dir(); - if !require_fixtures( - &base, - "the JVT conformance vectors", - "scripts/fetch-vectors.sh", - ) { - return; - } // One stream per entropy coder, plus one with B slices and multiple // references: CABAC's arithmetic decoder indexes context and coefficient // arrays from stream-derived values, and inter prediction indexes the @@ -682,9 +621,9 @@ fn corrupt_sweep(bytes: &[u8]) { // ffmpeg's own decoder as the oracle. // --------------------------------------------------------------------------- -/// Run a command, false when it fails or is not installed. -fn run(command: &str, args: &[&str]) -> bool { - Command::new(command) +/// Run the pinned ffmpeg, false when it fails. +fn run(args: &[&str]) -> bool { + ec_testkit::ffmpeg() .args(args) .stdout(std::process::Stdio::null()) .stderr(std::process::Stdio::null()) @@ -693,13 +632,6 @@ fn run(command: &str, args: &[&str]) -> bool { .unwrap_or(false) } -fn have_ffmpeg() -> bool { - run( - "ffmpeg", - &["-hide_banner", "-loglevel", "error", "-version"], - ) -} - /// A private scratch directory for one test. fn scratch(tag: &str) -> PathBuf { let dir = std::env::temp_dir().join(format!("ec-h264-{tag}-{}", std::process::id())); @@ -742,7 +674,7 @@ fn x264_encode(dir: &Path, tag: &str, size: &str, extra: &[&str]) -> Option = args.iter().map(|s| s.as_str()).collect(); - run("ffmpeg", &refs).then_some(stream) + run(&refs).then_some(stream) } /// Encode, decode both ways, return the number of differing bytes. @@ -787,10 +719,6 @@ const ENTROPY_MODES: [(&str, &[&str]); 2] = [ /// produces, none of which the QCIF single-slice vectors cover. #[test] fn geometry_and_slice_structure_match_ffmpeg() { - if !have_ffmpeg() { - eprintln!("SKIP: ffmpeg not on PATH"); - return; - } let dir = scratch("geometry"); let cases: &[(&str, &str, &[&str])] = &[ // 1080 lines are coded as 68 macroblock rows and cropped back to 1080. @@ -851,10 +779,6 @@ fn geometry_and_slice_structure_match_ffmpeg() { /// nothing else in the suite would notice it regressing into a refusal. #[test] fn jvt_scaling_matrices_decode_bit_exact() { - if !have_ffmpeg() { - eprintln!("SKIP: ffmpeg not on PATH"); - return; - } let dir = scratch("scaling"); let extra = [ "-profile:v", @@ -877,10 +801,6 @@ fn jvt_scaling_matrices_decode_bit_exact() { /// prefixed — how an MP4 or Matroska demuxer hands H.264 over. #[test] fn avcc_extradata_and_length_prefixed_packets() { - if !have_ffmpeg() { - eprintln!("SKIP: ffmpeg not on PATH"); - return; - } let dir = scratch("avcc"); let Some(annex_b) = x264_encode( &dir, @@ -960,10 +880,6 @@ fn avcc_extradata_and_length_prefixed_packets() { /// once, so it is the first test to look at when any of them regress. #[test] fn p_only_gop_matches_ffmpeg_every_frame() { - if !have_ffmpeg() { - eprintln!("SKIP: ffmpeg not on PATH"); - return; - } let dir = scratch("p-gop"); let mut failures = Vec::new(); for (mode, profile) in ENTROPY_MODES { @@ -992,13 +908,6 @@ fn p_only_gop_matches_ffmpeg_every_frame() { #[test] fn jvt_full_sequence_bit_exact() { let base = vectors_dir(); - if !require_fixtures( - &base, - "the JVT conformance vectors", - "scripts/fetch-vectors.sh", - ) { - return; - } let mut table = String::new(); let mut passed = 0usize; let mut refused = Vec::new(); @@ -1144,10 +1053,6 @@ fn slice_type_counts(bytes: &[u8]) -> [usize; 3] { /// they arrived. #[test] fn b_pictures_match_ffmpeg_every_frame() { - if !have_ffmpeg() { - eprintln!("SKIP: ffmpeg not on PATH"); - return; - } let dir = scratch("b-gop"); let cases: &[(&str, &[&str])] = &[ ( @@ -1227,10 +1132,6 @@ fn b_pictures_match_ffmpeg_every_frame() { /// test would pass on a decoder that never reorders anything. #[test] fn output_is_display_order_and_the_reorder_is_real() { - if !have_ffmpeg() { - eprintln!("SKIP: ffmpeg not on PATH"); - return; - } let dir = scratch("order"); let extra = [ "-profile:v", @@ -1296,10 +1197,6 @@ fn output_is_display_order_and_the_reorder_is_real() { /// preview after a seek. #[test] fn a_frame_num_gap_keeps_decoding() { - if !have_ffmpeg() { - eprintln!("SKIP: ffmpeg not on PATH"); - return; - } let dir = scratch("gap"); let extra = [ "-profile:v", @@ -1359,10 +1256,6 @@ fn a_frame_num_gap_keeps_decoding() { /// inter prediction and reordering active. #[test] fn geometry_with_motion_matches_ffmpeg() { - if !have_ffmpeg() { - eprintln!("SKIP: ffmpeg not on PATH"); - return; - } let dir = scratch("geometry-motion"); let cases: &[(&str, &str, &[&str])] = &[ ("hd", "1920x1080", &["bframes=2:b-adapt=0"]), @@ -1515,92 +1408,9 @@ fn switching_slices_are_refused_by_name() { // Real library: the files actually on this machine, not fixtures. // --------------------------------------------------------------------------- -/// Compare a long stream against ffmpeg without holding it in memory: ffmpeg's -/// raw output is consumed from a pipe one frame at a time, in step with our -/// own decoding, so a 500-frame 1080p sweep costs two frames of memory rather -/// than three gigabytes. -fn compare_sequence_streamed( - stream: &Path, - frames_wanted: usize, -) -> Result { - use std::io::Read; - - let bytes = std::fs::read(stream).map_err(|e| e.to_string())?; - let mut child = Command::new("ffmpeg") - .args(["-v", "error", "-i"]) - .arg(stream) - .args([ - "-frames:v", - &frames_wanted.to_string(), - "-f", - "rawvideo", - "-pix_fmt", - "yuv420p", - "-", - ]) - .stdout(std::process::Stdio::piped()) - .stderr(std::process::Stdio::null()) - .spawn() - .map_err(|e| e.to_string())?; - let mut out = child.stdout.take().expect("piped stdout"); - - let mut dec = Decoder::new(); - let mut reference = Vec::new(); - let mut result = StreamedResult::default(); - let mut oracle_open = true; - let mut take = |frame: Vec, result: &mut StreamedResult, reference: &mut Vec| { - result.produced += 1; - if !oracle_open || result.compared >= frames_wanted { - return; - } - reference.resize(frame.len(), 0); - if out.read_exact(reference).is_err() { - oracle_open = false; - return; - } - if let Some(pos) = first_diff(&frame, reference) { - result.diffs.push((result.compared, pos)); - } - result.compared += 1; - }; - - for nal in ec_h264_syntax::AnnexBIter::new(&bytes) { - match dec.push_nal(nal) { - Ok(NalOutcome::PictureBoundary) => { - dec.end_picture().map_err(|e| format!("{e}"))?; - dec.push_nal(nal).map_err(|e| format!("{e}"))?; - } - Ok(_) => {} - Err(e) => return Err(format!("{e}")), - } - while let Some(f) = dec.next_frame() { - take(frame_bytes(&f), &mut result, &mut reference); - } - } - dec.flush().map_err(|e| format!("{e}"))?; - while let Some(f) = dec.next_frame() { - take(frame_bytes(&f), &mut result, &mut reference); - } - let _ = child.kill(); - let _ = child.wait(); - Ok(result) -} - -/// Outcome of a streamed comparison. -#[derive(Default)] -struct StreamedResult { - /// Frames this decoder produced. - produced: usize, - /// Frames the oracle also produced, and which were therefore compared. - compared: usize, - /// `(frame index, byte offset)` of each mismatch. - diffs: Vec<(usize, usize)>, -} - /// Extract the video elementary stream of a real file as Annex B. fn extract_annexb(src: &Path, dst: &Path, frames: usize) -> bool { run( - "ffmpeg", &[ "-v", "error", @@ -1622,273 +1432,8 @@ fn extract_annexb(src: &Path, dst: &Path, frames: usize) -> bool { ) } -/// The same comparison, but demuxed from the container by [`ec_mp4`] instead -/// of extracted to Annex B by ffmpeg's bitstream filter. -/// -/// Some real MP4s produce an elementary stream that ffmpeg itself then decodes -/// only three frames of, silently. That is a property of the extraction, not of -/// the file: reading the sample table directly and handing the `avcC` and the -/// length-prefixed samples to the packet entry surface leaves the oracle able to -/// decode the original file, so the comparison is real again. -fn compare_container_streamed( - source: &Path, - frames_wanted: usize, -) -> Result { - use ec_core::registry::{Decoder as _, Demuxer as _}; - use std::io::Read; - - let file = std::fs::File::open(source).map_err(|e| e.to_string())?; - let mut demux = ec_mp4::Mp4Demuxer::new(std::io::BufReader::new(file)) - .map_err(|e| format!("ec-mp4 open: {e}"))?; - let (stream_index, params) = demux - .streams() - .iter() - .find(|s| s.params.codec == ec_core::registry::CodecId::H264) - .map(|s| (s.index, s.params.clone())) - .ok_or("no H.264 track")?; - let mut dec = ec_h264::H264Decoder::new(params).map_err(|e| format!("{e}"))?; - - let mut child = Command::new("ffmpeg") - .args(["-v", "error", "-i"]) - .arg(source) - .args([ - "-map", - "0:v:0", - "-frames:v", - &frames_wanted.to_string(), - "-f", - "rawvideo", - "-pix_fmt", - "yuv420p", - "-", - ]) - .stdout(std::process::Stdio::piped()) - .stderr(std::process::Stdio::null()) - .spawn() - .map_err(|e| e.to_string())?; - let mut out = child.stdout.take().expect("piped stdout"); - - let mut reference = Vec::new(); - let mut result = StreamedResult::default(); - let mut oracle_open = true; - let mut take = |frame: Vec, result: &mut StreamedResult, reference: &mut Vec| { - result.produced += 1; - if !oracle_open || result.compared >= frames_wanted { - return; - } - reference.resize(frame.len(), 0); - if out.read_exact(reference).is_err() { - oracle_open = false; - return; - } - if let Some(pos) = first_diff(&frame, reference) { - result.diffs.push((result.compared, pos)); - } - result.compared += 1; - }; - let mut drain = - |dec: &mut ec_h264::H264Decoder, result: &mut StreamedResult, reference: &mut Vec| { - while let Ok(ec_core::frame::Frame::Video(f)) = dec.receive_frame() { - take(frame_bytes(&f), result, reference); - } - }; - while result.produced < frames_wanted { - let packet = match demux.next_packet() { - Ok(p) => p, - Err(_) => break, - }; - if packet.stream != stream_index { - continue; - } - dec.send_packet(&packet).map_err(|e| format!("{e}"))?; - drain(&mut dec, &mut result, &mut reference); - } - dec.flush().map_err(|e| format!("{e}"))?; - drain(&mut dec, &mut result, &mut reference); - let _ = child.kill(); - let _ = child.wait(); - Ok(result) -} - -/// Decode real H.264 files from this machine's library, several hundred frames -/// each, frame for frame against ffmpeg. -/// -/// Synthetic clips and conformance vectors are both written by people trying to -/// exercise a decoder. Real files are written by encoders tuned for size, at -/// resolutions and GOP structures the fixtures never use, and they are the ones -/// a user actually opens. Every file either decodes bit-exactly or is refused -/// by name; a file that decodes to different pixels is a failure. -// lane-h264reallib: LOCAL-ONLY, and the reason lives in the attribute so it -// shows in `cargo test -- --list` instead of hiding in a skip print. -// -// The precondition is a PERSONAL MEDIA LIBRARY: the manifest is generated by -// `scripts/scan-real-library.sh`, which scans `~/Videos ~/Downloads ~/Music` -// by default and is gitignored precisely because it is machine-local. A -// runner host has none of those directories, so both of this test's possible -// behaviours there are wrong: -// -// - manifest absent -> the `SKIP: ... missing` early return, which prints -// green. That is the silent-skip class this batch is removing: a green -// that means "nothing was checked". -// - manifest present but its absolute paths unresolvable (a host that ran -// the scan script against an empty library) -> zero files swept and -// `decoded >= 3` fails. That is the red every fleet run currently eats, -// and it is red for a reason that has nothing to do with the decoder. -// -// Hence `#[ignore]` rather than an env gate: an env gate whose variable is -// absent on the runner prints the same green the missing manifest already -// prints, which is the defect rather than the fix. An ignore is visible in -// `--list`, cannot go green silently, and leaves the assertion itself intact -// -- "the sweep is the point" still holds on the machine that can run it. -// -// Run it on the workstation, where the library is: -// cargo test -p ec-h264 --test conformance real_library_streams_match_ffmpeg -- --ignored -#[ignore = "sweeps the PERSONAL media library (~/Videos, ~/Downloads, ~/Music) through the gitignored fixtures/real-library-manifest.tsv; MINUTES of wall time (measured past 840 s on the workstation), so workstation only -- budget an hour, it is not wedged. A runner host has no such library, so the test is either a silent green or a red for the wrong reason. Run it on the workstation with --ignored."] -#[test] -fn real_library_streams_match_ffmpeg() { - if !have_ffmpeg() { - eprintln!("SKIP: ffmpeg not on PATH"); - return; - } - let manifest = - Path::new(env!("CARGO_MANIFEST_DIR")).join("../../fixtures/real-library-manifest.tsv"); - let Ok(text) = std::fs::read_to_string(&manifest) else { - eprintln!("SKIP: {} missing", manifest.display()); - return; - }; - let dir = scratch("real-library"); - const FRAMES: usize = 500; - /// A file counts as swept only when the oracle stayed with us this long. - const MIN_FRAMES: usize = 100; - let mut table = String::new(); - let mut decoded = 0usize; - let mut refused = 0usize; - let mut failures = Vec::new(); - let mut seen_containers = std::collections::BTreeSet::new(); - - for line in text.lines().skip(1) { - let mut f = line.split('\t'); - let (Some(path), Some(container), Some(vcodec)) = (f.next(), f.next(), f.next()) else { - continue; - }; - if vcodec != "h264" || !Path::new(path).is_file() { - continue; - } - // One file per container family per resolution class keeps the sweep - // to a few minutes while still covering both demuxers. - let width = f.next().unwrap_or("0"); - let key = (container.to_string(), width.to_string()); - if !seen_containers.insert(key) { - continue; - } - let name: String = Path::new(path) - .file_name() - .map(|n| n.to_string_lossy().chars().take(38).collect()) - .unwrap_or_default(); - let annexb = dir.join("stream.264"); - if !extract_annexb(Path::new(path), &annexb, FRAMES) { - table.push_str(&format!("{name:<40} {container:<12} not extractable\n")); - continue; - } - match compare_sequence_streamed(&annexb, FRAMES) { - Ok(r) if !r.diffs.is_empty() => { - failures.push(format!( - "{name}: {} of {} frames differ", - r.diffs.len(), - r.compared - )); - table.push_str(&format!( - "{name:<40} {container:<12} {width:>5}px MISMATCH {} of {}\n", - r.diffs.len(), - r.compared - )); - } - // The oracle stopped before we did: ffmpeg gave up on the elementary - // stream its own bitstream filter produced. That is a property of - // the extraction, so the file is re-run straight out of the - // container, where the oracle can read the original samples. - Ok(r) if r.compared < r.produced.min(MIN_FRAMES) => { - match compare_container_streamed(Path::new(path), FRAMES) { - Ok(c) if !c.diffs.is_empty() => { - failures.push(format!( - "{name} (container demux): {} of {} frames differ", - c.diffs.len(), - c.compared - )); - table.push_str(&format!( - "{name:<40} {container:<12} {width:>5}px MISMATCH {} of {} \ - (container demux)\n", - c.diffs.len(), - c.compared - )); - } - Ok(c) if c.compared >= MIN_FRAMES => { - decoded += 1; - table.push_str(&format!( - "{name:<40} {container:<12} {width:>5}px {:>4} frames bit-exact \ - (container demux)\n", - c.compared - )); - } - Ok(c) => { - table.push_str(&format!( - "{name:<40} {container:<12} {width:>5}px oracle short both ways: \ - ffmpeg gave {} frames, we decoded {}\n", - c.compared, c.produced - )); - } - Err(e) => { - table.push_str(&format!( - "{name:<40} {container:<12} {width:>5}px oracle short, container \ - demux failed: {e}\n" - )); - } - } - } - Ok(r) => { - decoded += 1; - table.push_str(&format!( - "{name:<40} {container:<12} {width:>5}px {:>4} frames bit-exact\n", - r.compared - )); - } - Err(e) if e.contains("unsupported") => { - refused += 1; - table.push_str(&format!( - "{name:<40} {container:<12} {width:>5}px refused: {e}\n" - )); - } - Err(e) => { - failures.push(format!("{name}: {e}")); - table.push_str(&format!( - "{name:<40} {container:<12} {width:>5}px ERROR {e}\n" - )); - } - } - } - let _ = std::fs::remove_dir_all(&dir); - eprintln!("{table}"); - eprintln!("real library: {decoded} decoded bit-exact, {refused} refused by name"); - assert!(failures.is_empty(), "{failures:#?}"); - assert!( - decoded >= 3, - "only {decoded} real files swept end to end; the sweep is the point" - ); -} - -/// The registry entry surface, driven the way a demuxer drives it: one access -/// unit per packet, frames pulled with `receive_frame`. -/// -/// This is where display order has to actually arrive. Everything above tests -/// the NAL-level API; a player never touches that one, so a reordering decoder -/// whose packet API still hands back decode order would look correct in every -/// other test here and wrong on screen. #[test] fn packet_entry_surface_reorders_and_carries_timestamps() { - if !have_ffmpeg() { - eprintln!("SKIP: ffmpeg not on PATH"); - return; - } let dir = scratch("entry"); let extra = [ "-profile:v", @@ -2004,10 +1549,6 @@ fn packet_entry_surface_reorders_and_carries_timestamps() { /// are what makes the two readings differ at all, so this needs `-refs`. #[test] fn spatial_direct_over_a_b_reference_matches_ffmpeg() { - if !have_ffmpeg() { - eprintln!("SKIP: ffmpeg not on PATH"); - return; - } let dir = scratch("direct-bref"); let mut failures = Vec::new(); for (tag, coder) in [("cabac", "ac"), ("cavlc", "0")] { @@ -2073,10 +1614,6 @@ fn pps_enables_8x8(stream: &Path) -> bool { /// 8x8 macroblock alone (8.7). #[test] fn high_profile_8x8_inter_sequences_match_ffmpeg() { - if !have_ffmpeg() { - eprintln!("SKIP: ffmpeg not on PATH"); - return; - } let dir = scratch("high8x8-seq"); let mut failures = Vec::new(); let cases: &[(&str, &[&str])] = &[ @@ -2160,18 +1697,7 @@ fn high_profile_8x8_inter_sequences_match_ffmpeg() { /// picture itself, per D.2.8 absent a recovery_point SEI. #[test] fn h264_seek_matches_linear_open_gop() { - if !have_ffmpeg() { - eprintln!("SKIP: ffmpeg not on PATH"); - return; - } - let src = Path::new(env!("CARGO_MANIFEST_DIR")).join("../../fixtures/video/h264-open-gop.mp4"); - if !require_fixtures( - &src, - "the open-GOP fixture", - "scripts/gen-fixtures.sh (fixtures/video/h264-open-gop.mp4)", - ) { - return; - } + let src = ec_testkit::fixture("video/h264-open-gop.mp4"); let dir = scratch("open-gop"); std::fs::create_dir_all(&dir).unwrap(); let annexb = dir.join("open-gop.264"); diff --git a/crates/ec-h264/tests/it/common.rs b/crates/ec-h264/tests/it/common.rs index a2dc78e2..bc2de8ce 100644 --- a/crates/ec-h264/tests/it/common.rs +++ b/crates/ec-h264/tests/it/common.rs @@ -2,7 +2,6 @@ //! ffmpeg pipes and stream utilities that were identical in each file. use std::path::{Path, PathBuf}; -use std::process::Command; use ec_core::frame::{PixelFormat, VideoFrame}; @@ -25,7 +24,7 @@ pub(super) fn frame_bytes(frame: &VideoFrame) -> Vec { } pub(super) fn ffmpeg_frames(stream: &Path, pix_fmt: &str, frame_len: usize) -> Option> { - let out = Command::new("ffmpeg") + let out = ec_testkit::ffmpeg() .args(["-v", "error", "-i"]) .arg(stream) .args(["-f", "rawvideo", "-pix_fmt", pix_fmt, "-"]) @@ -78,7 +77,7 @@ pub(super) fn layout(f: PixelFormat) -> (usize, usize, usize) { } pub(super) fn ffmpeg_pix_frames(stream: &Path, pix_fmt: &str) -> Option> { - let out = Command::new("ffmpeg") + let out = ec_testkit::ffmpeg() .args(["-v", "error", "-f", "h264", "-i"]) .arg(stream) .args(["-f", "rawvideo", "-pix_fmt", pix_fmt, "-"]) diff --git a/crates/ec-h264/tests/it/encode.rs b/crates/ec-h264/tests/it/encode.rs index 2342b0b5..36cffd42 100644 --- a/crates/ec-h264/tests/it/encode.rs +++ b/crates/ec-h264/tests/it/encode.rs @@ -427,39 +427,6 @@ fn all_intra_when_the_gop_is_one() { // absent, exactly like the conformance suite's ffmpeg cross-check. // --------------------------------------------------------------------------- -fn have_ffmpeg() -> bool { - std::process::Command::new("ffmpeg") - .arg("-version") - .stdout(std::process::Stdio::null()) - .stderr(std::process::Stdio::null()) - .status() - .is_ok_and(|s| s.success()) -} - -/// Fixture-presence probe for ``. -/// Returns whether the fixture is present, but never silently: under -/// `EC_REQUIRE_FIXTURES=1` an absent fixture is a hard failure naming the path -/// and the script that regenerates it, so a host whose fixture library drifted -/// reports RED instead of a green SKIP (class: gate-skips-on-its-own-failure; -/// model `have_ffmpeg` in crates/ec-av1/src/stream.rs, which was silently -/// short-circuited because the probe ran first in a compound `if`). -/// -/// Order is load-bearing: probe, assert, return. Never merge the probe into -/// the same `if` as the escape. -fn require_fixture(path: &std::path::Path, generator: &str) -> bool { - let present = path.exists(); - assert!( - present || std::env::var_os("EC_REQUIRE_FIXTURES").is_none(), - "EC_REQUIRE_FIXTURES=1 but fixture {} is absent -- regenerate with: {}", - path.display(), - generator - ); - if !present { - eprintln!("SKIP: fixture {} absent", path.display()); - } - present -} - /// Write `bytes` to `path` and PROVE the file on disk is exactly that long. /// /// lane-h26xpinloud: every write below used `std::fs::write(..).ok()?` and then @@ -635,7 +602,7 @@ fn ffmpeg_decode(stream: &[u8], w: usize, h: usize, extra: &[&str]) -> Option = line.split('\t').collect(); - if f.len() < 7 || f[2] != "h264" || f[5] != "yuv420p" { - continue; - } - let (Ok(w), Ok(h)) = (f[3].parse::(), f[4].parse::()) else { - continue; - }; - if w < 1280 || h < 720 || !w.is_multiple_of(2) || !h.is_multiple_of(2) { - continue; - } - if !f[1].contains("mp4") || !std::path::Path::new(f[0]).exists() { - continue; - } - source = Some((f[0].to_string(), w, h)); - break; - } - let Some((path, w, h)) = source else { - // A manifest with no qualifying row is a corpus that drifted, not a - // reason to report PASS for a sweep that never ran. - assert!( - std::env::var_os("EC_REQUIRE_FIXTURES").is_none(), - "EC_REQUIRE_FIXTURES=1 but {} lists no H.264 4:2:0 mp4 of at least \ - 720p -- regenerate with: scripts/scan-real-library.sh", - manifest.display() - ); - eprintln!("SKIP real_library_frames: no H.264 4:2:0 mp4 in the manifest"); - return; - }; + let path = ec_testkit::fixture("open/sintel_trailer-720p.mp4"); + let (w, h) = (1280, 720); - // Decode a handful of real pictures. - let (params, mut demux, index) = open_h264_source(std::ffi::OsStr::new(&path)); + let (params, mut demux, index) = open_h264_source(path.as_os_str()); let mut dec = ec_h264::H264Decoder::new(params).expect("decoder"); let mut sources: Vec = Vec::new(); while sources.len() < 12 { @@ -1124,12 +1043,10 @@ fn clip_sources(path: &std::ffi::OsStr, want: usize) -> (usize, usize, Vec cargo test --release -p ec-h264 --test encode \ /// real_clip_t8x8_bd_psnr -- --ignored --nocapture #[test] -#[ignore = "set EC_H264_CLIP to a media file of yours"] +#[ignore = "slow measurement on the open 480p trailer"] fn real_clip_t8x8_bd_psnr() { - let Some(path) = std::env::var_os("EC_H264_CLIP") else { - panic!("EC_H264_CLIP must name a media file"); - }; - let (w, h, sources) = clip_sources(&path, 30); + let path = ec_testkit::fixture("open/sintel_trailer-480p.mp4"); + let (w, h, sources) = clip_sources(path.as_os_str(), 30); let run = |t8x8: bool, qp: i32| { let mut cfg = EncoderConfig::new(w as u32, h as u32); @@ -1200,7 +1117,7 @@ fn real_clip_t8x8_bd_psnr() { const BD_PSNR_VS_X264_FLOOR: f64 = -4.15; fn have_x264() -> bool { - std::process::Command::new("ffmpeg") + ec_testkit::ffmpeg() .args(["-v", "error", "-hide_banner", "-encoders"]) .output() .is_ok_and(|o| o.status.success() && String::from_utf8_lossy(&o.stdout).contains("libx264")) @@ -1228,7 +1145,7 @@ fn x264_encode_qp(sources: &[Planes], w: usize, h: usize, qp: i32, gop: u32) -> buf.extend_from_slice(v); } pin_or_bail("x264_encode_qp", &raw, &buf)?; - let status = std::process::Command::new("ffmpeg") + let status = ec_testkit::ffmpeg() .args(["-v", "error", "-y"]) .args(["-f", "rawvideo", "-pix_fmt", "yuv420p"]) .args(["-s", &format!("{w}x{h}"), "-r", "1"]) @@ -1310,14 +1227,7 @@ fn x264_encode_qp(sources: &[Planes], w: usize, h: usize, qp: i32, gop: u32) -> /// bd_psnr_vs_x264 -- --nocapture #[test] fn bd_psnr_vs_x264() { - if !have_ffmpeg() || !have_x264() { - eprintln!( - "SKIP bd_psnr_vs_x264: no ffmpeg with libx264 on PATH. \ - Install one, then: cargo test --release -p ec-h264 --test encode \ - bd_psnr_vs_x264 -- --nocapture" - ); - return; - } + assert!(have_x264(), "the pinned ffmpeg has no libx264"); let (w, h, sources) = match std::env::var_os("EC_H264_CLIP") { Some(path) => clip_sources(&path, 24), None => { @@ -1485,10 +1395,7 @@ fn bd_psnr_vs_x264() { /// bit_account_vs_x264 -- --nocapture #[test] fn bit_account_vs_x264() { - if !have_ffmpeg() || !have_x264() { - eprintln!("SKIP bit_account_vs_x264: no ffmpeg with libx264 on PATH"); - return; - } + assert!(have_x264(), "the pinned ffmpeg has no libx264"); let (w, h, sources) = match std::env::var_os("EC_H264_CLIP") { Some(path) => clip_sources(&path, 12), None => { @@ -1578,10 +1485,6 @@ fn bit_account_vs_x264() { /// never a `sub_mb_type` -- in front of another decoder. This does. #[test] fn balanced_partitions_decode_bit_exactly() { - if !have_ffmpeg() { - eprintln!("SKIP balanced_partitions_decode_bit_exactly: no ffmpeg on PATH"); - return; - } let (w, h) = (176, 144); let mut shapes = ec_h264::MbShapes::default(); for qp in [16, 26, 36] { diff --git a/crates/ec-h264/tests/it/high10.rs b/crates/ec-h264/tests/it/high10.rs index c9a4fda4..879d40e8 100644 --- a/crates/ec-h264/tests/it/high10.rs +++ b/crates/ec-h264/tests/it/high10.rs @@ -5,12 +5,10 @@ //! 1. Committed fixtures in `tests/data/high10/`: tiny libx264 streams with the //! MD5 of ffmpeg's decode beside them, checked on every run with no ffmpeg. //! 2. A sweep that encodes synthetic sources with libx264 (`-profile:v high10`) -//! and compares every frame with ffmpeg's decode. It skips, saying so, when -//! ffmpeg or a 10-bit libx264 is absent, and fails instead when -//! `EC_REQUIRE_FIXTURES` is set. +//! and compares every frame with ffmpeg's decode. It fails when +//! ffmpeg or a 10-bit libx264 is absent. use std::path::{Path, PathBuf}; -use std::process::Command; use ec_core::frame::{PixelFormat, VideoFrame}; use ec_h264::{Decoder, NalOutcome}; @@ -54,7 +52,7 @@ fn decode_all(bytes: &[u8]) -> Result>, ec_h264::Error> { } fn ffmpeg_frames(stream: &Path, frame_len: usize) -> Option> { - let out = Command::new("ffmpeg") + let out = ec_testkit::ffmpeg() .args(["-v", "error", "-i"]) .arg(stream) .args(["-f", "rawvideo", "-pix_fmt", "yuv420p10le", "-"]) @@ -202,22 +200,14 @@ fn encode(dir: &Path, c: &Case) -> Option { "h264".into(), stream.to_string_lossy().into_owned(), ]); - let st = Command::new("ffmpeg").args(&args).status().ok()?; + let st = ec_testkit::ffmpeg().args(&args).status().ok()?; st.success().then_some(stream) } fn check(c: &Case) -> Result { let dir = scratch(); - let Some(stream) = encode(&dir, c) else { - if std::env::var_os("EC_REQUIRE_FIXTURES").is_some() { - panic!("{}: ffmpeg/libx264 10-bit cannot encode", c.tag); - } - eprintln!( - "SKIP {}: ffmpeg with 10-bit libx264 is not available", - c.tag - ); - return Ok(0); - }; + let stream = + encode(&dir, c).unwrap_or_else(|| panic!("{}: ffmpeg/libx264 10-bit cannot encode", c.tag)); let bytes = std::fs::read(&stream).map_err(|e| e.to_string())?; let ours = decode_all(&bytes).map_err(|e| format!("{}: {e}", c.tag))?; let first = ours.first().ok_or("no frames decoded")?; diff --git a/crates/ec-h264/tests/it/high422.rs b/crates/ec-h264/tests/it/high422.rs index 57d46fbc..9a3d0ef5 100644 --- a/crates/ec-h264/tests/it/high422.rs +++ b/crates/ec-h264/tests/it/high422.rs @@ -4,13 +4,11 @@ //! scaling matrices, chroma QP offsets, several slices, progressive and //! MBAFF, at 8 and 10 bits. //! -//! Every case is generated in the test (no committed binaries). A case skips, -//! saying so, when ffmpeg or the needed libx264 is absent, and fails instead -//! when `EC_REQUIRE_FIXTURES` is set. The 1920x1080 cases are slow enough to be +//! Every case is generated in the test (no committed binaries). A case fails when +//! ffmpeg or the needed libx264 is absent. The 1920x1080 cases are slow enough to be //! opt-in: set `EC_H264_HI422_HD=1` (the lane gate does). use std::path::{Path, PathBuf}; -use std::process::Command; use ec_h264::{Decoder, NalOutcome}; @@ -72,7 +70,7 @@ fn encode(dir: &Path, c: &Case) -> Option { } else { c.params.to_string() }; - let st = Command::new("ffmpeg") + let st = ec_testkit::ffmpeg() .args([ "-hide_banner", "-loglevel", @@ -99,16 +97,8 @@ fn encode(dir: &Path, c: &Case) -> Option { fn check(c: &Case) -> Result { let dir = scratch(); - let Some(stream) = encode(&dir, c) else { - if std::env::var_os("EC_REQUIRE_FIXTURES").is_some() { - panic!("{}: ffmpeg/libx264 cannot encode this case", c.tag); - } - eprintln!( - "SKIP {}: ffmpeg with the needed libx264 is not available", - c.tag - ); - return Ok(0); - }; + let stream = encode(&dir, c) + .unwrap_or_else(|| panic!("{}: ffmpeg/libx264 cannot encode this case", c.tag)); let bytes = std::fs::read(&stream).map_err(|e| e.to_string())?; let ours = decode_all(&bytes).map_err(|e| format!("{}: {e}", c.tag))?; let first = ours diff --git a/crates/ec-h264/tests/it/high422_jvt.rs b/crates/ec-h264/tests/it/high422_jvt.rs index 79600fda..cfb4721f 100644 --- a/crates/ec-h264/tests/it/high422_jvt.rs +++ b/crates/ec-h264/tests/it/high422_jvt.rs @@ -5,13 +5,11 @@ //! Where the archive carries a reference YUV (Hi422FR10..15) each frame is //! compared to it; the other streams ship only a trace, so every stream is //! also compared frame by frame with ffmpeg's decode (`yuv422p` or -//! `yuv422p10le`). Fixtures live in the gitignored root `fixtures/` -//! (`scripts/fetch-vectors.sh h264-jvt`); a missing set skips with a message, -//! or fails when `EC_REQUIRE_FIXTURES` is set. The two 1920x1088 field +//! `yuv422p10le`). Fixtures come from `scripts/fixtures.sh`; a missing set +//! fails. The two 1920x1088 field //! streams are slow in a debug build and are skipped there. use std::path::{Path, PathBuf}; -use std::process::Command; use ec_core::frame::PixelFormat; use ec_h264::{Decoder, NalOutcome}; @@ -19,7 +17,7 @@ use ec_h264::{Decoder, NalOutcome}; use super::common::{ffmpeg_pix_frames, frame_bytes}; fn root() -> PathBuf { - Path::new(env!("CARGO_MANIFEST_DIR")).join("../../fixtures/vectors/h264-jvt-hi422") + ec_testkit::fixture("vectors/h264-jvt-hi422") } /// Every elementary stream (`.264`, `.jsv`) below `dir`, sorted. @@ -90,28 +88,15 @@ fn compare(name: &str, ours: &[Vec], theirs: &[u8], who: &str) -> Result<(), Ok(()) } -fn have_set() -> Option> { +fn have_set() -> Vec { let list = streams(&root()); - if list.is_empty() { - assert!( - std::env::var_os("EC_REQUIRE_FIXTURES").is_none(), - "h264-jvt-hi422 missing at {} - this gate would prove nothing; run \ - scripts/fetch-vectors.sh h264-jvt", - root().display() - ); - eprintln!("SKIP h264-jvt-hi422 missing at {}", root().display()); - return None; - } - Some(list) + assert!(list.len() >= 18, "only {} Hi422 streams found", list.len()); + list } #[test] fn jvt_hi422_vectors_bit_exact() { - let Some(list) = have_set() else { return }; - if std::env::var_os("EC_REQUIRE_FIXTURES").is_some() { - assert!(list.len() >= 18, "only {} Hi422 streams found", list.len()); - } - let have_ffmpeg = Command::new("ffmpeg").arg("-version").output().is_ok(); + let list = have_set(); let mut failed = Vec::new(); let mut exact = Vec::new(); for path in &list { @@ -148,26 +133,16 @@ fn jvt_hi422_vectors_bit_exact() { ok = false; } } - if have_ffmpeg { - let pix = if format == PixelFormat::I210 { - "yuv422p10le" - } else { - "yuv422p" - }; - match ffmpeg_pix_frames(path, pix) { - Some(t) => { - if let Err(e) = compare(&name, &ours, &t, "ffmpeg") { - failed.push(e); - ok = false; - } - } - None => { - assert!( - std::env::var_os("EC_REQUIRE_FIXTURES").is_none(), - "{name}: ffmpeg cannot decode" - ); - } - } + let pix = if format == PixelFormat::I210 { + "yuv422p10le" + } else { + "yuv422p" + }; + let theirs = + ffmpeg_pix_frames(path, pix).unwrap_or_else(|| panic!("{name}: ffmpeg cannot decode")); + if let Err(e) = compare(&name, &ours, &theirs, "ffmpeg") { + failed.push(e); + ok = false; } if ok { exact.push(format!("{name} ({} frames, {format:?})", ours.len())); diff --git a/crates/ec-h264/tests/it/high444.rs b/crates/ec-h264/tests/it/high444.rs index 91e9e39d..072c7f85 100644 --- a/crates/ec-h264/tests/it/high444.rs +++ b/crates/ec-h264/tests/it/high444.rs @@ -10,13 +10,11 @@ //! or 512 at 10 bits). Separate colour planes cannot be written by x264; the //! JVT vectors (`high444_jvt.rs`) cover them. //! -//! Every case is generated in the test (no committed binaries). A case skips, -//! saying so, when ffmpeg or the needed libx264 is absent, and fails instead -//! when `EC_REQUIRE_FIXTURES` is set. The 1280x720 cases are opt-in: +//! Every case is generated in the test (no committed binaries). A case fails when +//! ffmpeg or the needed libx264 is absent. The 1280x720 cases are opt-in: //! set `EC_H264_HI444_HD=1`. use std::path::{Path, PathBuf}; -use std::process::Command; use ec_core::frame::{PixelFormat, VideoFrame}; use ec_h264::{Decoder, NalOutcome}; @@ -93,7 +91,7 @@ fn encode(dir: &Path, c: &Case) -> Option { } else { c.params.to_string() }; - let st = Command::new("ffmpeg") + let st = ec_testkit::ffmpeg() .args([ "-hide_banner", "-loglevel", @@ -121,16 +119,8 @@ fn encode(dir: &Path, c: &Case) -> Option { fn check(c: &Case) -> Result { let dir = scratch(); - let Some(stream) = encode(&dir, c) else { - if std::env::var_os("EC_REQUIRE_FIXTURES").is_some() { - panic!("{}: ffmpeg/libx264 cannot encode this case", c.tag); - } - eprintln!( - "SKIP {}: ffmpeg with the needed libx264 is not available", - c.tag - ); - return Ok(0); - }; + let stream = encode(&dir, c) + .unwrap_or_else(|| panic!("{}: ffmpeg/libx264 cannot encode this case", c.tag)); let bytes = std::fs::read(&stream).map_err(|e| e.to_string())?; let ours = decode_all(&bytes).map_err(|e| format!("{}: {e}", c.tag))?; let (first, format) = ours diff --git a/crates/ec-h264/tests/it/high444_jvt.rs b/crates/ec-h264/tests/it/high444_jvt.rs index 9af85a15..b23f1cb0 100644 --- a/crates/ec-h264/tests/it/high444_jvt.rs +++ b/crates/ec-h264/tests/it/high444_jvt.rs @@ -8,13 +8,12 @@ //! the archive ships a reference YUV, that YUV is used instead of / as well as //! ffmpeg; a stream with neither is reported `unchecked` (and counted as a //! failure only if it also fails to decode). Fixtures live in the gitignored -//! root `fixtures/vectors/h264-jvt-hi444`; a missing set skips with a message, -//! or fails when `EC_REQUIRE_FIXTURES` is set. Heavy streams are skipped in +//! root `fixtures/vectors/h264-jvt-hi444`; a missing set fails. Heavy streams are skipped in //! debug builds. use std::io::Read; use std::path::{Path, PathBuf}; -use std::process::{Command, Stdio}; +use std::process::Stdio; use ec_core::frame::{PixelFormat, VideoFrame}; use ec_h264::{Decoder, NalOutcome}; @@ -22,7 +21,7 @@ use ec_h264::{Decoder, NalOutcome}; use super::common::layout; fn root() -> PathBuf { - Path::new(env!("CARGO_MANIFEST_DIR")).join("../../fixtures/vectors/h264-jvt-hi444") + ec_testkit::fixture("vectors/h264-jvt-hi444") } const STREAM_EXT: &[&str] = &["264", "jsv", "avc", "26l", "h264", "bit", "bits", "jvt"]; @@ -127,7 +126,7 @@ fn decode_all(bytes: &[u8]) -> Result { } fn probe_pix_fmt(stream: &Path) -> Option { - let out = Command::new("ffprobe") + let out = ec_testkit::ffprobe() .args(["-v", "error", "-f", "h264", "-select_streams", "v:0"]) .args(["-show_entries", "stream=pix_fmt", "-of", "csv=p=0"]) .arg(stream) @@ -140,7 +139,7 @@ fn probe_pix_fmt(stream: &Path) -> Option { /// ffmpeg's raw decode as a pipe, so a long 14-bit 4:4:4 stream is compared a /// frame at a time instead of held in memory. fn ffmpeg_pipe(stream: &Path, pix_fmt: &str) -> Option { - Command::new("ffmpeg") + ec_testkit::ffmpeg() .args(["-v", "error", "-f", "h264", "-i"]) .arg(stream) .args(["-f", "rawvideo", "-pix_fmt", pix_fmt, "-"]) @@ -205,17 +204,11 @@ fn reference_yuv(stream: &Path) -> Option { #[test] fn jvt_hi444_vectors_bit_exact() { let list = streams(&root()); - if list.is_empty() { - assert!( - std::env::var_os("EC_REQUIRE_FIXTURES").is_none(), - "h264-jvt-hi444 missing at {} - this gate would prove nothing; run \ - scripts/fetch-vectors.sh h264-jvt-hi444", - root().display() - ); - eprintln!("SKIP h264-jvt-hi444 missing at {}", root().display()); - return; - } - let have_ffmpeg = Command::new("ffmpeg").arg("-version").output().is_ok(); + assert!( + !list.is_empty(), + "no h264-jvt-hi444 streams in {}", + root().display() + ); let mut failed = Vec::new(); let mut summary = Vec::new(); for path in &list { @@ -262,41 +255,39 @@ fn jvt_hi444_vectors_bit_exact() { Err(e) => errors.push(e), } } - if have_ffmpeg { - // 9-bit streams are left-aligned to 10 bits by us. - let pix = match probe_pix_fmt(path).as_deref() { - Some("gray") => "gray".to_string(), - Some("gray10le" | "gray12le" | "gray9le") => "gray10le".to_string(), - Some(p) if p.contains("p9") => p.replace("p9", "p10"), - Some(p) => p.to_string(), - None => match format { - PixelFormat::I410 => "yuv444p10le".into(), - PixelFormat::I444 => "yuv444p".into(), - _ => String::new(), - }, - }; - let luma_only = pix.starts_with("gray"); - match (!pix.is_empty() && pix != "unknown") - .then(|| ffmpeg_pipe(path, &pix)) - .flatten() - { - Some(mut child) => { - let res = compare( - &name, - &ours, - child.stdout.as_mut().unwrap(), - luma_only, - "ffmpeg", - ); - let _ = child.kill(); - let _ = child.wait(); - match res { - Ok(()) => checked.push("ffmpeg"), - Err(e) => errors.push(e), - } + // 9-bit streams are left-aligned to 10 bits by us. + let pix = match probe_pix_fmt(path).as_deref() { + Some("gray") => "gray".to_string(), + Some("gray10le" | "gray12le" | "gray9le") => "gray10le".to_string(), + Some(p) if p.contains("p9") => p.replace("p9", "p10"), + Some(p) => p.to_string(), + None => match format { + PixelFormat::I410 => "yuv444p10le".into(), + PixelFormat::I444 => "yuv444p".into(), + _ => String::new(), + }, + }; + let luma_only = pix.starts_with("gray"); + match (!pix.is_empty() && pix != "unknown") + .then(|| ffmpeg_pipe(path, &pix)) + .flatten() + { + Some(mut child) => { + let res = compare( + &name, + &ours, + child.stdout.as_mut().unwrap(), + luma_only, + "ffmpeg", + ); + let _ = child.kill(); + let _ = child.wait(); + match res { + Ok(()) => checked.push("ffmpeg"), + Err(e) => errors.push(e), } - None => eprintln!("note {name}: ffmpeg cannot decode (pix_fmt {pix:?})"), } + None => eprintln!("note {name}: ffmpeg cannot decode (pix_fmt {pix:?})"), } if !errors.is_empty() { eprintln!("FAIL {name}: {}", errors.join("; ")); diff --git a/crates/ec-h264/tests/it/interlaced.rs b/crates/ec-h264/tests/it/interlaced.rs index b1669e26..eeffd04f 100644 --- a/crates/ec-h264/tests/it/interlaced.rs +++ b/crates/ec-h264/tests/it/interlaced.rs @@ -2,42 +2,26 @@ //! macroblock-adaptive frame/field coding (MBAFF), woven into frames. //! //! The authority is the JVT conformance suite: each vector's reference YUV is -//! compared frame by frame. Fixtures live in the gitignored root `fixtures/` -//! (`scripts/fetch-vectors.sh`); a missing one skips with a message, or fails -//! when `EC_REQUIRE_FIXTURES` is set, like the other conformance tests. +//! compared frame by frame. Fixtures come from `scripts/fixtures.sh`; a missing one fails. use std::path::{Path, PathBuf}; use ec_core::frame::{Interlace, VideoFrame}; use ec_h264::{Decoder, NalOutcome}; -/// Where a vector lives: the interlaced set (`scripts/fetch-vectors.sh`), or +/// Where a vector lives: the interlaced set (`scripts/fixtures.sh`), or /// the general JVT set for the few interlaced streams that were fetched first. fn vector_dir(name: &str) -> PathBuf { - let root = Path::new(env!("CARGO_MANIFEST_DIR")).join("../../fixtures/vectors"); - let own = root.join("h264-jvt-interlaced").join(name); + let own = ec_testkit::root() + .join("vectors/h264-jvt-interlaced") + .join(name); if own.exists() { own } else { - root.join("h264-jvt").join(name) + ec_testkit::fixture(&format!("vectors/h264-jvt/{name}")) } } -/// True when `path` exists; otherwise skip (or fail under `EC_REQUIRE_FIXTURES`). -fn have_fixture(path: &Path, what: &str) -> bool { - if path.exists() { - return true; - } - assert!( - std::env::var_os("EC_REQUIRE_FIXTURES").is_none(), - "{what} missing at {} - this gate would prove nothing; run \ - scripts/link-fixtures.sh or scripts/fetch-vectors.sh", - path.display() - ); - eprintln!("SKIP {what} missing at {}", path.display()); - false -} - fn find_with_ext(dir: &Path, exts: &[&str]) -> Option { let mut found: Vec = std::fs::read_dir(dir) .ok()? @@ -92,9 +76,6 @@ fn decode_all(bytes: &[u8]) -> Result, Interlace)>, ec_h264::Error> /// Decode one JVT vector and compare it with its reference YUV. fn check_vector(name: &str) -> Result { let dir = vector_dir(name); - if !have_fixture(&dir, &format!("JVT vector {name}")) { - return Ok(0); - } let stream = find_with_ext(&dir, &["jsv", "264", "avc", "26l", "h264", "jvt"]) .ok_or(format!("{name}: no bitstream"))?; let yuv = find_with_ext(&dir, &["yuv"]).ok_or(format!("{name}: no reference YUV"))?; diff --git a/crates/ec-h264/tests/it/mbaff_x264.rs b/crates/ec-h264/tests/it/mbaff_x264.rs index e5751bda..5a692553 100644 --- a/crates/ec-h264/tests/it/mbaff_x264.rs +++ b/crates/ec-h264/tests/it/mbaff_x264.rs @@ -4,13 +4,11 @@ //! spatial and temporal direct, weighted prediction, the 8x8 transform, //! several slices, and High 10. //! -//! Every case is generated in the test (no committed binaries). A case skips, -//! saying so, when ffmpeg or the needed libx264 is absent, and fails instead -//! when `EC_REQUIRE_FIXTURES` is set. The 1920x1080 cases are slow enough to be +//! Every case is generated in the test (no committed binaries). A case fails when +//! ffmpeg or the needed libx264 is absent. The 1920x1080 cases are slow enough to be //! opt-in: set `EC_H264_MBAFF_HD=1` (the lane gate does). use std::path::{Path, PathBuf}; -use std::process::Command; use ec_core::frame::{PixelFormat, VideoFrame}; use ec_h264::{Decoder, NalOutcome}; @@ -89,7 +87,7 @@ fn encode(dir: &Path, c: &Case) -> Option { ("yuv420p", "high") }; let params = format!("interlaced=1:{}", c.params); - let st = Command::new("ffmpeg") + let st = ec_testkit::ffmpeg() .args([ "-hide_banner", "-loglevel", @@ -112,16 +110,8 @@ fn encode(dir: &Path, c: &Case) -> Option { fn check(c: &Case) -> Result { let dir = scratch(); - let Some(stream) = encode(&dir, c) else { - if std::env::var_os("EC_REQUIRE_FIXTURES").is_some() { - panic!("{}: ffmpeg/libx264 cannot encode this case", c.tag); - } - eprintln!( - "SKIP {}: ffmpeg with the needed libx264 is not available", - c.tag - ); - return Ok(0); - }; + let stream = encode(&dir, c) + .unwrap_or_else(|| panic!("{}: ffmpeg/libx264 cannot encode this case", c.tag)); let bytes = std::fs::read(&stream).map_err(|e| e.to_string())?; let ours = decode_all(&bytes).map_err(|e| format!("{}: {e}", c.tag))?; let first = ours diff --git a/crates/ec-h264/tests/it/no_panic.rs b/crates/ec-h264/tests/it/no_panic.rs index 30c111c8..b0027ce5 100644 --- a/crates/ec-h264/tests/it/no_panic.rs +++ b/crates/ec-h264/tests/it/no_panic.rs @@ -5,8 +5,7 @@ //! fixed-seed positions. Every mutant is decoded end to end. An `Err` is fine; //! a panic fails the test. //! -//! Fixture-gated like the other conformance tests: without `fixtures/` the test -//! skips loudly, or fails when `EC_REQUIRE_FIXTURES` is set. +//! Fixtures come from `scripts/fixtures.sh`; a missing one fails. use std::path::{Path, PathBuf}; @@ -20,7 +19,7 @@ const CORRUPTIONS: usize = 30; const SEED: u32 = 0x9E37_79B9; fn vectors_dir() -> PathBuf { - Path::new(env!("CARGO_MANIFEST_DIR")).join("../../fixtures/vectors/h264-jvt") + ec_testkit::fixture("vectors/h264-jvt") } /// Every vector directory, in name order (the order `conformance.rs` walks). @@ -53,15 +52,6 @@ fn decode_everything(bytes: &[u8]) { #[test] fn truncated_and_corrupted_conformance_streams_never_panic() { let base = vectors_dir(); - if !base.exists() { - assert!( - std::env::var_os("EC_REQUIRE_FIXTURES").is_none(), - "JVT vectors missing at {} — run scripts/link-fixtures.sh or scripts/fetch-vectors.sh", - base.display() - ); - eprintln!("SKIP JVT vectors missing at {}", base.display()); - return; - } let mut streams = 0usize; for name in vector_names(&base).into_iter().take(STREAMS) { let Some(stream) = find_stream(&base.join(&name)) else { diff --git a/crates/ec-h264/tests/it/refusals.rs b/crates/ec-h264/tests/it/refusals.rs index ce7fa4c0..59cf4e73 100644 --- a/crates/ec-h264/tests/it/refusals.rs +++ b/crates/ec-h264/tests/it/refusals.rs @@ -10,8 +10,6 @@ //! maps every refused JVT conformance vector to the feature it really uses, //! and is fixture-gated like `conformance.rs`. -use std::path::Path; - use ec_core::BitWriter; use ec_h264::{Decoder, Error, NalOutcome}; @@ -294,21 +292,12 @@ fn different_luma_and_chroma_bit_depth_is_refused_by_name() { } } -/// Every refused vector in `fetch-vectors.sh`'s h264-jvt set, against the +/// Every refused vector in the h264-jvt set in `scripts/fixtures.sh`, against the /// feature it really uses. A vector that starts refusing for another reason, /// or stops being refused, changes this table and fails the test. #[test] fn jvt_refused_vectors_refuse_for_their_feature() { - let base = Path::new(env!("CARGO_MANIFEST_DIR")).join("../../fixtures/vectors/h264-jvt"); - if !base.exists() { - assert!( - std::env::var_os("EC_REQUIRE_FIXTURES").is_none(), - "JVT vectors missing at {} (run scripts/fetch-vectors.sh)", - base.display() - ); - eprintln!("SKIP JVT vectors missing at {}", base.display()); - return; - } + let base = ec_testkit::fixture("vectors/h264-jvt"); let expected: &[(&str, &str)] = &[]; let mut failures = Vec::new(); for &(name, feature) in expected { diff --git a/crates/ec-h265-syntax/Cargo.toml b/crates/ec-h265-syntax/Cargo.toml index af64454d..0871160b 100644 --- a/crates/ec-h265-syntax/Cargo.toml +++ b/crates/ec-h265-syntax/Cargo.toml @@ -8,3 +8,6 @@ authors.workspace = true [dependencies] ec-core.workspace = true + +[dev-dependencies] +ec-testkit.workspace = true diff --git a/crates/ec-h265-syntax/tests/sei_sweep.rs b/crates/ec-h265-syntax/tests/sei_sweep.rs index 07958751..2773aa94 100644 --- a/crates/ec-h265-syntax/tests/sei_sweep.rs +++ b/crates/ec-h265-syntax/tests/sei_sweep.rs @@ -1,22 +1,18 @@ //! The SEI reader over the JCT-VC conformance streams. //! //! Every prefix and suffix SEI NAL unit of every stream must parse without error, -//! and the streams that carry a `decoded_picture_hash` are counted. The sweep is -//! skipped when the vectors are absent, unless `EC_REQUIRE_FIXTURES` is set, in -//! which case an absent fixture fails the test. +//! and the streams that carry a `decoded_picture_hash` are counted. The sweep fails +//! when the vectors are absent. use std::path::{Path, PathBuf}; use ec_h265_syntax::nal::split_annex_b; use ec_h265_syntax::sei::{SeiMessage, parse_sei_rbsp}; -/// Every `.bin` or `.bit` stream under `fixtures/vectors/hevc-jctvc`, two directory -/// levels deep, sorted by path. `EC_H265_JCTVC_DIR` overrides the root. +/// Every `.bin` or `.bit` stream under `vectors/hevc-jctvc` in the fixtures root, two +/// directory levels deep, sorted by path. fn streams() -> Vec { - let root = match std::env::var("EC_H265_JCTVC_DIR") { - Ok(dir) => PathBuf::from(dir), - Err(_) => Path::new(env!("CARGO_MANIFEST_DIR")).join("../../fixtures/vectors/hevc-jctvc"), - }; + let root = ec_testkit::fixture("vectors/hevc-jctvc"); fn walk(dir: &Path, depth: u32, out: &mut Vec) { let Ok(entries) = std::fs::read_dir(dir) else { return; @@ -39,14 +35,7 @@ fn streams() -> Vec { #[test] fn every_sei_in_the_conformance_streams_parses() { let streams = streams(); - if streams.is_empty() { - assert!( - std::env::var_os("EC_REQUIRE_FIXTURES").is_none(), - "EC_REQUIRE_FIXTURES=1 but fixtures/vectors/hevc-jctvc has no streams" - ); - eprintln!("SEI sweep skipped: vectors absent"); - return; - } + assert!(!streams.is_empty(), "no streams under vectors/hevc-jctvc"); let mut with_hash = 0usize; let mut hash_streams = Vec::new(); let mut sei_nals = 0usize; diff --git a/crates/ec-h265/Cargo.toml b/crates/ec-h265/Cargo.toml index 5ebde593..4e42e6b7 100644 --- a/crates/ec-h265/Cargo.toml +++ b/crates/ec-h265/Cargo.toml @@ -15,4 +15,5 @@ archmage = "=0.9.31-beta.1" multiversion = "0.9" [dev-dependencies] +ec-testkit.workspace = true ec-h265-syntax.workspace = true diff --git a/crates/ec-h265/tests/it/conformance.rs b/crates/ec-h265/tests/it/conformance.rs index 59223582..8b1f45fd 100644 --- a/crates/ec-h265/tests/it/conformance.rs +++ b/crates/ec-h265/tests/it/conformance.rs @@ -8,7 +8,6 @@ use crate::common::{natural_frame, pin_or_panic, test_frame}; use ec_core::frame::VideoFrame; use ec_h265::encoder::{EncodedPicture, Encoder, EncoderConfig, RateControl, TransformSkip}; use std::path::{Path, PathBuf}; -use std::process::Command; fn scratch_dir() -> PathBuf { let dir = std::env::temp_dir().join("ec-h265-tests"); @@ -16,18 +15,10 @@ fn scratch_dir() -> PathBuf { dir } -fn have_ffmpeg() -> bool { - Command::new("ffmpeg") - .arg("-version") - .output() - .map(|o| o.status.success()) - .unwrap_or(false) -} - /// Decode an Annex-B file with ffmpeg into planar 8-bit 4:2:0. fn ffmpeg_decode(path: &Path) -> Result, String> { let out = path.with_extension("yuv"); - let status = Command::new("ffmpeg") + let status = ec_testkit::ffmpeg() .args(["-v", "error", "-y", "-i"]) .arg(path) .args(["-f", "rawvideo", "-pix_fmt", "yuv420p"]) @@ -147,10 +138,6 @@ fn encode_natural( /// the search actually fired — and still decode bit-exactly. #[test] fn chroma_mode_search_decodes_bit_exactly() { - if !have_ffmpeg() { - eprintln!("skipping: ffmpeg not installed"); - return; - } for &(w, h) in &[(64u32, 64u32), (130, 66), (352, 288)] { let (source, coded) = encode_with(w, h, 27, None, true, false); let (_, derived) = encode_with(w, h, 27, None, false, false); @@ -224,10 +211,6 @@ fn chroma_mode_search_decodes_bit_exactly() { /// partition are all where the decoder looks for them. #[test] fn intra_nxn_decodes_bit_exactly() { - if !have_ffmpeg() { - eprintln!("skipping: ffmpeg not installed"); - return; - } for &(w, h) in &[(64u32, 64u32), (130, 66), (352, 288)] { let (source, coded) = encode_natural(w, h, 22, true); let (_, square) = encode_natural(w, h, 22, false); @@ -305,10 +288,6 @@ fn intra_nxn_decodes_bit_exactly() { /// `EC_H265_SDH` arm of the clip gate measures. #[test] fn sign_hiding_decodes_bit_exactly() { - if !have_ffmpeg() { - eprintln!("skipping: ffmpeg not installed"); - return; - } for &(w, h) in &[(64u32, 64u32), (130, 66), (352, 288)] { let (source, coded) = encode_sdh(w, h, 22, true); let (_, plain) = encode_sdh(w, h, 22, false); @@ -414,10 +393,6 @@ fn encode_tskip( /// sample for sample. #[test] fn transform_skip_decodes_bit_exactly() { - if !have_ffmpeg() { - eprintln!("skipping: ffmpeg not installed"); - return; - } for &(w, h) in &[(64u32, 64u32), (130, 66), (352, 288)] { let (source, coded) = encode_tskip(w, h, 22, TransformSkip::AlwaysFor4x4); let (_, plain) = encode_tskip(w, h, 22, TransformSkip::Off); @@ -484,10 +459,6 @@ fn transform_skip_decodes_bit_exactly() { } #[test] fn ffmpeg_decodes_bit_exactly_at_every_shape() { - if !have_ffmpeg() { - eprintln!("skipping: ffmpeg not installed"); - return; - } // 1920x1080 needs the conformance window on the bottom (1088 coded rows are // not used: 1080 is a multiple of 8, but 64x64 CTBs still overhang), 1916 // needs it on the right, 130x66 exercises a partial CTB in both directions. @@ -577,10 +548,6 @@ fn ffmpeg_decodes_bit_exactly_at_every_shape() { /// pass without a single 64x64 coding unit ever being kept. #[test] fn cu64_decodes_bit_exactly() { - if !have_ffmpeg() { - eprintln!("skipping: ffmpeg not installed"); - return; - } // 130x66 is here for the partial coding tree blocks, not for the decision: // at that size only two tree blocks are whole and the search keeps neither, // so its stream is allowed to come out identical. @@ -684,13 +651,9 @@ fn ffmpeg_verifies_the_decoded_picture_hash() { // decoder checks that claim against what it decoded when asked to. This is // the one oracle that does not depend on this crate being right about // anything except the hash itself. - if !have_ffmpeg() { - eprintln!("skipping: ffmpeg not installed"); - return; - } let (_, coded) = encode(352, 288, 30, None); let path = write_au("hash-352x288", &coded); - let output = Command::new("ffmpeg") + let output = ec_testkit::ffmpeg() .args(["-v", "debug", "-err_detect", "crccheck", "-y", "-i"]) .arg(&path) .args(["-f", "null", "-"]) @@ -712,13 +675,13 @@ fn vaapi_hardware_decodes_the_stream() { // The other half of "it decodes": a GPU decoder is a different // implementation with different tolerances, and it is what edith's HEVC // path actually uses. Skipped where there is no render node. - if !have_ffmpeg() || !Path::new("/dev/dri/renderD128").exists() { - eprintln!("skipping: no ffmpeg or no VA-API render node"); + if !Path::new("/dev/dri/renderD128").exists() { + eprintln!("skipping: no VA-API render node"); return; } let (_, coded) = encode(1920, 1080, 27, None); let path = write_au("vaapi-1080p", &coded); - let output = Command::new("ffmpeg") + let output = ec_testkit::ffmpeg() .args([ "-v", "error", @@ -838,10 +801,6 @@ fn the_batch_helper_codes_every_picture_as_its_own_access_unit() { /// has to read them back to the same samples the encoder reconstructed. #[test] fn rdoq_decodes_bit_exactly() { - if !have_ffmpeg() { - eprintln!("skipping: ffmpeg not installed"); - return; - } for &(w, h) in &[(64u32, 64u32), (130, 66), (352, 288)] { let (source, coded) = encode_rdoq(w, h, 27, true); let (_, plain) = encode_rdoq(w, h, 27, false); @@ -925,10 +884,6 @@ fn encode_rdoq(width: u32, height: u32, qp: i32, rdoq: bool) -> (VideoFrame, Enc /// samples the encoder reconstructed. #[test] fn rqt_decodes_bit_exactly() { - if !have_ffmpeg() { - eprintln!("skipping: ffmpeg not installed"); - return; - } for &(w, h) in &[(64u32, 64u32), (130, 66), (352, 288)] { let (source, coded) = encode_rqt(w, h, 27, true); let (_, plain) = encode_rqt(w, h, 27, false); diff --git a/crates/ec-h265/tests/it/conformance_intra.rs b/crates/ec-h265/tests/it/conformance_intra.rs index 9988b989..90601919 100644 --- a/crates/ec-h265/tests/it/conformance_intra.rs +++ b/crates/ec-h265/tests/it/conformance_intra.rs @@ -24,12 +24,9 @@ struct Row { decode_secs: f64, } -/// The conformance directory: `EC_H265_JCTVC_DIR`, or the fixtures link. +/// The conformance directory under the fixtures root. fn jctvc_root() -> PathBuf { - match std::env::var("EC_H265_JCTVC_DIR") { - Ok(dir) => PathBuf::from(dir), - Err(_) => Path::new(env!("CARGO_MANIFEST_DIR")).join("../../fixtures/vectors/hevc-jctvc"), - } + ec_testkit::fixture("vectors/hevc-jctvc") } /// The conformance streams: the first `.bin` or `.bit` bitstream of each zip's @@ -67,7 +64,7 @@ fn streams() -> Vec { } /// Decodes one stream and checks every output picture against its MD5 SEI. -fn check_stream(path: &Path, name: &str, ref_dir: Option<&Path>) -> Row { +fn check_stream(path: &Path, name: &str) -> Row { let mut row = Row { name: name.to_string(), accepted: "no", @@ -84,7 +81,7 @@ fn check_stream(path: &Path, name: &str, ref_dir: Option<&Path>) -> Row { return row; } }; - let reference = ref_dir.and_then(|d| std::fs::read(d.join(format!("{name}.yuv"))).ok()); + let reference = std::fs::read(path.with_extension("yuv")).ok(); // A `_md5.txt` beside the bitstream is the authority for frames without a hash SEI. It // takes precedence over the ffmpeg reference YUV, which ffmpeg cannot reproduce for such a // stream (VPSSPSPPS_A: ffmpeg outputs 2 of its 6 frames). @@ -120,17 +117,6 @@ fn check_stream(path: &Path, name: &str, ref_dir: Option<&Path>) -> Row { // No hash SEI: the frame is checked against the reference YUV, when there is one. if let Some(reference) = reference.as_deref() { let want = cropped_bytes(&frame.picture, &frame.window); - if let Ok(dir) = std::env::var("EC_H265_DUMP_DIR") { - // Diagnostic: append this frame to the stream's dump file. - use std::io::Write; - if let Ok(mut f) = std::fs::OpenOptions::new() - .create(true) - .append(true) - .open(Path::new(&dir).join(format!("{name}.ours.yuv"))) - { - let _ = f.write_all(&want); - } - } let start = index * want.len(); row.checked += 1; if reference.get(start..start + want.len()) == Some(&want[..]) { @@ -197,19 +183,11 @@ fn check_stream(path: &Path, name: &str, ref_dir: Option<&Path>) -> Row { fn conformance_pictures_match_the_sei_hash() { let root = jctvc_root(); let streams = streams(); - if streams.is_empty() { - eprintln!( - "conformance check skipped: no streams under {}", - root.display() - ); - assert!( - !root.is_dir(), - "fixture directory {} exists but holds no bitstreams", - root.display() - ); - return; - } - let ref_dir = std::env::var("EC_H265_REF_YUV_DIR").ok().map(PathBuf::from); + assert!( + !streams.is_empty(), + "no conformance streams under {}", + root.display() + ); let mut rows = Vec::new(); for path in &streams { @@ -217,9 +195,7 @@ fn conformance_pictures_match_the_sei_hash() { .file_stem() .map(|s| s.to_string_lossy().into_owned()) .unwrap_or_default(); - let outcome = panic::catch_unwind(AssertUnwindSafe(|| { - check_stream(path, &name, ref_dir.as_deref()) - })); + let outcome = panic::catch_unwind(AssertUnwindSafe(|| check_stream(path, &name))); let mut row = match outcome { Ok(row) => row, Err(payload) => { diff --git a/crates/ec-h265/tests/it/conformance_rext.rs b/crates/ec-h265/tests/it/conformance_rext.rs index 5fe7e6c9..e69259c1 100644 --- a/crates/ec-h265/tests/it/conformance_rext.rs +++ b/crates/ec-h265/tests/it/conformance_rext.rs @@ -1,5 +1,5 @@ //! Checks every output picture of each JCT-VC range extension conformance stream -//! (`scripts/fetch-vectors.sh hevc-rext`) against the hash in its decoded picture hash SEI +//! (`scripts/fixtures.sh`, `vectors/hevc-rext`) against the hash in its decoded picture hash SEI //! (D.3.19), or against the whole-output MD5 of the package when the stream has no hash. //! //! A stream the decoder refuses must be refused by name: the error text has to be one of @@ -24,12 +24,9 @@ struct Row { decode_secs: f64, } -/// The conformance directory: `EC_H265_REXT_DIR`, or the fixtures link. +/// The conformance directory under the fixtures root. fn jctvc_root() -> PathBuf { - match std::env::var("EC_H265_REXT_DIR") { - Ok(dir) => PathBuf::from(dir), - Err(_) => Path::new(env!("CARGO_MANIFEST_DIR")).join("../../fixtures/vectors/hevc-rext"), - } + ec_testkit::fixture("vectors/hevc-rext") } /// The conformance streams: the first `.bin` or `.bit` bitstream of each zip's @@ -106,7 +103,7 @@ fn nal_chunks(data: &[u8]) -> Vec<&[u8]> { } /// Decodes one stream and checks every output picture against its MD5 SEI. -fn check_stream(path: &Path, name: &str, ref_dir: Option<&Path>) -> Row { +fn check_stream(path: &Path, name: &str) -> Row { let mut row = Row { name: name.to_string(), accepted: "no", @@ -123,7 +120,7 @@ fn check_stream(path: &Path, name: &str, ref_dir: Option<&Path>) -> Row { return row; } }; - let reference = ref_dir.and_then(|d| std::fs::read(d.join(format!("{name}.yuv"))).ok()); + let reference = std::fs::read(path.with_extension("yuv")).ok(); // A `_md5.txt` beside the bitstream is the authority for frames without a hash SEI. It // takes precedence over the ffmpeg reference YUV, which ffmpeg cannot reproduce for such a // stream (VPSSPSPPS_A: ffmpeg outputs 2 of its 6 frames). @@ -149,17 +146,6 @@ fn check_stream(path: &Path, name: &str, ref_dir: Option<&Path>) -> Row { // No hash SEI: the frame is checked against the reference YUV, when there is one. if let Some(reference) = reference.as_deref() { let want = cropped_bytes(&frame.picture, &frame.window); - if let Ok(dir) = std::env::var("EC_H265_DUMP_DIR") { - // Diagnostic: append this frame to the stream's dump file. - use std::io::Write; - if let Ok(mut f) = std::fs::OpenOptions::new() - .create(true) - .append(true) - .open(Path::new(&dir).join(format!("{name}.ours.yuv"))) - { - let _ = f.write_all(&want); - } - } let start = index * want.len(); row.checked += 1; if reference.get(start..start + want.len()) == Some(&want[..]) { @@ -244,19 +230,11 @@ fn check_stream(path: &Path, name: &str, ref_dir: Option<&Path>) -> Row { fn rext_conformance_pictures_match_the_sei_hash() { let root = jctvc_root(); let streams = streams(); - if streams.is_empty() { - eprintln!( - "conformance check skipped: no streams under {}", - root.display() - ); - assert!( - std::env::var_os("EC_REQUIRE_FIXTURES").is_none() && !root.is_dir(), - "fixture directory {} holds no bitstreams", - root.display() - ); - return; - } - let ref_dir = std::env::var("EC_H265_REF_YUV_DIR").ok().map(PathBuf::from); + assert!( + !streams.is_empty(), + "no conformance streams under {}", + root.display() + ); let mut rows = Vec::new(); for path in &streams { @@ -265,9 +243,7 @@ fn rext_conformance_pictures_match_the_sei_hash() { .map(|s| s.to_string_lossy().into_owned()) .unwrap_or_default(); eprintln!("stream {name}"); - let outcome = panic::catch_unwind(AssertUnwindSafe(|| { - check_stream(path, &name, ref_dir.as_deref()) - })); + let outcome = panic::catch_unwind(AssertUnwindSafe(|| check_stream(path, &name))); let mut row = match outcome { Ok(row) => row, Err(payload) => { diff --git a/crates/ec-h265/tests/it/conformance_rext422.rs b/crates/ec-h265/tests/it/conformance_rext422.rs index 0a8293bb..9d54be7d 100644 --- a/crates/ec-h265/tests/it/conformance_rext422.rs +++ b/crates/ec-h265/tests/it/conformance_rext422.rs @@ -2,12 +2,10 @@ //! //! The committed 64x64 stream is decoded by ffmpeg at run time and compared sample for //! sample. The Sony RExt conformance streams and the generated GOP/intra clips live in the -//! gitignored fixtures (`EC_H265_REXT_DIR`, default `fixtures/vectors/hevc-rext`, with the -//! ffmpeg output of each stream under `ref/` or next to it); a missing fixture is skipped -//! and reported, a present one must decode byte-exactly. +//! fixtures (`vectors/hevc-rext`, with the ffmpeg output of each stream under `ref/` or next +//! to it); a missing fixture fails, and every present one must decode byte-exactly. use std::path::{Path, PathBuf}; -use std::process::Command; use ec_h265::Decoder; @@ -59,16 +57,12 @@ fn first_diff(a: &[u8], b: &[u8]) -> Option { #[test] fn committed_422_stream_matches_ffmpeg() { - if Command::new("ffmpeg").arg("-version").output().is_err() { - eprintln!("skip: no ffmpeg"); - return; - } let dir = std::env::temp_dir().join("ec-h265-rext422"); std::fs::create_dir_all(&dir).unwrap(); let src = dir.join("yuv422_10.265"); let reference = dir.join("yuv422_10.yuv"); std::fs::write(&src, YUV422_10).unwrap(); - let st = Command::new("ffmpeg") + let st = ec_testkit::ffmpeg() .args(["-v", "error", "-y", "-i"]) .arg(&src) .args(["-f", "rawvideo", "-pix_fmt", "yuv422p10le"]) @@ -86,10 +80,7 @@ fn committed_422_stream_matches_ffmpeg() { } fn rext_root() -> PathBuf { - match std::env::var("EC_H265_REXT_DIR") { - Ok(d) => PathBuf::from(d), - Err(_) => Path::new(env!("CARGO_MANIFEST_DIR")).join("../../fixtures/vectors/hevc-rext"), - } + ec_testkit::fixture("vectors/hevc-rext") } fn find_stream(dir: &Path) -> Option { @@ -116,9 +107,8 @@ fn rext_422_vectors_are_byte_exact() { ("Main_422_10_A_RExt_Sony_2", 1920, 1080), ("Main_422_10_B_RExt_Sony_2", 2560, 1600), ] { - if let Some(s) = find_stream(&root.join(name)) { - cases.push((s, root.join("ref").join(format!("{name}.yuv")), w, h)); - } + let s = find_stream(&root.join(name)).unwrap_or_else(|| panic!("{name}: no stream")); + cases.push((s, root.join("ref").join(format!("{name}.yuv")), w, h)); } for name in [ "i422_8", @@ -137,10 +127,9 @@ fn rext_422_vectors_are_byte_exact() { } let mut checked = 0; for (stream, reference, w, h) in cases { - let (Ok(data), Ok(want)) = (std::fs::read(&stream), std::fs::read(&reference)) else { - eprintln!("skip (fixture missing): {}", stream.display()); - continue; - }; + let data = std::fs::read(&stream).unwrap_or_else(|e| panic!("{}: {e}", stream.display())); + let want = + std::fs::read(&reference).unwrap_or_else(|e| panic!("{}: {e}", reference.display())); let got = raw(&decode(&data), w, h); assert_eq!( first_diff(&got, &want), diff --git a/crates/ec-h265/tests/it/cu_syntax.rs b/crates/ec-h265/tests/it/cu_syntax.rs index a8735482..5be673ad 100644 --- a/crates/ec-h265/tests/it/cu_syntax.rs +++ b/crates/ec-h265/tests/it/cu_syntax.rs @@ -7,12 +7,9 @@ use ec_h265::dec::Decoder; use std::path::{Path, PathBuf}; /// The conformance streams: the first `.bin` or `.bit` bitstream of each directory -/// under `fixtures/vectors/hevc-jctvc` (or `EC_H265_JCTVC_DIR`), sorted. +/// under `vectors/hevc-jctvc` in the fixtures root, sorted. fn streams() -> Vec { - let root = match std::env::var("EC_H265_JCTVC_DIR") { - Ok(dir) => PathBuf::from(dir), - Err(_) => Path::new(env!("CARGO_MANIFEST_DIR")).join("../../fixtures/vectors/hevc-jctvc"), - }; + let root = ec_testkit::fixture("vectors/hevc-jctvc"); fn bitstreams_in(dir: &Path, depth: u32, out: &mut Vec) { let Ok(entries) = std::fs::read_dir(dir) else { return; @@ -84,10 +81,7 @@ fn inter_placeholder_runs_over_pb_slices() { use ec_h265_syntax::nal::{NalUnitType, unescape_rbsp}; use ec_h265_syntax::slice::{SliceHeader, SliceType}; let streams = streams(); - if streams.is_empty() { - eprintln!("inter placeholder: no conformance streams found, skipping"); - return; - } + assert!(!streams.is_empty(), "no conformance streams"); let (mut pb_slices, mut decoded, mut refused) = (0usize, 0usize, 0usize); for path in &streams { let data = std::fs::read(path).expect("read bitstream"); diff --git a/crates/ec-h265/tests/it/dec_meta.rs b/crates/ec-h265/tests/it/dec_meta.rs index e0867b33..b5e3d3c5 100644 --- a/crates/ec-h265/tests/it/dec_meta.rs +++ b/crates/ec-h265/tests/it/dec_meta.rs @@ -3,7 +3,7 @@ //! NAL units (62, 63) and malformed SEI change nothing. //! //! The streams come from `fixtures/vectors/hevc-jctvc`. Without them the tests -//! skip, unless `EC_REQUIRE_FIXTURES` is set, in which case they fail. +//! fail when the fixtures are absent. use std::path::{Path, PathBuf}; @@ -12,10 +12,7 @@ use ec_h265_syntax::nal::{escape_rbsp, split_annex_b}; use ec_h265_syntax::sei::{ContentLightLevel, MasteringDisplay, PictureHash}; fn stream_files() -> Vec { - let root = match std::env::var("EC_H265_JCTVC_DIR") { - Ok(dir) => PathBuf::from(dir), - Err(_) => Path::new(env!("CARGO_MANIFEST_DIR")).join("../../fixtures/vectors/hevc-jctvc"), - }; + let root = ec_testkit::fixture("vectors/hevc-jctvc"); fn walk(dir: &Path, depth: u32, out: &mut Vec) { let Ok(entries) = std::fs::read_dir(dir) else { return; @@ -81,16 +78,8 @@ fn clean_stream() -> Option<(String, Vec>)> { None } -fn require_stream() -> Option<(String, Vec>)> { - let found = clean_stream(); - if found.is_none() { - assert!( - std::env::var_os("EC_REQUIRE_FIXTURES").is_none(), - "EC_REQUIRE_FIXTURES=1 but no clean conformance stream is available" - ); - eprintln!("decoder metadata tests skipped: vectors absent"); - } - found +fn require_stream() -> (String, Vec>) { + clean_stream().expect("no clean conformance stream") } /// What a frame looks like to a caller, for comparing two decodes. @@ -140,9 +129,7 @@ fn hdr10_prefix_rbsp() -> Vec { #[test] fn dolby_vision_nal_units_change_nothing() { - let Some((name, nals)) = require_stream() else { - return; - }; + let (name, nals) = require_stream(); let base = decode(&nals).unwrap(); let mut injected = Vec::new(); for nal in &nals { @@ -164,9 +151,7 @@ fn dolby_vision_nal_units_change_nothing() { #[test] fn malformed_sei_is_skipped_and_the_stream_decodes_the_same() { - let Some((name, nals)) = require_stream() else { - return; - }; + let (name, nals) = require_stream(); let base = decode(&nals).unwrap(); let mut injected = Vec::new(); for nal in &nals { @@ -193,9 +178,7 @@ fn malformed_sei_is_skipped_and_the_stream_decodes_the_same() { #[test] fn hdr_sei_applies_to_every_frame_from_the_irap_on() { - let Some((name, nals)) = require_stream() else { - return; - }; + let (name, nals) = require_stream(); let mut injected = Vec::new(); let mut placed = false; for nal in &nals { @@ -225,9 +208,7 @@ fn hdr_sei_applies_to_every_frame_from_the_irap_on() { #[test] fn picture_hash_attaches_to_the_picture_it_follows() { - let Some((name, nals)) = require_stream() else { - return; - }; + let (name, nals) = require_stream(); // One MD5 plane: payloadType 132, payloadSize 17, hash_type 0, the digest. let digest = [0x5au8; 16]; let mut hash_rbsp = vec![132, 17, 0]; diff --git a/crates/ec-h265/tests/it/dec_shell.rs b/crates/ec-h265/tests/it/dec_shell.rs index 54e9b8db..f5b4ab84 100644 --- a/crates/ec-h265/tests/it/dec_shell.rs +++ b/crates/ec-h265/tests/it/dec_shell.rs @@ -4,11 +4,10 @@ //! The sweep parses every slice of every stream through the picture-management //! path (pixel decode off) and checks the output order against ffprobe. Streams //! whose slices are all intra are also pixel-decoded and compared with ffmpeg's -//! output. The sweep is skipped when the vectors are absent. +//! output. The sweep fails when the vectors are absent. use std::collections::VecDeque; use std::path::{Path, PathBuf}; -use std::process::Command; use ec_h265::dec::dpb::{Dpb, DpbLimits, Marking, PendingFrame}; use ec_h265::dec::poc::derive_poc; @@ -274,16 +273,8 @@ fn decoder_refuses_out_of_scope_parameter_sets_and_skips_layers() { assert!(dec.next_frame().is_none()); } -fn have_tool(tool: &str) -> bool { - Command::new(tool) - .arg("-version") - .output() - .map(|o| o.status.success()) - .unwrap_or(false) -} - -fn run(tool: &str, args: &[&str], file: &Path) -> Result, String> { - let out = Command::new(tool) +fn run(args: &[&str], file: &Path) -> Result, String> { + let out = ec_testkit::ffprobe() .args(["-v", "error"]) .args(args) .arg(file) @@ -303,14 +294,10 @@ fn numbers(text: &[u8]) -> Vec { } /// The conformance streams: the first `.bin` or `.bit` bitstream of each zip's -/// directory under `fixtures/vectors/hevc-jctvc` (or `EC_H265_JCTVC_DIR`), sorted +/// directory under `vectors/hevc-jctvc` in the fixtures root, sorted /// by name. Some zips extract one directory deeper, so two levels are searched. fn streams() -> Vec { - // EC_H265_JCTVC_DIR overrides the default, for hosts whose fixtures link is dangling. - let root = match std::env::var("EC_H265_JCTVC_DIR") { - Ok(dir) => PathBuf::from(dir), - Err(_) => Path::new(env!("CARGO_MANIFEST_DIR")).join("../../fixtures/vectors/hevc-jctvc"), - }; + let root = ec_testkit::fixture("vectors/hevc-jctvc"); fn bitstreams_in(dir: &Path, depth: u32, out: &mut Vec) { let Ok(entries) = std::fs::read_dir(dir) else { return; @@ -357,7 +344,6 @@ fn our_order(data: &[u8]) -> Result, String> { /// decode order) of each frame, in display order. fn ffprobe_order(path: &Path) -> Result, String> { let packets = numbers(&run( - "ffprobe", &[ "-select_streams", "v:0", @@ -369,7 +355,6 @@ fn ffprobe_order(path: &Path) -> Result, String> { path, )?); let frames = numbers(&run( - "ffprobe", &[ "-select_streams", "v:0", @@ -407,10 +392,7 @@ fn spec_expectation(name: &str) -> Option<(usize, &'static str)> { #[test] fn conformance_output_order_matches_ffprobe() { let streams = streams(); - if streams.is_empty() || !have_tool("ffprobe") { - eprintln!("conformance sweep skipped: vectors or ffprobe absent"); - return; - } + assert!(!streams.is_empty(), "no conformance streams"); let mut table = String::from("stream\tpictures_out\tffprobe_out\tresult\tdetail\n"); let mut pass = 0usize; let mut spec_ok = 0usize; diff --git a/crates/ec-h265/tests/it/dolby_vision_p8.rs b/crates/ec-h265/tests/it/dolby_vision_p8.rs index 827a6cc8..ebf9bf1e 100644 --- a/crates/ec-h265/tests/it/dolby_vision_p8.rs +++ b/crates/ec-h265/tests/it/dolby_vision_p8.rs @@ -6,32 +6,22 @@ //! inserted in front of every VCL NAL unit. ec-h265 must decode the injected stream //! to exactly the pictures it decodes from the clean one, and ffmpeg must decode the //! injected stream to the same bytes. -//! -//! The test skips when ffmpeg is absent, unless `EC_REQUIRE_FIXTURES` is set. use ec_h265::Decoder; use ec_h265::dec::Frame; use ec_h265_syntax::nal::{escape_rbsp, split_annex_b}; use std::path::Path; -use std::process::Command; const WIDTH: usize = 352; const HEIGHT: usize = 288; const FRAMES: usize = 12; -fn have_ffmpeg() -> bool { - Command::new("ffmpeg") - .arg("-version") - .output() - .is_ok_and(|o| o.status.success()) -} - /// The base layer: libx265, an IDR every 4 pictures, P pictures in between, no B. fn encode_base_layer(dir: &Path) -> Result, String> { let out = dir.join("base.hevc"); let frames = FRAMES.to_string(); let source = format!("testsrc2=size={WIDTH}x{HEIGHT}:rate=30"); - let status = Command::new("ffmpeg") + let status = ec_testkit::ffmpeg() .args(["-v", "error", "-y", "-f", "lavfi", "-i"]) .arg(&source) .arg("-frames:v") @@ -137,7 +127,7 @@ fn decode_ec(annex_b: &[u8]) -> Result<(Vec, usize), String> { /// Every picture ffmpeg outputs, as yuv420p. fn decode_ffmpeg(path: &Path, out: &Path) -> Result, String> { - let status = Command::new("ffmpeg") + let status = ec_testkit::ffmpeg() .args(["-v", "error", "-y", "-i"]) .arg(path) .args(["-f", "rawvideo", "-pix_fmt", "yuv420p"]) @@ -159,14 +149,6 @@ fn first_difference(a: &[u8], b: &[u8]) -> Option { #[test] fn dolby_vision_p8_base_layer_decodes_and_rpu_is_ignored() { - if !have_ffmpeg() { - assert!( - std::env::var_os("EC_REQUIRE_FIXTURES").is_none(), - "EC_REQUIRE_FIXTURES=1 but ffmpeg is absent" - ); - eprintln!("dolby vision profile 8 check skipped: ffmpeg absent"); - return; - } let dir = std::env::temp_dir().join(format!("ec-h265-dvp8-{}", std::process::id())); std::fs::create_dir_all(&dir).expect("temp dir"); diff --git a/crates/ec-h265/tests/it/encode.rs b/crates/ec-h265/tests/it/encode.rs index 2667a19c..6c4b2f51 100644 --- a/crates/ec-h265/tests/it/encode.rs +++ b/crates/ec-h265/tests/it/encode.rs @@ -266,17 +266,8 @@ fn bd_psnr_delta(candidate: &[(f64, f64)], anchor: &[(f64, f64)]) -> (f64, f64, (bd, cand_extrap, anc_extrap) } -fn have_ffmpeg() -> bool { - std::process::Command::new("ffmpeg") - .arg("-version") - .stdout(std::process::Stdio::null()) - .stderr(std::process::Stdio::null()) - .status() - .is_ok_and(|s| s.success()) -} - fn have_x265() -> bool { - std::process::Command::new("ffmpeg") + ec_testkit::ffmpeg() .args(["-v", "error", "-hide_banner", "-encoders"]) .output() .is_ok_and(|o| o.status.success() && String::from_utf8_lossy(&o.stdout).contains("libx265")) @@ -367,7 +358,7 @@ fn ffmpeg_decode(stream: &[u8], w: usize, h: usize) -> Option> { std::fs::create_dir_all(&dir).ok()?; let path = dir.join(format!("s{}.265", stream.len())); pin_or_bail("ffmpeg_decode", &path, stream)?; - let out = std::process::Command::new("ffmpeg") + let out = ec_testkit::ffmpeg() .args(["-v", "error"]) .arg("-i") .arg(&path) @@ -445,7 +436,7 @@ fn x265_encode_qp(sources: &[Planes], w: usize, h: usize, qp: i32) -> Option String::new(), } ); - let status = std::process::Command::new("ffmpeg") + let status = ec_testkit::ffmpeg() .args(["-v", "error", "-y"]) .args(["-f", "rawvideo", "-pix_fmt", "yuv420p"]) .args(["-s", &format!("{w}x{h}"), "-r", "1"]) @@ -486,14 +477,7 @@ fn x265_encode_qp(sources: &[Planes], w: usize, h: usize, qp: i32) -> Option clip_sources(&path, 24), None => { @@ -844,7 +828,7 @@ fn bd_psnr_vs_x265() { /// `EC_H265_CLIP_SKIP` passes over that many pictures before sampling (film /// heads are titles and fades). fn clip_sources(path: &std::ffi::OsStr, want: usize) -> (usize, usize, Vec) { - let dims = std::process::Command::new("ffprobe") + let dims = ec_testkit::ffprobe() .args([ "-v", "error", @@ -887,7 +871,7 @@ fn clip_sources(path: &std::ffi::OsStr, want: usize) -> (usize, usize, Vec bool { - Command::new("ffmpeg") - .arg("-version") - .stdout(Stdio::null()) - .stderr(Stdio::null()) - .status() - .is_ok_and(|s| s.success()) -} - fn scratch(tag: &str) -> PathBuf { let base = std::env::var_os("TMPDIR").map_or_else(std::env::temp_dir, PathBuf::from); let dir = base.join(format!("ec-h265-{tag}-{}", std::process::id())); @@ -50,31 +35,25 @@ struct Entry { pix_fmt: String, } -fn manifest_hevc_entries() -> Vec { - let manifest = - Path::new(env!("CARGO_MANIFEST_DIR")).join("../../fixtures/real-library-manifest.tsv"); - let text = std::fs::read_to_string(&manifest).unwrap_or_else(|e| { - panic!( - "{}: {e}. This test sweeps the personal library; generate the manifest with \ - scripts/scan-real-library.sh on the machine that holds the media.", - manifest.display() - ) - }); - let mut out = Vec::new(); - for line in text.lines().skip(1) { - let f: Vec<&str> = line.split('\t').collect(); - if f.len() < 6 || f[2] != "hevc" || !Path::new(f[0]).is_file() { - continue; - } - out.push(Entry { - path: PathBuf::from(f[0]), - container: f[1].to_string(), - width: f[3].to_string(), - height: f[4].to_string(), - pix_fmt: f[5].to_string(), - }); - } - out +fn hevc_entries() -> Vec { + [ + ( + "derived/sintel720-x265-main10.mp4", + "yuv420p10le", + "1280", + "720", + ), + ("open/sintel_trailer-1080p.mp4", "yuv420p", "1920", "1080"), + ] + .into_iter() + .map(|(rel, pix_fmt, width, height)| Entry { + path: ec_testkit::fixture(rel), + container: "mp4".to_string(), + width: width.to_string(), + height: height.to_string(), + pix_fmt: pix_fmt.to_string(), + }) + .collect() } /// The samples of a picture cropped to its conformance window, as the bytes of a @@ -232,7 +211,7 @@ fn short_name(path: &Path) -> String { /// with the text the table prints. fn sweep_file(entry: &Entry, es: &Path, bit_depth: u32) -> Result { let bps = if bit_depth > 8 { 2 } else { 1 }; - let mut child = Command::new("ffmpeg") + let mut child = ec_testkit::ffmpeg() .args(["-v", "error", "-c:v", "hevc", "-i"]) .arg(es) .args([ @@ -286,7 +265,7 @@ fn sweep_file(entry: &Entry, es: &Path, bit_depth: u32) -> Result bool { - Command::new("ffmpeg") + ec_testkit::ffmpeg() .args(["-v", "error", "-y", "-i"]) .arg(src) .args([ @@ -307,11 +286,9 @@ fn extract(src: &Path, dst: &Path) -> bool { } #[test] -#[ignore = "sweeps the PERSONAL media library (fixtures/real-library-manifest.tsv, hevc rows) through ffmpeg; minutes of wall time. Local only: run with --ignored."] +#[ignore = "slow: decodes and compares two open clips with ffmpeg; run with --ignored."] fn real_library_hevc_streams_match_ffmpeg() { - assert!(have_ffmpeg(), "ffmpeg is required to sweep the library"); - let entries = manifest_hevc_entries(); - assert!(!entries.is_empty(), "the manifest lists no hevc rows"); + let entries = hevc_entries(); let dir = scratch("real-library-hevc"); let mut table = String::new(); let mut decoded = 0usize; diff --git a/crates/ec-h265/tests/it/scaling_lists.rs b/crates/ec-h265/tests/it/scaling_lists.rs index efc037e3..426bad59 100644 --- a/crates/ec-h265/tests/it/scaling_lists.rs +++ b/crates/ec-h265/tests/it/scaling_lists.rs @@ -8,7 +8,6 @@ use ec_h265::Decoder; use ec_h265::dec::Frame; use std::path::{Path, PathBuf}; -use std::process::Command; /// The four scaling-list streams the picture-management sweep covers; `str` is /// the SLIST_D stream. @@ -20,10 +19,7 @@ const STREAMS: [&str; 4] = [ ]; fn vectors_dir() -> PathBuf { - match std::env::var("EC_H265_JCTVC_DIR") { - Ok(dir) => PathBuf::from(dir), - Err(_) => Path::new(env!("CARGO_MANIFEST_DIR")).join("../../fixtures/vectors/hevc-jctvc"), - } + ec_testkit::fixture("vectors/hevc-jctvc") } /// The first output picture as 4:2:0 bytes cropped to the conformance window. @@ -59,7 +55,7 @@ fn cropped_yuv(frame: &Frame) -> Vec { /// The first frame of `path` as ffmpeg decodes it, in yuv420p. fn ffmpeg_first_frame(path: &Path, tag: &str) -> Result, String> { let out = std::env::temp_dir().join(format!("ec-h265-scaling-{tag}.yuv")); - let status = Command::new("ffmpeg") + let status = ec_testkit::ffmpeg() .args(["-v", "error", "-y", "-i"]) .arg(path) .args(["-frames:v", "1", "-f", "rawvideo", "-pix_fmt", "yuv420p"]) @@ -72,31 +68,17 @@ fn ffmpeg_first_frame(path: &Path, tag: &str) -> Result, String> { std::fs::read(&out).map_err(|e| e.to_string()) } -fn have_ffmpeg() -> bool { - Command::new("ffmpeg") - .arg("-version") - .output() - .is_ok_and(|o| o.status.success()) -} - // Ignored until the intra path decodes the syntax these streams use: the decode // desyncs at the last CTB of the IDR, and the intra CTU loop has no SAO or // cu_qp_delta parsing. Run with `--ignored` to see the failure. #[ignore = "intra path lacks the syntax these streams use (desync at the IDR's last CTB)"] #[test] fn first_picture_of_each_scaling_list_stream_matches_ffmpeg() { - if !have_ffmpeg() { - eprintln!("scaling-list check skipped: ffmpeg absent"); - return; - } let dir = vectors_dir(); let mut checked = 0usize; for rel in STREAMS { let path = dir.join(rel); - let Ok(data) = std::fs::read(&path) else { - eprintln!("scaling-list check: {rel} absent, skipped"); - continue; - }; + let data = std::fs::read(&path).unwrap_or_else(|e| panic!("{rel}: {e}")); let mut decoder = Decoder::new(); decoder .decode_annex_b(&data)