From 0110b0edd9a6794d5f334445f64cccb517d083af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Wed, 2 Dec 2026 04:36:44 +0300 Subject: [PATCH] Fixture M6: mpeg2/mpeg4/prores/dnxhd/dv/mjpeg tests use ec_testkit ffmpeg and ffprobe, skip-if-missing gates removed so missing ffmpeg or encoder fails --- Cargo.lock | 6 ++++ crates/ec-dnxhd/Cargo.toml | 1 + crates/ec-dnxhd/tests/common/mod.rs | 25 +------------ crates/ec-dnxhd/tests/ffmpeg_parity.rs | 15 -------- crates/ec-dnxhd/tests/refusals.rs | 19 +++++----- crates/ec-dv/Cargo.toml | 1 + crates/ec-dv/tests/common/mod.rs | 21 +---------- crates/ec-dv/tests/containers.rs | 39 ++++++-------------- crates/ec-dv/tests/ffmpeg_parity.rs | 9 ----- crates/ec-dv/tests/perf.rs | 3 -- crates/ec-mjpeg/Cargo.toml | 1 + crates/ec-mjpeg/tests/ffmpeg_parity.rs | 48 ++----------------------- crates/ec-mpeg2/Cargo.toml | 3 ++ crates/ec-mpeg2/tests/common/mod.rs | 15 +------- crates/ec-mpeg2/tests/ffmpeg_parity.rs | 11 +----- crates/ec-mpeg2/tests/synth_parity.rs | 5 --- crates/ec-mpeg4/Cargo.toml | 1 + crates/ec-mpeg4/tests/common/mod.rs | 41 +-------------------- crates/ec-mpeg4/tests/containers.rs | 25 ++----------- crates/ec-mpeg4/tests/ffmpeg_parity.rs | 22 +----------- crates/ec-mpeg4/tests/msmpeg4.rs | 8 ----- crates/ec-prores/Cargo.toml | 1 + crates/ec-prores/tests/common/mod.rs | 25 +------------ crates/ec-prores/tests/encode.rs | 31 +++------------- crates/ec-prores/tests/ffmpeg_parity.rs | 3 -- crates/ec-prores/tests/perf.rs | 3 -- crates/ec-prores/tests/robust.rs | 19 +++++----- 27 files changed, 55 insertions(+), 346 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index cc823cef..557fbfc9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -431,6 +431,7 @@ dependencies = [ "ec-matroska", "ec-mp4", "ec-riff", + "ec-testkit", ] [[package]] @@ -455,6 +456,7 @@ dependencies = [ "ec-core", "ec-mp4", "ec-riff", + "ec-testkit", ] [[package]] @@ -573,6 +575,7 @@ dependencies = [ "ec-image", "ec-matroska", "ec-mp4", + "ec-testkit", ] [[package]] @@ -596,6 +599,7 @@ name = "ec-mpeg2" version = "0.1.0" dependencies = [ "ec-core", + "ec-testkit", ] [[package]] @@ -606,6 +610,7 @@ dependencies = [ "ec-matroska", "ec-mp4", "ec-riff", + "ec-testkit", ] [[package]] @@ -684,6 +689,7 @@ dependencies = [ "bytemuck", "ec-core", "ec-mp4", + "ec-testkit", "wide", ] diff --git a/crates/ec-dnxhd/Cargo.toml b/crates/ec-dnxhd/Cargo.toml index be334330..6d68e14b 100644 --- a/crates/ec-dnxhd/Cargo.toml +++ b/crates/ec-dnxhd/Cargo.toml @@ -10,6 +10,7 @@ authors.workspace = true ec-core = { workspace = true } [dev-dependencies] +ec-testkit.workspace = true ec-mp4 = { workspace = true } ec-matroska = { workspace = true } ec-riff = { workspace = true } diff --git a/crates/ec-dnxhd/tests/common/mod.rs b/crates/ec-dnxhd/tests/common/mod.rs index db12bbfe..d405f585 100644 --- a/crates/ec-dnxhd/tests/common/mod.rs +++ b/crates/ec-dnxhd/tests/common/mod.rs @@ -2,33 +2,10 @@ #![allow(dead_code)] use std::path::{Path, PathBuf}; -use std::process::Command; use ec_core::Demuxer; use ec_core::frame::VideoFrame; -pub fn require() -> bool { - std::env::var_os("EC_REQUIRE_FIXTURES").is_some() -} - -pub fn have_ffmpeg() -> bool { - Command::new("ffmpeg") - .arg("-version") - .output() - .map(|o| o.status.success()) - .unwrap_or(false) -} - -/// True when the test may run; panics instead of skipping when fixtures are required. -pub fn can_run() -> bool { - if have_ffmpeg() { - return true; - } - assert!(!require(), "ffmpeg is required (EC_REQUIRE_FIXTURES set)"); - eprintln!("skipping: no ffmpeg"); - false -} - pub fn scratch(tag: &str) -> PathBuf { let base = std::env::var_os("TMPDIR") .map(PathBuf::from) @@ -39,7 +16,7 @@ pub fn scratch(tag: &str) -> PathBuf { } pub fn ffmpeg(args: &[&str]) -> bool { - let out = Command::new("ffmpeg") + let out = ec_testkit::ffmpeg() .args(["-v", "error", "-y", "-nostdin"]) .args(args) .output(); diff --git a/crates/ec-dnxhd/tests/ffmpeg_parity.rs b/crates/ec-dnxhd/tests/ffmpeg_parity.rs index 6b635078..58379824 100644 --- a/crates/ec-dnxhd/tests/ffmpeg_parity.rs +++ b/crates/ec-dnxhd/tests/ffmpeg_parity.rs @@ -160,9 +160,6 @@ fn compare(tag: &str, frames: &[Vec], threads: usize) -> Result], f: impl Fn(&mut [u8])) -> Vec> { #[test] fn twelve_bit_streams_by_patching_the_depth_field() { - if !can_run() { - return; - } let dir = scratch("p12"); let mut failures = Vec::new(); for (tag, size, pix, prof, src) in [ @@ -311,9 +305,6 @@ fn twelve_bit_streams_by_patching_the_depth_field() { #[test] fn mbaff_cid_1260_by_patching_the_header() { - if !can_run() { - return; - } let dir = scratch("mbaff"); let mut failures = Vec::new(); for (tag, src) in [("mbaff_t", T), ("mbaff_n", N)] { @@ -358,9 +349,6 @@ fn mbaff_cid_1260_by_patching_the_header() { #[test] fn video_frame_output_formats_and_interlace_flag() { - if !can_run() { - return; - } use ec_core::frame::{Interlace, PixelFormat}; let dir = scratch("vf"); let mut dec = DnxhdDecoder::new(CodecParameters::new(CodecId::Dnxhd)).unwrap(); @@ -382,9 +370,6 @@ fn video_frame_output_formats_and_interlace_flag() { #[test] fn matroska_carries_dnxhd_too() { - if !can_run() { - return; - } let dir = scratch("mkv"); let mkv = dir.join("a.mkv"); let mov = dir.join("a.mov"); diff --git a/crates/ec-dnxhd/tests/refusals.rs b/crates/ec-dnxhd/tests/refusals.rs index 1db139f0..78826dc3 100644 --- a/crates/ec-dnxhd/tests/refusals.rs +++ b/crates/ec-dnxhd/tests/refusals.rs @@ -11,10 +11,7 @@ fn decoder() -> DnxhdDecoder { DnxhdDecoder::new(CodecParameters::new(CodecId::Dnxhd)).unwrap() } -fn encode_one(tag: &str, pix: &str, enc: &[&str]) -> Option> { - if !can_run() { - return None; - } +fn encode_one(tag: &str, pix: &str, enc: &[&str]) -> Vec { let dir = scratch(tag); let out = dir.join("a.mov"); let lavfi = format!("testsrc2=size=320x176:rate=25,format={pix}"); @@ -24,7 +21,7 @@ fn encode_one(tag: &str, pix: &str, enc: &[&str]) -> Option> { assert!(ffmpeg(&args)); let f = mov_frames(&out).remove(0); let _ = std::fs::remove_dir_all(&dir); - Some(f) + f } fn refused(r: Result, what: &str) { @@ -38,7 +35,7 @@ fn refused(r: Result, what: &str) { #[test] fn alpha_rgb_and_act_variants_are_refused_by_name() { - let Some(sq) = encode_one("ref-sq", "yuv422p", &["-profile:v", "dnxhr_sq"]) else { return }; + let sq = encode_one("ref-sq", "yuv422p", &["-profile:v", "dnxhr_sq"]); assert!(decoder().decode_bytes(&sq).is_ok()); let mut alpha = sq.clone(); @@ -50,16 +47,16 @@ fn alpha_rgb_and_act_variants_are_refused_by_name() { refused(decoder().decode_bytes(&act), "adaptive colour transform"); // GBR (RGB) 4:4:4: ffmpeg writes it with the ACT flag clear. - let rgb = encode_one("ref-rgb", "gbrp10le", &["-profile:v", "dnxhr_444"]).unwrap(); + let rgb = encode_one("ref-rgb", "gbrp10le", &["-profile:v", "dnxhr_444"]); refused(decoder().decode_bytes(&rgb), "RGB"); // The same encoder's YCbCr 4:4:4 is accepted. - let yuv = encode_one("ref-444", "yuv444p10le", &["-profile:v", "dnxhr_444"]).unwrap(); + let yuv = encode_one("ref-444", "yuv444p10le", &["-profile:v", "dnxhr_444"]); assert!(decoder().decode_bytes(&yuv).is_ok()); } #[test] fn unknown_cids_and_bad_headers_are_errors() { - let Some(sq) = encode_one("ref-bad", "yuv422p", &["-profile:v", "dnxhr_sq"]) else { return }; + let sq = encode_one("ref-bad", "yuv422p", &["-profile:v", "dnxhr_sq"]); let mut bad = sq.clone(); bad[0x28..0x2c].copy_from_slice(&1239u32.to_be_bytes()); assert!(matches!(decoder().decode_bytes(&bad), Err(Error::Unsupported { .. }))); @@ -76,7 +73,7 @@ fn unknown_cids_and_bad_headers_are_errors() { #[test] fn damaged_frames_never_panic() { - let Some(hq) = encode_one("ref-dmg", "yuv422p10le", &["-profile:v", "dnxhr_hqx"]) else { return }; + let hq = encode_one("ref-dmg", "yuv422p10le", &["-profile:v", "dnxhr_hqx"]); let mut dec = decoder(); let mut s = 0x9E37_79B9_7F4A_7C15u64; let mut next = move || { @@ -119,7 +116,7 @@ fn damaged_frames_never_panic() { #[test] fn registry_decoder_path_returns_a_frame() { use ec_core::registry::Decoder; - let Some(hq) = encode_one("ref-reg", "yuv422p", &["-profile:v", "dnxhr_hq"]) else { return }; + let hq = encode_one("ref-reg", "yuv422p", &["-profile:v", "dnxhr_hq"]); let mut d = decoder(); let pkt = ec_core::packet::Packet::new(0, ec_core::timebase::TimeBase::new(1, 25), hq); d.send_packet(&pkt).unwrap(); diff --git a/crates/ec-dv/Cargo.toml b/crates/ec-dv/Cargo.toml index fd6117ea..1164f9fe 100644 --- a/crates/ec-dv/Cargo.toml +++ b/crates/ec-dv/Cargo.toml @@ -10,5 +10,6 @@ authors.workspace = true ec-core = { workspace = true } [dev-dependencies] +ec-testkit.workspace = true ec-mp4 = { workspace = true } ec-riff = { workspace = true } diff --git a/crates/ec-dv/tests/common/mod.rs b/crates/ec-dv/tests/common/mod.rs index 225df4a8..453f294a 100644 --- a/crates/ec-dv/tests/common/mod.rs +++ b/crates/ec-dv/tests/common/mod.rs @@ -2,25 +2,6 @@ #![allow(dead_code)] use std::path::{Path, PathBuf}; -use std::process::Command; - -pub fn require() -> bool { - std::env::var_os("EC_REQUIRE_FIXTURES").is_some() -} - -pub fn have_ffmpeg() -> bool { - Command::new("ffmpeg").arg("-version").output().map(|o| o.status.success()).unwrap_or(false) -} - -/// Skip (or fail under EC_REQUIRE_FIXTURES) when ffmpeg is missing. -pub fn ffmpeg_or_skip() -> bool { - if have_ffmpeg() { - return true; - } - assert!(!require(), "EC_REQUIRE_FIXTURES set but ffmpeg is not available"); - eprintln!("skipping: no ffmpeg"); - false -} pub fn scratch(tag: &str) -> PathBuf { let base = std::env::var_os("TMPDIR").map(PathBuf::from).unwrap_or_else(std::env::temp_dir); @@ -30,7 +11,7 @@ pub fn scratch(tag: &str) -> PathBuf { } pub fn run(args: &[&str]) -> bool { - let out = Command::new("ffmpeg").args(["-v", "error", "-y", "-nostdin"]).args(args).output(); + let out = ec_testkit::ffmpeg().args(["-v", "error", "-y", "-nostdin"]).args(args).output(); match out { Ok(o) => { if !o.status.success() { diff --git a/crates/ec-dv/tests/containers.rs b/crates/ec-dv/tests/containers.rs index ed431dc2..f6fc33de 100644 --- a/crates/ec-dv/tests/containers.rs +++ b/crates/ec-dv/tests/containers.rs @@ -35,9 +35,6 @@ fn native(frames: &[Vec]) -> Vec { #[test] fn avi_and_mov_carry_dv() { - if !ffmpeg_or_skip() { - return; - } for f in [&FLAVOURS[0], &FLAVOURS[1], &FLAVOURS[3], &FLAVOURS[5]] { for ext in ["avi", "mov"] { let Some(path) = make(f, "c", ext, true, 8) else { @@ -65,9 +62,6 @@ fn avi_and_mov_carry_dv() { #[test] fn decoder_trait_output_formats() { - if !ffmpeg_or_skip() { - return; - } use ec_core::frame::{Frame, Interlace, PixelFormat}; use ec_core::registry::CodecParameters; let cases = [(0usize, PixelFormat::I422), (1, PixelFormat::I420), (3, PixelFormat::I422), (5, PixelFormat::I422)]; @@ -110,9 +104,6 @@ fn decoder_trait_output_formats() { #[test] fn field_order_matches_ffprobe_view() { - if !ffmpeg_or_skip() { - return; - } use ec_core::frame::Interlace; // ffmpeg's encoder: +ilme marks the stream interlaced; SD output is bottom-field-first // unless the (top-field-first) flag is requested. @@ -125,27 +116,23 @@ fn field_order_matches_ffprobe_view() { }; let a = first(&ilme); let b = first(&prog); - let out = std::process::Command::new("ffprobe") + let out = ec_testkit::ffprobe() .args(["-v", "error", "-select_streams", "v:0", "-show_frames", "-read_intervals", "%+#1", "-show_entries", "frame=interlaced_frame,top_field_first,flags", "-of", "default=nw=1"]) .arg(&ilme) - .output(); - if let Ok(o) = out { - let txt = String::from_utf8_lossy(&o.stdout).to_string(); - let interlaced = txt.contains("interlaced_frame=1") || txt.contains("interlaced"); - let tff = txt.contains("top_field_first=1") || txt.contains("top_first"); - assert_eq!(a.is_interlaced(), interlaced, "ffprobe says: {txt}"); - if interlaced { - assert_eq!(a == Interlace::TopFieldFirst, tff, "ffprobe says: {txt}"); - } + .output() + .unwrap(); + let txt = String::from_utf8_lossy(&out.stdout).to_string(); + let interlaced = txt.contains("interlaced_frame=1") || txt.contains("interlaced"); + let tff = txt.contains("top_field_first=1") || txt.contains("top_first"); + assert_eq!(a.is_interlaced(), interlaced, "ffprobe says: {txt}"); + if interlaced { + assert_eq!(a == Interlace::TopFieldFirst, tff, "ffprobe says: {txt}"); } assert!(!b.is_interlaced() || a.is_interlaced()); } #[test] fn raw_demuxer_sniff_seek_and_junk() { - if !ffmpeg_or_skip() { - return; - } let f = &FLAVOURS[0]; let path = make(f, "s", "dv", true, 8).unwrap(); let data = std::fs::read(&path).unwrap(); @@ -178,19 +165,13 @@ fn raw_demuxer_sniff_seek_and_junk() { #[test] fn audio_rates_and_12bit_match_ffmpeg() { - if !ffmpeg_or_skip() { - return; - } let f = &FLAVOURS[1]; // PAL for ar in ["44100", "32000"] { let dir = scratch("ar"); let p = dir.join(format!("a{ar}.dv")); let vsrc = "testsrc2=size=720x576:rate=25:duration=2,noise=alls=8:allf=t"; let asrc = format!("sine=frequency=1000:sample_rate={ar}:duration=2"); - if !run(&["-f", "lavfi", "-i", vsrc, "-f", "lavfi", "-i", &asrc, "-ac", "2", "-frames:v", "6", "-c:v", "dvvideo", "-pix_fmt", f.pix_fmt, "-c:a", "pcm_s16le", "-ar", ar, "-shortest", "-f", "dv", p.to_str().unwrap()]) { - assert!(!require(), "ffmpeg could not write {ar} Hz DV"); - continue; - } + assert!(run(&["-f", "lavfi", "-i", vsrc, "-f", "lavfi", "-i", &asrc, "-ac", "2", "-frames:v", "6", "-c:v", "dvvideo", "-pix_fmt", f.pix_fmt, "-c:a", "pcm_s16le", "-ar", ar, "-shortest", "-f", "dv", p.to_str().unwrap()]), "ffmpeg could not write {ar} Hz DV"); compare_audio(&p, ar.parse().unwrap()); // flip the audio source pack to 12-bit non-linear and compare again let mut data = std::fs::read(&p).unwrap(); diff --git a/crates/ec-dv/tests/ffmpeg_parity.rs b/crates/ec-dv/tests/ffmpeg_parity.rs index 79a7420f..651318ab 100644 --- a/crates/ec-dv/tests/ffmpeg_parity.rs +++ b/crates/ec-dv/tests/ffmpeg_parity.rs @@ -67,9 +67,6 @@ macro_rules! flavour_test { ($name:ident, $idx:expr) => { #[test] fn $name() { - if !ffmpeg_or_skip() { - return; - } let f = &FLAVOURS[$idx]; for (ilme, noise) in [(false, 0), (true, 6), (true, 25), (false, 40)] { check_flavour(f, ilme, noise); @@ -90,9 +87,6 @@ flavour_test!(hd_720p60, 8); #[test] fn native_formats() { - if !ffmpeg_or_skip() { - return; - } for (i, want) in [Chroma::Yuv411, Chroma::Yuv420, Chroma::Yuv411, Chroma::Yuv422, Chroma::Yuv422].into_iter().enumerate() { let f = &FLAVOURS[i]; let path = make(f, "fmt", "dv", false, 5).unwrap(); @@ -187,9 +181,6 @@ fn check_mutated(f: &Flavour, mode: u32, seed: u64) { #[test] fn mutated_streams_match_ffmpeg() { - if !ffmpeg_or_skip() { - return; - } for f in FLAVOURS { for mode in 0..5 { for seed in [1u64, 2, 3] { diff --git a/crates/ec-dv/tests/perf.rs b/crates/ec-dv/tests/perf.rs index 89ae9215..784488b0 100644 --- a/crates/ec-dv/tests/perf.rs +++ b/crates/ec-dv/tests/perf.rs @@ -37,9 +37,6 @@ fn machine_is_busy() -> bool { #[test] fn decode_speed() { - if !ffmpeg_or_skip() { - return; - } let mut bad = Vec::new(); for f in FLAVOURS { let hd = f.size.starts_with("1440") || f.size.starts_with("1280") || f.size.starts_with("960"); diff --git a/crates/ec-mjpeg/Cargo.toml b/crates/ec-mjpeg/Cargo.toml index 25f2180c..fae3dca2 100644 --- a/crates/ec-mjpeg/Cargo.toml +++ b/crates/ec-mjpeg/Cargo.toml @@ -11,5 +11,6 @@ ec-core = { workspace = true } ec-image = { workspace = true } [dev-dependencies] +ec-testkit.workspace = true ec-mp4 = { workspace = true } ec-matroska = { workspace = true } diff --git a/crates/ec-mjpeg/tests/ffmpeg_parity.rs b/crates/ec-mjpeg/tests/ffmpeg_parity.rs index c48b9c34..80575fbc 100644 --- a/crates/ec-mjpeg/tests/ffmpeg_parity.rs +++ b/crates/ec-mjpeg/tests/ffmpeg_parity.rs @@ -3,39 +3,16 @@ //! //! All sources are synthetic: lavfi test patterns encoded by ffmpeg, and the Pillow-made JPEGs in //! `tests/data` (restart markers, progressive). Expected pixels are never stored; ffmpeg is the -//! oracle at run time. Without ffmpeg the tests skip, unless `EC_REQUIRE_FIXTURES` is set. +//! oracle at run time. use std::io::BufReader; use std::path::{Path, PathBuf}; -use std::process::Command; use ec_core::frame::{Interlace, PixelFormat, VideoFrame}; use ec_core::registry::{CodecId, CodecParameters, Demuxer, MediaParameters}; use ec_image::Limits; use ec_mjpeg::MjpegDecoder; -fn require() -> bool { - std::env::var_os("EC_REQUIRE_FIXTURES").is_some() -} - -fn have_ffmpeg() -> bool { - Command::new("ffmpeg") - .arg("-version") - .output() - .map(|o| o.status.success()) - .unwrap_or(false) -} - -/// False (after saying so) when the oracle is missing and fixtures are optional. -fn oracle() -> bool { - if have_ffmpeg() { - return true; - } - assert!(!require(), "ffmpeg missing and EC_REQUIRE_FIXTURES is set"); - eprintln!("SKIP: no ffmpeg"); - false -} - fn scratch(tag: &str) -> PathBuf { let base = std::env::var_os("TMPDIR") .map(PathBuf::from) @@ -46,7 +23,7 @@ fn scratch(tag: &str) -> PathBuf { } fn ffmpeg(args: &[&str]) { - let ok = Command::new("ffmpeg") + let ok = ec_testkit::ffmpeg() .args(["-v", "error", "-y", "-nostdin"]) .args(args) .status() @@ -155,9 +132,6 @@ fn format_name(f: PixelFormat) -> &'static str { #[test] fn still_fixtures_match_ffmpeg() { - if !oracle() { - return; - } let dir = Path::new(env!("CARGO_MANIFEST_DIR")).join("tests/data"); let work = scratch("stills"); let mut n = 0; @@ -186,9 +160,6 @@ fn still_fixtures_match_ffmpeg() { /// into mov and mkv by a stream copy. #[test] fn gray_video_matches_ffmpeg() { - if !oracle() { - return; - } let work = scratch("gray"); for name in ["basegray", "rstgray", "proggray"] { let jpg = Path::new(env!("CARGO_MANIFEST_DIR")).join(format!("tests/data/{name}.jpg")); @@ -215,9 +186,6 @@ fn gray_video_matches_ffmpeg() { #[test] fn video_matrix_matches_ffmpeg() { - if !oracle() { - return; - } let work = scratch("matrix"); let mut cases = 0; for (pix, expect) in [ @@ -372,9 +340,6 @@ fn write_avi(path: &Path, w: u32, h: u32, packets: &[Vec]) { #[test] fn avi1_packets_without_dht_use_the_default_tables() { - if !oracle() { - return; - } let work = scratch("nodht"); for (pix, size) in [ ("yuvj420p", "64x48"), @@ -430,9 +395,6 @@ fn avi1_packets_without_dht_use_the_default_tables() { #[test] fn two_field_packets_weave_like_ffmpeg() { - if !oracle() { - return; - } let work = scratch("fields"); // ffmpeg's mjpeg encoder refuses `-flags +ildct` ("interlacing not supported by codec"), // so the interlaced material is built from separated fields, one JPEG per field. @@ -755,9 +717,6 @@ fn mjpeg_stream_packets(path: &Path) -> Vec> { #[test] fn mjpegb_matches_ffmpeg() { - if !oracle() { - return; - } let work = scratch("mjpegb"); // Progressive: one field per packet, all three layouts, odd sizes. for (pix, size, w, h, q) in [ @@ -805,9 +764,6 @@ fn mjpegb_matches_ffmpeg() { #[test] fn mjpegb_two_fields_match_ffmpeg() { - if !oracle() { - return; - } let work = scratch("mjpegb2"); for (pix, size, w, h) in [ ("yuvj420p", "64x48", 64u16, 48u16), diff --git a/crates/ec-mpeg2/Cargo.toml b/crates/ec-mpeg2/Cargo.toml index 43e29f94..d01b8f22 100644 --- a/crates/ec-mpeg2/Cargo.toml +++ b/crates/ec-mpeg2/Cargo.toml @@ -8,3 +8,6 @@ authors.workspace = true [dependencies] ec-core = { workspace = true } + +[dev-dependencies] +ec-testkit.workspace = true diff --git a/crates/ec-mpeg2/tests/common/mod.rs b/crates/ec-mpeg2/tests/common/mod.rs index d08b3986..c8309fc5 100644 --- a/crates/ec-mpeg2/tests/common/mod.rs +++ b/crates/ec-mpeg2/tests/common/mod.rs @@ -4,23 +4,10 @@ pub mod synth; use std::path::{Path, PathBuf}; -use std::process::Command; use ec_core::frame::VideoFrame; use ec_mpeg2::Mpeg2Decoder; -pub fn require() -> bool { - std::env::var_os("EC_REQUIRE_FIXTURES").is_some() -} - -pub fn have_ffmpeg() -> bool { - Command::new("ffmpeg") - .arg("-version") - .output() - .map(|o| o.status.success()) - .unwrap_or(false) -} - pub fn scratch(tag: &str) -> PathBuf { let base = std::env::var_os("TMPDIR") .map(PathBuf::from) @@ -31,7 +18,7 @@ pub fn scratch(tag: &str) -> PathBuf { } pub fn run(args: &[&str]) -> bool { - Command::new("ffmpeg") + ec_testkit::ffmpeg() .args(["-v", "error", "-y", "-nostdin"]) .args(args) .status() diff --git a/crates/ec-mpeg2/tests/ffmpeg_parity.rs b/crates/ec-mpeg2/tests/ffmpeg_parity.rs index f0b3b50d..da385c6b 100644 --- a/crates/ec-mpeg2/tests/ffmpeg_parity.rs +++ b/crates/ec-mpeg2/tests/ffmpeg_parity.rs @@ -65,22 +65,13 @@ fn generate(c: &Case) -> Option { #[test] fn parity_matrix() { - if !have_ffmpeg() { - assert!(!require(), "ffmpeg missing"); - eprintln!("SKIP: no ffmpeg"); - return; - } let only = std::env::var("EC_MPEG2_CASE").ok(); let mut failures = Vec::new(); for c in CASES { if only.as_deref().is_some_and(|o| o != c.tag) { continue; } - let Some(es) = generate(c) else { - assert!(!require(), "{}: ffmpeg cannot encode", c.tag); - eprintln!("SKIP {}", c.tag); - continue; - }; + let es = generate(c).unwrap_or_else(|| panic!("{}: ffmpeg cannot encode", c.tag)); match compare(c.tag, &es, c.pix, &[]) { Ok(n) => eprintln!("OK {} ({n} frames)", c.tag), Err(e) => { diff --git a/crates/ec-mpeg2/tests/synth_parity.rs b/crates/ec-mpeg2/tests/synth_parity.rs index 208bbbe0..831cbf3f 100644 --- a/crates/ec-mpeg2/tests/synth_parity.rs +++ b/crates/ec-mpeg2/tests/synth_parity.rs @@ -16,11 +16,6 @@ fn run_one(tag: &str, cfg: &SynthCfg, pix: &str) -> Result { #[test] fn synthetic_streams_match_ffmpeg() { - if !have_ffmpeg() { - assert!(!require(), "ffmpeg missing"); - eprintln!("SKIP: no ffmpeg"); - return; - } let n: u64 = std::env::var("EC_SYNTH_N").ok().and_then(|v| v.parse().ok()).unwrap_or(24); let base: u64 = std::env::var("EC_SYNTH_SEED").ok().and_then(|v| v.parse().ok()).unwrap_or(1); let heavy = std::env::var_os("EC_SYNTH_LIGHT").is_none(); diff --git a/crates/ec-mpeg4/Cargo.toml b/crates/ec-mpeg4/Cargo.toml index 8ecc7a10..0d287433 100644 --- a/crates/ec-mpeg4/Cargo.toml +++ b/crates/ec-mpeg4/Cargo.toml @@ -10,6 +10,7 @@ authors.workspace = true ec-core = { workspace = true } [dev-dependencies] +ec-testkit.workspace = true ec-mp4 = { workspace = true } ec-riff = { workspace = true } ec-matroska = { workspace = true } diff --git a/crates/ec-mpeg4/tests/common/mod.rs b/crates/ec-mpeg4/tests/common/mod.rs index 6af7609e..9e8da84f 100644 --- a/crates/ec-mpeg4/tests/common/mod.rs +++ b/crates/ec-mpeg4/tests/common/mod.rs @@ -8,50 +8,11 @@ #![allow(dead_code)] use std::path::{Path, PathBuf}; -use std::process::Command; use ec_core::frame::VideoFrame; use ec_core::registry::{CodecId, CodecParameters}; use ec_mpeg4::{Mpeg4Decoder, PictureInfo}; -pub fn require() -> bool { - std::env::var_os("EC_REQUIRE_FIXTURES").is_some() -} - -pub fn have_ffmpeg() -> bool { - Command::new("ffmpeg") - .arg("-version") - .output() - .map(|o| o.status.success()) - .unwrap_or(false) -} - -/// Whether the local ffmpeg lists `name` as an encoder. -pub fn have_encoder(name: &str) -> bool { - Command::new("ffmpeg") - .args(["-hide_banner", "-encoders"]) - .output() - .map(|o| { - String::from_utf8_lossy(&o.stdout) - .lines() - .any(|l| l.split_whitespace().nth(1) == Some(name)) - }) - .unwrap_or(false) -} - -/// `true` when the test may run; under `EC_REQUIRE_FIXTURES` a missing ffmpeg is a failure. -pub fn gate() -> bool { - if have_ffmpeg() { - return true; - } - assert!( - !require(), - "ffmpeg is required (EC_REQUIRE_FIXTURES is set)" - ); - eprintln!("skipped: no ffmpeg"); - false -} - pub fn scratch(tag: &str) -> PathBuf { let base = std::env::var_os("TMPDIR") .map(PathBuf::from) @@ -62,7 +23,7 @@ pub fn scratch(tag: &str) -> PathBuf { } pub fn run(args: &[&str]) -> bool { - Command::new("ffmpeg") + ec_testkit::ffmpeg() .args(["-v", "error", "-y", "-nostdin"]) .args(args) .status() diff --git a/crates/ec-mpeg4/tests/containers.rs b/crates/ec-mpeg4/tests/containers.rs index c69621e6..220c7e32 100644 --- a/crates/ec-mpeg4/tests/containers.rs +++ b/crates/ec-mpeg4/tests/containers.rs @@ -69,9 +69,6 @@ fn decode_registry(params: ec_core::registry::CodecParameters, pk: &[Packet]) -> } fn check(tag: &str, file: &str, enc: &[&str]) { - if !gate() { - return; - } let dir = scratch(tag); let path = dir.join(file); assert!(encode("176x144", 30, enc, &path), "encode"); @@ -179,9 +176,6 @@ fn mkv_asp() { } #[test] fn gp3_h263() { - if !gate() { - return; - } let dir = scratch("3gp"); let path = dir.join("a.3gp"); assert!(encode( @@ -205,9 +199,6 @@ fn gp3_h263() { /// where it was. #[test] fn packed_bitstream_matches_unpacked() { - if !gate() { - return; - } let dir = scratch("packed"); let path = dir.join("a.avi"); assert!(encode( @@ -246,12 +237,9 @@ fn packed_bitstream_matches_unpacked() { #[test] fn data_partitioning_is_refused_by_name() { - if !gate() { - return; - } let dir = scratch("dp"); let path = dir.join("a.m4v"); - if !encode( + assert!(encode( "176x144", 4, &[ @@ -265,10 +253,7 @@ fn data_partitioning_is_refused_by_name() { "m4v", ], &path, - ) { - eprintln!("SKIP: encoder rejects data partitioning"); - return; - } + ), "encoder rejects data partitioning"); let es = std::fs::read(&path).unwrap(); let mut dec = new_decoder(); let mut err = None; @@ -288,9 +273,6 @@ fn data_partitioning_is_refused_by_name() { #[test] fn corrupt_input_does_not_panic() { - if !gate() { - return; - } let dir = scratch("corrupt"); let path = dir.join("a.m4v"); assert!(encode( @@ -349,9 +331,6 @@ fn corrupt_input_does_not_panic() { #[test] #[ignore] fn speed_720p_at_least_120_fps() { - if !gate() { - return; - } let dir = scratch("speed"); let path = dir.join("hd.m4v"); assert!(encode( diff --git a/crates/ec-mpeg4/tests/ffmpeg_parity.rs b/crates/ec-mpeg4/tests/ffmpeg_parity.rs index b5a2f3b3..60615545 100644 --- a/crates/ec-mpeg4/tests/ffmpeg_parity.rs +++ b/crates/ec-mpeg4/tests/ffmpeg_parity.rs @@ -1,6 +1,5 @@ //! Byte-exact parity with ffmpeg's MPEG-4 Part 2 / H.263 decoder on streams ffmpeg encodes at test -//! time (`ffmpeg -c:v mpeg4`, `libxvid`, `h263`). Skipped without ffmpeg unless `EC_REQUIRE_FIXTURES` -//! is set; the libxvid cases (GMC, N-VOPs, XviD IDCT) also skip when the encoder is not built in. +//! time (`ffmpeg -c:v mpeg4`, `libxvid`, `h263`). mod common; @@ -10,9 +9,6 @@ macro_rules! parity { ($name:ident, $size:expr, $frames:expr, [$($arg:expr),* $(,)?]) => { #[test] fn $name() { - if !gate() { - return; - } let n = parity_es(stringify!($name), $size, $frames, &[$($arg),*], "m4v").unwrap(); assert!(n >= $frames - 2, "decoded only {n} of {} pictures", $frames); } @@ -295,9 +291,6 @@ parity!( #[test] fn hd_720p_with_everything() { - if !gate() { - return; - } let n = parity_es( "hd720", "1280x720", @@ -321,9 +314,6 @@ fn hd_720p_with_everything() { // H.263 baseline (short video header). #[test] fn h263_formats() { - if !gate() { - return; - } for (size, q, gop) in [ ("128x96", "4", "8"), ("176x144", "4", "10"), @@ -346,9 +336,6 @@ fn h263_formats() { #[test] fn h263_with_gob_headers() { - if !gate() { - return; - } // `-ps` makes ffmpeg's H.263 encoder start a GOB (with its header) every n macroblocks. let n = parity_es( "h263_gob", @@ -363,13 +350,6 @@ fn h263_with_gob_headers() { // libxvid: GMC with warp points, N-VOPs, the XviD IDCT and XviD's qpel/bframe habits. fn libxvid(tag: &str, size: &str, frames: u32, extra: &[&str]) { - if !gate() { - return; - } - if !have_encoder("libxvid") { - eprintln!("skipped {tag}: ffmpeg has no libxvid encoder"); - return; - } let mut enc = vec!["-c:v", "libxvid"]; enc.extend_from_slice(extra); let n = parity_es(tag, size, frames, &enc, "m4v").unwrap_or_else(|e| panic!("{tag}: {e}")); diff --git a/crates/ec-mpeg4/tests/msmpeg4.rs b/crates/ec-mpeg4/tests/msmpeg4.rs index d4367494..4a4d60c9 100644 --- a/crates/ec-mpeg4/tests/msmpeg4.rs +++ b/crates/ec-mpeg4/tests/msmpeg4.rs @@ -12,14 +12,6 @@ use ec_mpeg4::Mpeg4Decoder; #[allow(clippy::too_many_arguments)] fn check(tag: &str, vtag: &str, codec: &str, id: CodecId, lavfi: &str, size: &str, frames: u32, enc: &[&str]) { - if !gate() { - return; - } - if !have_encoder(codec) { - assert!(!require(), "ffmpeg encoder {codec} missing"); - eprintln!("skipped: no {codec} encoder"); - return; - } let dir = scratch(tag); let path = dir.join(format!("{tag}.avi")); let input = format!("{lavfi}=size={size}:rate=25"); diff --git a/crates/ec-prores/Cargo.toml b/crates/ec-prores/Cargo.toml index b2ec80d8..732a4573 100644 --- a/crates/ec-prores/Cargo.toml +++ b/crates/ec-prores/Cargo.toml @@ -13,4 +13,5 @@ bytemuck = "1" wide = { workspace = true } [dev-dependencies] +ec-testkit.workspace = true ec-mp4 = { workspace = true } diff --git a/crates/ec-prores/tests/common/mod.rs b/crates/ec-prores/tests/common/mod.rs index 319b458b..09c29fc9 100644 --- a/crates/ec-prores/tests/common/mod.rs +++ b/crates/ec-prores/tests/common/mod.rs @@ -3,34 +3,11 @@ use std::io::Cursor; use std::path::PathBuf; -use std::process::Command; use ec_core::registry::{CodecId, CodecParameters, Demuxer}; use ec_mp4::Mp4Demuxer; use ec_prores::{DecodedFrame, ProResDecoder}; -pub fn require() -> bool { - std::env::var_os("EC_REQUIRE_FIXTURES").is_some() -} - -pub fn have_ffmpeg() -> bool { - Command::new("ffmpeg") - .arg("-version") - .output() - .map(|o| o.status.success()) - .unwrap_or(false) -} - -/// Skip (or fail under EC_REQUIRE_FIXTURES) when ffmpeg is missing. -pub fn ffmpeg_or_skip() -> bool { - if have_ffmpeg() { - return true; - } - assert!(!require(), "EC_REQUIRE_FIXTURES set but ffmpeg is not available"); - eprintln!("skipping: no ffmpeg"); - false -} - pub fn scratch(tag: &str) -> PathBuf { let base = std::env::var_os("TMPDIR").map(PathBuf::from).unwrap_or_else(std::env::temp_dir); let dir = base.join(format!("ec-prores-{}-{}", std::process::id(), tag)); @@ -39,7 +16,7 @@ pub fn scratch(tag: &str) -> PathBuf { } pub fn run(args: &[&str]) -> bool { - Command::new("ffmpeg") + ec_testkit::ffmpeg() .args(["-v", "error", "-y", "-nostdin"]) .args(args) .status() diff --git a/crates/ec-prores/tests/encode.rs b/crates/ec-prores/tests/encode.rs index 610d84ab..160c95d4 100644 --- a/crates/ec-prores/tests/encode.rs +++ b/crates/ec-prores/tests/encode.rs @@ -1,11 +1,9 @@ //! The ProRes encoder: ffmpeg decodes what we write exactly as ec-prores does, frame sizes sit on //! Apple's rates, quality matches or beats ffmpeg's `prores_ks`, the .mov probes right. -//! All media is synthetic; ffmpeg-dependent tests skip (or fail under `EC_REQUIRE_FIXTURES`) -//! when ffmpeg is missing. +//! All media is synthetic. mod common; use std::io::Cursor; -use std::process::Command; use common::*; use ec_core::frame::{ColorInfo, PixelFormat, Plane, VideoFrame}; @@ -135,9 +133,6 @@ fn pix(p: Profile) -> &'static str { #[test] fn ffmpeg_and_ec_prores_decode_every_profile_identically() { - if !ffmpeg_or_skip() { - return; - } let dir = scratch("enc-rt"); for (i, p) in ALL.into_iter().enumerate() { // Odd size: padding macroblocks on both axes, 3 slice widths in a row. @@ -223,9 +218,6 @@ fn frame_sizes_sit_on_apples_rates() { #[test] fn encoder_trait_and_mov_probe() { - if !ffmpeg_or_skip() { - return; - } let dir = scratch("enc-probe"); let (w, h) = (192, 108); for p in ALL { @@ -249,7 +241,7 @@ fn encoder_trait_and_mov_probe() { assert!(!mov.windows(4).any(|x| x == b"avcC" || x == b"esds"), "{p:?}: a config box"); let path = dir.join(format!("{}.mov", String::from_utf8_lossy(&p.fourcc()))); std::fs::write(&path, &mov).unwrap(); - let out = Command::new("ffprobe") + let out = ec_testkit::ffprobe() .args(["-v", "error", "-select_streams", "v:0", "-show_entries"]) .arg("stream=codec_name,profile,pix_fmt,field_order,color_space,color_transfer,color_primaries,codec_tag_string,width,height,nb_frames") .args(["-of", "default=nw=1"]) @@ -336,25 +328,16 @@ fn psnr_vs_prores_ks(generator: &str, post: &str, tag: &str) { #[test] fn quality_matches_prores_ks_testsrc2() { - if !ffmpeg_or_skip() { - return; - } psnr_vs_prores_ks("testsrc2", "", "q-testsrc2"); } #[test] fn quality_matches_prores_ks_mandelbrot() { - if !ffmpeg_or_skip() { - return; - } psnr_vs_prores_ks("mandelbrot", "", "q-mandel"); } #[test] fn quality_matches_prores_ks_noisy() { - if !ffmpeg_or_skip() { - return; - } psnr_vs_prores_ks("testsrc2", ",noise=alls=12:allf=t", "q-noisy"); } @@ -404,7 +387,7 @@ fn encode_speed_1080p_hq() { } fn probe(path: &std::path::Path, entry: &str) -> String { - let out = Command::new("ffprobe") + let out = ec_testkit::ffprobe() .args(["-v", "error", "-select_streams", "v:0", "-show_entries", &format!("stream={entry}"), "-of", "default=nw=1:nk=1"]) .arg(path) .output() @@ -413,7 +396,7 @@ fn probe(path: &std::path::Path, entry: &str) -> String { } fn probe_frame(path: &std::path::Path, entry: &str) -> String { - let out = Command::new("ffprobe") + let out = ec_testkit::ffprobe() .args(["-v", "error", "-select_streams", "v:0", "-show_frames", "-read_intervals", "%+#1", "-show_entries", &format!("frame={entry}"), "-of", "default=nw=1:nk=1"]) .arg(path) .output() @@ -424,9 +407,6 @@ fn probe_frame(path: &std::path::Path, entry: &str) -> String { #[test] fn interlaced_every_profile_ffmpeg_and_ours_agree() { use ec_core::frame::Interlace; - if !ffmpeg_or_skip() { - return; - } let dir = scratch("enc-field"); for (i, p) in ALL.into_iter().enumerate() { for (order, field_order) in [(Interlace::TopFieldFirst, "tt"), (Interlace::BottomFieldFirst, "bb")] { @@ -508,9 +488,6 @@ fn alpha_pattern(w: usize, h: usize, seed: u64) -> Vec { fn alpha_4444_round_trips_and_ffmpeg_agrees() { use ec_core::frame::Interlace; use ec_prores::AlphaPlane; - if !ffmpeg_or_skip() { - return; - } let dir = scratch("enc-alpha"); let mut n = 0; for p in [Profile::P4444, Profile::P4444Xq] { diff --git a/crates/ec-prores/tests/ffmpeg_parity.rs b/crates/ec-prores/tests/ffmpeg_parity.rs index 255265f3..ea76d955 100644 --- a/crates/ec-prores/tests/ffmpeg_parity.rs +++ b/crates/ec-prores/tests/ffmpeg_parity.rs @@ -112,9 +112,6 @@ fn generate(c: &Case) -> std::path::PathBuf { #[test] fn matches_ffmpeg() { - if !ffmpeg_or_skip() { - return; - } let mut bad = Vec::new(); for c in CASES { let mov = generate(c); diff --git a/crates/ec-prores/tests/perf.rs b/crates/ec-prores/tests/perf.rs index 98214b34..e6f6515b 100644 --- a/crates/ec-prores/tests/perf.rs +++ b/crates/ec-prores/tests/perf.rs @@ -6,9 +6,6 @@ use common::*; #[test] fn hd_hq_throughput() { - if !ffmpeg_or_skip() { - return; - } let dir = scratch("perf"); let mov = dir.join("hd.mov"); assert!(run(&[ diff --git a/crates/ec-prores/tests/robust.rs b/crates/ec-prores/tests/robust.rs index 3b6ed418..09c91129 100644 --- a/crates/ec-prores/tests/robust.rs +++ b/crates/ec-prores/tests/robust.rs @@ -19,15 +19,12 @@ impl Rng { } /// Small frames: progressive 422, interlaced 422, 4444 with alpha. -fn frames() -> Option>> { - static CACHE: std::sync::OnceLock>>> = std::sync::OnceLock::new(); +fn frames() -> Vec> { + static CACHE: std::sync::OnceLock>> = std::sync::OnceLock::new(); CACHE.get_or_init(make_frames).clone() } -fn make_frames() -> Option>> { - if !ffmpeg_or_skip() { - return None; - } +fn make_frames() -> Vec> { let dir = scratch("robust"); let mut out = Vec::new(); for (i, (prof, fmt, extra)) in [ @@ -51,12 +48,12 @@ fn make_frames() -> Option>> { out.push(packets(&std::fs::read(&mov).unwrap()).remove(0)); } let _ = std::fs::remove_dir_all(dir); - Some(out) + out } #[test] fn truncations_never_panic() { - let Some(fs) = frames() else { return }; + let fs = frames(); for f in &fs { let mut d = decoder(2); assert!(d.decode(f).is_ok()); @@ -68,7 +65,7 @@ fn truncations_never_panic() { #[test] fn corruptions_never_panic() { - let Some(fs) = frames() else { return }; + let fs = frames(); let mut rng = Rng(0x9E3779B97F4A7C15); for f in &fs { let mut d = decoder(3); @@ -105,7 +102,7 @@ fn garbage_is_refused_by_name() { #[test] fn hostile_dimensions_are_bounded() { - let Some(fs) = frames() else { return }; + let fs = frames(); let mut g = fs[0].clone(); // width/height at frame-header bytes 8..12 (after size+icpf: offset 8+8). g[16..20].copy_from_slice(&[0xFF, 0xFF, 0xFF, 0xFF]); @@ -131,7 +128,7 @@ fn wrong_codec_is_unsupported() { fn dump_seeds() { let dir = std::env::var("EC_SEED_DIR").expect("EC_SEED_DIR"); std::fs::create_dir_all(&dir).unwrap(); - let Some(fs) = frames() else { return }; + let fs = frames(); for (i, f) in fs.iter().enumerate() { std::fs::write(format!("{dir}/seed{i}.bin"), f).unwrap(); }