From 18f2c3a78ac4f8f4373c92228d64e4c94916a898 Mon Sep 17 00:00:00 2001 From: steigr Date: Fri, 20 Nov 2026 10:35:54 +0100 Subject: [PATCH 1/3] hal2: count frames the host stream skips in the real-clock tone test On a loaded Windows runner the file backend's thread can stall long enough for the queue to pass its ceiling; the stream then skips ahead (overruns) or the ring refuses frames (dropped). Those frames reached the host and were let go on purpose, so the check that every moved frame reached the file now adds them back before allowing for what is still queued at the stop. Co-Authored-By: Claude Opus 5.5 --- src/dev/hal2.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/dev/hal2.rs b/src/dev/hal2.rs index fe03cbec4..d20e9c073 100644 --- a/src/dev/hal2.rs +++ b/src/dev/hal2.rs @@ -1321,6 +1321,7 @@ mod host_tests { let started = Instant::now(); h.apply_dma_enable(0, DMA_EN_CODECA); std::thread::sleep(Duration::from_millis(800)); + let st = h.ca_state.lock().out.as_ref().map(|o| o.stats()).expect("codec A has a host stream"); Device::stop(&h); let wall = started.elapsed().as_secs_f64(); let moved = dma.at.load(Ordering::Relaxed) as u64 / 2; @@ -1329,7 +1330,13 @@ mod host_tests { // Half at least: a timer held up by a busy host holds the clock back. assert!(moved as f64 >= 0.5 * wall * 48000.0, "the clock ran: {moved} frames in {wall:.3} s"); let heard = sounding(&pcm, 2); - assert!((heard.len() / 2) as u64 + 9600 >= moved, "{} of {moved} frames reached the file", heard.len() / 2); + // A file thread held up by a busy host (a loaded CI runner) lets the + // queue pass its ceiling, and the stream skips ahead rather than + // play late. Those frames reached the host and were let go on + // purpose; the 200 ms is what was still queued at the stop. + let skipped = st.overruns + st.dropped; + assert!((heard.len() / 2) as u64 + skipped + 9600 >= moved, + "{} of {moved} frames reached the file ({skipped} skipped by the host stream)", heard.len() / 2); assert_tones(&heard, 2, 48000, left, right, 15000); } From 607c23e0c46645caf5742c43121bf2c8fd5a2dae Mon Sep 17 00:00:00 2001 From: steigr Date: Fri, 20 Nov 2026 11:17:17 +0100 Subject: [PATCH 2/3] mace_audio: count pairs the host stream skips in the real-clock tone test The O2 test makes the same check as HAL2's: every pair played before the mute must reach the file, give or take what was still queued. A file thread stalled on a busy host makes the stream skip ahead or refuse pairs on purpose, so those are now added back too. Co-Authored-By: Claude Opus 5.5 --- src/dev/mace_audio.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/dev/mace_audio.rs b/src/dev/mace_audio.rs index 6e920d46c..6a81fda44 100644 --- a/src/dev/mace_audio.rs +++ b/src/dev/mace_audio.rs @@ -1036,6 +1036,11 @@ mod tests { run(300); let wall = started.elapsed().as_secs_f64(); let moved = a.msc_ust(1) >> 32; + // A file thread held up by a busy host (a loaded CI runner) lets the + // queue pass its ceiling, and the stream skips ahead rather than + // play late. Those pairs reached the host and were let go on + // purpose. + let skipped: u64 = a.player.lock().out.iter().flatten().map(|o| { let s = o.stats(); s.overruns + s.dropped }).sum(); // Dropping the output completes the file. *a.player.lock() = Player::default(); let (rate, channels, pcm) = read_wav(&path.0); @@ -1045,7 +1050,8 @@ mod tests { let heard = sounding(&pcm, 2); let frames = (heard.len() / 2) as u64; // The rate converter's filter rings for a few frames past the mute. - assert!(frames + 9600 >= loud && frames <= loud + 48, "{frames} pairs heard of {loud} played before the mute"); + assert!(frames + skipped + 9600 >= loud && frames <= loud + 48, + "{frames} pairs heard of {loud} played before the mute ({skipped} skipped by the host stream)"); assert_tones(&heard, 2, 48000, left, right, 15000); } From 7e420ea9070db75d85efcaba973ed9d4e631798c Mon Sep 17 00:00:00 2001 From: steigr Date: Fri, 20 Nov 2026 12:09:13 +0100 Subject: [PATCH 3/3] rad1: count frames the host stream skips in the real-clock tone test The Octane test makes the same lower-bound check as HAL2's and the O2's. Frames the host stream skips or refuses after a stalled file thread are added back, converted from the card's 44.1 kHz to the file's 48 kHz. Co-Authored-By: Claude Opus 5.5 --- src/dev/rad1/tests.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/dev/rad1/tests.rs b/src/dev/rad1/tests.rs index 22c5133fd..47bb8f65c 100644 --- a/src/dev/rad1/tests.rs +++ b/src/dev/rad1/tests.rs @@ -1547,6 +1547,10 @@ fn a_tone_in_guest_memory_reaches_the_host_on_the_real_clock() { Device::stop(&r); let wall = started.elapsed().as_secs_f64(); let moved = r.state.lock().chan[CH_OUT].frames; + // A file thread held up by a busy host (a loaded CI runner) lets the + // queue pass its ceiling, and the stream skips ahead rather than play + // late. Those frames reached the host and were let go on purpose. + let skipped = r.sink.lock().as_ref().and_then(|sk| sk.host.as_ref()).map_or(0, |o| { let s = o.stats(); s.overruns + s.dropped }); r.sink.lock().take(); let (rate, channels, pcm) = read_wav(&path.0); assert_eq!((rate, channels), (crate::host_audio::FILE_RATE, 2)); @@ -1560,7 +1564,9 @@ fn a_tone_in_guest_memory_reaches_the_host_on_the_real_clock() { // of a stretch of sound: one, or more where a busy host held the card up. let expect = loud as f64 * 48000.0 / 44100.0; let most = expect * 1.005 + 48.0 * bursts(&pcm, 2) as f64; - assert!((heard.len() / 2) as f64 >= expect - 9600.0 && (heard.len() / 2) as f64 <= most, "{} frames heard, {expect:.0} played", heard.len() / 2); + let least = expect - skipped as f64 * 48000.0 / 44100.0 - 9600.0; + assert!((heard.len() / 2) as f64 >= least && (heard.len() / 2) as f64 <= most, + "{} frames heard, {expect:.0} played ({skipped} card frames skipped by the host stream)", heard.len() / 2); assert_tones(&heard, 2, rate, left, right, 15000); }