forge
Explore
Log in

Don't you dare go Hollow

The ignored encoder:: gates raced on the process-global speed preset

Browse files at this commit

8c24e30032a9073e46982a05139b4bdde8e3e69cAhmet Kaan GümüşParent: d248e08
  • test
    • the ignored encoder:: gates raced on the process-global speed preset
Show full message
test(av1): the ignored encoder:: gates raced on the process-global speed preset

`Av1Encoder::with_speed` stores the preset in a process-global atomic
(`speed::SPEED`) and `par::set_tile_threads` in another, so with the default
`--test-threads` the ignored gate
`every_speed_preset_decodes_sample_exact_through_both_decoders` (presets
0..=10) and the `tile_*`/`filter_stage_*` wall tables changed the preset
UNDER five concurrently encoding gates: four died in the encoder's own
"a reference frame selected with no picture at this frame's own
ref_frame_idx slot" (a sequence planned at one preset continuing at another)
and `the_facade_codes_the_same_bytes_as_encode_sequence` on a byte compare.
Every one of them passes standalone or at --test-threads 1.

Root fix, test-only: `speed::KNOBS`, a reader/writer lock -- a test that SETS
a process-global knob holds `knob_write()` for its whole body, every other
`encoder::` test holds `knob_read()`, so a setter never overlaps an encode.
Poison is ignored so one failing gate does not turn every later one into a
lock panic. No production path changes; the temp files these gates write were
already PID-keyed and no test in the crate calls `set_var`.

