Serialize sbr_real_library tests against a cross-test env-var race
Browse files at this commita7e507da94c07ab9371fbf05f6d4af69f3d1ff7dParent: 360bf3b- fix
- serialize sbr_real_library tests against a cross-test env-var race
1 changed file +30 -0
crates/ec-aac/tests/sbr_real_library.rsmodified+30 -0
| @@ -16,6 +16,20 @@ use ec_core::{CodecId, Demuxer, Packet}; | ||
| 16 | 16 | use ec_matroska::MatroskaDemuxer; |
| 17 | 17 | use ec_mp4::Mp4Demuxer; |
| 18 | 18 | |
| 19 | +/// Every `#[test]` in this file decodes real SBR content through | |
| 20 | +/// `our_decode`/`our_decode_uncapped`, and a handful of them steer that | |
| 21 | +/// decode with process-global env vars (`EC_AAC_SBR_HF_BYPASS`, | |
| 22 | +/// `EC_AAC_SBR_SIDEINFO_DEBUG`, `EC_AAC_SBR_NOISE_ZERO`, | |
| 23 | +/// `EC_AAC_SBR_NOISE_FRACTION`) as debug toggles, set then removed mid-test. | |
| 24 | +/// Cargo runs this binary's tests in parallel threads by default, so an | |
| 25 | +/// unguarded `set_var`/`remove_var` window in one test can flip decode | |
| 26 | +/// behaviour out from under another test's own concurrent decode -- this is | |
| 27 | +/// exactly what turned `sbr_real_library_matches_reference`'s HF-band | |
| 28 | +/// correlation into a full-suite-only flake (`sbr_hf_window_band_probe` | |
| 29 | +/// toggling `EC_AAC_SBR_HF_BYPASS` while it ran). Every test locks this for | |
| 30 | +/// its whole body so no toggle window and no concurrent read can interleave. | |
| 31 | +static DECODE_SERIAL: std::sync::Mutex<()> = std::sync::Mutex::new(()); | |
| 32 | + | |
| 19 | 33 | fn have_ffmpeg() -> bool { |
| 20 | 34 | Command::new("ffmpeg") |
| 21 | 35 | .arg("-version") |
| @@ -2189,6 +2203,7 @@ fn ffmpeg_decode_at_rate( | ||
| 2189 | 2203 | /// the crossover at all. |
| 2190 | 2204 | #[test] |
| 2191 | 2205 | fn core_only_matches_reference() { |
| 2206 | + let _guard = DECODE_SERIAL.lock().unwrap_or_else(|e| e.into_inner()); | |
| 2192 | 2207 | if !have_ffmpeg() { |
| 2193 | 2208 | eprintln!("SKIP: ffmpeg not on PATH"); |
| 2194 | 2209 | return; |
| @@ -2228,6 +2243,7 @@ fn core_only_matches_reference() { | ||
| 2228 | 2243 | /// that scaling. |
| 2229 | 2244 | #[test] |
| 2230 | 2245 | fn dump_sideinfo_kx() { |
| 2246 | + let _guard = DECODE_SERIAL.lock().unwrap_or_else(|e| e.into_inner()); | |
| 2231 | 2247 | unsafe { |
| 2232 | 2248 | std::env::set_var("EC_AAC_SBR_SIDEINFO_DEBUG", "1"); |
| 2233 | 2249 | } |
| @@ -2261,6 +2277,7 @@ fn dump_sideinfo_kx() { | ||
| 2261 | 2277 | /// content itself being wrong. |
| 2262 | 2278 | #[test] |
| 2263 | 2279 | fn wide_lag_search_full_chain() { |
| 2280 | + let _guard = DECODE_SERIAL.lock().unwrap_or_else(|e| e.into_inner()); | |
| 2264 | 2281 | if !have_ffmpeg() { |
| 2265 | 2282 | eprintln!("SKIP: ffmpeg not on PATH"); |
| 2266 | 2283 | return; |
| @@ -2313,6 +2330,7 @@ fn wide_lag_search_full_chain() { | ||
| 2313 | 2330 | /// factor (alignment against a reference, different tool, etc.) to blame. |
| 2314 | 2331 | #[test] |
| 2315 | 2332 | fn full_chain_low_band_matches_own_core() { |
| 2333 | + let _guard = DECODE_SERIAL.lock().unwrap_or_else(|e| e.into_inner()); | |
| 2316 | 2334 | for c in &candidates() { |
| 2317 | 2335 | let Some((core, core_rate)) = our_decode_core_only(&c.path, c.aac_stream) else { |
| 2318 | 2336 | continue; |
| @@ -2405,6 +2423,7 @@ fn full_chain_low_band_matches_own_core() { | ||
| 2405 | 2423 | /// directory is absent. |
| 2406 | 2424 | #[test] |
| 2407 | 2425 | fn synthetic_heaac_matrix() { |
| 2426 | + let _guard = DECODE_SERIAL.lock().unwrap_or_else(|e| e.into_inner()); | |
| 2408 | 2427 | if !have_ffmpeg() { |
| 2409 | 2428 | eprintln!("SKIP: ffmpeg not on PATH"); |
| 2410 | 2429 | return; |
| @@ -2719,6 +2738,7 @@ fn candidates() -> Vec<Candidate> { | ||
| 2719 | 2738 | /// touches. |
| 2720 | 2739 | #[test] |
| 2721 | 2740 | fn sbr_real_library_matches_reference() { |
| 2741 | + let _guard = DECODE_SERIAL.lock().unwrap_or_else(|e| e.into_inner()); | |
| 2722 | 2742 | if !have_ffmpeg() { |
| 2723 | 2743 | eprintln!("SKIP: ffmpeg not on PATH"); |
| 2724 | 2744 | return; |
| @@ -3391,6 +3411,7 @@ fn report_conviction(label: &str, rows: &[(f64, f64, f64, f64, f64, f64)]) { | ||
| 3391 | 3411 | /// need to be recalibrated against whatever this control actually measures. |
| 3392 | 3412 | #[test] |
| 3393 | 3413 | fn sbr_instrument_anchor_controls() { |
| 3414 | + let _guard = DECODE_SERIAL.lock().unwrap_or_else(|e| e.into_inner()); | |
| 3394 | 3415 | if std::env::var("EC_AAC_SBR_INSTRUMENT_ANCHOR").is_err() { |
| 3395 | 3416 | eprintln!( |
| 3396 | 3417 | "SKIP (round-41 Task 1): EC_AAC_SBR_INSTRUMENT_ANCHOR=1 cargo test -p ec-aac \ |
| @@ -3470,6 +3491,7 @@ fn sbr_instrument_anchor_controls() { | ||
| 3470 | 3491 | /// ACTUALLY realizes in the output, independent of either prior claim. |
| 3471 | 3492 | #[test] |
| 3472 | 3493 | fn sbr_actual_noise_fraction() { |
| 3494 | + let _guard = DECODE_SERIAL.lock().unwrap_or_else(|e| e.into_inner()); | |
| 3473 | 3495 | if std::env::var("EC_AAC_SBR_NOISE_ANCHOR").is_err() { |
| 3474 | 3496 | eprintln!( |
| 3475 | 3497 | "SKIP (round-41 Task 2): EC_AAC_SBR_NOISE_ANCHOR=1 cargo test -p ec-aac \ |
| @@ -3666,6 +3688,7 @@ fn sbr_actual_noise_fraction() { | ||
| 3666 | 3688 | /// generates nothing. |
| 3667 | 3689 | #[test] |
| 3668 | 3690 | fn sbr_header_feature_table() { |
| 3691 | + let _guard = DECODE_SERIAL.lock().unwrap_or_else(|e| e.into_inner()); | |
| 3669 | 3692 | if !have_ffmpeg() { |
| 3670 | 3693 | eprintln!("SKIP: ffmpeg not on PATH"); |
| 3671 | 3694 | return; |
| @@ -3915,6 +3938,7 @@ fn per_au_low_band_probe(label: &str, path: &Path, aac_stream: usize) { | ||
| 3915 | 3938 | |
| 3916 | 3939 | #[test] |
| 3917 | 3940 | fn per_au_low_band_divergence() { |
| 3941 | + let _guard = DECODE_SERIAL.lock().unwrap_or_else(|e| e.into_inner()); | |
| 3918 | 3942 | if !have_ffmpeg() { |
| 3919 | 3943 | eprintln!("SKIP: ffmpeg not on PATH"); |
| 3920 | 3944 | return; |
| @@ -3948,6 +3972,7 @@ fn per_au_low_band_divergence() { | ||
| 3948 | 3972 | /// own_core`'s FMJ probe with `WIDE_LAG_MAX` raised to 100_000. |
| 3949 | 3973 | #[test] |
| 3950 | 3974 | fn probe_explicit_config_and_wide_lag() { |
| 3975 | + let _guard = DECODE_SERIAL.lock().unwrap_or_else(|e| e.into_inner()); | |
| 3951 | 3976 | if !have_ffmpeg() { |
| 3952 | 3977 | eprintln!("SKIP: ffmpeg not on PATH"); |
| 3953 | 3978 | return; |
| @@ -4149,6 +4174,7 @@ fn ffmpeg_decode_pan_channel(path: &Path, absolute_stream: usize, channel: usize | ||
| 4149 | 4174 | /// (never `-ac 1`, which would remix rather than isolate). |
| 4150 | 4175 | #[test] |
| 4151 | 4176 | fn reelq_multichannel_lc_matches_reference() { |
| 4177 | + let _guard = DECODE_SERIAL.lock().unwrap_or_else(|e| e.into_inner()); | |
| 4152 | 4178 | if !have_ffmpeg() { |
| 4153 | 4179 | eprintln!("SKIP: ffmpeg not on PATH"); |
| 4154 | 4180 | return; |
| @@ -4208,6 +4234,7 @@ fn reelq_multichannel_lc_matches_reference() { | ||
| 4208 | 4234 | /// the swap-shaped-result gate this round adds. |
| 4209 | 4235 | #[test] |
| 4210 | 4236 | fn coupled_cpe_channel_swap_probe() { |
| 4237 | + let _guard = DECODE_SERIAL.lock().unwrap_or_else(|e| e.into_inner()); | |
| 4211 | 4238 | if !have_ffmpeg() { |
| 4212 | 4239 | eprintln!("SKIP: ffmpeg not on PATH"); |
| 4213 | 4240 | return; |
| @@ -4537,6 +4564,7 @@ fn narrow_lag_at( | ||
| 4537 | 4564 | /// (real 44.1k HE-AAC) as controls that are known NOT to show the drift. |
| 4538 | 4565 | #[test] |
| 4539 | 4566 | fn sbr441_family_sample_drift_probe() { |
| 4567 | + let _guard = DECODE_SERIAL.lock().unwrap_or_else(|e| e.into_inner()); | |
| 4540 | 4568 | if !have_ffmpeg() { |
| 4541 | 4569 | eprintln!("SKIP: ffmpeg not on PATH"); |
| 4542 | 4570 | return; |
| @@ -4657,6 +4685,7 @@ fn sbr441_family_sample_drift_probe() { | ||
| 4657 | 4685 | /// readable straight from the printed corr numbers. |
| 4658 | 4686 | #[test] |
| 4659 | 4687 | fn sbr_hf_window_band_probe() { |
| 4688 | + let _guard = DECODE_SERIAL.lock().unwrap_or_else(|e| e.into_inner()); | |
| 4660 | 4689 | if !have_ffmpeg() { |
| 4661 | 4690 | eprintln!("SKIP: ffmpeg not on PATH"); |
| 4662 | 4691 | return; |
| @@ -4761,6 +4790,7 @@ fn sbr_hf_window_band_probe() { | ||
| 4761 | 4790 | /// band, so it needs no calibration) with an ours-vs-ours self-check column. |
| 4762 | 4791 | #[test] |
| 4763 | 4792 | fn sbr_residual_locator() { |
| 4793 | + let _guard = DECODE_SERIAL.lock().unwrap_or_else(|e| e.into_inner()); | |
| 4764 | 4794 | if !have_ffmpeg() { |
| 4765 | 4795 | return; |
| 4766 | 4796 | } |