forge
Explore
Log in

Don't you dare go Hollow

Merge branch 'lane-gaterace' (963327d2): the ignored encoder gates raced on the process-global speed preset; a test-only knob lock serialises the setters

Browse files at this commit

4a514363b7c322151dec3b6c2ccad94057617e8dAhmet Kaan GümüşParent: 8f9d3718c24e30
crates/ec-av1/src/encoder.rsmodified+28 -0
@@ -1551,6 +1551,7 @@ mod tests {
1551 /// exactly one non-empty packet per picture, `depth - 1` calls later.1551 /// exactly one non-empty packet per picture, `depth - 1` calls later.
1552 #[test]1552 #[test]
1553 fn one_in_one_out_delayed_by_the_lookahead_depth() {1553 fn one_in_one_out_delayed_by_the_lookahead_depth() {
1554+ let _knobs = crate::speed::knob_read();
1554 let config = EncoderConfig {1555 let config = EncoderConfig {
1555 width: 64,1556 width: 64,
1556 height: 64,1557 height: 64,
@@ -1617,6 +1618,7 @@ mod tests {
1617 /// to catch.1618 /// to catch.
1618 #[test]1619 #[test]
1619 fn the_facade_codes_the_same_bytes_as_encode_sequence() {1620 fn the_facade_codes_the_same_bytes_as_encode_sequence() {
1621+ let _knobs = crate::speed::knob_read();
1620 let frames = 12usize;1622 let frames = 12usize;
1621 let film = h264_clip_frames(640, 384, frames).unwrap_or_else(|| {1623 let film = h264_clip_frames(640, 384, frames).unwrap_or_else(|| {
1622 eprintln!("no h264 clip: the facade identity gate runs on a synthetic card");1624 eprintln!("no h264 clip: the facade identity gate runs on a synthetic card");
@@ -1693,6 +1695,7 @@ mod tests {
1693 /// that only checked the screen half would pass with the pyramid deleted).1695 /// that only checked the screen half would pass with the pyramid deleted).
1694 #[test]1696 #[test]
1695 fn the_content_gate_keeps_screen_streams_flat() {1697 fn the_content_gate_keeps_screen_streams_flat() {
1698+ let _knobs = crate::speed::knob_read();
1696 let frames = 8usize;1699 let frames = 8usize;
1697 let pictures: Vec<Picture> = (0..frames).map(|t| test_card(64, 64, t)).collect();1700 let pictures: Vec<Picture> = (0..frames).map(|t| test_card(64, 64, t)).collect();
1698 let config = EncoderConfig {1701 let config = EncoderConfig {
@@ -1731,6 +1734,7 @@ mod tests {
1731 /// reads back out of the coded bytes.1734 /// reads back out of the coded bytes.
1732 #[test]1735 #[test]
1733 fn gop_cadence_is_honored() {1736 fn gop_cadence_is_honored() {
1737+ let _knobs = crate::speed::knob_read();
1734 let config = EncoderConfig {1738 let config = EncoderConfig {
1735 width: 64,1739 width: 64,
1736 height: 64,1740 height: 64,
@@ -1828,6 +1832,7 @@ mod tests {
1828 /// coded size confirm what the facade already reported.1832 /// coded size confirm what the facade already reported.
1829 #[test]1833 #[test]
1830 fn thirty_pictures_at_gop_fifteen_decode_to_two_key_frames() {1834 fn thirty_pictures_at_gop_fifteen_decode_to_two_key_frames() {
1835+ let _knobs = crate::speed::knob_read();
1831 if !have_ffmpeg() {1836 if !have_ffmpeg() {
1832 eprintln!("SKIP thirty_pictures_at_gop_fifteen_decode_to_two_key_frames: no ffmpeg");1837 eprintln!("SKIP thirty_pictures_at_gop_fifteen_decode_to_two_key_frames: no ffmpeg");
1833 return;1838 return;
@@ -1883,6 +1888,7 @@ mod tests {
1883 /// which is a visibly different string).1888 /// which is a visibly different string).
1884 #[test]1889 #[test]
1885 fn bt709_limited_colour_is_reported_by_ffprobe() {1890 fn bt709_limited_colour_is_reported_by_ffprobe() {
1891+ let _knobs = crate::speed::knob_read();
1886 if !have_ffmpeg() {1892 if !have_ffmpeg() {
1887 eprintln!("SKIP bt709_limited_colour_is_reported_by_ffprobe: no ffmpeg");1893 eprintln!("SKIP bt709_limited_colour_is_reported_by_ffprobe: no ffmpeg");
1888 return;1894 return;
@@ -1907,6 +1913,7 @@ mod tests {
1907 /// as BT.709 for every input.1913 /// as BT.709 for every input.
1908 #[test]1914 #[test]
1909 fn bt601_limited_colour_is_reported_by_ffprobe() {1915 fn bt601_limited_colour_is_reported_by_ffprobe() {
1916+ let _knobs = crate::speed::knob_read();
1910 if !have_ffmpeg() {1917 if !have_ffmpeg() {
1911 eprintln!("SKIP bt601_limited_colour_is_reported_by_ffprobe: no ffmpeg");1918 eprintln!("SKIP bt601_limited_colour_is_reported_by_ffprobe: no ffmpeg");
1912 return;1919 return;
@@ -1933,6 +1940,7 @@ mod tests {
1933 /// is refused by name.1940 /// is refused by name.
1934 #[test]1941 #[test]
1935 fn geometry_mismatch_is_refused() {1942 fn geometry_mismatch_is_refused() {
1943+ let _knobs = crate::speed::knob_read();
1936 let config = EncoderConfig {1944 let config = EncoderConfig {
1937 width: 64,1945 width: 64,
1938 height: 64,1946 height: 64,
@@ -1950,6 +1958,7 @@ mod tests {
1950 /// `gop == 0` is refused at construction, not the first `encode()` call.1958 /// `gop == 0` is refused at construction, not the first `encode()` call.
1951 #[test]1959 #[test]
1952 fn zero_gop_is_refused() {1960 fn zero_gop_is_refused() {
1961+ let _knobs = crate::speed::knob_read();
1953 let config = EncoderConfig {1962 let config = EncoderConfig {
1954 width: 64,1963 width: 64,
1955 height: 64,1964 height: 64,
@@ -2026,6 +2035,7 @@ mod tests {
2026 /// state and the controller's first couple of steps).2035 /// state and the controller's first couple of steps).
2027 #[test]2036 #[test]
2028 fn bytes_per_frame_target_settles_within_20_percent() {2037 fn bytes_per_frame_target_settles_within_20_percent() {
2038+ let _knobs = crate::speed::knob_read();
2029 let Some(pictures) = h264_clip_frames(640, 384, 24) else {2039 let Some(pictures) = h264_clip_frames(640, 384, 24) else {
2030 eprintln!("SKIP bytes_per_frame_target_settles_within_20_percent: no ffmpeg/fixture");2040 eprintln!("SKIP bytes_per_frame_target_settles_within_20_percent: no ffmpeg/fixture");
2031 return;2041 return;
@@ -2065,6 +2075,7 @@ mod tests {
2065 /// its own level and one clamped proportional step.2075 /// its own level and one clamped proportional step.
2066 #[test]2076 #[test]
2067 fn bitrate_target_lands_within_10_percent_over_48_frames() {2077 fn bitrate_target_lands_within_10_percent_over_48_frames() {
2078+ let _knobs = crate::speed::knob_read();
2068 let (width, height, frames) = (640usize, 384usize, 48usize);2079 let (width, height, frames) = (640usize, 384usize, 48usize);
2069 let Some(pictures) = h264_clip_frames(width, height, frames) else {2080 let Some(pictures) = h264_clip_frames(width, height, frames) else {
2070 eprintln!("SKIP bitrate_target_lands_within_10_percent_over_48_frames: no ffmpeg/fixture");2081 eprintln!("SKIP bitrate_target_lands_within_10_percent_over_48_frames: no ffmpeg/fixture");
@@ -2132,6 +2143,7 @@ mod tests {
2132 /// break it.2143 /// break it.
2133 #[test]2144 #[test]
2134 fn bytes_per_frame_controller_never_oscillates_past_its_clamp() {2145 fn bytes_per_frame_controller_never_oscillates_past_its_clamp() {
2146+ let _knobs = crate::speed::knob_read();
2135 let Some(pictures) = h264_clip_frames(640, 384, 24) else {2147 let Some(pictures) = h264_clip_frames(640, 384, 24) else {
2136 eprintln!(2148 eprintln!(
2137 "SKIP bytes_per_frame_controller_never_oscillates_past_its_clamp: no ffmpeg/fixture"2149 "SKIP bytes_per_frame_controller_never_oscillates_past_its_clamp: no ffmpeg/fixture"
@@ -2235,6 +2247,7 @@ mod tests {
2235 /// display-order list and fails here.2247 /// display-order list and fails here.
2236 #[test]2248 #[test]
2237 fn a_pyramid_stream_decodes_in_display_order_through_both_decoders() {2249 fn a_pyramid_stream_decodes_in_display_order_through_both_decoders() {
2250+ let _knobs = crate::speed::knob_read();
2238 let (width, height) = (128usize, 128usize);2251 let (width, height) = (128usize, 128usize);
2239 let config = EncoderConfig {2252 let config = EncoderConfig {
2240 width,2253 width,
@@ -2350,6 +2363,7 @@ mod tests {
2350 /// nothing about whether a single 64x64 block was ever written.2363 /// nothing about whether a single 64x64 block was ever written.
2351 #[test]2364 #[test]
2352 fn a_static_clip_codes_64x64_roots_and_decodes_sample_exact() {2365 fn a_static_clip_codes_64x64_roots_and_decodes_sample_exact() {
2366+ let _knobs = crate::speed::knob_read();
2353 let _gate_lock = crate::stream::tests::lock_gate_counters();2367 let _gate_lock = crate::stream::tests::lock_gate_counters();
2354 let (width, height) = (256usize, 128usize);2368 let (width, height) = (256usize, 128usize);
2355 let still = test_card(width, height, 0);2369 let still = test_card(width, height, 0);
@@ -2401,6 +2415,7 @@ mod tests {
2401 2415
2402 #[test]2416 #[test]
2403 fn every_tile_layout_decodes_sample_exact_through_both_decoders() {2417 fn every_tile_layout_decodes_sample_exact_through_both_decoders() {
2418+ let _knobs = crate::speed::knob_read();
2404 let (width, height) = (640usize, 384usize);2419 let (width, height) = (640usize, 384usize);
2405 let sources: Vec<Picture> = (0..4).map(|t| test_card(width, height, t * 3)).collect();2420 let sources: Vec<Picture> = (0..4).map(|t| test_card(width, height, t * 3)).collect();
2406 let mut sizes = Vec::new();2421 let mut sizes = Vec::new();
@@ -2493,6 +2508,7 @@ mod tests {
2493 #[test]2508 #[test]
2494 #[ignore = "sets the process-global speed preset: run it alone"]2509 #[ignore = "sets the process-global speed preset: run it alone"]
2495 fn every_speed_preset_decodes_sample_exact_through_both_decoders() {2510 fn every_speed_preset_decodes_sample_exact_through_both_decoders() {
2511+ let _knobs = crate::speed::knob_write();
2496 let _gate_lock = crate::stream::tests::lock_gate_counters();2512 let _gate_lock = crate::stream::tests::lock_gate_counters();
2497 let (width, height) = (640usize, 384usize);2513 let (width, height) = (640usize, 384usize);
2498 let sources: Vec<Picture> = (0..4).map(|t| test_card(width, height, t * 3)).collect();2514 let sources: Vec<Picture> = (0..4).map(|t| test_card(width, height, t * 3)).collect();
@@ -2556,6 +2572,7 @@ mod tests {
2556 #[test]2572 #[test]
2557 #[ignore = "1080p wall table: minutes, run it with --ignored"]2573 #[ignore = "1080p wall table: minutes, run it with --ignored"]
2558 fn tile_wall_table_at_1080p() {2574 fn tile_wall_table_at_1080p() {
2575+ let _knobs = crate::speed::knob_write();
2559 let _gate_lock = crate::stream::tests::lock_gate_counters();2576 let _gate_lock = crate::stream::tests::lock_gate_counters();
2560 let (width, height) = (1920usize, 1080usize);2577 let (width, height) = (1920usize, 1080usize);
2561 let Some(sources) = h264_clip_frames(width, height, 8) else {2578 let Some(sources) = h264_clip_frames(width, height, 8) else {
@@ -2606,6 +2623,7 @@ mod tests {
2606 /// thread and at four, per layout.2623 /// thread and at four, per layout.
2607 #[test]2624 #[test]
2608 fn tile_bytes_do_not_depend_on_the_thread_count() {2625 fn tile_bytes_do_not_depend_on_the_thread_count() {
2626+ let _knobs = crate::speed::knob_write();
2609 let _gate_lock = crate::stream::tests::lock_gate_counters();2627 let _gate_lock = crate::stream::tests::lock_gate_counters();
2610 let (width, height) = (320usize, 192usize);2628 let (width, height) = (320usize, 192usize);
2611 let sources: Vec<Picture> = (0..3).map(|t| test_card(width, height, t * 3)).collect();2629 let sources: Vec<Picture> = (0..3).map(|t| test_card(width, height, t * 3)).collect();
@@ -2655,6 +2673,7 @@ mod tests {
2655 #[test]2673 #[test]
2656 #[ignore = "wall measurement: minutes, run it with --ignored --nocapture"]2674 #[ignore = "wall measurement: minutes, run it with --ignored --nocapture"]
2657 fn tile_search_wall_1080p() {2675 fn tile_search_wall_1080p() {
2676+ let _knobs = crate::speed::knob_write();
2658 tile_search_wall(1920, 1080, 12, &[(0, 0), (1, 0), (1, 1), (2, 1)], &[1, 2, 4, 8]);2677 tile_search_wall(1920, 1080, 12, &[(0, 0), (1, 0), (1, 1), (2, 1)], &[1, 2, 4, 8]);
2659 }2678 }
2660 2679
@@ -2663,6 +2682,7 @@ mod tests {
2663 #[test]2682 #[test]
2664 #[ignore = "wall measurement: minutes, run it with --ignored --nocapture"]2683 #[ignore = "wall measurement: minutes, run it with --ignored --nocapture"]
2665 fn tile_search_wall_4k() {2684 fn tile_search_wall_4k() {
2685+ let _knobs = crate::speed::knob_write();
2666 tile_search_wall(3840, 1608, 6, &[(2, 1), (3, 2)], &[1, 8, 12]);2686 tile_search_wall(3840, 1608, 6, &[(2, 1), (3, 2)], &[1, 8, 12]);
2667 }2687 }
2668 2688
@@ -2674,6 +2694,7 @@ mod tests {
2674 /// rows tall, which is what makes the bands non-trivial.2694 /// rows tall, which is what makes the bands non-trivial.
2675 #[test]2695 #[test]
2676 fn filter_stage_bytes_do_not_depend_on_the_thread_count() {2696 fn filter_stage_bytes_do_not_depend_on_the_thread_count() {
2697+ let _knobs = crate::speed::knob_write();
2677 let _gate_lock = crate::stream::tests::lock_gate_counters();2698 let _gate_lock = crate::stream::tests::lock_gate_counters();
2678 let (width, height) = (384usize, 288usize);2699 let (width, height) = (384usize, 288usize);
2679 let sources: Vec<Picture> = (0..4).map(|t| test_card(width, height, t * 3)).collect();2700 let sources: Vec<Picture> = (0..4).map(|t| test_card(width, height, t * 3)).collect();
@@ -2711,6 +2732,7 @@ mod tests {
2711 /// which is the arm this lane opened.2732 /// which is the arm this lane opened.
2712 #[test]2733 #[test]
2713 fn filter_replay_codes_the_same_stream_as_a_full_decode() {2734 fn filter_replay_codes_the_same_stream_as_a_full_decode() {
2735+ let _knobs = crate::speed::knob_read();
2714 let _gate_lock = crate::stream::tests::lock_gate_counters();2736 let _gate_lock = crate::stream::tests::lock_gate_counters();
2715 let run = |width: usize, height: usize, off: bool| {2737 let run = |width: usize, height: usize, off: bool| {
2716 let sources: Vec<Picture> = (0..4).map(|t| test_card(width, height, t * 3)).collect();2738 let sources: Vec<Picture> = (0..4).map(|t| test_card(width, height, t * 3)).collect();
@@ -2756,6 +2778,7 @@ mod tests {
2756 /// the loop-restoration search reads are bit-identical.2778 /// the loop-restoration search reads are bit-identical.
2757 #[test]2779 #[test]
2758 fn filter_replay_final_matches_the_capture_decode() {2780 fn filter_replay_final_matches_the_capture_decode() {
2781+ let _knobs = crate::speed::knob_read();
2759 let _gate_lock = crate::stream::tests::lock_gate_counters();2782 let _gate_lock = crate::stream::tests::lock_gate_counters();
2760 let run = |sources: &[Picture], width: usize, height: usize, tiles: (u32, u32)| {2783 let run = |sources: &[Picture], width: usize, height: usize, tiles: (u32, u32)| {
2761 let config = EncoderConfig {2784 let config = EncoderConfig {
@@ -2799,12 +2822,14 @@ mod tests {
2799 #[test]2822 #[test]
2800 #[ignore = "wall measurement: minutes, run it with --ignored --nocapture"]2823 #[ignore = "wall measurement: minutes, run it with --ignored --nocapture"]
2801 fn filter_stage_wall_1080p() {2824 fn filter_stage_wall_1080p() {
2825+ let _knobs = crate::speed::knob_write();
2802 filter_stage_wall(1920, 1080, 8, (2, 1), &[8]);2826 filter_stage_wall(1920, 1080, 8, (2, 1), &[8]);
2803 }2827 }
2804 2828
2805 #[test]2829 #[test]
2806 #[ignore = "wall measurement: minutes, run it with --ignored --nocapture"]2830 #[ignore = "wall measurement: minutes, run it with --ignored --nocapture"]
2807 fn filter_stage_wall_4k() {2831 fn filter_stage_wall_4k() {
2832+ let _knobs = crate::speed::knob_write();
2808 filter_stage_wall(3840, 1608, 4, (2, 1), &[8, 12]);2833 filter_stage_wall(3840, 1608, 4, (2, 1), &[8, 12]);
2809 }2834 }
2810 2835
@@ -2815,6 +2840,7 @@ mod tests {
2815 #[test]2840 #[test]
2816 #[ignore = "wall measurement: minutes, run it with --ignored --nocapture"]2841 #[ignore = "wall measurement: minutes, run it with --ignored --nocapture"]
2817 fn filter_stage_wall_film() {2842 fn filter_stage_wall_film() {
2843+ let _knobs = crate::speed::knob_write();
2818 filter_stage_wall(1920, 768, 4, (2, 1), &[8]);2844 filter_stage_wall(1920, 768, 4, (2, 1), &[8]);
2819 }2845 }
2820 2846
@@ -3039,6 +3065,7 @@ mod tests {
3039 #[test]3065 #[test]
3040 #[ignore = "1080p encode: minutes, run it with --ignored"]3066 #[ignore = "1080p encode: minutes, run it with --ignored"]
3041 fn a_1080p_multi_tile_stream_decodes_sample_exact_through_both_decoders() {3067 fn a_1080p_multi_tile_stream_decodes_sample_exact_through_both_decoders() {
3068+ let _knobs = crate::speed::knob_read();
3042 let (width, height) = (1920usize, 1080usize);3069 let (width, height) = (1920usize, 1080usize);
3043 let Some(sources) = h264_clip_frames(width, height, 3) else {3070 let Some(sources) = h264_clip_frames(width, height, 3) else {
3044 eprintln!("SKIP the 1080p tile round trip: no fixture");3071 eprintln!("SKIP the 1080p tile round trip: no fixture");
@@ -3087,6 +3114,7 @@ mod tests {
3087 /// the same real clip.3114 /// the same real clip.
3088 #[test]3115 #[test]
3089 fn quality_target_is_monotone_in_bytes_and_psnr() {3116 fn quality_target_is_monotone_in_bytes_and_psnr() {
3117+ let _knobs = crate::speed::knob_read();
3090 if !have_ffmpeg() {3118 if !have_ffmpeg() {
3091 eprintln!("SKIP quality_target_is_monotone_in_bytes_and_psnr: no ffmpeg");3119 eprintln!("SKIP quality_target_is_monotone_in_bytes_and_psnr: no ffmpeg");
3092 return;3120 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+}