Gates: the parallel run 28/28 twice (603 s, 658 s; it was 23 passed / 5 failed
before), --test-threads 1 28/28, `cargo test -p ec-av1 --release -j4`
545 passed / 43 ignored, `cargo check --workspace --all-targets` 0 errors and
0 ec-av1 warnings, pins 8446 / 28548 unchanged.
crates/ec-av1/src/encoder.rsmodified+28 -0
@@ -1467,6 +1467,7 @@ mod tests {
1467 /// exactly one non-empty packet per picture, `depth - 1` calls later.1467 /// exactly one non-empty packet per picture, `depth - 1` calls later.
1468 #[test]1468 #[test]
1469 fn one_in_one_out_delayed_by_the_lookahead_depth() {1469 fn one_in_one_out_delayed_by_the_lookahead_depth() {
1470+ let _knobs = crate::speed::knob_read();
1470 let config = EncoderConfig {1471 let config = EncoderConfig {
1471 width: 64,1472 width: 64,
1472 height: 64,1473 height: 64,
@@ -1533,6 +1534,7 @@ mod tests {
1533 /// to catch.1534 /// to catch.
1534 #[test]1535 #[test]
1535 fn the_facade_codes_the_same_bytes_as_encode_sequence() {1536 fn the_facade_codes_the_same_bytes_as_encode_sequence() {
1537+ let _knobs = crate::speed::knob_read();
1536 let frames = 12usize;1538 let frames = 12usize;
1537 let film = h264_clip_frames(640, 384, frames).unwrap_or_else(|| {1539 let film = h264_clip_frames(640, 384, frames).unwrap_or_else(|| {
1538 eprintln!("no h264 clip: the facade identity gate runs on a synthetic card");1540 eprintln!("no h264 clip: the facade identity gate runs on a synthetic card");
@@ -1609,6 +1611,7 @@ mod tests {
1609 /// that only checked the screen half would pass with the pyramid deleted).1611 /// that only checked the screen half would pass with the pyramid deleted).
1610 #[test]1612 #[test]
1611 fn the_content_gate_keeps_screen_streams_flat() {1613 fn the_content_gate_keeps_screen_streams_flat() {
1614+ let _knobs = crate::speed::knob_read();
1612 let frames = 8usize;1615 let frames = 8usize;
1613 let pictures: Vec<Picture> = (0..frames).map(|t| test_card(64, 64, t)).collect();1616 let pictures: Vec<Picture> = (0..frames).map(|t| test_card(64, 64, t)).collect();
1614 let config = EncoderConfig {1617 let config = EncoderConfig {
@@ -1647,6 +1650,7 @@ mod tests {
1647 /// reads back out of the coded bytes.1650 /// reads back out of the coded bytes.
1648 #[test]1651 #[test]
1649 fn gop_cadence_is_honored() {1652 fn gop_cadence_is_honored() {
1653+ let _knobs = crate::speed::knob_read();
1650 let config = EncoderConfig {1654 let config = EncoderConfig {
1651 width: 64,1655 width: 64,
1652 height: 64,1656 height: 64,
@@ -1744,6 +1748,7 @@ mod tests {
1744 /// coded size confirm what the facade already reported.1748 /// coded size confirm what the facade already reported.
1745 #[test]1749 #[test]
1746 fn thirty_pictures_at_gop_fifteen_decode_to_two_key_frames() {1750 fn thirty_pictures_at_gop_fifteen_decode_to_two_key_frames() {
1751+ let _knobs = crate::speed::knob_read();
1747 if !have_ffmpeg() {1752 if !have_ffmpeg() {
1748 eprintln!("SKIP thirty_pictures_at_gop_fifteen_decode_to_two_key_frames: no ffmpeg");1753 eprintln!("SKIP thirty_pictures_at_gop_fifteen_decode_to_two_key_frames: no ffmpeg");
1749 return;1754 return;
@@ -1799,6 +1804,7 @@ mod tests {
1799 /// which is a visibly different string).1804 /// which is a visibly different string).
1800 #[test]1805 #[test]
1801 fn bt709_limited_colour_is_reported_by_ffprobe() {1806 fn bt709_limited_colour_is_reported_by_ffprobe() {
1807+ let _knobs = crate::speed::knob_read();
1802 if !have_ffmpeg() {1808 if !have_ffmpeg() {
1803 eprintln!("SKIP bt709_limited_colour_is_reported_by_ffprobe: no ffmpeg");1809 eprintln!("SKIP bt709_limited_colour_is_reported_by_ffprobe: no ffmpeg");
1804 return;1810 return;
@@ -1823,6 +1829,7 @@ mod tests {
1823 /// as BT.709 for every input.1829 /// as BT.709 for every input.
1824 #[test]1830 #[test]
1825 fn bt601_limited_colour_is_reported_by_ffprobe() {1831 fn bt601_limited_colour_is_reported_by_ffprobe() {
1832+ let _knobs = crate::speed::knob_read();
1826 if !have_ffmpeg() {1833 if !have_ffmpeg() {
1827 eprintln!("SKIP bt601_limited_colour_is_reported_by_ffprobe: no ffmpeg");1834 eprintln!("SKIP bt601_limited_colour_is_reported_by_ffprobe: no ffmpeg");
1828 return;1835 return;
@@ -1849,6 +1856,7 @@ mod tests {
1849 /// is refused by name.1856 /// is refused by name.
1850 #[test]1857 #[test]
1851 fn geometry_mismatch_is_refused() {1858 fn geometry_mismatch_is_refused() {
1859+ let _knobs = crate::speed::knob_read();
1852 let config = EncoderConfig {1860 let config = EncoderConfig {
1853 width: 64,1861 width: 64,
1854 height: 64,1862 height: 64,
@@ -1866,6 +1874,7 @@ mod tests {
1866 /// `gop == 0` is refused at construction, not the first `encode()` call.1874 /// `gop == 0` is refused at construction, not the first `encode()` call.
1867 #[test]1875 #[test]
1868 fn zero_gop_is_refused() {1876 fn zero_gop_is_refused() {
1877+ let _knobs = crate::speed::knob_read();
1869 let config = EncoderConfig {1878 let config = EncoderConfig {
1870 width: 64,1879 width: 64,
1871 height: 64,1880 height: 64,
@@ -1942,6 +1951,7 @@ mod tests {
1942 /// state and the controller's first couple of steps).1951 /// state and the controller's first couple of steps).
1943 #[test]1952 #[test]
1944 fn bytes_per_frame_target_settles_within_20_percent() {1953 fn bytes_per_frame_target_settles_within_20_percent() {
1954+ let _knobs = crate::speed::knob_read();
1945 let Some(pictures) = h264_clip_frames(640, 384, 24) else {1955 let Some(pictures) = h264_clip_frames(640, 384, 24) else {
1946 eprintln!("SKIP bytes_per_frame_target_settles_within_20_percent: no ffmpeg/fixture");1956 eprintln!("SKIP bytes_per_frame_target_settles_within_20_percent: no ffmpeg/fixture");
1947 return;1957 return;
@@ -1981,6 +1991,7 @@ mod tests {
1981 /// its own level and one clamped proportional step.1991 /// its own level and one clamped proportional step.
1982 #[test]1992 #[test]
1983 fn bitrate_target_lands_within_10_percent_over_48_frames() {1993 fn bitrate_target_lands_within_10_percent_over_48_frames() {
1994+ let _knobs = crate::speed::knob_read();
1984 let (width, height, frames) = (640usize, 384usize, 48usize);1995 let (width, height, frames) = (640usize, 384usize, 48usize);
1985 let Some(pictures) = h264_clip_frames(width, height, frames) else {1996 let Some(pictures) = h264_clip_frames(width, height, frames) else {
1986 eprintln!("SKIP bitrate_target_lands_within_10_percent_over_48_frames: no ffmpeg/fixture");1997 eprintln!("SKIP bitrate_target_lands_within_10_percent_over_48_frames: no ffmpeg/fixture");
@@ -2048,6 +2059,7 @@ mod tests {
2048 /// break it.2059 /// break it.
2049 #[test]2060 #[test]
2050 fn bytes_per_frame_controller_never_oscillates_past_its_clamp() {2061 fn bytes_per_frame_controller_never_oscillates_past_its_clamp() {
2062+ let _knobs = crate::speed::knob_read();
2051 let Some(pictures) = h264_clip_frames(640, 384, 24) else {2063 let Some(pictures) = h264_clip_frames(640, 384, 24) else {
2052 eprintln!(2064 eprintln!(
2053 "SKIP bytes_per_frame_controller_never_oscillates_past_its_clamp: no ffmpeg/fixture"2065 "SKIP bytes_per_frame_controller_never_oscillates_past_its_clamp: no ffmpeg/fixture"
@@ -2151,6 +2163,7 @@ mod tests {
2151 /// display-order list and fails here.2163 /// display-order list and fails here.
2152 #[test]2164 #[test]
2153 fn a_pyramid_stream_decodes_in_display_order_through_both_decoders() {2165 fn a_pyramid_stream_decodes_in_display_order_through_both_decoders() {
2166+ let _knobs = crate::speed::knob_read();
2154 let (width, height) = (128usize, 128usize);2167 let (width, height) = (128usize, 128usize);
2155 let config = EncoderConfig {2168 let config = EncoderConfig {
2156 width,2169 width,
@@ -2266,6 +2279,7 @@ mod tests {
2266 /// nothing about whether a single 64x64 block was ever written.2279 /// nothing about whether a single 64x64 block was ever written.
2267 #[test]2280 #[test]
2268 fn a_static_clip_codes_64x64_roots_and_decodes_sample_exact() {2281 fn a_static_clip_codes_64x64_roots_and_decodes_sample_exact() {
2282+ let _knobs = crate::speed::knob_read();
2269 let _gate_lock = crate::stream::tests::lock_gate_counters();2283 let _gate_lock = crate::stream::tests::lock_gate_counters();
2270 let (width, height) = (256usize, 128usize);2284 let (width, height) = (256usize, 128usize);
2271 let still = test_card(width, height, 0);2285 let still = test_card(width, height, 0);
@@ -2317,6 +2331,7 @@ mod tests {
2317 2331
2318 #[test]2332 #[test]
2319 fn every_tile_layout_decodes_sample_exact_through_both_decoders() {2333 fn every_tile_layout_decodes_sample_exact_through_both_decoders() {
2334+ let _knobs = crate::speed::knob_read();
2320 let (width, height) = (640usize, 384usize);2335 let (width, height) = (640usize, 384usize);
2321 let sources: Vec<Picture> = (0..4).map(|t| test_card(width, height, t * 3)).collect();2336 let sources: Vec<Picture> = (0..4).map(|t| test_card(width, height, t * 3)).collect();
2322 let mut sizes = Vec::new();2337 let mut sizes = Vec::new();
@@ -2409,6 +2424,7 @@ mod tests {
2409 #[test]2424 #[test]
2410 #[ignore = "sets the process-global speed preset: run it alone"]2425 #[ignore = "sets the process-global speed preset: run it alone"]
2411 fn every_speed_preset_decodes_sample_exact_through_both_decoders() {2426 fn every_speed_preset_decodes_sample_exact_through_both_decoders() {
2427+ let _knobs = crate::speed::knob_write();
2412 let _gate_lock = crate::stream::tests::lock_gate_counters();2428 let _gate_lock = crate::stream::tests::lock_gate_counters();
2413 let (width, height) = (640usize, 384usize);2429 let (width, height) = (640usize, 384usize);
2414 let sources: Vec<Picture> = (0..4).map(|t| test_card(width, height, t * 3)).collect();2430 let sources: Vec<Picture> = (0..4).map(|t| test_card(width, height, t * 3)).collect();
@@ -2472,6 +2488,7 @@ mod tests {
2472 #[test]2488 #[test]
2473 #[ignore = "1080p wall table: minutes, run it with --ignored"]2489 #[ignore = "1080p wall table: minutes, run it with --ignored"]
2474 fn tile_wall_table_at_1080p() {2490 fn tile_wall_table_at_1080p() {
2491+ let _knobs = crate::speed::knob_write();
2475 let _gate_lock = crate::stream::tests::lock_gate_counters();2492 let _gate_lock = crate::stream::tests::lock_gate_counters();
2476 let (width, height) = (1920usize, 1080usize);2493 let (width, height) = (1920usize, 1080usize);
2477 let Some(sources) = h264_clip_frames(width, height, 8) else {2494 let Some(sources) = h264_clip_frames(width, height, 8) else {
@@ -2522,6 +2539,7 @@ mod tests {
2522 /// thread and at four, per layout.2539 /// thread and at four, per layout.
2523 #[test]2540 #[test]
2524 fn tile_bytes_do_not_depend_on_the_thread_count() {2541 fn tile_bytes_do_not_depend_on_the_thread_count() {
2542+ let _knobs = crate::speed::knob_write();
2525 let _gate_lock = crate::stream::tests::lock_gate_counters();2543 let _gate_lock = crate::stream::tests::lock_gate_counters();
2526 let (width, height) = (320usize, 192usize);2544 let (width, height) = (320usize, 192usize);
2527 let sources: Vec<Picture> = (0..3).map(|t| test_card(width, height, t * 3)).collect();2545 let sources: Vec<Picture> = (0..3).map(|t| test_card(width, height, t * 3)).collect();
@@ -2571,6 +2589,7 @@ mod tests {
2571 #[test]2589 #[test]
2572 #[ignore = "wall measurement: minutes, run it with --ignored --nocapture"]2590 #[ignore = "wall measurement: minutes, run it with --ignored --nocapture"]
2573 fn tile_search_wall_1080p() {2591 fn tile_search_wall_1080p() {
2592+ let _knobs = crate::speed::knob_write();
2574 tile_search_wall(1920, 1080, 12, &[(0, 0), (1, 0), (1, 1), (2, 1)], &[1, 2, 4, 8]);2593 tile_search_wall(1920, 1080, 12, &[(0, 0), (1, 0), (1, 1), (2, 1)], &[1, 2, 4, 8]);
2575 }2594 }
2576 2595
@@ -2579,6 +2598,7 @@ mod tests {
2579 #[test]2598 #[test]
2580 #[ignore = "wall measurement: minutes, run it with --ignored --nocapture"]2599 #[ignore = "wall measurement: minutes, run it with --ignored --nocapture"]
2581 fn tile_search_wall_4k() {2600 fn tile_search_wall_4k() {
2601+ let _knobs = crate::speed::knob_write();
2582 tile_search_wall(3840, 1608, 6, &[(2, 1), (3, 2)], &[1, 8, 12]);2602 tile_search_wall(3840, 1608, 6, &[(2, 1), (3, 2)], &[1, 8, 12]);
2583 }2603 }
2584 2604
@@ -2590,6 +2610,7 @@ mod tests {
2590 /// rows tall, which is what makes the bands non-trivial.2610 /// rows tall, which is what makes the bands non-trivial.
2591 #[test]2611 #[test]
2592 fn filter_stage_bytes_do_not_depend_on_the_thread_count() {2612 fn filter_stage_bytes_do_not_depend_on_the_thread_count() {
2613+ let _knobs = crate::speed::knob_write();
2593 let _gate_lock = crate::stream::tests::lock_gate_counters();2614 let _gate_lock = crate::stream::tests::lock_gate_counters();
2594 let (width, height) = (384usize, 288usize);2615 let (width, height) = (384usize, 288usize);
2595 let sources: Vec<Picture> = (0..4).map(|t| test_card(width, height, t * 3)).collect();2616 let sources: Vec<Picture> = (0..4).map(|t| test_card(width, height, t * 3)).collect();
@@ -2627,6 +2648,7 @@ mod tests {
2627 /// which is the arm this lane opened.2648 /// which is the arm this lane opened.
2628 #[test]2649 #[test]
2629 fn filter_replay_codes_the_same_stream_as_a_full_decode() {2650 fn filter_replay_codes_the_same_stream_as_a_full_decode() {
2651+ let _knobs = crate::speed::knob_read();
2630 let _gate_lock = crate::stream::tests::lock_gate_counters();2652 let _gate_lock = crate::stream::tests::lock_gate_counters();
2631 let run = |width: usize, height: usize, off: bool| {2653 let run = |width: usize, height: usize, off: bool| {
2632 let sources: Vec<Picture> = (0..4).map(|t| test_card(width, height, t * 3)).collect();2654 let sources: Vec<Picture> = (0..4).map(|t| test_card(width, height, t * 3)).collect();
@@ -2672,6 +2694,7 @@ mod tests {
2672 /// the loop-restoration search reads are bit-identical.2694 /// the loop-restoration search reads are bit-identical.
2673 #[test]2695 #[test]
2674 fn filter_replay_final_matches_the_capture_decode() {2696 fn filter_replay_final_matches_the_capture_decode() {
2697+ let _knobs = crate::speed::knob_read();
2675 let _gate_lock = crate::stream::tests::lock_gate_counters();2698 let _gate_lock = crate::stream::tests::lock_gate_counters();
2676 let run = |sources: &[Picture], width: usize, height: usize, tiles: (u32, u32)| {2699 let run = |sources: &[Picture], width: usize, height: usize, tiles: (u32, u32)| {
2677 let config = EncoderConfig {2700 let config = EncoderConfig {
@@ -2715,12 +2738,14 @@ mod tests {
2715 #[test]2738 #[test]
2716 #[ignore = "wall measurement: minutes, run it with --ignored --nocapture"]2739 #[ignore = "wall measurement: minutes, run it with --ignored --nocapture"]
2717 fn filter_stage_wall_1080p() {2740 fn filter_stage_wall_1080p() {
2741+ let _knobs = crate::speed::knob_write();
2718 filter_stage_wall(1920, 1080, 8, (2, 1), &[8]);2742 filter_stage_wall(1920, 1080, 8, (2, 1), &[8]);
2719 }2743 }
2720 2744
2721 #[test]2745 #[test]
2722 #[ignore = "wall measurement: minutes, run it with --ignored --nocapture"]2746 #[ignore = "wall measurement: minutes, run it with --ignored --nocapture"]
2723 fn filter_stage_wall_4k() {2747 fn filter_stage_wall_4k() {
2748+ let _knobs = crate::speed::knob_write();
2724 filter_stage_wall(3840, 1608, 4, (2, 1), &[8, 12]);2749 filter_stage_wall(3840, 1608, 4, (2, 1), &[8, 12]);
2725 }2750 }
2726 2751
@@ -2731,6 +2756,7 @@ mod tests {
2731 #[test]2756 #[test]
2732 #[ignore = "wall measurement: minutes, run it with --ignored --nocapture"]2757 #[ignore = "wall measurement: minutes, run it with --ignored --nocapture"]
2733 fn filter_stage_wall_film() {2758 fn filter_stage_wall_film() {
2759+ let _knobs = crate::speed::knob_write();
2734 filter_stage_wall(1920, 768, 4, (2, 1), &[8]);2760 filter_stage_wall(1920, 768, 4, (2, 1), &[8]);
2735 }2761 }
2736 2762
@@ -2955,6 +2981,7 @@ mod tests {
2955 #[test]2981 #[test]
2956 #[ignore = "1080p encode: minutes, run it with --ignored"]2982 #[ignore = "1080p encode: minutes, run it with --ignored"]
2957 fn a_1080p_multi_tile_stream_decodes_sample_exact_through_both_decoders() {2983 fn a_1080p_multi_tile_stream_decodes_sample_exact_through_both_decoders() {
2984+ let _knobs = crate::speed::knob_read();
2958 let (width, height) = (1920usize, 1080usize);2985 let (width, height) = (1920usize, 1080usize);
2959 let Some(sources) = h264_clip_frames(width, height, 3) else {2986 let Some(sources) = h264_clip_frames(width, height, 3) else {
2960 eprintln!("SKIP the 1080p tile round trip: no fixture");2987 eprintln!("SKIP the 1080p tile round trip: no fixture");
@@ -3003,6 +3030,7 @@ mod tests {
3003 /// the same real clip.3030 /// the same real clip.
3004 #[test]3031 #[test]
3005 fn quality_target_is_monotone_in_bytes_and_psnr() {3032 fn quality_target_is_monotone_in_bytes_and_psnr() {
3033+ let _knobs = crate::speed::knob_read();
3006 if !have_ffmpeg() {3034 if !have_ffmpeg() {
3007 eprintln!("SKIP quality_target_is_monotone_in_bytes_and_psnr: no ffmpeg");3035 eprintln!("SKIP quality_target_is_monotone_in_bytes_and_psnr: no ffmpeg");
3008 return;3036 return;
crates/ec-av1/src/speed.rsmodified+32 -0
@@ -504,3 +504,35 @@ mod tests {
504 assert!(!levers(MAX_SPEED).is_empty());504 assert!(!levers(MAX_SPEED).is_empty());
505 }505 }
506 }506 }
507+
508+// ---------------------------------------------------------------------------
509+// Test-only serialisation of the process-global encoder knobs (lane-gaterace)
510+// ---------------------------------------------------------------------------
511+
512+/// [`SPEED`] and [`crate::par::TILE_THREADS`] are PROCESS-global, so a test
513+/// that stores one of them changes what every test encoding concurrently on
514+/// another test thread codes: with the default `--test-threads`,
515+/// `every_speed_preset_decodes_sample_exact_through_both_decoders` (presets
516+/// 0..=10) and the `tile_*`/`filter_stage_*` wall tables poisoned five of the
517+/// ignored `encoder::` gates, each of which passes standalone. The rule is
518+/// reader/writer, not a plain mutex: a test that SETS a knob holds
519+/// [`knob_write`] for its whole body, and every test that ENCODES (i.e. reads
520+/// the knobs, over more than one call) holds [`knob_read`], so a setter never
521+/// overlaps an encode. Poison is ignored deliberately -- one failing gate
522+/// must not turn every later one into a lock panic.
523+#[cfg(test)]
524+static KNOBS: std::sync::RwLock<()> = std::sync::RwLock::new(());
525+
526+/// Held by a test that reads the process-global knobs; see [`KNOBS`].
527+#[cfg(test)]
528+#[must_use]
529+pub(crate) fn knob_read() -> std::sync::RwLockReadGuard<'static, ()> {
530+ KNOBS.read().unwrap_or_else(std::sync::PoisonError::into_inner)
531+}
532+
533+/// Held by a test that SETS a process-global knob; see [`KNOBS`].
534+#[cfg(test)]
535+#[must_use]
536+pub(crate) fn knob_write() -> std::sync::RwLockWriteGuard<'static, ()> {
537+ KNOBS.write().unwrap_or_else(std::sync::PoisonError::into_inner)
538+}