From 950b183aae7ddbbf18f7c1fe3cbd18faa0a340e3 Mon Sep 17 00:00:00 2001 From: BBareth <179921368+BBareth@users.noreply.github.com> Date: Mon, 30 Nov 2026 23:50:55 +0100 Subject: [PATCH] Tests: XMA voice tests no longer race on the shared decode counters xma2_source_voice_decodes_and_manages_lifetime reads the process-wide XMA decode counters before and after its own two submits and expects each to have moved by one. xma_voice_keeps_the_decoders_ten_channels submits an undecodable XMA2 buffer of its own, which moves the same error counter. When the two run at the same time the first sees 2 instead of 1 (xaudio2.rs:1793). Seen in 1 of 2 whole-suite runs and 3 of 46 `--lib xaudio2` runs on a branch that does not touch this file; 0 of 43 on main ff0c364b with the same source, so it depends on timing. Both tests now hold one test-only lock. 100 of 100 `--lib xaudio2` runs pass with it. Co-Authored-By: Claude Fable 5.2 --- crates/xcl/src/hle/xaudio2.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/crates/xcl/src/hle/xaudio2.rs b/crates/xcl/src/hle/xaudio2.rs index 38f9912727..41adedcfad 100644 --- a/crates/xcl/src/hle/xaudio2.rs +++ b/crates/xcl/src/hle/xaudio2.rs @@ -1336,6 +1336,10 @@ pub fn note_console_decode(packets: u64, errors: u64, frames: u64, nonzero: u64) mod tests { use super::*; + /// Held by the tests that submit buffers to an XMA voice: they move the process-wide XMA + /// counters, and one of them compares those counters before and after its own submits. + static XMA_COUNTERS: Mutex<()> = Mutex::new(()); + fn xma2(channels: u16, rate: u32, samples: u32, bpb: u32, blocks: u16) -> Xma2WaveFormatEx { Xma2WaveFormatEx { wfx: WaveFormatEx { tag: WAVE_FORMAT_XMA2, channels, rate, avg_bytes: 0, block_align: 1, bits: 16, cb_size: 34 }, @@ -1399,6 +1403,7 @@ mod tests { #[test] fn xma_voice_keeps_the_decoders_ten_channels() { + let _counters = XMA_COUNTERS.lock().unwrap_or_else(|e| e.into_inner()); unsafe { let mut eng: *mut c_void = std::ptr::null_mut(); assert_eq!(XAudio2Create(&mut eng, 0, 1), S_OK); @@ -1684,6 +1689,7 @@ mod tests { #[test] fn xma2_source_voice_decodes_and_manages_lifetime() { use std::sync::atomic::AtomicUsize; + let _counters = XMA_COUNTERS.lock().unwrap_or_else(|e| e.into_inner()); static ENDED: AtomicUsize = AtomicUsize::new(0); static STARTED: AtomicUsize = AtomicUsize::new(0);