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

Merged
BBareth merged 1 commit from upstream-pr/3551 into main 2026-12-02 17:40:07 +00:00
BBareth commented 2026-11-30 23:06:07 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by BBareth on 2026-11-30T23:06:07Z.


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 950b183a (on main 86e86fcb): 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 #3549 (which does not touch this file), and in 0 of 43 on main ff0c364b 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

  • A machine without an audio device: both tests return early there.
  • Wine (#2481 reports a different failure of the same test there; this does not address it).

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

<!-- greyfinch-sync:ivall/xcl:issue:5575410665 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3551). Originally posted by [BBareth](https://github.com/BBareth) on 2026-11-30T23:06:07Z. --- `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 950b183a (on main 86e86fcb): 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 #3549 (which does not touch this file), and in 0 of 43 on main ff0c364b 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** - A machine without an audio device: both tests return early there. - Wine (#2481 reports a different failure of the same test there; this does not address it). **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](https://claude.com/claude-code)
Foniass commented 2026-12-01 07:58:12 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T07:58:12Z.


merge-check
base: 7d86c5d2b7
head: 950b183aae
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.

<!-- greyfinch-sync:ivall/xcl:comment:7304707186 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3551#issuecomment-7304707186). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T07:58:12Z. --- merge-check base: 7d86c5d2b7845695031eeea1327aa81b6c439323 head: 950b183aae7ddbbf18f7c1fe3cbd18faa0a340e3 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.
Foniass commented 2026-12-01 10:12:58 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T10:12:58Z.


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.

<!-- greyfinch-sync:ivall/xcl:comment:7307846465 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3551#issuecomment-7307846465). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T10:12:58Z. --- **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 commented 2026-12-01 16:40:04 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by fromthemoonx on 2026-12-01T16:40:04Z.


merge-check
base: 6bfb5c5153
head: 950b183aae
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)
<!-- greyfinch-sync:ivall/xcl:comment:7317996778 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3551#issuecomment-7317996778). Originally posted by [fromthemoonx](https://github.com/fromthemoonx) on 2026-12-01T16:40:04Z. --- merge-check base: 6bfb5c5153ccc23517daf30aa1071ddb0fadb53c head: 950b183aae7ddbbf18f7c1fe3cbd18faa0a340e3 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)
bmjask commented 2026-12-02 14:11:20 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T14:11:20Z.


@Prime1997 could you take a look at this one for review and merge? My automated review notes are above, if any.

<!-- greyfinch-sync:ivall/xcl:comment:7348132412 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3551#issuecomment-7348132412). Originally posted by [bmjask](https://github.com/bmjask) on 2026-12-02T14:11:20Z. --- @Prime1997 could you take a look at this one for review and merge? My automated review notes are above, if any.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
xcl-dev/xcl!3551
No description provided.