Skip to content

Tests: XMA voice tests no longer race on the shared decode counters - #3551

Open
BBareth wants to merge 1 commit into
xcl-dev:mainfrom
BBareth:tests/xaudio2-xma-counter-race
Open

BBareth wants to merge 1 commit into
xcl-dev:mainfrom
BBareth:tests/xaudio2-xma-counter-race

Conversation

@BBareth

@BBareth BBareth commented Nov 30, 2026

Copy link
Copy Markdown
Contributor

xma2_source_voice_decodes_and_manages_lifetime fails now and then in whole-suite runs (xaudio2.rs:1793, left 2, right 1). It 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, and the two tests run at the same time. Both now hold one test-only lock. No runtime code changes.

What is in it

  • crates/xcl/src/hle/xaudio2.rs (mod tests only): a XMA_COUNTERS lock held by the two tests that submit buffers to an XMA voice.

Tested

  • RTX 5070 Ti, driver 32.0.16.2124; i7-12700K; Windows 11 Pro 26200; rustc 1.95.0; debug suite, release smoke.
  • cargo build --workspace, then cargo test --workspace --no-fail-fast -- --test-threads=4 on 950b183 (on main 86e86fc): 2889 passed, 0 failed, 51 ignored.
  • SKIPPED on this adapter: 28: 22 no wave64; 2 no heap windows; 2 no d3d12SDKLayers.dll; 1 no D3D12 debug layer; 1 cannot disable the driver cache (no Developer Mode).
  • cargo test -p xcl --lib xaudio2 -- --test-threads=4, repeated: 100 of 100 runs with 15 passed on this commit. Without the lock the failure showed in 1 of 2 whole-suite runs and 3 of 46 of these runs on the branch of D3D12.X: leave uncommitted pages out when publishing a texture download #3549 (which does not touch this file), and in 0 of 43 on main ff0c364 with the same source: it depends on timing, so the 100 clean runs do not prove the fix by themselves; the cause above was read from the two tests.

Regression run
The diff is test-only, but it is in a runtime file, so both blocks are here.

xcl-smoke v1
commit: ff0c364b3de011c13ed45865480c21918a79ec89
gpu: NVIDIA GeForce RTX 5070 Ti
title: 9cc6a39e
seconds: 120
exit: 0x0
frames shown: 3048 (PresentX 3048)
presents per 2 s (last 3): 35 40 47
device removals: 0
crashes: 0
peak commit: 30406 MB
xcl-smoke v1
commit: 950b183aae7ddbbf18f7c1fe3cbd18faa0a340e3
gpu: NVIDIA GeForce RTX 5070 Ti
title: 9cc6a39e
seconds: 120
exit: 0x0
frames shown: 3018 (PresentX 3018)
presents per 2 s (last 3): 20 54 8
device removals: 0
crashes: 0
peak commit: 30962 MB

A second round on the same builds: main 3074 frames, peak 30565 MB, device removals 0, crashes 0; this PR 3048 frames, peak 30649 MB, device removals 0, crashes 0. The A button is pressed once at 70 s.

Not tested

AI use

  • Claude Code, Claude Fable 5.2: found the cause, wrote the change and this description, and ran the tests and the regression runs above.

🤖 Generated with Claude Code

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 ff0c364 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 <noreply@anthropic.com>
@github-actions github-actions Bot added the area:hle kernelx, XGameRuntime, XAudio2, VFS, PE loader, TLS, EH label Nov 30, 2026
@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

merge-check
base: 7d86c5d
head: 950b183
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2896 passed, 0 failed, 51 ignored; SKIPPED: 28 (20 no wave64, 2 no d3d12SDKLayers.dll, 1 no D3D12 debug layer, 1 no heap windows, 1 cannot disable the driver cache, 3 others; the same set as on main); failing: none
review: read the whole diff (xaudio2.rs, +6, all inside #[cfg(test)] mod tests). No findings. The race is real: XMA_BUFFERS_DECODED / XMA_DECODE_ERRORS are process-wide, xma2_source_voice_decodes_and_manages_lifetime compares them before and after its submits (~1798-1799), and xma_voice_keeps_the_decoders_ten_channels submits an undecodable buffer that moves the error counter at the same time. The fix holds a static XMA_COUNTERS mutex (~1341) for the whole of both tests (~1406, ~1692), ignoring lock poisoning, and no assertion changed. The counters only move inside submit_decoded_buffer, synchronously in the submit call; no other lib test submits to an XMA voice, and acphal moves the separate PCM_* counters, so the comparison can no longer see another test's submits. No smoke run here: test-only.
performance: no smoke run (the default path doesn't reach this change); not measured.
verdict: safe to merge (test-only)
hardware / tool and model: RTX 5070 Ti (driver 621.14), Ryzen 7 7800X3D, Windows 11 26300 / Claude Code with Claude Opus 5.5

AI-written and posted by Foniass without a human check of each point.

@github-actions github-actions Bot added the needs-2nd-check Has 1 safe merge-check; needs second independent check (#3041) label Dec 1, 2026
@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Triage (#1607) – head 950b183

No open or merged PR makes the same change. #1219 adds its own XMA_TEST_LOCK for its new test and xma2_source_voice_decodes_and_manages_lifetime, but not for xma_voice_keeps_the_decoders_ten_channels. If both land, they should share one lock.
No problems found in the diff. The only tests that submit to an XMA voice (and so move XMA_BUFFERS_DECODED / XMA_DECODE_ERRORS) are the two now holding XMA_COUNTERS.
Recommendation: keep open.

AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.

@fromthemoonx

fromthemoonx commented Dec 1, 2026 •

Copy link
Copy Markdown

merge-check
base: 6bfb5c5
head: 950b183
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2904 passed, 0 failed, 51 ignored (base: 2904 passed, 0 failed, 51 ignored); SKIPPED: 25 (22 no wave64, 2 no heap windows, 1 no GPU_UPLOAD heaps), the same set as base; failing: none
review: read the whole diff (xaudio2.rs, +6, all in mod tests). No findings.

  • Only these two tests submit to an XMA voice, so only they move XMA_BUFFERS_DECODED / XMA_DECODE_ERRORS. decoded_voice_reports_no_bytes_required_to_the_title builds an XMA decoder but submits nothing.
  • The race is real here: the whole lib on main 6bfb5c5 failed xma2_source_voice_decodes_and_manages_lifetime (xaudio2.rs:1793, left 2, right 1) in 1 of 3 runs today.
  • At normal timing it did not show in short runs on either tree:
    • hle::xaudio2::tests:: at --test-threads=8, 40 runs each: main 40 of 40 ok, merge 40 of 40 ok.
    • The three hle::xaudio2::tests::xma tests at --test-threads=2, 200 runs each: 200 of 200 ok on both.
  • With the window widened (scratch, not pushed): I added a 300 ms sleep right after the test reads before_errors, on both trees, and ran the three xma tests at --test-threads=3, 10 runs each.
    • main: 7 of 10 fail, all with the reported left: 2, right: 1 at xaudio2.rs:1793.
    • merge: 10 of 10 pass. The lock is what keeps the other test's bad buffer out of the window.
      performance: none: test code only.
      verdict: safe to merge
      hardware / tool and model: RTX 3060 12 GB (610.88), Ryzen 7 5700X, Windows 11 Pro 26300 / Claude Code (Claude Opus 5.5)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:hle kernelx, XGameRuntime, XAudio2, VFS, PE loader, TLS, EH ready-to-merge Has 2 independent safe merge-checks on current head (#3041)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants