From f9a61726cb6ef876c5358aff255707ba4ce98526 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 07:43:18 +0300 Subject: [PATCH] Shim tests read deterministic fixtures through ec_testkit::fixture (no silent skip, no gen-fixtures.sh); opus-rs look-ahead expectations follow libopus OPUS_GET_LOOKAHEAD = Fs/400 + Fs/250 per input rate (312 at 48 kHz, 52/78/104/156 at 8/12/16/24 kHz, all 312 at 48 kHz on the pinned ffmpeg 9.0.2 libopus, which encodes at 48 kHz) --- shims/opus-rs/src/lib.rs | 18 +++++++-------- shims/oxideav-ac3/Cargo.toml | 3 +++ shims/oxideav-ac3/tests/edith_surface.rs | 22 ++++--------------- shims/symphonia/Cargo.toml | 1 + shims/symphonia/tests/edith_surface.rs | 28 +++++++----------------- 5 files changed, 24 insertions(+), 48 deletions(-) diff --git a/shims/opus-rs/src/lib.rs b/shims/opus-rs/src/lib.rs index d9df9ae7..e879b82e 100644 --- a/shims/opus-rs/src/lib.rs +++ b/shims/opus-rs/src/lib.rs @@ -374,19 +374,17 @@ mod tests { } /// Input below 48 kHz, which the shim used to refuse outright, and the - /// `look_ahead` that goes with it. 48/24 kHz VoIP at 32 kbps run - /// hybrid (SWB/FB), so the delay is CELT's 120-sample overlap, scaled; - /// 16 kHz and below cap the bandwidth at WB or narrower, where hybrid - /// does not exist, so dispatch takes SILK and the delay is the SILK - /// resampler look-ahead (WB 50 / MB 54 / NB 58 at 48 kHz), scaled. + /// `look_ahead` that goes with it: libopus's `OPUS_GET_LOOKAHEAD`, + /// `Fs/400 + Fs/250` (120 + 192 at 48 kHz), in the input rate's samples. + /// ffmpeg's libopus encoder runs at 48 kHz and reports 312 for every rate. #[test] fn slower_input_rates_encode_and_report_their_own_delay() { for &(rate, frame, look) in &[ - (48_000i32, 960usize, 120usize), - (24_000, 480, 60), - (16_000, 320, 50 / 3), - (12_000, 240, 54 / 4), - (8_000, 160, 58 / 6), + (48_000i32, 960usize, 312usize), + (24_000, 480, 156), + (16_000, 320, 104), + (12_000, 240, 78), + (8_000, 160, 52), ] { let mut enc = OpusEncoder::new(rate, 1, Application::Voip).unwrap(); enc.bitrate_bps = 32_000; diff --git a/shims/oxideav-ac3/Cargo.toml b/shims/oxideav-ac3/Cargo.toml index ef55dee3..68934fc4 100644 --- a/shims/oxideav-ac3/Cargo.toml +++ b/shims/oxideav-ac3/Cargo.toml @@ -11,3 +11,6 @@ publish = false ec-ac3 = { path = "../../crates/ec-ac3", version = "0.1.0" } ec-core = { path = "../../crates/ec-core", version = "0.1.0" } oxideav-core = { path = "../oxideav-core", version = "0.1.34" } + +[dev-dependencies] +ec-testkit.workspace = true diff --git a/shims/oxideav-ac3/tests/edith_surface.rs b/shims/oxideav-ac3/tests/edith_surface.rs index 745b163a..f0525926 100644 --- a/shims/oxideav-ac3/tests/edith_surface.rs +++ b/shims/oxideav-ac3/tests/edith_surface.rs @@ -2,20 +2,12 @@ //! layout out of the first syncframe's headers, ask the registry for a decoder //! folded to that layout, decode, and read the frame back as S16 little-endian //! (`engine/src/audio.rs:1954-2170`). -//! -//! Missing fixtures skip rather than fail, as the `ec-ac3` matrix does; -//! `scripts/gen-fixtures.sh` writes them. - -use std::path::{Path, PathBuf}; use oxideav_ac3::{bsi, eac3, register_codecs, syncinfo}; use oxideav_core::{CodecId, CodecParameters, CodecRegistry, Decoder, Error, Frame, Packet, TimeBase}; -fn fixture(name: &str) -> Option> { - let path: PathBuf = Path::new(env!("CARGO_MANIFEST_DIR")) - .join("../../fixtures/audio") - .join(name); - std::fs::read(path).ok() +fn fixture(name: &str) -> Vec { + std::fs::read(ec_testkit::fixture(&format!("audio/{name}"))).expect("fixture") } /// `engine/src/audio.rs:2130` — a fresh decoder out of a fresh registry. @@ -77,10 +69,8 @@ fn the_replicas_open_path_lands_on_audible_pcm() { ("eac3-5.1-48000.eac3", "eac3", 48_000, 5, 2), ("eac3-mono-48000.eac3", "eac3", 48_000, 1, 1), ]; - let mut ran = 0; for (name, codec, rate, nfchans_want, channels_want) in cases { - let Some(data) = fixture(name) else { continue }; - ran += 1; + let data = fixture(name); let (sample_rate, nfchans) = header(codec, &data); assert_eq!(sample_rate, rate, "{name}: sample rate"); @@ -103,7 +93,6 @@ fn the_replicas_open_path_lands_on_audible_pcm() { assert_eq!((pcm.len() as u64 / samples.max(1)) as u16, channels_want); } } - assert!(ran > 0, "no AC-3 fixtures: run scripts/gen-fixtures.sh"); } /// A packet holding two or three syncframes, handed over the registry's @@ -115,10 +104,8 @@ fn a_packet_of_two_and_three_syncframes_decodes_to_its_frames() { ("ac3-5.1-48000.ac3", "ac3", Some(2)), ("eac3-5.1-48000.eac3", "eac3", Some(2)), ]; - let mut ran = 0; for (name, codec, requested) in cases { - let Some(data) = fixture(name) else { continue }; - ran += 1; + let data = fixture(name); let mut frames = Vec::new(); let mut pos = 0; while let Ok(len) = ec_ac3::frame_size(&data[pos..]) { @@ -147,5 +134,4 @@ fn a_packet_of_two_and_three_syncframes_decodes_to_its_frames() { assert_eq!(pcm, reference[..pcm.len()], "{name}: {n} frames, PCM"); } } - assert!(ran > 0, "no AC-3 fixtures: run scripts/gen-fixtures.sh"); } diff --git a/shims/symphonia/Cargo.toml b/shims/symphonia/Cargo.toml index 9252044b..2f38a70b 100644 --- a/shims/symphonia/Cargo.toml +++ b/shims/symphonia/Cargo.toml @@ -14,6 +14,7 @@ ec-probe = { path = "../../crates/ec-probe", version = "0.1.0" } symphonia-core = { path = "../symphonia-core", version = "0.6.0" } [dev-dependencies] +ec-testkit.workspace = true symphonia-codec-aac = { path = "../symphonia-codec-aac", version = "0.6.0" } ec-vorbis = { path = "../../crates/ec-vorbis", version = "0.1.0" } rusty_vorbis = { path = "../rusty_vorbis", version = "0.1.1" } diff --git a/shims/symphonia/tests/edith_surface.rs b/shims/symphonia/tests/edith_surface.rs index b33d07b9..413b0ae3 100644 --- a/shims/symphonia/tests/edith_surface.rs +++ b/shims/symphonia/tests/edith_surface.rs @@ -6,7 +6,7 @@ //! shim rather than merely type-checking against it. use std::fs::File; -use std::path::{Path, PathBuf}; +use std::path::Path; use symphonia_codec_aac::AacDecoder; use symphonia_core::codecs::CodecParameters; @@ -22,8 +22,8 @@ use symphonia_core::io::MediaSourceStream; use symphonia_core::meta::MetadataOptions; use symphonia_core::units::{Time, TimeBase, Timestamp}; -fn fixtures() -> PathBuf { - Path::new(env!("CARGO_MANIFEST_DIR")).join("../../fixtures/audio") +fn fixture(name: &str) -> std::path::PathBuf { + ec_testkit::fixture(&format!("audio/{name}")) } /// edith's `sym_reader`, verbatim in shape. @@ -138,12 +138,8 @@ fn every_file_opens_describes_and_decodes_through_the_shim() { ("aac-mka-stereo-48000.mka", "aac", 2), ("av-h264-aac-stereo-48000.mkv", "aac", 2), ]; - let mut checked = 0; for (name, codec, channels) in files { - let path = fixtures().join(name); - if !path.exists() { - continue; - } + let path = fixture(name); let mut track = SymTrack::open(&path).unwrap_or_else(|| panic!("{name}: no audio track")); assert_eq!(track.codec, codec, "{name}: codec name"); assert_eq!(track.channels, channels, "{name}: channels"); @@ -170,10 +166,8 @@ fn every_file_opens_describes_and_decodes_through_the_shim() { frames * 20 > want * 19, "{name}: decoded {frames} of {want} frames" ); - checked += 1; } - assert!(checked > 0, "no fixtures — run scripts/gen-fixtures.sh"); - eprintln!("edith's symphonia surface: {checked} files opened and decoded"); + eprintln!("edith's symphonia surface: {} files opened and decoded", files.len()); } /// The defect this shim exists to fix: the incumbent's Matroska seek is @@ -183,10 +177,7 @@ fn every_file_opens_describes_and_decodes_through_the_shim() { #[test] fn twenty_seeks_on_one_reader_all_land() { for name in ["av-h264-aac-stereo-48000.mkv", "aac-mka-stereo-48000.mka"] { - let path = fixtures().join(name); - if !path.exists() { - continue; - } + let path = fixture(name); let mut track = SymTrack::open(&path).expect("track"); let mut decoder = track.decoder(); let mut out = Vec::new(); @@ -221,10 +212,7 @@ fn twenty_seeks_on_one_reader_all_land() { /// stereo. A 5.1 AAC track decodes here, through the AAC shim, as 6 channels. #[test] fn multichannel_aac_decodes_rather_than_being_refused() { - let path = fixtures().join("aac-mp4-5.1-44100.mp4"); - if !path.exists() { - return; - } + let path = fixture("aac-mp4-5.1-44100.mp4"); let mut track = SymTrack::open(&path).expect("track"); assert_eq!(track.channels, 6); let mut decoder = track.decoder(); @@ -289,7 +277,7 @@ fn opus_has_a_decoder_in_the_registry() { /// header and an ID3v1 tail, so this needs no real file on disk. #[test] fn cover_art_and_id3v1_tail_do_not_stop_the_probe() { - let raw = std::fs::read(fixtures().join("mp3-stereo-48000.mp3")).expect("fixture mp3"); + let raw = std::fs::read(fixture("mp3-stereo-48000.mp3")).expect("fixture mp3"); // A 2 MB ID3v2.3 tag: one oversized `APIC` frame of filler bytes. The // probe only needs to skip past the tag's declared size, so the frame // body's content does not matter.