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 {
15511551 /// exactly one non-empty packet per picture, `depth - 1` calls later.
15521552 #[test]
15531553 fn one_in_one_out_delayed_by_the_lookahead_depth() {
1554+ let _knobs = crate::speed::knob_read();
15541555 let config = EncoderConfig {
15551556 width: 64,
15561557 height: 64,
@@ -1617,6 +1618,7 @@ mod tests {
16171618 /// to catch.
16181619 #[test]
16191620 fn the_facade_codes_the_same_bytes_as_encode_sequence() {
1621+ let _knobs = crate::speed::knob_read();
16201622 let frames = 12usize;
16211623 let film = h264_clip_frames(640, 384, frames).unwrap_or_else(|| {
16221624 eprintln!("no h264 clip: the facade identity gate runs on a synthetic card");
@@ -1693,6 +1695,7 @@ mod tests {
16931695 /// that only checked the screen half would pass with the pyramid deleted).
16941696 #[test]
16951697 fn the_content_gate_keeps_screen_streams_flat() {
1698+ let _knobs = crate::speed::knob_read();
16961699 let frames = 8usize;
16971700 let pictures: Vec<Picture> = (0..frames).map(|t| test_card(64, 64, t)).collect();
16981701 let config = EncoderConfig {
@@ -1731,6 +1734,7 @@ mod tests {
17311734 /// reads back out of the coded bytes.
17321735 #[test]
17331736 fn gop_cadence_is_honored() {
1737+ let _knobs = crate::speed::knob_read();
17341738 let config = EncoderConfig {
17351739 width: 64,
17361740 height: 64,
@@ -1828,6 +1832,7 @@ mod tests {
18281832 /// coded size confirm what the facade already reported.
18291833 #[test]
18301834 fn thirty_pictures_at_gop_fifteen_decode_to_two_key_frames() {
1835+ let _knobs = crate::speed::knob_read();
18311836 if !have_ffmpeg() {
18321837 eprintln!("SKIP thirty_pictures_at_gop_fifteen_decode_to_two_key_frames: no ffmpeg");
18331838 return;
@@ -1883,6 +1888,7 @@ mod tests {
18831888 /// which is a visibly different string).
18841889 #[test]
18851890 fn bt709_limited_colour_is_reported_by_ffprobe() {
1891+ let _knobs = crate::speed::knob_read();
18861892 if !have_ffmpeg() {
18871893 eprintln!("SKIP bt709_limited_colour_is_reported_by_ffprobe: no ffmpeg");
18881894 return;
@@ -1907,6 +1913,7 @@ mod tests {
19071913 /// as BT.709 for every input.
19081914 #[test]
19091915 fn bt601_limited_colour_is_reported_by_ffprobe() {
1916+ let _knobs = crate::speed::knob_read();
19101917 if !have_ffmpeg() {
19111918 eprintln!("SKIP bt601_limited_colour_is_reported_by_ffprobe: no ffmpeg");
19121919 return;
@@ -1933,6 +1940,7 @@ mod tests {
19331940 /// is refused by name.
19341941 #[test]
19351942 fn geometry_mismatch_is_refused() {
1943+ let _knobs = crate::speed::knob_read();
19361944 let config = EncoderConfig {
19371945 width: 64,
19381946 height: 64,
@@ -1950,6 +1958,7 @@ mod tests {
19501958 /// `gop == 0` is refused at construction, not the first `encode()` call.
19511959 #[test]
19521960 fn zero_gop_is_refused() {
1961+ let _knobs = crate::speed::knob_read();
19531962 let config = EncoderConfig {
19541963 width: 64,
19551964 height: 64,
@@ -2026,6 +2035,7 @@ mod tests {
20262035 /// state and the controller's first couple of steps).
20272036 #[test]
20282037 fn bytes_per_frame_target_settles_within_20_percent() {
2038+ let _knobs = crate::speed::knob_read();
20292039 let Some(pictures) = h264_clip_frames(640, 384, 24) else {
20302040 eprintln!("SKIP bytes_per_frame_target_settles_within_20_percent: no ffmpeg/fixture");
20312041 return;
@@ -2065,6 +2075,7 @@ mod tests {
20652075 /// its own level and one clamped proportional step.
20662076 #[test]
20672077 fn bitrate_target_lands_within_10_percent_over_48_frames() {
2078+ let _knobs = crate::speed::knob_read();
20682079 let (width, height, frames) = (640usize, 384usize, 48usize);
20692080 let Some(pictures) = h264_clip_frames(width, height, frames) else {
20702081 eprintln!("SKIP bitrate_target_lands_within_10_percent_over_48_frames: no ffmpeg/fixture");
@@ -2132,6 +2143,7 @@ mod tests {
21322143 /// break it.
21332144 #[test]
21342145 fn bytes_per_frame_controller_never_oscillates_past_its_clamp() {
2146+ let _knobs = crate::speed::knob_read();
21352147 let Some(pictures) = h264_clip_frames(640, 384, 24) else {
21362148 eprintln!(
21372149 "SKIP bytes_per_frame_controller_never_oscillates_past_its_clamp: no ffmpeg/fixture"
@@ -2235,6 +2247,7 @@ mod tests {
22352247 /// display-order list and fails here.
22362248 #[test]
22372249 fn a_pyramid_stream_decodes_in_display_order_through_both_decoders() {
2250+ let _knobs = crate::speed::knob_read();
22382251 let (width, height) = (128usize, 128usize);
22392252 let config = EncoderConfig {
22402253 width,
@@ -2350,6 +2363,7 @@ mod tests {
23502363 /// nothing about whether a single 64x64 block was ever written.
23512364 #[test]
23522365 fn a_static_clip_codes_64x64_roots_and_decodes_sample_exact() {
2366+ let _knobs = crate::speed::knob_read();
23532367 let _gate_lock = crate::stream::tests::lock_gate_counters();
23542368 let (width, height) = (256usize, 128usize);
23552369 let still = test_card(width, height, 0);
@@ -2401,6 +2415,7 @@ mod tests {
24012415
24022416 #[test]
24032417 fn every_tile_layout_decodes_sample_exact_through_both_decoders() {
2418+ let _knobs = crate::speed::knob_read();
24042419 let (width, height) = (640usize, 384usize);
24052420 let sources: Vec<Picture> = (0..4).map(|t| test_card(width, height, t * 3)).collect();
24062421 let mut sizes = Vec::new();
@@ -2493,6 +2508,7 @@ mod tests {
24932508 #[test]
24942509 #[ignore = "sets the process-global speed preset: run it alone"]
24952510 fn every_speed_preset_decodes_sample_exact_through_both_decoders() {
2511+ let _knobs = crate::speed::knob_write();
24962512 let _gate_lock = crate::stream::tests::lock_gate_counters();
24972513 let (width, height) = (640usize, 384usize);
24982514 let sources: Vec<Picture> = (0..4).map(|t| test_card(width, height, t * 3)).collect();
@@ -2556,6 +2572,7 @@ mod tests {
25562572 #[test]
25572573 #[ignore = "1080p wall table: minutes, run it with --ignored"]
25582574 fn tile_wall_table_at_1080p() {
2575+ let _knobs = crate::speed::knob_write();
25592576 let _gate_lock = crate::stream::tests::lock_gate_counters();
25602577 let (width, height) = (1920usize, 1080usize);
25612578 let Some(sources) = h264_clip_frames(width, height, 8) else {
@@ -2606,6 +2623,7 @@ mod tests {
26062623 /// thread and at four, per layout.
26072624 #[test]
26082625 fn tile_bytes_do_not_depend_on_the_thread_count() {
2626+ let _knobs = crate::speed::knob_write();
26092627 let _gate_lock = crate::stream::tests::lock_gate_counters();
26102628 let (width, height) = (320usize, 192usize);
26112629 let sources: Vec<Picture> = (0..3).map(|t| test_card(width, height, t * 3)).collect();
@@ -2655,6 +2673,7 @@ mod tests {
26552673 #[test]
26562674 #[ignore = "wall measurement: minutes, run it with --ignored --nocapture"]
26572675 fn tile_search_wall_1080p() {
2676+ let _knobs = crate::speed::knob_write();
26582677 tile_search_wall(1920, 1080, 12, &[(0, 0), (1, 0), (1, 1), (2, 1)], &[1, 2, 4, 8]);
26592678 }
26602679
@@ -2663,6 +2682,7 @@ mod tests {
26632682 #[test]
26642683 #[ignore = "wall measurement: minutes, run it with --ignored --nocapture"]
26652684 fn tile_search_wall_4k() {
2685+ let _knobs = crate::speed::knob_write();
26662686 tile_search_wall(3840, 1608, 6, &[(2, 1), (3, 2)], &[1, 8, 12]);
26672687 }
26682688
@@ -2674,6 +2694,7 @@ mod tests {
26742694 /// rows tall, which is what makes the bands non-trivial.
26752695 #[test]
26762696 fn filter_stage_bytes_do_not_depend_on_the_thread_count() {
2697+ let _knobs = crate::speed::knob_write();
26772698 let _gate_lock = crate::stream::tests::lock_gate_counters();
26782699 let (width, height) = (384usize, 288usize);
26792700 let sources: Vec<Picture> = (0..4).map(|t| test_card(width, height, t * 3)).collect();
@@ -2711,6 +2732,7 @@ mod tests {
27112732 /// which is the arm this lane opened.
27122733 #[test]
27132734 fn filter_replay_codes_the_same_stream_as_a_full_decode() {
2735+ let _knobs = crate::speed::knob_read();
27142736 let _gate_lock = crate::stream::tests::lock_gate_counters();
27152737 let run = |width: usize, height: usize, off: bool| {
27162738 let sources: Vec<Picture> = (0..4).map(|t| test_card(width, height, t * 3)).collect();
@@ -2756,6 +2778,7 @@ mod tests {
27562778 /// the loop-restoration search reads are bit-identical.
27572779 #[test]
27582780 fn filter_replay_final_matches_the_capture_decode() {
2781+ let _knobs = crate::speed::knob_read();
27592782 let _gate_lock = crate::stream::tests::lock_gate_counters();
27602783 let run = |sources: &[Picture], width: usize, height: usize, tiles: (u32, u32)| {
27612784 let config = EncoderConfig {
@@ -2799,12 +2822,14 @@ mod tests {
27992822 #[test]
28002823 #[ignore = "wall measurement: minutes, run it with --ignored --nocapture"]
28012824 fn filter_stage_wall_1080p() {
2825+ let _knobs = crate::speed::knob_write();
28022826 filter_stage_wall(1920, 1080, 8, (2, 1), &[8]);
28032827 }
28042828
28052829 #[test]
28062830 #[ignore = "wall measurement: minutes, run it with --ignored --nocapture"]
28072831 fn filter_stage_wall_4k() {
2832+ let _knobs = crate::speed::knob_write();
28082833 filter_stage_wall(3840, 1608, 4, (2, 1), &[8, 12]);
28092834 }
28102835
@@ -2815,6 +2840,7 @@ mod tests {
28152840 #[test]
28162841 #[ignore = "wall measurement: minutes, run it with --ignored --nocapture"]
28172842 fn filter_stage_wall_film() {
2843+ let _knobs = crate::speed::knob_write();
28182844 filter_stage_wall(1920, 768, 4, (2, 1), &[8]);
28192845 }
28202846
@@ -3039,6 +3065,7 @@ mod tests {
30393065 #[test]
30403066 #[ignore = "1080p encode: minutes, run it with --ignored"]
30413067 fn a_1080p_multi_tile_stream_decodes_sample_exact_through_both_decoders() {
3068+ let _knobs = crate::speed::knob_read();
30423069 let (width, height) = (1920usize, 1080usize);
30433070 let Some(sources) = h264_clip_frames(width, height, 3) else {
30443071 eprintln!("SKIP the 1080p tile round trip: no fixture");
@@ -3087,6 +3114,7 @@ mod tests {
30873114 /// the same real clip.
30883115 #[test]
30893116 fn quality_target_is_monotone_in_bytes_and_psnr() {
3117+ let _knobs = crate::speed::knob_read();
30903118 if !have_ffmpeg() {
30913119 eprintln!("SKIP quality_target_is_monotone_in_bytes_and_psnr: no ffmpeg");
30923120 return;
crates/ec-av1/src/speed.rsmodified+32 -0
@@ -504,3 +504,35 @@ mod tests {
504504 assert!(!levers(MAX_SPEED).is_empty());
505505 }
506506 }
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+}