forge
Explore
Log in

Don't you dare go Hollow

Migrate ec-h264/ec-h265 tests to ec-testkit: pinned ffmpeg and fixture paths, missing fixtures and ffmpeg now fail instead of skipping, personal-media sweeps retargeted to open clips

Browse files at this commit

82c21c8a4269ffc67f8c6565793e5f46a8b603deAhmet Kaan GümüşParent: 155ce74

29 changed files +221 -1132

Cargo.lockmodified+3 -0
@@ -491,6 +491,7 @@ dependencies = [
491491 "ec-h264-syntax",
492492 "ec-matroska",
493493 "ec-mp4",
494+ "ec-testkit",
494495 "tracking-allocator",
495496 "wide",
496497 ]
@@ -510,6 +511,7 @@ dependencies = [
510511 "bytemuck",
511512 "ec-core",
512513 "ec-h265-syntax",
514+ "ec-testkit",
513515 "multiversion",
514516 "wide",
515517 ]
@@ -519,6 +521,7 @@ name = "ec-h265-syntax"
519521 version = "0.1.0"
520522 dependencies = [
521523 "ec-core",
524+ "ec-testkit",
522525 ]
523526
524527 [[package]]
crates/ec-h264/Cargo.tomlmodified+1 -0
@@ -18,6 +18,7 @@ ec-h264-syntax = { workspace = true }
1818 wide = { workspace = true }
1919
2020 [dev-dependencies]
21+ec-testkit.workspace = true
2122 # The conformance harness walks Annex B itself to drive push_nal.
2223 ec-h264-syntax = { workspace = true }
2324 # ... and demuxes an MP4 directly where ffmpeg's own Annex B extraction of it
crates/ec-h264/fuzz/seed.shmodified+2 -2
@@ -4,7 +4,7 @@
44 set -euo pipefail
55
66 here=$(cd -- "$(dirname -- "$0")" && pwd)
7-src="$here/../../../fixtures/vectors/h264-jvt"
7+src="${EC_FIXTURES:-$here/../../../fixtures}/vectors/h264-jvt"
88 dst="$here/corpus/decode_annexb"
99
1010 seeds=(
@@ -19,7 +19,7 @@ mkdir -p "$dst"
1919 for rel in "${seeds[@]}"; do
2020 f="$src/$rel"
2121 if [ ! -f "$f" ]; then
22- echo "seed.sh: missing fixture $f (run scripts/link-fixtures.sh)" >&2
22+ echo "seed.sh: missing fixture $f (run scripts/fixtures.sh)" >&2
2323 exit 1
2424 fi
2525 cp -f "$f" "$dst/$(basename "$rel")"
crates/ec-h264/tests/conformance.rsmodified+12 -486
@@ -1,7 +1,6 @@
11 //! JVT conformance: first IDR picture, bit-exact.
22 //!
3-//! Fixture-gated like tools/oracle: fixtures/ is gitignored, so a checkout
4-//! without `scripts/fetch-vectors.sh` skips loudly instead of failing.
3+//! Fixtures come from `scripts/fixtures.sh`; a missing one fails.
54 //!
65 //! Oracles, in order of authority:
76 //! 1. The reference decoder YUV that ships with each JVT vector (first
@@ -18,7 +17,6 @@ use std::sync::Once;
1817 use tracking_allocator::{AllocationGroupId, AllocationRegistry, AllocationTracker, Allocator};
1918 use std::cell::Cell;
2019 use std::path::{Path, PathBuf};
21-use std::process::Command;
2220 use std::sync::atomic::{AtomicU64, Ordering};
2321
2422 use ec_core::registry::{CodecId, CodecParameters, Decoder as _};
@@ -76,38 +74,10 @@ fn install_counter() {
7674 // ---------------------------------------------------------------------------
7775
7876 fn vectors_dir() -> PathBuf {
79- Path::new(env!("CARGO_MANIFEST_DIR")).join("../../fixtures/vectors/h264-jvt")
77+ ec_testkit::fixture("vectors/h264-jvt")
8078 }
8179
82-/// A gate that skips when its fixtures are absent reports GREEN having checked
83-/// nothing — the "gate skips on its own failure" class. The root `fixtures/`
84-/// directory is gitignored, so `git worktree add` hands every lane worktree a
85-/// tree without it and the whole conformance suite silently stops testing.
86-///
87-/// `EC_REQUIRE_FIXTURES=1` turns the skip into a hard failure naming the exact
88-/// missing path and the command that produces it; unset (the default), the skip
89-/// is kept and now says what it skipped. Set it in every batch run.
90-fn require_fixtures(path: &Path, what: &str, generator: &str) -> bool {
91- if path.exists() {
92- return true;
93- }
94- assert!(
95- std::env::var_os("EC_REQUIRE_FIXTURES").is_none(),
96- "{what} missing at {} — this gate would prove nothing. A worktree has no \
97- gitignored root `fixtures/`: run scripts/link-fixtures.sh, or generate \
98- them with {generator}.",
99- path.display()
100- );
101- eprintln!(
102- "SKIP {what} missing at {} — this gate proved nothing; run \
103- scripts/link-fixtures.sh, or generate them with {generator} \
104- (or set EC_REQUIRE_FIXTURES=1 to make this a failure).",
105- path.display()
106- );
107- false
108-}
109-
110-/// Every vector directory `scripts/fetch-vectors.sh` has populated, in name
80+/// Every vector directory `scripts/fixtures.sh` has populated, in name
11181 /// order.
11282 ///
11383 /// 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<PathBuf> {
153123 }
154124
155125 fn ffmpeg_first_frame(stream: &Path) -> Option<Vec<u8>> {
156- let out = Command::new("ffmpeg")
126+ let out = ec_testkit::ffmpeg()
157127 .args(["-v", "error", "-i"])
158128 .arg(stream)
159129 .args([
@@ -235,7 +205,7 @@ fn decode_all(bytes: &[u8]) -> Result<Vec<Vec<u8>>, Error> {
235205
236206 /// Every frame ffmpeg decodes from `stream`, as raw I420.
237207 fn ffmpeg_all_frames(stream: &Path, frame_len: usize) -> Option<Vec<Vec<u8>>> {
238- let out = Command::new("ffmpeg")
208+ let out = ec_testkit::ffmpeg()
239209 .args(["-v", "error", "-i"])
240210 .arg(stream)
241211 .args(["-f", "rawvideo", "-pix_fmt", "yuv420p", "-"])
@@ -291,7 +261,7 @@ fn x264_encode_gop(
291261 stream.to_string_lossy().into_owned(),
292262 ]);
293263 let refs: Vec<&str> = args.iter().map(|s| s.as_str()).collect();
294- run("ffmpeg", &refs).then_some(stream)
264+ run(&refs).then_some(stream)
295265 }
296266
297267 /// Decode `stream` both ways and report the first frame that differs.
@@ -328,23 +298,13 @@ fn compare_sequence(stream: &Path) -> Result<usize, String> {
328298 #[test]
329299 fn jvt_cavlc_first_idr_bit_exact() {
330300 let base = vectors_dir();
331- if !require_fixtures(
332- &base,
333- "the JVT conformance vectors",
334- "scripts/fetch-vectors.sh",
335- ) {
336- return;
337- }
338301 let mut passed = Vec::new();
339302 let mut failed = Vec::new();
340303 let mut refused = Vec::new();
341304 for name in all_vectors(&base) {
342305 let name = name.as_str();
343306 let dir = base.join(name);
344- let Some(stream) = find_stream(&dir) else {
345- eprintln!("SKIP {name}: no bitstream file");
346- continue;
347- };
307+ let stream = find_stream(&dir).unwrap_or_else(|| panic!("{name}: no bitstream file"));
348308 let bytes = std::fs::read(&stream).unwrap();
349309 match decode_first(&bytes) {
350310 Ok((ours, w, h)) => {
@@ -436,13 +396,6 @@ fn jvt_cavlc_first_idr_bit_exact() {
436396 fn steady_state_decode_loop_zero_alloc() {
437397 install_counter();
438398 let base = vectors_dir();
439- if !require_fixtures(
440- &base,
441- "the JVT conformance vectors",
442- "scripts/fetch-vectors.sh",
443- ) {
444- return;
445- }
446399 // One stream per entropy coder, and one with B slices and multiple
447400 // reference frames so the decoded picture buffer really recycles pictures.
448401 for name in ["BA1_Sony_D", "CABA1_SVA_B", "CABA3_SVA_B"] {
@@ -523,13 +476,6 @@ fn steady_state_decode_loop_zero_alloc() {
523476 #[test]
524477 fn ns_per_macroblock_measurement() {
525478 let base = vectors_dir();
526- if !require_fixtures(
527- &base,
528- "the JVT conformance vectors",
529- "scripts/fetch-vectors.sh",
530- ) {
531- return;
532- }
533479 for name in [
534480 "BA1_Sony_D",
535481 "CI_MW_D",
@@ -610,13 +556,6 @@ fn perf_whole_sequence() {
610556 #[test]
611557 fn corrupt_streams_never_panic() {
612558 let base = vectors_dir();
613- if !require_fixtures(
614- &base,
615- "the JVT conformance vectors",
616- "scripts/fetch-vectors.sh",
617- ) {
618- return;
619- }
620559 // One stream per entropy coder, plus one with B slices and multiple
621560 // references: CABAC's arithmetic decoder indexes context and coefficient
622561 // arrays from stream-derived values, and inter prediction indexes the
@@ -682,9 +621,9 @@ fn corrupt_sweep(bytes: &[u8]) {
682621 // ffmpeg's own decoder as the oracle.
683622 // ---------------------------------------------------------------------------
684623
685-/// Run a command, false when it fails or is not installed.
686-fn run(command: &str, args: &[&str]) -> bool {
687- Command::new(command)
624+/// Run the pinned ffmpeg, false when it fails.
625+fn run(args: &[&str]) -> bool {
626+ ec_testkit::ffmpeg()
688627 .args(args)
689628 .stdout(std::process::Stdio::null())
690629 .stderr(std::process::Stdio::null())
@@ -693,13 +632,6 @@ fn run(command: &str, args: &[&str]) -> bool {
693632 .unwrap_or(false)
694633 }
695634
696-fn have_ffmpeg() -> bool {
697- run(
698- "ffmpeg",
699- &["-hide_banner", "-loglevel", "error", "-version"],
700- )
701-}
702-
703635 /// A private scratch directory for one test.
704636 fn scratch(tag: &str) -> PathBuf {
705637 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<Path
742674 stream.to_string_lossy().into_owned(),
743675 ]);
744676 let refs: Vec<&str> = args.iter().map(|s| s.as_str()).collect();
745- run("ffmpeg", &refs).then_some(stream)
677+ run(&refs).then_some(stream)
746678 }
747679
748680 /// Encode, decode both ways, return the number of differing bytes.
@@ -787,10 +719,6 @@ const ENTROPY_MODES: [(&str, &[&str]); 2] = [
787719 /// produces, none of which the QCIF single-slice vectors cover.
788720 #[test]
789721 fn geometry_and_slice_structure_match_ffmpeg() {
790- if !have_ffmpeg() {
791- eprintln!("SKIP: ffmpeg not on PATH");
792- return;
793- }
794722 let dir = scratch("geometry");
795723 let cases: &[(&str, &str, &[&str])] = &[
796724 // 1080 lines are coded as 68 macroblock rows and cropped back to 1080.
@@ -851,10 +779,6 @@ fn geometry_and_slice_structure_match_ffmpeg() {
851779 /// nothing else in the suite would notice it regressing into a refusal.
852780 #[test]
853781 fn jvt_scaling_matrices_decode_bit_exact() {
854- if !have_ffmpeg() {
855- eprintln!("SKIP: ffmpeg not on PATH");
856- return;
857- }
858782 let dir = scratch("scaling");
859783 let extra = [
860784 "-profile:v",
@@ -877,10 +801,6 @@ fn jvt_scaling_matrices_decode_bit_exact() {
877801 /// prefixed — how an MP4 or Matroska demuxer hands H.264 over.
878802 #[test]
879803 fn avcc_extradata_and_length_prefixed_packets() {
880- if !have_ffmpeg() {
881- eprintln!("SKIP: ffmpeg not on PATH");
882- return;
883- }
884804 let dir = scratch("avcc");
885805 let Some(annex_b) = x264_encode(
886806 &dir,
@@ -960,10 +880,6 @@ fn avcc_extradata_and_length_prefixed_packets() {
960880 /// once, so it is the first test to look at when any of them regress.
961881 #[test]
962882 fn p_only_gop_matches_ffmpeg_every_frame() {
963- if !have_ffmpeg() {
964- eprintln!("SKIP: ffmpeg not on PATH");
965- return;
966- }
967883 let dir = scratch("p-gop");
968884 let mut failures = Vec::new();
969885 for (mode, profile) in ENTROPY_MODES {
@@ -992,13 +908,6 @@ fn p_only_gop_matches_ffmpeg_every_frame() {
992908 #[test]
993909 fn jvt_full_sequence_bit_exact() {
994910 let base = vectors_dir();
995- if !require_fixtures(
996- &base,
997- "the JVT conformance vectors",
998- "scripts/fetch-vectors.sh",
999- ) {
1000- return;
1001- }
1002911 let mut table = String::new();
1003912 let mut passed = 0usize;
1004913 let mut refused = Vec::new();
@@ -1144,10 +1053,6 @@ fn slice_type_counts(bytes: &[u8]) -> [usize; 3] {
11441053 /// they arrived.
11451054 #[test]
11461055 fn b_pictures_match_ffmpeg_every_frame() {
1147- if !have_ffmpeg() {
1148- eprintln!("SKIP: ffmpeg not on PATH");
1149- return;
1150- }
11511056 let dir = scratch("b-gop");
11521057 let cases: &[(&str, &[&str])] = &[
11531058 (
@@ -1227,10 +1132,6 @@ fn b_pictures_match_ffmpeg_every_frame() {
12271132 /// test would pass on a decoder that never reorders anything.
12281133 #[test]
12291134 fn output_is_display_order_and_the_reorder_is_real() {
1230- if !have_ffmpeg() {
1231- eprintln!("SKIP: ffmpeg not on PATH");
1232- return;
1233- }
12341135 let dir = scratch("order");
12351136 let extra = [
12361137 "-profile:v",
@@ -1296,10 +1197,6 @@ fn output_is_display_order_and_the_reorder_is_real() {
12961197 /// preview after a seek.
12971198 #[test]
12981199 fn a_frame_num_gap_keeps_decoding() {
1299- if !have_ffmpeg() {
1300- eprintln!("SKIP: ffmpeg not on PATH");
1301- return;
1302- }
13031200 let dir = scratch("gap");
13041201 let extra = [
13051202 "-profile:v",
@@ -1359,10 +1256,6 @@ fn a_frame_num_gap_keeps_decoding() {
13591256 /// inter prediction and reordering active.
13601257 #[test]
13611258 fn geometry_with_motion_matches_ffmpeg() {
1362- if !have_ffmpeg() {
1363- eprintln!("SKIP: ffmpeg not on PATH");
1364- return;
1365- }
13661259 let dir = scratch("geometry-motion");
13671260 let cases: &[(&str, &str, &[&str])] = &[
13681261 ("hd", "1920x1080", &["bframes=2:b-adapt=0"]),
@@ -1515,92 +1408,9 @@ fn switching_slices_are_refused_by_name() {
15151408 // Real library: the files actually on this machine, not fixtures.
15161409 // ---------------------------------------------------------------------------
15171410
1518-/// Compare a long stream against ffmpeg without holding it in memory: ffmpeg's
1519-/// raw output is consumed from a pipe one frame at a time, in step with our
1520-/// own decoding, so a 500-frame 1080p sweep costs two frames of memory rather
1521-/// than three gigabytes.
1522-fn compare_sequence_streamed(
1523- stream: &Path,
1524- frames_wanted: usize,
1525-) -> Result<StreamedResult, String> {
1526- use std::io::Read;
1527-
1528- let bytes = std::fs::read(stream).map_err(|e| e.to_string())?;
1529- let mut child = Command::new("ffmpeg")
1530- .args(["-v", "error", "-i"])
1531- .arg(stream)
1532- .args([
1533- "-frames:v",
1534- &frames_wanted.to_string(),
1535- "-f",
1536- "rawvideo",
1537- "-pix_fmt",
1538- "yuv420p",
1539- "-",
1540- ])
1541- .stdout(std::process::Stdio::piped())
1542- .stderr(std::process::Stdio::null())
1543- .spawn()
1544- .map_err(|e| e.to_string())?;
1545- let mut out = child.stdout.take().expect("piped stdout");
1546-
1547- let mut dec = Decoder::new();
1548- let mut reference = Vec::new();
1549- let mut result = StreamedResult::default();
1550- let mut oracle_open = true;
1551- let mut take = |frame: Vec<u8>, result: &mut StreamedResult, reference: &mut Vec<u8>| {
1552- result.produced += 1;
1553- if !oracle_open || result.compared >= frames_wanted {
1554- return;
1555- }
1556- reference.resize(frame.len(), 0);
1557- if out.read_exact(reference).is_err() {
1558- oracle_open = false;
1559- return;
1560- }
1561- if let Some(pos) = first_diff(&frame, reference) {
1562- result.diffs.push((result.compared, pos));
1563- }
1564- result.compared += 1;
1565- };
1566-
1567- for nal in ec_h264_syntax::AnnexBIter::new(&bytes) {
1568- match dec.push_nal(nal) {
1569- Ok(NalOutcome::PictureBoundary) => {
1570- dec.end_picture().map_err(|e| format!("{e}"))?;
1571- dec.push_nal(nal).map_err(|e| format!("{e}"))?;
1572- }
1573- Ok(_) => {}
1574- Err(e) => return Err(format!("{e}")),
1575- }
1576- while let Some(f) = dec.next_frame() {
1577- take(frame_bytes(&f), &mut result, &mut reference);
1578- }
1579- }
1580- dec.flush().map_err(|e| format!("{e}"))?;
1581- while let Some(f) = dec.next_frame() {
1582- take(frame_bytes(&f), &mut result, &mut reference);
1583- }
1584- let _ = child.kill();
1585- let _ = child.wait();
1586- Ok(result)
1587-}
1588-
1589-/// Outcome of a streamed comparison.
1590-#[derive(Default)]
1591-struct StreamedResult {
1592- /// Frames this decoder produced.
1593- produced: usize,
1594- /// Frames the oracle also produced, and which were therefore compared.
1595- compared: usize,
1596- /// `(frame index, byte offset)` of each mismatch.
1597- diffs: Vec<(usize, usize)>,
1598-}
1599-
16001411 /// Extract the video elementary stream of a real file as Annex B.
16011412 fn extract_annexb(src: &Path, dst: &Path, frames: usize) -> bool {
16021413 run(
1603- "ffmpeg",
16041414 &[
16051415 "-v",
16061416 "error",
@@ -1622,273 +1432,8 @@ fn extract_annexb(src: &Path, dst: &Path, frames: usize) -> bool {
16221432 )
16231433 }
16241434
1625-/// The same comparison, but demuxed from the container by [`ec_mp4`] instead
1626-/// of extracted to Annex B by ffmpeg's bitstream filter.
1627-///
1628-/// Some real MP4s produce an elementary stream that ffmpeg itself then decodes
1629-/// only three frames of, silently. That is a property of the extraction, not of
1630-/// the file: reading the sample table directly and handing the `avcC` and the
1631-/// length-prefixed samples to the packet entry surface leaves the oracle able to
1632-/// decode the original file, so the comparison is real again.
1633-fn compare_container_streamed(
1634- source: &Path,
1635- frames_wanted: usize,
1636-) -> Result<StreamedResult, String> {
1637- use ec_core::registry::{Decoder as _, Demuxer as _};
1638- use std::io::Read;
1639-
1640- let file = std::fs::File::open(source).map_err(|e| e.to_string())?;
1641- let mut demux = ec_mp4::Mp4Demuxer::new(std::io::BufReader::new(file))
1642- .map_err(|e| format!("ec-mp4 open: {e}"))?;
1643- let (stream_index, params) = demux
1644- .streams()
1645- .iter()
1646- .find(|s| s.params.codec == ec_core::registry::CodecId::H264)
1647- .map(|s| (s.index, s.params.clone()))
1648- .ok_or("no H.264 track")?;
1649- let mut dec = ec_h264::H264Decoder::new(params).map_err(|e| format!("{e}"))?;
1650-
1651- let mut child = Command::new("ffmpeg")
1652- .args(["-v", "error", "-i"])
1653- .arg(source)
1654- .args([
1655- "-map",
1656- "0:v:0",
1657- "-frames:v",
1658- &frames_wanted.to_string(),
1659- "-f",
1660- "rawvideo",
1661- "-pix_fmt",
1662- "yuv420p",
1663- "-",
1664- ])
1665- .stdout(std::process::Stdio::piped())
1666- .stderr(std::process::Stdio::null())
1667- .spawn()
1668- .map_err(|e| e.to_string())?;
1669- let mut out = child.stdout.take().expect("piped stdout");
1670-
1671- let mut reference = Vec::new();
1672- let mut result = StreamedResult::default();
1673- let mut oracle_open = true;
1674- let mut take = |frame: Vec<u8>, result: &mut StreamedResult, reference: &mut Vec<u8>| {
1675- result.produced += 1;
1676- if !oracle_open || result.compared >= frames_wanted {
1677- return;
1678- }
1679- reference.resize(frame.len(), 0);
1680- if out.read_exact(reference).is_err() {
1681- oracle_open = false;
1682- return;
1683- }
1684- if let Some(pos) = first_diff(&frame, reference) {
1685- result.diffs.push((result.compared, pos));
1686- }
1687- result.compared += 1;
1688- };
1689- let mut drain =
1690- |dec: &mut ec_h264::H264Decoder, result: &mut StreamedResult, reference: &mut Vec<u8>| {
1691- while let Ok(ec_core::frame::Frame::Video(f)) = dec.receive_frame() {
1692- take(frame_bytes(&f), result, reference);
1693- }
1694- };
1695- while result.produced < frames_wanted {
1696- let packet = match demux.next_packet() {
1697- Ok(p) => p,
1698- Err(_) => break,
1699- };
1700- if packet.stream != stream_index {
1701- continue;
1702- }
1703- dec.send_packet(&packet).map_err(|e| format!("{e}"))?;
1704- drain(&mut dec, &mut result, &mut reference);
1705- }
1706- dec.flush().map_err(|e| format!("{e}"))?;
1707- drain(&mut dec, &mut result, &mut reference);
1708- let _ = child.kill();
1709- let _ = child.wait();
1710- Ok(result)
1711-}
1712-
1713-/// Decode real H.264 files from this machine's library, several hundred frames
1714-/// each, frame for frame against ffmpeg.
1715-///
1716-/// Synthetic clips and conformance vectors are both written by people trying to
1717-/// exercise a decoder. Real files are written by encoders tuned for size, at
1718-/// resolutions and GOP structures the fixtures never use, and they are the ones
1719-/// a user actually opens. Every file either decodes bit-exactly or is refused
1720-/// by name; a file that decodes to different pixels is a failure.
1721-// lane-h264reallib: LOCAL-ONLY, and the reason lives in the attribute so it
1722-// shows in `cargo test -- --list` instead of hiding in a skip print.
1723-//
1724-// The precondition is a PERSONAL MEDIA LIBRARY: the manifest is generated by
1725-// `scripts/scan-real-library.sh`, which scans `~/Videos ~/Downloads ~/Music`
1726-// by default and is gitignored precisely because it is machine-local. A
1727-// runner host has none of those directories, so both of this test's possible
1728-// behaviours there are wrong:
1729-//
1730-// - manifest absent -> the `SKIP: ... missing` early return, which prints
1731-// green. That is the silent-skip class this batch is removing: a green
1732-// that means "nothing was checked".
1733-// - manifest present but its absolute paths unresolvable (a host that ran
1734-// the scan script against an empty library) -> zero files swept and
1735-// `decoded >= 3` fails. That is the red every fleet run currently eats,
1736-// and it is red for a reason that has nothing to do with the decoder.
1737-//
1738-// Hence `#[ignore]` rather than an env gate: an env gate whose variable is
1739-// absent on the runner prints the same green the missing manifest already
1740-// prints, which is the defect rather than the fix. An ignore is visible in
1741-// `--list`, cannot go green silently, and leaves the assertion itself intact
1742-// -- "the sweep is the point" still holds on the machine that can run it.
1743-//
1744-// Run it on the workstation, where the library is:
1745-// cargo test -p ec-h264 --test conformance real_library_streams_match_ffmpeg -- --ignored
1746-#[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."]
1747-#[test]
1748-fn real_library_streams_match_ffmpeg() {
1749- if !have_ffmpeg() {
1750- eprintln!("SKIP: ffmpeg not on PATH");
1751- return;
1752- }
1753- let manifest =
1754- Path::new(env!("CARGO_MANIFEST_DIR")).join("../../fixtures/real-library-manifest.tsv");
1755- let Ok(text) = std::fs::read_to_string(&manifest) else {
1756- eprintln!("SKIP: {} missing", manifest.display());
1757- return;
1758- };
1759- let dir = scratch("real-library");
1760- const FRAMES: usize = 500;
1761- /// A file counts as swept only when the oracle stayed with us this long.
1762- const MIN_FRAMES: usize = 100;
1763- let mut table = String::new();
1764- let mut decoded = 0usize;
1765- let mut refused = 0usize;
1766- let mut failures = Vec::new();
1767- let mut seen_containers = std::collections::BTreeSet::new();
1768-
1769- for line in text.lines().skip(1) {
1770- let mut f = line.split('\t');
1771- let (Some(path), Some(container), Some(vcodec)) = (f.next(), f.next(), f.next()) else {
1772- continue;
1773- };
1774- if vcodec != "h264" || !Path::new(path).is_file() {
1775- continue;
1776- }
1777- // One file per container family per resolution class keeps the sweep
1778- // to a few minutes while still covering both demuxers.
1779- let width = f.next().unwrap_or("0");
1780- let key = (container.to_string(), width.to_string());
1781- if !seen_containers.insert(key) {
1782- continue;
1783- }
1784- let name: String = Path::new(path)
1785- .file_name()
1786- .map(|n| n.to_string_lossy().chars().take(38).collect())
1787- .unwrap_or_default();
1788- let annexb = dir.join("stream.264");
1789- if !extract_annexb(Path::new(path), &annexb, FRAMES) {
1790- table.push_str(&format!("{name:<40} {container:<12} not extractable\n"));
1791- continue;
1792- }
1793- match compare_sequence_streamed(&annexb, FRAMES) {
1794- Ok(r) if !r.diffs.is_empty() => {
1795- failures.push(format!(
1796- "{name}: {} of {} frames differ",
1797- r.diffs.len(),
1798- r.compared
1799- ));
1800- table.push_str(&format!(
1801- "{name:<40} {container:<12} {width:>5}px MISMATCH {} of {}\n",
1802- r.diffs.len(),
1803- r.compared
1804- ));
1805- }
1806- // The oracle stopped before we did: ffmpeg gave up on the elementary
1807- // stream its own bitstream filter produced. That is a property of
1808- // the extraction, so the file is re-run straight out of the
1809- // container, where the oracle can read the original samples.
1810- Ok(r) if r.compared < r.produced.min(MIN_FRAMES) => {
1811- match compare_container_streamed(Path::new(path), FRAMES) {
1812- Ok(c) if !c.diffs.is_empty() => {
1813- failures.push(format!(
1814- "{name} (container demux): {} of {} frames differ",
1815- c.diffs.len(),
1816- c.compared
1817- ));
1818- table.push_str(&format!(
1819- "{name:<40} {container:<12} {width:>5}px MISMATCH {} of {} \
1820- (container demux)\n",
1821- c.diffs.len(),
1822- c.compared
1823- ));
1824- }
1825- Ok(c) if c.compared >= MIN_FRAMES => {
1826- decoded += 1;
1827- table.push_str(&format!(
1828- "{name:<40} {container:<12} {width:>5}px {:>4} frames bit-exact \
1829- (container demux)\n",
1830- c.compared
1831- ));
1832- }
1833- Ok(c) => {
1834- table.push_str(&format!(
1835- "{name:<40} {container:<12} {width:>5}px oracle short both ways: \
1836- ffmpeg gave {} frames, we decoded {}\n",
1837- c.compared, c.produced
1838- ));
1839- }
1840- Err(e) => {
1841- table.push_str(&format!(
1842- "{name:<40} {container:<12} {width:>5}px oracle short, container \
1843- demux failed: {e}\n"
1844- ));
1845- }
1846- }
1847- }
1848- Ok(r) => {
1849- decoded += 1;
1850- table.push_str(&format!(
1851- "{name:<40} {container:<12} {width:>5}px {:>4} frames bit-exact\n",
1852- r.compared
1853- ));
1854- }
1855- Err(e) if e.contains("unsupported") => {
1856- refused += 1;
1857- table.push_str(&format!(
1858- "{name:<40} {container:<12} {width:>5}px refused: {e}\n"
1859- ));
1860- }
1861- Err(e) => {
1862- failures.push(format!("{name}: {e}"));
1863- table.push_str(&format!(
1864- "{name:<40} {container:<12} {width:>5}px ERROR {e}\n"
1865- ));
1866- }
1867- }
1868- }
1869- let _ = std::fs::remove_dir_all(&dir);
1870- eprintln!("{table}");
1871- eprintln!("real library: {decoded} decoded bit-exact, {refused} refused by name");
1872- assert!(failures.is_empty(), "{failures:#?}");
1873- assert!(
1874- decoded >= 3,
1875- "only {decoded} real files swept end to end; the sweep is the point"
1876- );
1877-}
1878-
1879-/// The registry entry surface, driven the way a demuxer drives it: one access
1880-/// unit per packet, frames pulled with `receive_frame`.
1881-///
1882-/// This is where display order has to actually arrive. Everything above tests
1883-/// the NAL-level API; a player never touches that one, so a reordering decoder
1884-/// whose packet API still hands back decode order would look correct in every
1885-/// other test here and wrong on screen.
18861435 #[test]
18871436 fn packet_entry_surface_reorders_and_carries_timestamps() {
1888- if !have_ffmpeg() {
1889- eprintln!("SKIP: ffmpeg not on PATH");
1890- return;
1891- }
18921437 let dir = scratch("entry");
18931438 let extra = [
18941439 "-profile:v",
@@ -2004,10 +1549,6 @@ fn packet_entry_surface_reorders_and_carries_timestamps() {
20041549 /// are what makes the two readings differ at all, so this needs `-refs`.
20051550 #[test]
20061551 fn spatial_direct_over_a_b_reference_matches_ffmpeg() {
2007- if !have_ffmpeg() {
2008- eprintln!("SKIP: ffmpeg not on PATH");
2009- return;
2010- }
20111552 let dir = scratch("direct-bref");
20121553 let mut failures = Vec::new();
20131554 for (tag, coder) in [("cabac", "ac"), ("cavlc", "0")] {
@@ -2073,10 +1614,6 @@ fn pps_enables_8x8(stream: &Path) -> bool {
20731614 /// 8x8 macroblock alone (8.7).
20741615 #[test]
20751616 fn high_profile_8x8_inter_sequences_match_ffmpeg() {
2076- if !have_ffmpeg() {
2077- eprintln!("SKIP: ffmpeg not on PATH");
2078- return;
2079- }
20801617 let dir = scratch("high8x8-seq");
20811618 let mut failures = Vec::new();
20821619 let cases: &[(&str, &[&str])] = &[
@@ -2160,18 +1697,7 @@ fn high_profile_8x8_inter_sequences_match_ffmpeg() {
21601697 /// picture itself, per D.2.8 absent a recovery_point SEI.
21611698 #[test]
21621699 fn h264_seek_matches_linear_open_gop() {
2163- if !have_ffmpeg() {
2164- eprintln!("SKIP: ffmpeg not on PATH");
2165- return;
2166- }
2167- let src = Path::new(env!("CARGO_MANIFEST_DIR")).join("../../fixtures/video/h264-open-gop.mp4");
2168- if !require_fixtures(
2169- &src,
2170- "the open-GOP fixture",
2171- "scripts/gen-fixtures.sh (fixtures/video/h264-open-gop.mp4)",
2172- ) {
2173- return;
2174- }
1700+ let src = ec_testkit::fixture("video/h264-open-gop.mp4");
21751701 let dir = scratch("open-gop");
21761702 std::fs::create_dir_all(&dir).unwrap();
21771703 let annexb = dir.join("open-gop.264");
crates/ec-h264/tests/it/common.rsmodified+2 -3
@@ -2,7 +2,6 @@
22 //! ffmpeg pipes and stream utilities that were identical in each file.
33
44 use std::path::{Path, PathBuf};
5-use std::process::Command;
65
76 use ec_core::frame::{PixelFormat, VideoFrame};
87
@@ -25,7 +24,7 @@ pub(super) fn frame_bytes(frame: &VideoFrame) -> Vec<u8> {
2524 }
2625
2726 pub(super) fn ffmpeg_frames(stream: &Path, pix_fmt: &str, frame_len: usize) -> Option<Vec<u8>> {
28- let out = Command::new("ffmpeg")
27+ let out = ec_testkit::ffmpeg()
2928 .args(["-v", "error", "-i"])
3029 .arg(stream)
3130 .args(["-f", "rawvideo", "-pix_fmt", pix_fmt, "-"])
@@ -78,7 +77,7 @@ pub(super) fn layout(f: PixelFormat) -> (usize, usize, usize) {
7877 }
7978
8079 pub(super) fn ffmpeg_pix_frames(stream: &Path, pix_fmt: &str) -> Option<Vec<u8>> {
81- let out = Command::new("ffmpeg")
80+ let out = ec_testkit::ffmpeg()
8281 .args(["-v", "error", "-f", "h264", "-i"])
8382 .arg(stream)
8483 .args(["-f", "rawvideo", "-pix_fmt", pix_fmt, "-"])
crates/ec-h264/tests/it/encode.rsmodified+13 -110
@@ -427,39 +427,6 @@ fn all_intra_when_the_gop_is_one() {
427427 // absent, exactly like the conformance suite's ffmpeg cross-check.
428428 // ---------------------------------------------------------------------------
429429
430-fn have_ffmpeg() -> bool {
431- std::process::Command::new("ffmpeg")
432- .arg("-version")
433- .stdout(std::process::Stdio::null())
434- .stderr(std::process::Stdio::null())
435- .status()
436- .is_ok_and(|s| s.success())
437-}
438-
439-/// Fixture-presence probe for `<what this test needs>`.
440-/// Returns whether the fixture is present, but never silently: under
441-/// `EC_REQUIRE_FIXTURES=1` an absent fixture is a hard failure naming the path
442-/// and the script that regenerates it, so a host whose fixture library drifted
443-/// reports RED instead of a green SKIP (class: gate-skips-on-its-own-failure;
444-/// model `have_ffmpeg` in crates/ec-av1/src/stream.rs, which was silently
445-/// short-circuited because the probe ran first in a compound `if`).
446-///
447-/// Order is load-bearing: probe, assert, return. Never merge the probe into
448-/// the same `if` as the escape.
449-fn require_fixture(path: &std::path::Path, generator: &str) -> bool {
450- let present = path.exists();
451- assert!(
452- present || std::env::var_os("EC_REQUIRE_FIXTURES").is_none(),
453- "EC_REQUIRE_FIXTURES=1 but fixture {} is absent -- regenerate with: {}",
454- path.display(),
455- generator
456- );
457- if !present {
458- eprintln!("SKIP: fixture {} absent", path.display());
459- }
460- present
461-}
462-
463430 /// Write `bytes` to `path` and PROVE the file on disk is exactly that long.
464431 ///
465432 /// 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<Ve
635602 SEQ.fetch_add(1, std::sync::atomic::Ordering::Relaxed)
636603 ));
637604 pin_or_bail("ffmpeg_decode", &path, stream)?;
638- let mut cmd = std::process::Command::new("ffmpeg");
605+ let mut cmd = ec_testkit::ffmpeg();
639606 cmd.args(["-v", "error"]);
640607 cmd.args(extra);
641608 cmd.arg("-i").arg(&path);
@@ -777,10 +744,6 @@ fn eight_by_eight_gains_on_flat_and_text() {
777744 /// across a QP sweep and at a size that is not a multiple of a macroblock.
778745 #[test]
779746 fn ffmpeg_decodes_bit_exactly() {
780- if !have_ffmpeg() {
781- eprintln!("SKIP ffmpeg_decodes_bit_exactly: no ffmpeg on PATH");
782- return;
783- }
784747 let mut t8x8_mbs = (0, 0);
785748 for (w, h) in [(176, 144), (322, 242)] {
786749 for qp in [10, 20, 28, 37, 47] {
@@ -813,10 +776,6 @@ fn ffmpeg_decodes_bit_exactly() {
813776 /// The same stream under constant bitrate, which is the mode edith exports in.
814777 #[test]
815778 fn ffmpeg_decodes_a_cbr_stream_bit_exactly() {
816- if !have_ffmpeg() {
817- eprintln!("SKIP ffmpeg_decodes_a_cbr_stream_bit_exactly: no ffmpeg on PATH");
818- return;
819- }
820779 let (w, h) = (352, 288);
821780 let (stream, recons, _) = encode_clip(w, h, 12, |cfg| {
822781 cfg.bitrate = 2_000_000;
@@ -839,8 +798,8 @@ fn ffmpeg_decodes_a_cbr_stream_bit_exactly() {
839798 /// software decoder says about it.
840799 #[test]
841800 fn vaapi_decodes_our_stream() {
842- if !have_ffmpeg() || !std::path::Path::new("/dev/dri/renderD128").exists() {
843- eprintln!("SKIP vaapi_decodes_our_stream: no ffmpeg or no render node");
801+ if !std::path::Path::new("/dev/dri/renderD128").exists() {
802+ eprintln!("SKIP vaapi_decodes_our_stream: no render node");
844803 return;
845804 }
846805 let (w, h) = (352, 288);
@@ -882,50 +841,10 @@ fn vaapi_decodes_our_stream() {
882841 fn real_library_frames_encode_and_decode_exactly() {
883842 use ec_core::registry::Decoder as _;
884843
885- if !have_ffmpeg() {
886- eprintln!("SKIP real_library_frames: no ffmpeg on PATH");
887- return;
888- }
889- let manifest = std::path::Path::new(env!("CARGO_MANIFEST_DIR"))
890- .join("../../fixtures/real-library-manifest.tsv");
891- if !require_fixture(&manifest, "scripts/scan-real-library.sh") {
892- return;
893- }
894- let text = std::fs::read_to_string(&manifest).expect("manifest reads");
895- // The first 8-bit 4:2:0 H.264 mp4 of at least 720p in the manifest.
896- let mut source = None;
897- for line in text.lines().skip(1) {
898- let f: Vec<&str> = line.split('\t').collect();
899- if f.len() < 7 || f[2] != "h264" || f[5] != "yuv420p" {
900- continue;
901- }
902- let (Ok(w), Ok(h)) = (f[3].parse::<usize>(), f[4].parse::<usize>()) else {
903- continue;
904- };
905- if w < 1280 || h < 720 || !w.is_multiple_of(2) || !h.is_multiple_of(2) {
906- continue;
907- }
908- if !f[1].contains("mp4") || !std::path::Path::new(f[0]).exists() {
909- continue;
910- }
911- source = Some((f[0].to_string(), w, h));
912- break;
913- }
914- let Some((path, w, h)) = source else {
915- // A manifest with no qualifying row is a corpus that drifted, not a
916- // reason to report PASS for a sweep that never ran.
917- assert!(
918- std::env::var_os("EC_REQUIRE_FIXTURES").is_none(),
919- "EC_REQUIRE_FIXTURES=1 but {} lists no H.264 4:2:0 mp4 of at least \
920- 720p -- regenerate with: scripts/scan-real-library.sh",
921- manifest.display()
922- );
923- eprintln!("SKIP real_library_frames: no H.264 4:2:0 mp4 in the manifest");
924- return;
925- };
844+ let path = ec_testkit::fixture("open/sintel_trailer-720p.mp4");
845+ let (w, h) = (1280, 720);
926846
927- // Decode a handful of real pictures.
928- let (params, mut demux, index) = open_h264_source(std::ffi::OsStr::new(&path));
847+ let (params, mut demux, index) = open_h264_source(path.as_os_str());
929848 let mut dec = ec_h264::H264Decoder::new(params).expect("decoder");
930849 let mut sources: Vec<Planes> = Vec::new();
931850 while sources.len() < 12 {
@@ -1124,12 +1043,10 @@ fn clip_sources(path: &std::ffi::OsStr, want: usize) -> (usize, usize, Vec<Plane
11241043 /// EC_H264_CLIP=<file> cargo test --release -p ec-h264 --test encode \
11251044 /// real_clip_t8x8_bd_psnr -- --ignored --nocapture
11261045 #[test]
1127-#[ignore = "set EC_H264_CLIP to a media file of yours"]
1046+#[ignore = "slow measurement on the open 480p trailer"]
11281047 fn real_clip_t8x8_bd_psnr() {
1129- let Some(path) = std::env::var_os("EC_H264_CLIP") else {
1130- panic!("EC_H264_CLIP must name a media file");
1131- };
1132- let (w, h, sources) = clip_sources(&path, 30);
1048+ let path = ec_testkit::fixture("open/sintel_trailer-480p.mp4");
1049+ let (w, h, sources) = clip_sources(path.as_os_str(), 30);
11331050
11341051 let run = |t8x8: bool, qp: i32| {
11351052 let mut cfg = EncoderConfig::new(w as u32, h as u32);
@@ -1200,7 +1117,7 @@ fn real_clip_t8x8_bd_psnr() {
12001117 const BD_PSNR_VS_X264_FLOOR: f64 = -4.15;
12011118
12021119 fn have_x264() -> bool {
1203- std::process::Command::new("ffmpeg")
1120+ ec_testkit::ffmpeg()
12041121 .args(["-v", "error", "-hide_banner", "-encoders"])
12051122 .output()
12061123 .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) ->
12281145 buf.extend_from_slice(v);
12291146 }
12301147 pin_or_bail("x264_encode_qp", &raw, &buf)?;
1231- let status = std::process::Command::new("ffmpeg")
1148+ let status = ec_testkit::ffmpeg()
12321149 .args(["-v", "error", "-y"])
12331150 .args(["-f", "rawvideo", "-pix_fmt", "yuv420p"])
12341151 .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) ->
13101227 /// bd_psnr_vs_x264 -- --nocapture
13111228 #[test]
13121229 fn bd_psnr_vs_x264() {
1313- if !have_ffmpeg() || !have_x264() {
1314- eprintln!(
1315- "SKIP bd_psnr_vs_x264: no ffmpeg with libx264 on PATH. \
1316- Install one, then: cargo test --release -p ec-h264 --test encode \
1317- bd_psnr_vs_x264 -- --nocapture"
1318- );
1319- return;
1320- }
1230+ assert!(have_x264(), "the pinned ffmpeg has no libx264");
13211231 let (w, h, sources) = match std::env::var_os("EC_H264_CLIP") {
13221232 Some(path) => clip_sources(&path, 24),
13231233 None => {
@@ -1485,10 +1395,7 @@ fn bd_psnr_vs_x264() {
14851395 /// bit_account_vs_x264 -- --nocapture
14861396 #[test]
14871397 fn bit_account_vs_x264() {
1488- if !have_ffmpeg() || !have_x264() {
1489- eprintln!("SKIP bit_account_vs_x264: no ffmpeg with libx264 on PATH");
1490- return;
1491- }
1398+ assert!(have_x264(), "the pinned ffmpeg has no libx264");
14921399 let (w, h, sources) = match std::env::var_os("EC_H264_CLIP") {
14931400 Some(path) => clip_sources(&path, 12),
14941401 None => {
@@ -1578,10 +1485,6 @@ fn bit_account_vs_x264() {
15781485 /// never a `sub_mb_type` -- in front of another decoder. This does.
15791486 #[test]
15801487 fn balanced_partitions_decode_bit_exactly() {
1581- if !have_ffmpeg() {
1582- eprintln!("SKIP balanced_partitions_decode_bit_exactly: no ffmpeg on PATH");
1583- return;
1584- }
15851488 let (w, h) = (176, 144);
15861489 let mut shapes = ec_h264::MbShapes::default();
15871490 for qp in [16, 26, 36] {
crates/ec-h264/tests/it/high10.rsmodified+6 -16
@@ -5,12 +5,10 @@
55 //! 1. Committed fixtures in `tests/data/high10/`: tiny libx264 streams with the
66 //! MD5 of ffmpeg's decode beside them, checked on every run with no ffmpeg.
77 //! 2. A sweep that encodes synthetic sources with libx264 (`-profile:v high10`)
8-//! and compares every frame with ffmpeg's decode. It skips, saying so, when
9-//! ffmpeg or a 10-bit libx264 is absent, and fails instead when
10-//! `EC_REQUIRE_FIXTURES` is set.
8+//! and compares every frame with ffmpeg's decode. It fails when
9+//! ffmpeg or a 10-bit libx264 is absent.
1110
1211 use std::path::{Path, PathBuf};
13-use std::process::Command;
1412
1513 use ec_core::frame::{PixelFormat, VideoFrame};
1614 use ec_h264::{Decoder, NalOutcome};
@@ -54,7 +52,7 @@ fn decode_all(bytes: &[u8]) -> Result<Vec<Vec<u8>>, ec_h264::Error> {
5452 }
5553
5654 fn ffmpeg_frames(stream: &Path, frame_len: usize) -> Option<Vec<u8>> {
57- let out = Command::new("ffmpeg")
55+ let out = ec_testkit::ffmpeg()
5856 .args(["-v", "error", "-i"])
5957 .arg(stream)
6058 .args(["-f", "rawvideo", "-pix_fmt", "yuv420p10le", "-"])
@@ -202,22 +200,14 @@ fn encode(dir: &Path, c: &Case) -> Option<PathBuf> {
202200 "h264".into(),
203201 stream.to_string_lossy().into_owned(),
204202 ]);
205- let st = Command::new("ffmpeg").args(&args).status().ok()?;
203+ let st = ec_testkit::ffmpeg().args(&args).status().ok()?;
206204 st.success().then_some(stream)
207205 }
208206
209207 fn check(c: &Case) -> Result<usize, String> {
210208 let dir = scratch();
211- let Some(stream) = encode(&dir, c) else {
212- if std::env::var_os("EC_REQUIRE_FIXTURES").is_some() {
213- panic!("{}: ffmpeg/libx264 10-bit cannot encode", c.tag);
214- }
215- eprintln!(
216- "SKIP {}: ffmpeg with 10-bit libx264 is not available",
217- c.tag
218- );
219- return Ok(0);
220- };
209+ let stream =
210+ encode(&dir, c).unwrap_or_else(|| panic!("{}: ffmpeg/libx264 10-bit cannot encode", c.tag));
221211 let bytes = std::fs::read(&stream).map_err(|e| e.to_string())?;
222212 let ours = decode_all(&bytes).map_err(|e| format!("{}: {e}", c.tag))?;
223213 let first = ours.first().ok_or("no frames decoded")?;
crates/ec-h264/tests/it/high422.rsmodified+5 -15
@@ -4,13 +4,11 @@
44 //! scaling matrices, chroma QP offsets, several slices, progressive and
55 //! MBAFF, at 8 and 10 bits.
66 //!
7-//! Every case is generated in the test (no committed binaries). A case skips,
8-//! saying so, when ffmpeg or the needed libx264 is absent, and fails instead
9-//! when `EC_REQUIRE_FIXTURES` is set. The 1920x1080 cases are slow enough to be
7+//! Every case is generated in the test (no committed binaries). A case fails when
8+//! ffmpeg or the needed libx264 is absent. The 1920x1080 cases are slow enough to be
109 //! opt-in: set `EC_H264_HI422_HD=1` (the lane gate does).
1110
1211 use std::path::{Path, PathBuf};
13-use std::process::Command;
1412
1513 use ec_h264::{Decoder, NalOutcome};
1614
@@ -72,7 +70,7 @@ fn encode(dir: &Path, c: &Case) -> Option<PathBuf> {
7270 } else {
7371 c.params.to_string()
7472 };
75- let st = Command::new("ffmpeg")
73+ let st = ec_testkit::ffmpeg()
7674 .args([
7775 "-hide_banner",
7876 "-loglevel",
@@ -99,16 +97,8 @@ fn encode(dir: &Path, c: &Case) -> Option<PathBuf> {
9997
10098 fn check(c: &Case) -> Result<usize, String> {
10199 let dir = scratch();
102- let Some(stream) = encode(&dir, c) else {
103- if std::env::var_os("EC_REQUIRE_FIXTURES").is_some() {
104- panic!("{}: ffmpeg/libx264 cannot encode this case", c.tag);
105- }
106- eprintln!(
107- "SKIP {}: ffmpeg with the needed libx264 is not available",
108- c.tag
109- );
110- return Ok(0);
111- };
100+ let stream = encode(&dir, c)
101+ .unwrap_or_else(|| panic!("{}: ffmpeg/libx264 cannot encode this case", c.tag));
112102 let bytes = std::fs::read(&stream).map_err(|e| e.to_string())?;
113103 let ours = decode_all(&bytes).map_err(|e| format!("{}: {e}", c.tag))?;
114104 let first = ours
crates/ec-h264/tests/it/high422_jvt.rsmodified+17 -42
@@ -5,13 +5,11 @@
55 //! Where the archive carries a reference YUV (Hi422FR10..15) each frame is
66 //! compared to it; the other streams ship only a trace, so every stream is
77 //! also compared frame by frame with ffmpeg's decode (`yuv422p` or
8-//! `yuv422p10le`). Fixtures live in the gitignored root `fixtures/`
9-//! (`scripts/fetch-vectors.sh h264-jvt`); a missing set skips with a message,
10-//! or fails when `EC_REQUIRE_FIXTURES` is set. The two 1920x1088 field
8+//! `yuv422p10le`). Fixtures come from `scripts/fixtures.sh`; a missing set
9+//! fails. The two 1920x1088 field
1110 //! streams are slow in a debug build and are skipped there.
1211
1312 use std::path::{Path, PathBuf};
14-use std::process::Command;
1513
1614 use ec_core::frame::PixelFormat;
1715 use ec_h264::{Decoder, NalOutcome};
@@ -19,7 +17,7 @@ use ec_h264::{Decoder, NalOutcome};
1917 use super::common::{ffmpeg_pix_frames, frame_bytes};
2018
2119 fn root() -> PathBuf {
22- Path::new(env!("CARGO_MANIFEST_DIR")).join("../../fixtures/vectors/h264-jvt-hi422")
20+ ec_testkit::fixture("vectors/h264-jvt-hi422")
2321 }
2422
2523 /// Every elementary stream (`.264`, `.jsv`) below `dir`, sorted.
@@ -90,28 +88,15 @@ fn compare(name: &str, ours: &[Vec<u8>], theirs: &[u8], who: &str) -> Result<(),
9088 Ok(())
9189 }
9290
93-fn have_set() -> Option<Vec<PathBuf>> {
91+fn have_set() -> Vec<PathBuf> {
9492 let list = streams(&root());
95- if list.is_empty() {
96- assert!(
97- std::env::var_os("EC_REQUIRE_FIXTURES").is_none(),
98- "h264-jvt-hi422 missing at {} - this gate would prove nothing; run \
99- scripts/fetch-vectors.sh h264-jvt",
100- root().display()
101- );
102- eprintln!("SKIP h264-jvt-hi422 missing at {}", root().display());
103- return None;
104- }
105- Some(list)
93+ assert!(list.len() >= 18, "only {} Hi422 streams found", list.len());
94+ list
10695 }
10796
10897 #[test]
10998 fn jvt_hi422_vectors_bit_exact() {
110- let Some(list) = have_set() else { return };
111- if std::env::var_os("EC_REQUIRE_FIXTURES").is_some() {
112- assert!(list.len() >= 18, "only {} Hi422 streams found", list.len());
113- }
114- let have_ffmpeg = Command::new("ffmpeg").arg("-version").output().is_ok();
99+ let list = have_set();
115100 let mut failed = Vec::new();
116101 let mut exact = Vec::new();
117102 for path in &list {
@@ -148,26 +133,16 @@ fn jvt_hi422_vectors_bit_exact() {
148133 ok = false;
149134 }
150135 }
151- if have_ffmpeg {
152- let pix = if format == PixelFormat::I210 {
153- "yuv422p10le"
154- } else {
155- "yuv422p"
156- };
157- match ffmpeg_pix_frames(path, pix) {
158- Some(t) => {
159- if let Err(e) = compare(&name, &ours, &t, "ffmpeg") {
160- failed.push(e);
161- ok = false;
162- }
163- }
164- None => {
165- assert!(
166- std::env::var_os("EC_REQUIRE_FIXTURES").is_none(),
167- "{name}: ffmpeg cannot decode"
168- );
169- }
170- }
136+ let pix = if format == PixelFormat::I210 {
137+ "yuv422p10le"
138+ } else {
139+ "yuv422p"
140+ };
141+ let theirs =
142+ ffmpeg_pix_frames(path, pix).unwrap_or_else(|| panic!("{name}: ffmpeg cannot decode"));
143+ if let Err(e) = compare(&name, &ours, &theirs, "ffmpeg") {
144+ failed.push(e);
145+ ok = false;
171146 }
172147 if ok {
173148 exact.push(format!("{name} ({} frames, {format:?})", ours.len()));
crates/ec-h264/tests/it/high444.rsmodified+5 -15
@@ -10,13 +10,11 @@
1010 //! or 512 at 10 bits). Separate colour planes cannot be written by x264; the
1111 //! JVT vectors (`high444_jvt.rs`) cover them.
1212 //!
13-//! Every case is generated in the test (no committed binaries). A case skips,
14-//! saying so, when ffmpeg or the needed libx264 is absent, and fails instead
15-//! when `EC_REQUIRE_FIXTURES` is set. The 1280x720 cases are opt-in:
13+//! Every case is generated in the test (no committed binaries). A case fails when
14+//! ffmpeg or the needed libx264 is absent. The 1280x720 cases are opt-in:
1615 //! set `EC_H264_HI444_HD=1`.
1716
1817 use std::path::{Path, PathBuf};
19-use std::process::Command;
2018
2119 use ec_core::frame::{PixelFormat, VideoFrame};
2220 use ec_h264::{Decoder, NalOutcome};
@@ -93,7 +91,7 @@ fn encode(dir: &Path, c: &Case) -> Option<PathBuf> {
9391 } else {
9492 c.params.to_string()
9593 };
96- let st = Command::new("ffmpeg")
94+ let st = ec_testkit::ffmpeg()
9795 .args([
9896 "-hide_banner",
9997 "-loglevel",
@@ -121,16 +119,8 @@ fn encode(dir: &Path, c: &Case) -> Option<PathBuf> {
121119
122120 fn check(c: &Case) -> Result<usize, String> {
123121 let dir = scratch();
124- let Some(stream) = encode(&dir, c) else {
125- if std::env::var_os("EC_REQUIRE_FIXTURES").is_some() {
126- panic!("{}: ffmpeg/libx264 cannot encode this case", c.tag);
127- }
128- eprintln!(
129- "SKIP {}: ffmpeg with the needed libx264 is not available",
130- c.tag
131- );
132- return Ok(0);
133- };
122+ let stream = encode(&dir, c)
123+ .unwrap_or_else(|| panic!("{}: ffmpeg/libx264 cannot encode this case", c.tag));
134124 let bytes = std::fs::read(&stream).map_err(|e| e.to_string())?;
135125 let ours = decode_all(&bytes).map_err(|e| format!("{}: {e}", c.tag))?;
136126 let (first, format) = ours
crates/ec-h264/tests/it/high444_jvt.rsmodified+41 -50
@@ -8,13 +8,12 @@
88 //! the archive ships a reference YUV, that YUV is used instead of / as well as
99 //! ffmpeg; a stream with neither is reported `unchecked` (and counted as a
1010 //! failure only if it also fails to decode). Fixtures live in the gitignored
11-//! root `fixtures/vectors/h264-jvt-hi444`; a missing set skips with a message,
12-//! or fails when `EC_REQUIRE_FIXTURES` is set. Heavy streams are skipped in
11+//! root `fixtures/vectors/h264-jvt-hi444`; a missing set fails. Heavy streams are skipped in
1312 //! debug builds.
1413
1514 use std::io::Read;
1615 use std::path::{Path, PathBuf};
17-use std::process::{Command, Stdio};
16+use std::process::Stdio;
1817
1918 use ec_core::frame::{PixelFormat, VideoFrame};
2019 use ec_h264::{Decoder, NalOutcome};
@@ -22,7 +21,7 @@ use ec_h264::{Decoder, NalOutcome};
2221 use super::common::layout;
2322
2423 fn root() -> PathBuf {
25- Path::new(env!("CARGO_MANIFEST_DIR")).join("../../fixtures/vectors/h264-jvt-hi444")
24+ ec_testkit::fixture("vectors/h264-jvt-hi444")
2625 }
2726
2827 const STREAM_EXT: &[&str] = &["264", "jsv", "avc", "26l", "h264", "bit", "bits", "jvt"];
@@ -127,7 +126,7 @@ fn decode_all(bytes: &[u8]) -> Result<Decoded, ec_h264::Error> {
127126 }
128127
129128 fn probe_pix_fmt(stream: &Path) -> Option<String> {
130- let out = Command::new("ffprobe")
129+ let out = ec_testkit::ffprobe()
131130 .args(["-v", "error", "-f", "h264", "-select_streams", "v:0"])
132131 .args(["-show_entries", "stream=pix_fmt", "-of", "csv=p=0"])
133132 .arg(stream)
@@ -140,7 +139,7 @@ fn probe_pix_fmt(stream: &Path) -> Option<String> {
140139 /// ffmpeg's raw decode as a pipe, so a long 14-bit 4:4:4 stream is compared a
141140 /// frame at a time instead of held in memory.
142141 fn ffmpeg_pipe(stream: &Path, pix_fmt: &str) -> Option<std::process::Child> {
143- Command::new("ffmpeg")
142+ ec_testkit::ffmpeg()
144143 .args(["-v", "error", "-f", "h264", "-i"])
145144 .arg(stream)
146145 .args(["-f", "rawvideo", "-pix_fmt", pix_fmt, "-"])
@@ -205,17 +204,11 @@ fn reference_yuv(stream: &Path) -> Option<PathBuf> {
205204 #[test]
206205 fn jvt_hi444_vectors_bit_exact() {
207206 let list = streams(&root());
208- if list.is_empty() {
209- assert!(
210- std::env::var_os("EC_REQUIRE_FIXTURES").is_none(),
211- "h264-jvt-hi444 missing at {} - this gate would prove nothing; run \
212- scripts/fetch-vectors.sh h264-jvt-hi444",
213- root().display()
214- );
215- eprintln!("SKIP h264-jvt-hi444 missing at {}", root().display());
216- return;
217- }
218- let have_ffmpeg = Command::new("ffmpeg").arg("-version").output().is_ok();
207+ assert!(
208+ !list.is_empty(),
209+ "no h264-jvt-hi444 streams in {}",
210+ root().display()
211+ );
219212 let mut failed = Vec::new();
220213 let mut summary = Vec::new();
221214 for path in &list {
@@ -262,41 +255,39 @@ fn jvt_hi444_vectors_bit_exact() {
262255 Err(e) => errors.push(e),
263256 }
264257 }
265- if have_ffmpeg {
266- // 9-bit streams are left-aligned to 10 bits by us.
267- let pix = match probe_pix_fmt(path).as_deref() {
268- Some("gray") => "gray".to_string(),
269- Some("gray10le" | "gray12le" | "gray9le") => "gray10le".to_string(),
270- Some(p) if p.contains("p9") => p.replace("p9", "p10"),
271- Some(p) => p.to_string(),
272- None => match format {
273- PixelFormat::I410 => "yuv444p10le".into(),
274- PixelFormat::I444 => "yuv444p".into(),
275- _ => String::new(),
276- },
277- };
278- let luma_only = pix.starts_with("gray");
279- match (!pix.is_empty() && pix != "unknown")
280- .then(|| ffmpeg_pipe(path, &pix))
281- .flatten()
282- {
283- Some(mut child) => {
284- let res = compare(
285- &name,
286- &ours,
287- child.stdout.as_mut().unwrap(),
288- luma_only,
289- "ffmpeg",
290- );
291- let _ = child.kill();
292- let _ = child.wait();
293- match res {
294- Ok(()) => checked.push("ffmpeg"),
295- Err(e) => errors.push(e),
296- }
258+ // 9-bit streams are left-aligned to 10 bits by us.
259+ let pix = match probe_pix_fmt(path).as_deref() {
260+ Some("gray") => "gray".to_string(),
261+ Some("gray10le" | "gray12le" | "gray9le") => "gray10le".to_string(),
262+ Some(p) if p.contains("p9") => p.replace("p9", "p10"),
263+ Some(p) => p.to_string(),
264+ None => match format {
265+ PixelFormat::I410 => "yuv444p10le".into(),
266+ PixelFormat::I444 => "yuv444p".into(),
267+ _ => String::new(),
268+ },
269+ };
270+ let luma_only = pix.starts_with("gray");
271+ match (!pix.is_empty() && pix != "unknown")
272+ .then(|| ffmpeg_pipe(path, &pix))
273+ .flatten()
274+ {
275+ Some(mut child) => {
276+ let res = compare(
277+ &name,
278+ &ours,
279+ child.stdout.as_mut().unwrap(),
280+ luma_only,
281+ "ffmpeg",
282+ );
283+ let _ = child.kill();
284+ let _ = child.wait();
285+ match res {
286+ Ok(()) => checked.push("ffmpeg"),
287+ Err(e) => errors.push(e),
297288 }
298- None => eprintln!("note {name}: ffmpeg cannot decode (pix_fmt {pix:?})"),
299289 }
290+ None => eprintln!("note {name}: ffmpeg cannot decode (pix_fmt {pix:?})"),
300291 }
301292 if !errors.is_empty() {
302293 eprintln!("FAIL {name}: {}", errors.join("; "));
crates/ec-h264/tests/it/interlaced.rsmodified+6 -25
@@ -2,42 +2,26 @@
22 //! macroblock-adaptive frame/field coding (MBAFF), woven into frames.
33 //!
44 //! The authority is the JVT conformance suite: each vector's reference YUV is
5-//! compared frame by frame. Fixtures live in the gitignored root `fixtures/`
6-//! (`scripts/fetch-vectors.sh`); a missing one skips with a message, or fails
7-//! when `EC_REQUIRE_FIXTURES` is set, like the other conformance tests.
5+//! compared frame by frame. Fixtures come from `scripts/fixtures.sh`; a missing one fails.
86
97 use std::path::{Path, PathBuf};
108
119 use ec_core::frame::{Interlace, VideoFrame};
1210 use ec_h264::{Decoder, NalOutcome};
1311
14-/// Where a vector lives: the interlaced set (`scripts/fetch-vectors.sh`), or
12+/// Where a vector lives: the interlaced set (`scripts/fixtures.sh`), or
1513 /// the general JVT set for the few interlaced streams that were fetched first.
1614 fn vector_dir(name: &str) -> PathBuf {
17- let root = Path::new(env!("CARGO_MANIFEST_DIR")).join("../../fixtures/vectors");
18- let own = root.join("h264-jvt-interlaced").join(name);
15+ let own = ec_testkit::root()
16+ .join("vectors/h264-jvt-interlaced")
17+ .join(name);
1918 if own.exists() {
2019 own
2120 } else {
22- root.join("h264-jvt").join(name)
21+ ec_testkit::fixture(&format!("vectors/h264-jvt/{name}"))
2322 }
2423 }
2524
26-/// True when `path` exists; otherwise skip (or fail under `EC_REQUIRE_FIXTURES`).
27-fn have_fixture(path: &Path, what: &str) -> bool {
28- if path.exists() {
29- return true;
30- }
31- assert!(
32- std::env::var_os("EC_REQUIRE_FIXTURES").is_none(),
33- "{what} missing at {} - this gate would prove nothing; run \
34- scripts/link-fixtures.sh or scripts/fetch-vectors.sh",
35- path.display()
36- );
37- eprintln!("SKIP {what} missing at {}", path.display());
38- false
39-}
40-
4125 fn find_with_ext(dir: &Path, exts: &[&str]) -> Option<PathBuf> {
4226 let mut found: Vec<PathBuf> = std::fs::read_dir(dir)
4327 .ok()?
@@ -92,9 +76,6 @@ fn decode_all(bytes: &[u8]) -> Result<Vec<(Vec<u8>, Interlace)>, ec_h264::Error>
9276 /// Decode one JVT vector and compare it with its reference YUV.
9377 fn check_vector(name: &str) -> Result<usize, String> {
9478 let dir = vector_dir(name);
95- if !have_fixture(&dir, &format!("JVT vector {name}")) {
96- return Ok(0);
97- }
9879 let stream = find_with_ext(&dir, &["jsv", "264", "avc", "26l", "h264", "jvt"])
9980 .ok_or(format!("{name}: no bitstream"))?;
10081 let yuv = find_with_ext(&dir, &["yuv"]).ok_or(format!("{name}: no reference YUV"))?;
crates/ec-h264/tests/it/mbaff_x264.rsmodified+5 -15
@@ -4,13 +4,11 @@
44 //! spatial and temporal direct, weighted prediction, the 8x8 transform,
55 //! several slices, and High 10.
66 //!
7-//! Every case is generated in the test (no committed binaries). A case skips,
8-//! saying so, when ffmpeg or the needed libx264 is absent, and fails instead
9-//! when `EC_REQUIRE_FIXTURES` is set. The 1920x1080 cases are slow enough to be
7+//! Every case is generated in the test (no committed binaries). A case fails when
8+//! ffmpeg or the needed libx264 is absent. The 1920x1080 cases are slow enough to be
109 //! opt-in: set `EC_H264_MBAFF_HD=1` (the lane gate does).
1110
1211 use std::path::{Path, PathBuf};
13-use std::process::Command;
1412
1513 use ec_core::frame::{PixelFormat, VideoFrame};
1614 use ec_h264::{Decoder, NalOutcome};
@@ -89,7 +87,7 @@ fn encode(dir: &Path, c: &Case) -> Option<PathBuf> {
8987 ("yuv420p", "high")
9088 };
9189 let params = format!("interlaced=1:{}", c.params);
92- let st = Command::new("ffmpeg")
90+ let st = ec_testkit::ffmpeg()
9391 .args([
9492 "-hide_banner",
9593 "-loglevel",
@@ -112,16 +110,8 @@ fn encode(dir: &Path, c: &Case) -> Option<PathBuf> {
112110
113111 fn check(c: &Case) -> Result<usize, String> {
114112 let dir = scratch();
115- let Some(stream) = encode(&dir, c) else {
116- if std::env::var_os("EC_REQUIRE_FIXTURES").is_some() {
117- panic!("{}: ffmpeg/libx264 cannot encode this case", c.tag);
118- }
119- eprintln!(
120- "SKIP {}: ffmpeg with the needed libx264 is not available",
121- c.tag
122- );
123- return Ok(0);
124- };
113+ let stream = encode(&dir, c)
114+ .unwrap_or_else(|| panic!("{}: ffmpeg/libx264 cannot encode this case", c.tag));
125115 let bytes = std::fs::read(&stream).map_err(|e| e.to_string())?;
126116 let ours = decode_all(&bytes).map_err(|e| format!("{}: {e}", c.tag))?;
127117 let first = ours
crates/ec-h264/tests/it/no_panic.rsmodified+2 -12
@@ -5,8 +5,7 @@
55 //! fixed-seed positions. Every mutant is decoded end to end. An `Err` is fine;
66 //! a panic fails the test.
77 //!
8-//! Fixture-gated like the other conformance tests: without `fixtures/` the test
9-//! skips loudly, or fails when `EC_REQUIRE_FIXTURES` is set.
8+//! Fixtures come from `scripts/fixtures.sh`; a missing one fails.
109
1110 use std::path::{Path, PathBuf};
1211
@@ -20,7 +19,7 @@ const CORRUPTIONS: usize = 30;
2019 const SEED: u32 = 0x9E37_79B9;
2120
2221 fn vectors_dir() -> PathBuf {
23- Path::new(env!("CARGO_MANIFEST_DIR")).join("../../fixtures/vectors/h264-jvt")
22+ ec_testkit::fixture("vectors/h264-jvt")
2423 }
2524
2625 /// Every vector directory, in name order (the order `conformance.rs` walks).
@@ -53,15 +52,6 @@ fn decode_everything(bytes: &[u8]) {
5352 #[test]
5453 fn truncated_and_corrupted_conformance_streams_never_panic() {
5554 let base = vectors_dir();
56- if !base.exists() {
57- assert!(
58- std::env::var_os("EC_REQUIRE_FIXTURES").is_none(),
59- "JVT vectors missing at {} — run scripts/link-fixtures.sh or scripts/fetch-vectors.sh",
60- base.display()
61- );
62- eprintln!("SKIP JVT vectors missing at {}", base.display());
63- return;
64- }
6555 let mut streams = 0usize;
6656 for name in vector_names(&base).into_iter().take(STREAMS) {
6757 let Some(stream) = find_stream(&base.join(&name)) else {
crates/ec-h264/tests/it/refusals.rsmodified+2 -13
@@ -10,8 +10,6 @@
1010 //! maps every refused JVT conformance vector to the feature it really uses,
1111 //! and is fixture-gated like `conformance.rs`.
1212
13-use std::path::Path;
14-
1513 use ec_core::BitWriter;
1614 use ec_h264::{Decoder, Error, NalOutcome};
1715
@@ -294,21 +292,12 @@ fn different_luma_and_chroma_bit_depth_is_refused_by_name() {
294292 }
295293 }
296294
297-/// Every refused vector in `fetch-vectors.sh`'s h264-jvt set, against the
295+/// Every refused vector in the h264-jvt set in `scripts/fixtures.sh`, against the
298296 /// feature it really uses. A vector that starts refusing for another reason,
299297 /// or stops being refused, changes this table and fails the test.
300298 #[test]
301299 fn jvt_refused_vectors_refuse_for_their_feature() {
302- let base = Path::new(env!("CARGO_MANIFEST_DIR")).join("../../fixtures/vectors/h264-jvt");
303- if !base.exists() {
304- assert!(
305- std::env::var_os("EC_REQUIRE_FIXTURES").is_none(),
306- "JVT vectors missing at {} (run scripts/fetch-vectors.sh)",
307- base.display()
308- );
309- eprintln!("SKIP JVT vectors missing at {}", base.display());
310- return;
311- }
300+ let base = ec_testkit::fixture("vectors/h264-jvt");
312301 let expected: &[(&str, &str)] = &[];
313302 let mut failures = Vec::new();
314303 for &(name, feature) in expected {
crates/ec-h265-syntax/Cargo.tomlmodified+3 -0
@@ -8,3 +8,6 @@ authors.workspace = true
88
99 [dependencies]
1010 ec-core.workspace = true
11+
12+[dev-dependencies]
13+ec-testkit.workspace = true
crates/ec-h265-syntax/tests/sei_sweep.rsmodified+6 -17
@@ -1,22 +1,18 @@
11 //! The SEI reader over the JCT-VC conformance streams.
22 //!
33 //! Every prefix and suffix SEI NAL unit of every stream must parse without error,
4-//! and the streams that carry a `decoded_picture_hash` are counted. The sweep is
5-//! skipped when the vectors are absent, unless `EC_REQUIRE_FIXTURES` is set, in
6-//! which case an absent fixture fails the test.
4+//! and the streams that carry a `decoded_picture_hash` are counted. The sweep fails
5+//! when the vectors are absent.
76
87 use std::path::{Path, PathBuf};
98
109 use ec_h265_syntax::nal::split_annex_b;
1110 use ec_h265_syntax::sei::{SeiMessage, parse_sei_rbsp};
1211
13-/// Every `.bin` or `.bit` stream under `fixtures/vectors/hevc-jctvc`, two directory
14-/// levels deep, sorted by path. `EC_H265_JCTVC_DIR` overrides the root.
12+/// Every `.bin` or `.bit` stream under `vectors/hevc-jctvc` in the fixtures root, two
13+/// directory levels deep, sorted by path.
1514 fn streams() -> Vec<PathBuf> {
16- let root = match std::env::var("EC_H265_JCTVC_DIR") {
17- Ok(dir) => PathBuf::from(dir),
18- Err(_) => Path::new(env!("CARGO_MANIFEST_DIR")).join("../../fixtures/vectors/hevc-jctvc"),
19- };
15+ let root = ec_testkit::fixture("vectors/hevc-jctvc");
2016 fn walk(dir: &Path, depth: u32, out: &mut Vec<PathBuf>) {
2117 let Ok(entries) = std::fs::read_dir(dir) else {
2218 return;
@@ -39,14 +35,7 @@ fn streams() -> Vec<PathBuf> {
3935 #[test]
4036 fn every_sei_in_the_conformance_streams_parses() {
4137 let streams = streams();
42- if streams.is_empty() {
43- assert!(
44- std::env::var_os("EC_REQUIRE_FIXTURES").is_none(),
45- "EC_REQUIRE_FIXTURES=1 but fixtures/vectors/hevc-jctvc has no streams"
46- );
47- eprintln!("SEI sweep skipped: vectors absent");
48- return;
49- }
38+ assert!(!streams.is_empty(), "no streams under vectors/hevc-jctvc");
5039 let mut with_hash = 0usize;
5140 let mut hash_streams = Vec::new();
5241 let mut sei_nals = 0usize;
crates/ec-h265/Cargo.tomlmodified+1 -0
@@ -15,4 +15,5 @@ archmage = "=0.9.31-beta.1"
1515 multiversion = "0.9"
1616
1717 [dev-dependencies]
18+ec-testkit.workspace = true
1819 ec-h265-syntax.workspace = true
crates/ec-h265/tests/it/conformance.rsmodified+5 -50
@@ -8,7 +8,6 @@ use crate::common::{natural_frame, pin_or_panic, test_frame};
88 use ec_core::frame::VideoFrame;
99 use ec_h265::encoder::{EncodedPicture, Encoder, EncoderConfig, RateControl, TransformSkip};
1010 use std::path::{Path, PathBuf};
11-use std::process::Command;
1211
1312 fn scratch_dir() -> PathBuf {
1413 let dir = std::env::temp_dir().join("ec-h265-tests");
@@ -16,18 +15,10 @@ fn scratch_dir() -> PathBuf {
1615 dir
1716 }
1817
19-fn have_ffmpeg() -> bool {
20- Command::new("ffmpeg")
21- .arg("-version")
22- .output()
23- .map(|o| o.status.success())
24- .unwrap_or(false)
25-}
26-
2718 /// Decode an Annex-B file with ffmpeg into planar 8-bit 4:2:0.
2819 fn ffmpeg_decode(path: &Path) -> Result<Vec<u8>, String> {
2920 let out = path.with_extension("yuv");
30- let status = Command::new("ffmpeg")
21+ let status = ec_testkit::ffmpeg()
3122 .args(["-v", "error", "-y", "-i"])
3223 .arg(path)
3324 .args(["-f", "rawvideo", "-pix_fmt", "yuv420p"])
@@ -147,10 +138,6 @@ fn encode_natural(
147138 /// the search actually fired — and still decode bit-exactly.
148139 #[test]
149140 fn chroma_mode_search_decodes_bit_exactly() {
150- if !have_ffmpeg() {
151- eprintln!("skipping: ffmpeg not installed");
152- return;
153- }
154141 for &(w, h) in &[(64u32, 64u32), (130, 66), (352, 288)] {
155142 let (source, coded) = encode_with(w, h, 27, None, true, false);
156143 let (_, derived) = encode_with(w, h, 27, None, false, false);
@@ -224,10 +211,6 @@ fn chroma_mode_search_decodes_bit_exactly() {
224211 /// partition are all where the decoder looks for them.
225212 #[test]
226213 fn intra_nxn_decodes_bit_exactly() {
227- if !have_ffmpeg() {
228- eprintln!("skipping: ffmpeg not installed");
229- return;
230- }
231214 for &(w, h) in &[(64u32, 64u32), (130, 66), (352, 288)] {
232215 let (source, coded) = encode_natural(w, h, 22, true);
233216 let (_, square) = encode_natural(w, h, 22, false);
@@ -305,10 +288,6 @@ fn intra_nxn_decodes_bit_exactly() {
305288 /// `EC_H265_SDH` arm of the clip gate measures.
306289 #[test]
307290 fn sign_hiding_decodes_bit_exactly() {
308- if !have_ffmpeg() {
309- eprintln!("skipping: ffmpeg not installed");
310- return;
311- }
312291 for &(w, h) in &[(64u32, 64u32), (130, 66), (352, 288)] {
313292 let (source, coded) = encode_sdh(w, h, 22, true);
314293 let (_, plain) = encode_sdh(w, h, 22, false);
@@ -414,10 +393,6 @@ fn encode_tskip(
414393 /// sample for sample.
415394 #[test]
416395 fn transform_skip_decodes_bit_exactly() {
417- if !have_ffmpeg() {
418- eprintln!("skipping: ffmpeg not installed");
419- return;
420- }
421396 for &(w, h) in &[(64u32, 64u32), (130, 66), (352, 288)] {
422397 let (source, coded) = encode_tskip(w, h, 22, TransformSkip::AlwaysFor4x4);
423398 let (_, plain) = encode_tskip(w, h, 22, TransformSkip::Off);
@@ -484,10 +459,6 @@ fn transform_skip_decodes_bit_exactly() {
484459 }
485460 #[test]
486461 fn ffmpeg_decodes_bit_exactly_at_every_shape() {
487- if !have_ffmpeg() {
488- eprintln!("skipping: ffmpeg not installed");
489- return;
490- }
491462 // 1920x1080 needs the conformance window on the bottom (1088 coded rows are
492463 // not used: 1080 is a multiple of 8, but 64x64 CTBs still overhang), 1916
493464 // 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() {
577548 /// pass without a single 64x64 coding unit ever being kept.
578549 #[test]
579550 fn cu64_decodes_bit_exactly() {
580- if !have_ffmpeg() {
581- eprintln!("skipping: ffmpeg not installed");
582- return;
583- }
584551 // 130x66 is here for the partial coding tree blocks, not for the decision:
585552 // at that size only two tree blocks are whole and the search keeps neither,
586553 // so its stream is allowed to come out identical.
@@ -684,13 +651,9 @@ fn ffmpeg_verifies_the_decoded_picture_hash() {
684651 // decoder checks that claim against what it decoded when asked to. This is
685652 // the one oracle that does not depend on this crate being right about
686653 // anything except the hash itself.
687- if !have_ffmpeg() {
688- eprintln!("skipping: ffmpeg not installed");
689- return;
690- }
691654 let (_, coded) = encode(352, 288, 30, None);
692655 let path = write_au("hash-352x288", &coded);
693- let output = Command::new("ffmpeg")
656+ let output = ec_testkit::ffmpeg()
694657 .args(["-v", "debug", "-err_detect", "crccheck", "-y", "-i"])
695658 .arg(&path)
696659 .args(["-f", "null", "-"])
@@ -712,13 +675,13 @@ fn vaapi_hardware_decodes_the_stream() {
712675 // The other half of "it decodes": a GPU decoder is a different
713676 // implementation with different tolerances, and it is what edith's HEVC
714677 // path actually uses. Skipped where there is no render node.
715- if !have_ffmpeg() || !Path::new("/dev/dri/renderD128").exists() {
716- eprintln!("skipping: no ffmpeg or no VA-API render node");
678+ if !Path::new("/dev/dri/renderD128").exists() {
679+ eprintln!("skipping: no VA-API render node");
717680 return;
718681 }
719682 let (_, coded) = encode(1920, 1080, 27, None);
720683 let path = write_au("vaapi-1080p", &coded);
721- let output = Command::new("ffmpeg")
684+ let output = ec_testkit::ffmpeg()
722685 .args([
723686 "-v",
724687 "error",
@@ -838,10 +801,6 @@ fn the_batch_helper_codes_every_picture_as_its_own_access_unit() {
838801 /// has to read them back to the same samples the encoder reconstructed.
839802 #[test]
840803 fn rdoq_decodes_bit_exactly() {
841- if !have_ffmpeg() {
842- eprintln!("skipping: ffmpeg not installed");
843- return;
844- }
845804 for &(w, h) in &[(64u32, 64u32), (130, 66), (352, 288)] {
846805 let (source, coded) = encode_rdoq(w, h, 27, true);
847806 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
925884 /// samples the encoder reconstructed.
926885 #[test]
927886 fn rqt_decodes_bit_exactly() {
928- if !have_ffmpeg() {
929- eprintln!("skipping: ffmpeg not installed");
930- return;
931- }
932887 for &(w, h) in &[(64u32, 64u32), (130, 66), (352, 288)] {
933888 let (source, coded) = encode_rqt(w, h, 27, true);
934889 let (_, plain) = encode_rqt(w, h, 27, false);
crates/ec-h265/tests/it/conformance_intra.rsmodified+10 -34
@@ -24,12 +24,9 @@ struct Row {
2424 decode_secs: f64,
2525 }
2626
27-/// The conformance directory: `EC_H265_JCTVC_DIR`, or the fixtures link.
27+/// The conformance directory under the fixtures root.
2828 fn jctvc_root() -> PathBuf {
29- match std::env::var("EC_H265_JCTVC_DIR") {
30- Ok(dir) => PathBuf::from(dir),
31- Err(_) => Path::new(env!("CARGO_MANIFEST_DIR")).join("../../fixtures/vectors/hevc-jctvc"),
32- }
29+ ec_testkit::fixture("vectors/hevc-jctvc")
3330 }
3431
3532 /// The conformance streams: the first `.bin` or `.bit` bitstream of each zip's
@@ -67,7 +64,7 @@ fn streams() -> Vec<PathBuf> {
6764 }
6865
6966 /// Decodes one stream and checks every output picture against its MD5 SEI.
70-fn check_stream(path: &Path, name: &str, ref_dir: Option<&Path>) -> Row {
67+fn check_stream(path: &Path, name: &str) -> Row {
7168 let mut row = Row {
7269 name: name.to_string(),
7370 accepted: "no",
@@ -84,7 +81,7 @@ fn check_stream(path: &Path, name: &str, ref_dir: Option<&Path>) -> Row {
8481 return row;
8582 }
8683 };
87- let reference = ref_dir.and_then(|d| std::fs::read(d.join(format!("{name}.yuv"))).ok());
84+ let reference = std::fs::read(path.with_extension("yuv")).ok();
8885 // A `<name>_md5.txt` beside the bitstream is the authority for frames without a hash SEI. It
8986 // takes precedence over the ffmpeg reference YUV, which ffmpeg cannot reproduce for such a
9087 // 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 {
120117 // No hash SEI: the frame is checked against the reference YUV, when there is one.
121118 if let Some(reference) = reference.as_deref() {
122119 let want = cropped_bytes(&frame.picture, &frame.window);
123- if let Ok(dir) = std::env::var("EC_H265_DUMP_DIR") {
124- // Diagnostic: append this frame to the stream's dump file.
125- use std::io::Write;
126- if let Ok(mut f) = std::fs::OpenOptions::new()
127- .create(true)
128- .append(true)
129- .open(Path::new(&dir).join(format!("{name}.ours.yuv")))
130- {
131- let _ = f.write_all(&want);
132- }
133- }
134120 let start = index * want.len();
135121 row.checked += 1;
136122 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 {
197183 fn conformance_pictures_match_the_sei_hash() {
198184 let root = jctvc_root();
199185 let streams = streams();
200- if streams.is_empty() {
201- eprintln!(
202- "conformance check skipped: no streams under {}",
203- root.display()
204- );
205- assert!(
206- !root.is_dir(),
207- "fixture directory {} exists but holds no bitstreams",
208- root.display()
209- );
210- return;
211- }
212- let ref_dir = std::env::var("EC_H265_REF_YUV_DIR").ok().map(PathBuf::from);
186+ assert!(
187+ !streams.is_empty(),
188+ "no conformance streams under {}",
189+ root.display()
190+ );
213191
214192 let mut rows = Vec::new();
215193 for path in &streams {
@@ -217,9 +195,7 @@ fn conformance_pictures_match_the_sei_hash() {
217195 .file_stem()
218196 .map(|s| s.to_string_lossy().into_owned())
219197 .unwrap_or_default();
220- let outcome = panic::catch_unwind(AssertUnwindSafe(|| {
221- check_stream(path, &name, ref_dir.as_deref())
222- }));
198+ let outcome = panic::catch_unwind(AssertUnwindSafe(|| check_stream(path, &name)));
223199 let mut row = match outcome {
224200 Ok(row) => row,
225201 Err(payload) => {
crates/ec-h265/tests/it/conformance_rext.rsmodified+11 -35
@@ -1,5 +1,5 @@
11 //! Checks every output picture of each JCT-VC range extension conformance stream
2-//! (`scripts/fetch-vectors.sh hevc-rext`) against the hash in its decoded picture hash SEI
2+//! (`scripts/fixtures.sh`, `vectors/hevc-rext`) against the hash in its decoded picture hash SEI
33 //! (D.3.19), or against the whole-output MD5 of the package when the stream has no hash.
44 //!
55 //! A stream the decoder refuses must be refused by name: the error text has to be one of
@@ -24,12 +24,9 @@ struct Row {
2424 decode_secs: f64,
2525 }
2626
27-/// The conformance directory: `EC_H265_REXT_DIR`, or the fixtures link.
27+/// The conformance directory under the fixtures root.
2828 fn jctvc_root() -> PathBuf {
29- match std::env::var("EC_H265_REXT_DIR") {
30- Ok(dir) => PathBuf::from(dir),
31- Err(_) => Path::new(env!("CARGO_MANIFEST_DIR")).join("../../fixtures/vectors/hevc-rext"),
32- }
29+ ec_testkit::fixture("vectors/hevc-rext")
3330 }
3431
3532 /// The conformance streams: the first `.bin` or `.bit` bitstream of each zip's
@@ -106,7 +103,7 @@ fn nal_chunks(data: &[u8]) -> Vec<&[u8]> {
106103 }
107104
108105 /// Decodes one stream and checks every output picture against its MD5 SEI.
109-fn check_stream(path: &Path, name: &str, ref_dir: Option<&Path>) -> Row {
106+fn check_stream(path: &Path, name: &str) -> Row {
110107 let mut row = Row {
111108 name: name.to_string(),
112109 accepted: "no",
@@ -123,7 +120,7 @@ fn check_stream(path: &Path, name: &str, ref_dir: Option<&Path>) -> Row {
123120 return row;
124121 }
125122 };
126- let reference = ref_dir.and_then(|d| std::fs::read(d.join(format!("{name}.yuv"))).ok());
123+ let reference = std::fs::read(path.with_extension("yuv")).ok();
127124 // A `<name>_md5.txt` beside the bitstream is the authority for frames without a hash SEI. It
128125 // takes precedence over the ffmpeg reference YUV, which ffmpeg cannot reproduce for such a
129126 // 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 {
149146 // No hash SEI: the frame is checked against the reference YUV, when there is one.
150147 if let Some(reference) = reference.as_deref() {
151148 let want = cropped_bytes(&frame.picture, &frame.window);
152- if let Ok(dir) = std::env::var("EC_H265_DUMP_DIR") {
153- // Diagnostic: append this frame to the stream's dump file.
154- use std::io::Write;
155- if let Ok(mut f) = std::fs::OpenOptions::new()
156- .create(true)
157- .append(true)
158- .open(Path::new(&dir).join(format!("{name}.ours.yuv")))
159- {
160- let _ = f.write_all(&want);
161- }
162- }
163149 let start = index * want.len();
164150 row.checked += 1;
165151 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 {
244230 fn rext_conformance_pictures_match_the_sei_hash() {
245231 let root = jctvc_root();
246232 let streams = streams();
247- if streams.is_empty() {
248- eprintln!(
249- "conformance check skipped: no streams under {}",
250- root.display()
251- );
252- assert!(
253- std::env::var_os("EC_REQUIRE_FIXTURES").is_none() && !root.is_dir(),
254- "fixture directory {} holds no bitstreams",
255- root.display()
256- );
257- return;
258- }
259- let ref_dir = std::env::var("EC_H265_REF_YUV_DIR").ok().map(PathBuf::from);
233+ assert!(
234+ !streams.is_empty(),
235+ "no conformance streams under {}",
236+ root.display()
237+ );
260238
261239 let mut rows = Vec::new();
262240 for path in &streams {
@@ -265,9 +243,7 @@ fn rext_conformance_pictures_match_the_sei_hash() {
265243 .map(|s| s.to_string_lossy().into_owned())
266244 .unwrap_or_default();
267245 eprintln!("stream {name}");
268- let outcome = panic::catch_unwind(AssertUnwindSafe(|| {
269- check_stream(path, &name, ref_dir.as_deref())
270- }));
246+ let outcome = panic::catch_unwind(AssertUnwindSafe(|| check_stream(path, &name)));
271247 let mut row = match outcome {
272248 Ok(row) => row,
273249 Err(payload) => {
crates/ec-h265/tests/it/conformance_rext422.rsmodified+9 -20
@@ -2,12 +2,10 @@
22 //!
33 //! The committed 64x64 stream is decoded by ffmpeg at run time and compared sample for
44 //! sample. The Sony RExt conformance streams and the generated GOP/intra clips live in the
5-//! gitignored fixtures (`EC_H265_REXT_DIR`, default `fixtures/vectors/hevc-rext`, with the
6-//! ffmpeg output of each stream under `ref/` or next to it); a missing fixture is skipped
7-//! and reported, a present one must decode byte-exactly.
5+//! fixtures (`vectors/hevc-rext`, with the ffmpeg output of each stream under `ref/` or next
6+//! to it); a missing fixture fails, and every present one must decode byte-exactly.
87
98 use std::path::{Path, PathBuf};
10-use std::process::Command;
119
1210 use ec_h265::Decoder;
1311
@@ -59,16 +57,12 @@ fn first_diff(a: &[u8], b: &[u8]) -> Option<usize> {
5957
6058 #[test]
6159 fn committed_422_stream_matches_ffmpeg() {
62- if Command::new("ffmpeg").arg("-version").output().is_err() {
63- eprintln!("skip: no ffmpeg");
64- return;
65- }
6660 let dir = std::env::temp_dir().join("ec-h265-rext422");
6761 std::fs::create_dir_all(&dir).unwrap();
6862 let src = dir.join("yuv422_10.265");
6963 let reference = dir.join("yuv422_10.yuv");
7064 std::fs::write(&src, YUV422_10).unwrap();
71- let st = Command::new("ffmpeg")
65+ let st = ec_testkit::ffmpeg()
7266 .args(["-v", "error", "-y", "-i"])
7367 .arg(&src)
7468 .args(["-f", "rawvideo", "-pix_fmt", "yuv422p10le"])
@@ -86,10 +80,7 @@ fn committed_422_stream_matches_ffmpeg() {
8680 }
8781
8882 fn rext_root() -> PathBuf {
89- match std::env::var("EC_H265_REXT_DIR") {
90- Ok(d) => PathBuf::from(d),
91- Err(_) => Path::new(env!("CARGO_MANIFEST_DIR")).join("../../fixtures/vectors/hevc-rext"),
92- }
83+ ec_testkit::fixture("vectors/hevc-rext")
9384 }
9485
9586 fn find_stream(dir: &Path) -> Option<PathBuf> {
@@ -116,9 +107,8 @@ fn rext_422_vectors_are_byte_exact() {
116107 ("Main_422_10_A_RExt_Sony_2", 1920, 1080),
117108 ("Main_422_10_B_RExt_Sony_2", 2560, 1600),
118109 ] {
119- if let Some(s) = find_stream(&root.join(name)) {
120- cases.push((s, root.join("ref").join(format!("{name}.yuv")), w, h));
121- }
110+ let s = find_stream(&root.join(name)).unwrap_or_else(|| panic!("{name}: no stream"));
111+ cases.push((s, root.join("ref").join(format!("{name}.yuv")), w, h));
122112 }
123113 for name in [
124114 "i422_8",
@@ -137,10 +127,9 @@ fn rext_422_vectors_are_byte_exact() {
137127 }
138128 let mut checked = 0;
139129 for (stream, reference, w, h) in cases {
140- let (Ok(data), Ok(want)) = (std::fs::read(&stream), std::fs::read(&reference)) else {
141- eprintln!("skip (fixture missing): {}", stream.display());
142- continue;
143- };
130+ let data = std::fs::read(&stream).unwrap_or_else(|e| panic!("{}: {e}", stream.display()));
131+ let want =
132+ std::fs::read(&reference).unwrap_or_else(|e| panic!("{}: {e}", reference.display()));
144133 let got = raw(&decode(&data), w, h);
145134 assert_eq!(
146135 first_diff(&got, &want),
crates/ec-h265/tests/it/cu_syntax.rsmodified+3 -9
@@ -7,12 +7,9 @@ use ec_h265::dec::Decoder;
77 use std::path::{Path, PathBuf};
88
99 /// The conformance streams: the first `.bin` or `.bit` bitstream of each directory
10-/// under `fixtures/vectors/hevc-jctvc` (or `EC_H265_JCTVC_DIR`), sorted.
10+/// under `vectors/hevc-jctvc` in the fixtures root, sorted.
1111 fn streams() -> Vec<PathBuf> {
12- let root = match std::env::var("EC_H265_JCTVC_DIR") {
13- Ok(dir) => PathBuf::from(dir),
14- Err(_) => Path::new(env!("CARGO_MANIFEST_DIR")).join("../../fixtures/vectors/hevc-jctvc"),
15- };
12+ let root = ec_testkit::fixture("vectors/hevc-jctvc");
1613 fn bitstreams_in(dir: &Path, depth: u32, out: &mut Vec<PathBuf>) {
1714 let Ok(entries) = std::fs::read_dir(dir) else {
1815 return;
@@ -84,10 +81,7 @@ fn inter_placeholder_runs_over_pb_slices() {
8481 use ec_h265_syntax::nal::{NalUnitType, unescape_rbsp};
8582 use ec_h265_syntax::slice::{SliceHeader, SliceType};
8683 let streams = streams();
87- if streams.is_empty() {
88- eprintln!("inter placeholder: no conformance streams found, skipping");
89- return;
90- }
84+ assert!(!streams.is_empty(), "no conformance streams");
9185 let (mut pb_slices, mut decoded, mut refused) = (0usize, 0usize, 0usize);
9286 for path in &streams {
9387 let data = std::fs::read(path).expect("read bitstream");
crates/ec-h265/tests/it/dec_meta.rsmodified+8 -27
@@ -3,7 +3,7 @@
33 //! NAL units (62, 63) and malformed SEI change nothing.
44 //!
55 //! The streams come from `fixtures/vectors/hevc-jctvc`. Without them the tests
6-//! skip, unless `EC_REQUIRE_FIXTURES` is set, in which case they fail.
6+//! fail when the fixtures are absent.
77
88 use std::path::{Path, PathBuf};
99
@@ -12,10 +12,7 @@ use ec_h265_syntax::nal::{escape_rbsp, split_annex_b};
1212 use ec_h265_syntax::sei::{ContentLightLevel, MasteringDisplay, PictureHash};
1313
1414 fn stream_files() -> Vec<PathBuf> {
15- let root = match std::env::var("EC_H265_JCTVC_DIR") {
16- Ok(dir) => PathBuf::from(dir),
17- Err(_) => Path::new(env!("CARGO_MANIFEST_DIR")).join("../../fixtures/vectors/hevc-jctvc"),
18- };
15+ let root = ec_testkit::fixture("vectors/hevc-jctvc");
1916 fn walk(dir: &Path, depth: u32, out: &mut Vec<PathBuf>) {
2017 let Ok(entries) = std::fs::read_dir(dir) else {
2118 return;
@@ -81,16 +78,8 @@ fn clean_stream() -> Option<(String, Vec<Vec<u8>>)> {
8178 None
8279 }
8380
84-fn require_stream() -> Option<(String, Vec<Vec<u8>>)> {
85- let found = clean_stream();
86- if found.is_none() {
87- assert!(
88- std::env::var_os("EC_REQUIRE_FIXTURES").is_none(),
89- "EC_REQUIRE_FIXTURES=1 but no clean conformance stream is available"
90- );
91- eprintln!("decoder metadata tests skipped: vectors absent");
92- }
93- found
81+fn require_stream() -> (String, Vec<Vec<u8>>) {
82+ clean_stream().expect("no clean conformance stream")
9483 }
9584
9685 /// What a frame looks like to a caller, for comparing two decodes.
@@ -140,9 +129,7 @@ fn hdr10_prefix_rbsp() -> Vec<u8> {
140129
141130 #[test]
142131 fn dolby_vision_nal_units_change_nothing() {
143- let Some((name, nals)) = require_stream() else {
144- return;
145- };
132+ let (name, nals) = require_stream();
146133 let base = decode(&nals).unwrap();
147134 let mut injected = Vec::new();
148135 for nal in &nals {
@@ -164,9 +151,7 @@ fn dolby_vision_nal_units_change_nothing() {
164151
165152 #[test]
166153 fn malformed_sei_is_skipped_and_the_stream_decodes_the_same() {
167- let Some((name, nals)) = require_stream() else {
168- return;
169- };
154+ let (name, nals) = require_stream();
170155 let base = decode(&nals).unwrap();
171156 let mut injected = Vec::new();
172157 for nal in &nals {
@@ -193,9 +178,7 @@ fn malformed_sei_is_skipped_and_the_stream_decodes_the_same() {
193178
194179 #[test]
195180 fn hdr_sei_applies_to_every_frame_from_the_irap_on() {
196- let Some((name, nals)) = require_stream() else {
197- return;
198- };
181+ let (name, nals) = require_stream();
199182 let mut injected = Vec::new();
200183 let mut placed = false;
201184 for nal in &nals {
@@ -225,9 +208,7 @@ fn hdr_sei_applies_to_every_frame_from_the_irap_on() {
225208
226209 #[test]
227210 fn picture_hash_attaches_to_the_picture_it_follows() {
228- let Some((name, nals)) = require_stream() else {
229- return;
230- };
211+ let (name, nals) = require_stream();
231212 // One MD5 plane: payloadType 132, payloadSize 17, hash_type 0, the digest.
232213 let digest = [0x5au8; 16];
233214 let mut hash_rbsp = vec![132, 17, 0];
crates/ec-h265/tests/it/dec_shell.rsmodified+6 -24
@@ -4,11 +4,10 @@
44 //! The sweep parses every slice of every stream through the picture-management
55 //! path (pixel decode off) and checks the output order against ffprobe. Streams
66 //! whose slices are all intra are also pixel-decoded and compared with ffmpeg's
7-//! output. The sweep is skipped when the vectors are absent.
7+//! output. The sweep fails when the vectors are absent.
88
99 use std::collections::VecDeque;
1010 use std::path::{Path, PathBuf};
11-use std::process::Command;
1211
1312 use ec_h265::dec::dpb::{Dpb, DpbLimits, Marking, PendingFrame};
1413 use ec_h265::dec::poc::derive_poc;
@@ -274,16 +273,8 @@ fn decoder_refuses_out_of_scope_parameter_sets_and_skips_layers() {
274273 assert!(dec.next_frame().is_none());
275274 }
276275
277-fn have_tool(tool: &str) -> bool {
278- Command::new(tool)
279- .arg("-version")
280- .output()
281- .map(|o| o.status.success())
282- .unwrap_or(false)
283-}
284-
285-fn run(tool: &str, args: &[&str], file: &Path) -> Result<Vec<u8>, String> {
286- let out = Command::new(tool)
276+fn run(args: &[&str], file: &Path) -> Result<Vec<u8>, String> {
277+ let out = ec_testkit::ffprobe()
287278 .args(["-v", "error"])
288279 .args(args)
289280 .arg(file)
@@ -303,14 +294,10 @@ fn numbers(text: &[u8]) -> Vec<u64> {
303294 }
304295
305296 /// The conformance streams: the first `.bin` or `.bit` bitstream of each zip's
306-/// directory under `fixtures/vectors/hevc-jctvc` (or `EC_H265_JCTVC_DIR`), sorted
297+/// directory under `vectors/hevc-jctvc` in the fixtures root, sorted
307298 /// by name. Some zips extract one directory deeper, so two levels are searched.
308299 fn streams() -> Vec<PathBuf> {
309- // EC_H265_JCTVC_DIR overrides the default, for hosts whose fixtures link is dangling.
310- let root = match std::env::var("EC_H265_JCTVC_DIR") {
311- Ok(dir) => PathBuf::from(dir),
312- Err(_) => Path::new(env!("CARGO_MANIFEST_DIR")).join("../../fixtures/vectors/hevc-jctvc"),
313- };
300+ let root = ec_testkit::fixture("vectors/hevc-jctvc");
314301 fn bitstreams_in(dir: &Path, depth: u32, out: &mut Vec<PathBuf>) {
315302 let Ok(entries) = std::fs::read_dir(dir) else {
316303 return;
@@ -357,7 +344,6 @@ fn our_order(data: &[u8]) -> Result<Vec<(i32, u32)>, String> {
357344 /// decode order) of each frame, in display order.
358345 fn ffprobe_order(path: &Path) -> Result<Vec<u32>, String> {
359346 let packets = numbers(&run(
360- "ffprobe",
361347 &[
362348 "-select_streams",
363349 "v:0",
@@ -369,7 +355,6 @@ fn ffprobe_order(path: &Path) -> Result<Vec<u32>, String> {
369355 path,
370356 )?);
371357 let frames = numbers(&run(
372- "ffprobe",
373358 &[
374359 "-select_streams",
375360 "v:0",
@@ -407,10 +392,7 @@ fn spec_expectation(name: &str) -> Option<(usize, &'static str)> {
407392 #[test]
408393 fn conformance_output_order_matches_ffprobe() {
409394 let streams = streams();
410- if streams.is_empty() || !have_tool("ffprobe") {
411- eprintln!("conformance sweep skipped: vectors or ffprobe absent");
412- return;
413- }
395+ assert!(!streams.is_empty(), "no conformance streams");
414396 let mut table = String::from("stream\tpictures_out\tffprobe_out\tresult\tdetail\n");
415397 let mut pass = 0usize;
416398 let mut spec_ok = 0usize;
crates/ec-h265/tests/it/dolby_vision_p8.rsmodified+2 -20
@@ -6,32 +6,22 @@
66 //! inserted in front of every VCL NAL unit. ec-h265 must decode the injected stream
77 //! to exactly the pictures it decodes from the clean one, and ffmpeg must decode the
88 //! injected stream to the same bytes.
9-//!
10-//! The test skips when ffmpeg is absent, unless `EC_REQUIRE_FIXTURES` is set.
119
1210 use ec_h265::Decoder;
1311 use ec_h265::dec::Frame;
1412 use ec_h265_syntax::nal::{escape_rbsp, split_annex_b};
1513 use std::path::Path;
16-use std::process::Command;
1714
1815 const WIDTH: usize = 352;
1916 const HEIGHT: usize = 288;
2017 const FRAMES: usize = 12;
2118
22-fn have_ffmpeg() -> bool {
23- Command::new("ffmpeg")
24- .arg("-version")
25- .output()
26- .is_ok_and(|o| o.status.success())
27-}
28-
2919 /// The base layer: libx265, an IDR every 4 pictures, P pictures in between, no B.
3020 fn encode_base_layer(dir: &Path) -> Result<Vec<u8>, String> {
3121 let out = dir.join("base.hevc");
3222 let frames = FRAMES.to_string();
3323 let source = format!("testsrc2=size={WIDTH}x{HEIGHT}:rate=30");
34- let status = Command::new("ffmpeg")
24+ let status = ec_testkit::ffmpeg()
3525 .args(["-v", "error", "-y", "-f", "lavfi", "-i"])
3626 .arg(&source)
3727 .arg("-frames:v")
@@ -137,7 +127,7 @@ fn decode_ec(annex_b: &[u8]) -> Result<(Vec<u8>, usize), String> {
137127
138128 /// Every picture ffmpeg outputs, as yuv420p.
139129 fn decode_ffmpeg(path: &Path, out: &Path) -> Result<Vec<u8>, String> {
140- let status = Command::new("ffmpeg")
130+ let status = ec_testkit::ffmpeg()
141131 .args(["-v", "error", "-y", "-i"])
142132 .arg(path)
143133 .args(["-f", "rawvideo", "-pix_fmt", "yuv420p"])
@@ -159,14 +149,6 @@ fn first_difference(a: &[u8], b: &[u8]) -> Option<usize> {
159149
160150 #[test]
161151 fn dolby_vision_p8_base_layer_decodes_and_rpu_is_ignored() {
162- if !have_ffmpeg() {
163- assert!(
164- std::env::var_os("EC_REQUIRE_FIXTURES").is_none(),
165- "EC_REQUIRE_FIXTURES=1 but ffmpeg is absent"
166- );
167- eprintln!("dolby vision profile 8 check skipped: ffmpeg absent");
168- return;
169- }
170152 let dir = std::env::temp_dir().join(format!("ec-h265-dvp8-{}", std::process::id()));
171153 std::fs::create_dir_all(&dir).expect("temp dir");
172154
crates/ec-h265/tests/it/encode.rsmodified+6 -22
@@ -266,17 +266,8 @@ fn bd_psnr_delta(candidate: &[(f64, f64)], anchor: &[(f64, f64)]) -> (f64, f64,
266266 (bd, cand_extrap, anc_extrap)
267267 }
268268
269-fn have_ffmpeg() -> bool {
270- std::process::Command::new("ffmpeg")
271- .arg("-version")
272- .stdout(std::process::Stdio::null())
273- .stderr(std::process::Stdio::null())
274- .status()
275- .is_ok_and(|s| s.success())
276-}
277-
278269 fn have_x265() -> bool {
279- std::process::Command::new("ffmpeg")
270+ ec_testkit::ffmpeg()
280271 .args(["-v", "error", "-hide_banner", "-encoders"])
281272 .output()
282273 .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<Vec<Planes>> {
367358 std::fs::create_dir_all(&dir).ok()?;
368359 let path = dir.join(format!("s{}.265", stream.len()));
369360 pin_or_bail("ffmpeg_decode", &path, stream)?;
370- let out = std::process::Command::new("ffmpeg")
361+ let out = ec_testkit::ffmpeg()
371362 .args(["-v", "error"])
372363 .arg("-i")
373364 .arg(&path)
@@ -445,7 +436,7 @@ fn x265_encode_qp(sources: &[Planes], w: usize, h: usize, qp: i32) -> Option<Vec
445436 _ => String::new(),
446437 }
447438 );
448- let status = std::process::Command::new("ffmpeg")
439+ let status = ec_testkit::ffmpeg()
449440 .args(["-v", "error", "-y"])
450441 .args(["-f", "rawvideo", "-pix_fmt", "yuv420p"])
451442 .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<Vec
486477 /// bd_psnr_vs_x265 -- --nocapture
487478 #[test]
488479 fn bd_psnr_vs_x265() {
489- if !have_ffmpeg() || !have_x265() {
490- eprintln!(
491- "SKIP bd_psnr_vs_x265: no ffmpeg with libx265 on PATH. \
492- Install one, then: cargo test --release -p ec-h265 --test encode \
493- bd_psnr_vs_x265 -- --nocapture"
494- );
495- return;
496- }
480+ assert!(have_x265(), "the pinned ffmpeg has no libx265");
497481 let (w, h, sources) = match std::env::var_os("EC_H265_CLIP") {
498482 Some(path) => clip_sources(&path, 24),
499483 None => {
@@ -844,7 +828,7 @@ fn bd_psnr_vs_x265() {
844828 /// `EC_H265_CLIP_SKIP` passes over that many pictures before sampling (film
845829 /// heads are titles and fades).
846830 fn clip_sources(path: &std::ffi::OsStr, want: usize) -> (usize, usize, Vec<Planes>) {
847- let dims = std::process::Command::new("ffprobe")
831+ let dims = ec_testkit::ffprobe()
848832 .args([
849833 "-v",
850834 "error",
@@ -887,7 +871,7 @@ fn clip_sources(path: &std::ffi::OsStr, want: usize) -> (usize, usize, Vec<Plane
887871 // killer. `select` drops the skipped pictures inside ffmpeg and
888872 // `-frames:v` stops the decode once `want` have come out, so what reaches
889873 // this process is exactly `want` frames.
890- let raw = std::process::Command::new("ffmpeg")
874+ let raw = ec_testkit::ffmpeg()
891875 .args(["-v", "error", "-i"])
892876 .arg(path)
893877 .args([
crates/ec-h265/tests/it/real_library.rsmodified+26 -49
@@ -1,19 +1,13 @@
1-//! The personal media library, HEVC half: every `hevc` row of
2-//! `fixtures/real-library-manifest.tsv` is extracted to Annex B, its first
3-//! `FRAMES` pictures are decoded, and each output frame is compared sample for
4-//! sample with ffmpeg's own `hevc` decoder at the same pixel format.
1+//! HEVC clips from the open media: each is decoded, and its output frames are
2+//! compared sample for sample with ffmpeg's own `hevc` decoder at the same pixel format.
53 //!
64 //! Every file either decodes bit-exactly, is refused by name (a pixel format or
75 //! a bit depth outside 4:2:0 8/10-bit, or a decoder refusal that says
86 //! "unsupported"), or fails. A refusal is reported, not counted as a failure.
9-//!
10-//! LOCAL ONLY and ignored: the manifest is generated from the user's own media
11-//! by `scripts/scan-real-library.sh` and is gitignored, so no other host has it.
12-//! cargo test -p ec-h265 --test real_library -- --ignored --nocapture
137
148 use std::io::Read;
159 use std::path::{Path, PathBuf};
16-use std::process::{Command, Stdio};
10+use std::process::Stdio;
1711
1812 use ec_h265::dec::Decoder;
1913 use ec_h265::decode::DecodedPicture;
@@ -25,15 +19,6 @@ const FRAMES: usize = 300;
2519 /// Pixel formats inside the decoder's scope: 4:2:0 at 8 or 10 bits.
2620 const IN_SCOPE_PIX_FMTS: [&str; 2] = ["yuv420p", "yuv420p10le"];
2721
28-fn have_ffmpeg() -> bool {
29- Command::new("ffmpeg")
30- .arg("-version")
31- .stdout(Stdio::null())
32- .stderr(Stdio::null())
33- .status()
34- .is_ok_and(|s| s.success())
35-}
36-
3722 fn scratch(tag: &str) -> PathBuf {
3823 let base = std::env::var_os("TMPDIR").map_or_else(std::env::temp_dir, PathBuf::from);
3924 let dir = base.join(format!("ec-h265-{tag}-{}", std::process::id()));
@@ -50,31 +35,25 @@ struct Entry {
5035 pix_fmt: String,
5136 }
5237
53-fn manifest_hevc_entries() -> Vec<Entry> {
54- let manifest =
55- Path::new(env!("CARGO_MANIFEST_DIR")).join("../../fixtures/real-library-manifest.tsv");
56- let text = std::fs::read_to_string(&manifest).unwrap_or_else(|e| {
57- panic!(
58- "{}: {e}. This test sweeps the personal library; generate the manifest with \
59- scripts/scan-real-library.sh on the machine that holds the media.",
60- manifest.display()
61- )
62- });
63- let mut out = Vec::new();
64- for line in text.lines().skip(1) {
65- let f: Vec<&str> = line.split('\t').collect();
66- if f.len() < 6 || f[2] != "hevc" || !Path::new(f[0]).is_file() {
67- continue;
68- }
69- out.push(Entry {
70- path: PathBuf::from(f[0]),
71- container: f[1].to_string(),
72- width: f[3].to_string(),
73- height: f[4].to_string(),
74- pix_fmt: f[5].to_string(),
75- });
76- }
77- out
38+fn hevc_entries() -> Vec<Entry> {
39+ [
40+ (
41+ "derived/sintel720-x265-main10.mp4",
42+ "yuv420p10le",
43+ "1280",
44+ "720",
45+ ),
46+ ("open/sintel_trailer-1080p.mp4", "yuv420p", "1920", "1080"),
47+ ]
48+ .into_iter()
49+ .map(|(rel, pix_fmt, width, height)| Entry {
50+ path: ec_testkit::fixture(rel),
51+ container: "mp4".to_string(),
52+ width: width.to_string(),
53+ height: height.to_string(),
54+ pix_fmt: pix_fmt.to_string(),
55+ })
56+ .collect()
7857 }
7958
8059 /// 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 {
232211 /// with the text the table prints.
233212 fn sweep_file(entry: &Entry, es: &Path, bit_depth: u32) -> Result<Compare, String> {
234213 let bps = if bit_depth > 8 { 2 } else { 1 };
235- let mut child = Command::new("ffmpeg")
214+ let mut child = ec_testkit::ffmpeg()
236215 .args(["-v", "error", "-c:v", "hevc", "-i"])
237216 .arg(es)
238217 .args([
@@ -286,7 +265,7 @@ fn sweep_file(entry: &Entry, es: &Path, bit_depth: u32) -> Result<Compare, Strin
286265
287266 /// Extracts the first `FRAMES` pictures of the video as Annex B.
288267 fn extract(src: &Path, dst: &Path) -> bool {
289- Command::new("ffmpeg")
268+ ec_testkit::ffmpeg()
290269 .args(["-v", "error", "-y", "-i"])
291270 .arg(src)
292271 .args([
@@ -307,11 +286,9 @@ fn extract(src: &Path, dst: &Path) -> bool {
307286 }
308287
309288 #[test]
310-#[ignore = "sweeps the PERSONAL media library (fixtures/real-library-manifest.tsv, hevc rows) through ffmpeg; minutes of wall time. Local only: run with --ignored."]
289+#[ignore = "slow: decodes and compares two open clips with ffmpeg; run with --ignored."]
311290 fn real_library_hevc_streams_match_ffmpeg() {
312- assert!(have_ffmpeg(), "ffmpeg is required to sweep the library");
313- let entries = manifest_hevc_entries();
314- assert!(!entries.is_empty(), "the manifest lists no hevc rows");
291+ let entries = hevc_entries();
315292 let dir = scratch("real-library-hevc");
316293 let mut table = String::new();
317294 let mut decoded = 0usize;
crates/ec-h265/tests/it/scaling_lists.rsmodified+3 -21
@@ -8,7 +8,6 @@
88 use ec_h265::Decoder;
99 use ec_h265::dec::Frame;
1010 use std::path::{Path, PathBuf};
11-use std::process::Command;
1211
1312 /// The four scaling-list streams the picture-management sweep covers; `str` is
1413 /// the SLIST_D stream.
@@ -20,10 +19,7 @@ const STREAMS: [&str; 4] = [
2019 ];
2120
2221 fn vectors_dir() -> PathBuf {
23- match std::env::var("EC_H265_JCTVC_DIR") {
24- Ok(dir) => PathBuf::from(dir),
25- Err(_) => Path::new(env!("CARGO_MANIFEST_DIR")).join("../../fixtures/vectors/hevc-jctvc"),
26- }
22+ ec_testkit::fixture("vectors/hevc-jctvc")
2723 }
2824
2925 /// The first output picture as 4:2:0 bytes cropped to the conformance window.
@@ -59,7 +55,7 @@ fn cropped_yuv(frame: &Frame) -> Vec<u8> {
5955 /// The first frame of `path` as ffmpeg decodes it, in yuv420p.
6056 fn ffmpeg_first_frame(path: &Path, tag: &str) -> Result<Vec<u8>, String> {
6157 let out = std::env::temp_dir().join(format!("ec-h265-scaling-{tag}.yuv"));
62- let status = Command::new("ffmpeg")
58+ let status = ec_testkit::ffmpeg()
6359 .args(["-v", "error", "-y", "-i"])
6460 .arg(path)
6561 .args(["-frames:v", "1", "-f", "rawvideo", "-pix_fmt", "yuv420p"])
@@ -72,31 +68,17 @@ fn ffmpeg_first_frame(path: &Path, tag: &str) -> Result<Vec<u8>, String> {
7268 std::fs::read(&out).map_err(|e| e.to_string())
7369 }
7470
75-fn have_ffmpeg() -> bool {
76- Command::new("ffmpeg")
77- .arg("-version")
78- .output()
79- .is_ok_and(|o| o.status.success())
80-}
81-
8271 // Ignored until the intra path decodes the syntax these streams use: the decode
8372 // desyncs at the last CTB of the IDR, and the intra CTU loop has no SAO or
8473 // cu_qp_delta parsing. Run with `--ignored` to see the failure.
8574 #[ignore = "intra path lacks the syntax these streams use (desync at the IDR's last CTB)"]
8675 #[test]
8776 fn first_picture_of_each_scaling_list_stream_matches_ffmpeg() {
88- if !have_ffmpeg() {
89- eprintln!("scaling-list check skipped: ffmpeg absent");
90- return;
91- }
9277 let dir = vectors_dir();
9378 let mut checked = 0usize;
9479 for rel in STREAMS {
9580 let path = dir.join(rel);
96- let Ok(data) = std::fs::read(&path) else {
97- eprintln!("scaling-list check: {rel} absent, skipped");
98- continue;
99- };
81+ let data = std::fs::read(&path).unwrap_or_else(|e| panic!("{rel}: {e}"));
10082 let mut decoder = Decoder::new();
10183 decoder
10284 .decode_annex_b(&data)