[pr-tests] gpu_owned: the test of eight faults on one block no longer fails by chance (199 of 200 runs of its module on main) #261

Open
blazecoding2009 wants to merge 1 commit from blazecoding2009/Darner:pr/test-readback-count into main
First-time contributor

Contributor role (optional)

  • Fluxer ID:

What it changes

  • The problem on main: gpu_owned::tests::concurrent_faults_on_same_block_serialize_single_readback fails by chance: in 199 of 200 runs of its module alone here, and now and then in a whole run of darner-gpu's tests (1 of 8 here). Most often with:

    thread 'gpu_owned::tests::concurrent_faults_on_same_block_serialize_single_readback' panicked at crates\darner-gpu\src\gpu_owned.rs:1046:9:
    assertion `left == right` failed: one readback for the block, not eight
      left: 3
     right: 1
    

There are two causes, both in the test.

  1. The test sets TEST_READBACKS to zero, lets eight threads fault on one trapped block and asserts that the count is one. The count is one static for every trapped block. veh_read_fault_and_partial_write_zero_clobber, the other test that traps blocks, traps two and so makes two readbacks, and it runs beside this one on another test thread. When the two meet, the count is two or three (192 of the 200 runs). Both tests now hold one lock, ONE_TRAP_TEST, for their whole length.
  2. The test's stand-in handler gives the block its protection back before the bytes go in, as read_back does. A thread that comes to the block between the two reads it with no fault, and not the pattern: left: 7, right: 8, "all eight threads read the card's bytes" (7 of the 200 runs, and 18 of 200 with the lock of 1 alone). The test now holds the handler's turn (TEST_SERIAL) until all eight threads have faulted, which is what its name says it is about, and asserts that they did.

Test code only: mod tests of gpu_owned.rs. read_back itself is not changed: with DARNER_GPU_OWNED=1 a second thread of the title that first touches a block in that window reads the bytes of before the readback. I read that from the code only and did not look for it in the game.

How it was tested

  • Tested revision: 224cbec (this one commit on main f3840d7).

  • Commands and results: cargo test --locked -p darner-gpu --lib --no-run on each revision, then that test binary run by itself with the filter gpu_owned::tests (the module's 6 tests, the two with trapped blocks among them), 200 and 300 times.

    A (main, f3840d7) B (224cbec)
    runs of gpu_owned::tests 200 300
    all passed 1 300
    concurrent_faults_on_same_block_serialize_single_readback failed 199 0

    All of the crate's tests on 224cbec, 4 runs with a 150 s limit: this test passed in all four. One run passed whole; in the other three one other test failed (watch::tests::ask_once_by_res_splits_reservations_without_refusals, which #150 is about, host::refresh_tests::chunked_nothing_new_with_matches_individual and host::watch_pipe::tests::ask_once_delta_runs_on_collector_and_preserves_ahead).

  • Changes a default: no.

  • Gates run on that revision (the three in AGENTS.md; there is no CI): cargo clippy --workspace --all-targets --locked -- -D warnings: passed. The same with --all-features: passed. cargo xtask policy: 555 files ok. cargo test --workspace --locked: not run as one command on this revision. Of it, I ran darner-gpu's tests as above. On main that gate fails or stands still by chance in this crate (#224 has the counts), and in darner-shader one test fails, which #227 is about.

  • Gameplay: not run in the game. The change is in test code only.

  • Shader wave sizes tested, when relevant: not relevant.

  • Hardware dependence: likely general. How often the two tests meet depends on timing and on the number of test threads: 16 here (Ryzen 7 8845HS, Windows 11 build 26300).

  • Coverage gaps: one PC. Other tests of the crate still fail by chance, as the four whole runs show.

Checklist

  • I ran this change in the game, or say below why it can't be (docs, tests only).
  • This PR contains one change based on main.
  • The diff follows docs/asset-policy.md.
  • I recorded this PR's dependencies below.
    • Depends on: none

Checked for overlap

  • I searched the open pull requests for the same issue and for the files this touches.
  • Related PRs: none found for this test. Searches of open and closed issues and pull requests for TEST_READBACKS, concurrent_faults_on_same_block and flaky found no report. I searched the diff of every open pull request (100): #57 changes gpu_owned.rs outside its tests, none changes these two tests. #224 and #150 are about other tests of the crate that fail or stand still by chance.
  • Replaces or overlaps: none found

This change was made with AI assistance (Claude Code).

🤖 Generated with Claude Code

## Contributor role (optional) - Fluxer ID: ## What it changes - The problem on main: `gpu_owned::tests::concurrent_faults_on_same_block_serialize_single_readback` fails by chance: in 199 of 200 runs of its module alone here, and now and then in a whole run of `darner-gpu`'s tests (1 of 8 here). Most often with: ``` thread 'gpu_owned::tests::concurrent_faults_on_same_block_serialize_single_readback' panicked at crates\darner-gpu\src\gpu_owned.rs:1046:9: assertion `left == right` failed: one readback for the block, not eight left: 3 right: 1 ``` There are two causes, both in the test. 1. The test sets `TEST_READBACKS` to zero, lets eight threads fault on one trapped block and asserts that the count is one. The count is one static for every trapped block. `veh_read_fault_and_partial_write_zero_clobber`, the other test that traps blocks, traps two and so makes two readbacks, and it runs beside this one on another test thread. When the two meet, the count is two or three (192 of the 200 runs). Both tests now hold one lock, `ONE_TRAP_TEST`, for their whole length. 2. The test's stand-in handler gives the block its protection back before the bytes go in, as `read_back` does. A thread that comes to the block between the two reads it with no fault, and not the pattern: `left: 7, right: 8`, "all eight threads read the card's bytes" (7 of the 200 runs, and 18 of 200 with the lock of 1 alone). The test now holds the handler's turn (`TEST_SERIAL`) until all eight threads have faulted, which is what its name says it is about, and asserts that they did. Test code only: `mod tests` of `gpu_owned.rs`. `read_back` itself is not changed: with `DARNER_GPU_OWNED=1` a second thread of the title that first touches a block in that window reads the bytes of before the readback. I read that from the code only and did not look for it in the game. ## How it was tested - Tested revision: 224cbec (this one commit on `main` f3840d7). - Commands and results: `cargo test --locked -p darner-gpu --lib --no-run` on each revision, then that test binary run by itself with the filter `gpu_owned::tests` (the module's 6 tests, the two with trapped blocks among them), 200 and 300 times. | | A (main, f3840d7) | B (224cbec) | |---|---|---| | runs of `gpu_owned::tests` | 200 | 300 | | all passed | 1 | 300 | | `concurrent_faults_on_same_block_serialize_single_readback` failed | 199 | 0 | All of the crate's tests on 224cbec, 4 runs with a 150 s limit: this test passed in all four. One run passed whole; in the other three one other test failed (`watch::tests::ask_once_by_res_splits_reservations_without_refusals`, which #150 is about, `host::refresh_tests::chunked_nothing_new_with_matches_individual` and `host::watch_pipe::tests::ask_once_delta_runs_on_collector_and_preserves_ahead`). - Changes a default: no. - Gates run on that revision (the three in AGENTS.md; there is no CI): `cargo clippy --workspace --all-targets --locked -- -D warnings`: passed. The same with `--all-features`: passed. `cargo xtask policy`: 555 files ok. `cargo test --workspace --locked`: not run as one command on this revision. Of it, I ran `darner-gpu`'s tests as above. On `main` that gate fails or stands still by chance in this crate (#224 has the counts), and in `darner-shader` one test fails, which #227 is about. - Gameplay: not run in the game. The change is in test code only. - Shader wave sizes tested, when relevant: not relevant. - Hardware dependence: likely general. How often the two tests meet depends on timing and on the number of test threads: 16 here (Ryzen 7 8845HS, Windows 11 build 26300). - Coverage gaps: one PC. Other tests of the crate still fail by chance, as the four whole runs show. ## Checklist - [x] I ran this change in the game, or say below why it can't be (docs, tests only). - [x] This PR contains one change based on `main`. - [x] The diff follows `docs/asset-policy.md`. - [x] I recorded this PR's dependencies below. - Depends on: none ## Checked for overlap - [x] I searched the open pull requests for the same issue and for the files this touches. - Related PRs: none found for this test. Searches of open and closed issues and pull requests for `TEST_READBACKS`, `concurrent_faults_on_same_block` and `flaky` found no report. I searched the diff of every open pull request (100): #57 changes `gpu_owned.rs` outside its tests, none changes these two tests. #224 and #150 are about other tests of the crate that fail or stand still by chance. - Replaces or overlaps: none found This change was made with AI assistance (Claude Code). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
`gpu_owned::tests::concurrent_faults_on_same_block_serialize_single_readback` failed in
199 of 200 runs of its module, for two reasons.

It sets `TEST_READBACKS` to zero, lets eight threads fault on one trapped block and asserts
that the count is one. The count is one static for every trapped block, and
`veh_read_fault_and_partial_write_zero_clobber`, which traps two blocks and so makes two
readbacks, runs beside it on another test thread: the count was two or three
(`left: 3, right: 1`, "one readback for the block, not eight"; 192 of the 200 runs). Both
tests now hold one lock, `ONE_TRAP_TEST`, for their whole length.

And its stand-in handler gives the block its protection back before the bytes go in, as
`read_back` does, so a thread that came to the block between the two read it with no
fault and not the pattern (`left: 7, right: 8`, "all eight threads read the card's
bytes"; 7 of the 200 runs, and 18 of 200 with the lock alone). The test now holds the
handler's turn until all eight threads have faulted, which is what its name says it is
about, and asserts that they did.

300 of 300 runs of the module pass.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
First-time contributor

Independent Windows build, gate, and code-read review of 224cbec12 (based on main f3840d73d). Test-only change; not run in-game.

Environment

  • Windows 11 Pro 26H2 (build 26300.10075), Intel Core i9-14900K, NVIDIA RTX A2000 12GB (driver 621.47), Rust 1.98.1 (x86_64-pc-windows-msvc), MSVC 19.44.35230.

Measured results

  • Gate 1 (cargo clippy --workspace --all-targets --locked -- -D warnings): PASS
  • Gate 2 (cargo clippy --workspace --all-targets --all-features --locked -- -D warnings): PASS
  • cargo xtask policy: PASS (asset policy: 555 files ok)
  • cargo test --locked -p darner-gpu --lib gpu_owned (10 passed; 0 failed per run): 20/20 PASS

Code-read audit

  • Cleanly fixes both causes of nondeterminism in crates/darner-gpu/src/gpu_owned.rs (mod tests):
    1. ONE_TRAP_TEST serializes veh_read_fault_and_partial_write_zero_clobber and concurrent_faults_on_same_block_serialize_single_readback so their shared TEST_READBACKS counter no longer observes the other test's 2 readbacks.
    2. Holding TEST_SERIAL until TEST_FAULTS == 8 (with a 30 s timeout) guarantees all 8 worker threads fault concurrently before the first readback restores PAGE_READWRITE and copies the pattern bytes, closing the VirtualProtect -> copy_nonoverlapping race in test_fault.
  • No deadlock risk: TEST_FAULTS.fetch_add executes before TEST_SERIAL.lock(), stack-growth guard-page exceptions are ignored at gpu_owned.rs:950, and std::thread::scope establishes happens-before for TEST_WAITED/TEST_FAULTS.
  • As candidly noted in the PR description, production read_back (gpu_owned.rs:550-560, opt-in DARNER_GPU_OWNED=1) has an analogous unreserve -> copy_nonoverlapping window, which this test never exercised in the first place.

Verdict: PASS.

AI-assisted: yes (Gemini 4 Neon).

Independent Windows build, gate, and code-read review of `224cbec12` (based on `main` `f3840d73d`). Test-only change; not run in-game. ### Environment - Windows 11 Pro 26H2 (build 26300.10075), Intel Core i9-14900K, NVIDIA RTX A2000 12GB (driver 621.47), Rust 1.98.1 (`x86_64-pc-windows-msvc`), MSVC 19.44.35230. ### Measured results - Gate 1 (`cargo clippy --workspace --all-targets --locked -- -D warnings`): **PASS** - Gate 2 (`cargo clippy --workspace --all-targets --all-features --locked -- -D warnings`): **PASS** - `cargo xtask policy`: **PASS** (`asset policy: 555 files ok`) - `cargo test --locked -p darner-gpu --lib gpu_owned` (`10 passed; 0 failed` per run): **20/20 PASS** ### Code-read audit - Cleanly fixes both causes of nondeterminism in `crates/darner-gpu/src/gpu_owned.rs` (`mod tests`): 1. `ONE_TRAP_TEST` serializes `veh_read_fault_and_partial_write_zero_clobber` and `concurrent_faults_on_same_block_serialize_single_readback` so their shared `TEST_READBACKS` counter no longer observes the other test's 2 readbacks. 2. Holding `TEST_SERIAL` until `TEST_FAULTS == 8` (with a 30 s timeout) guarantees all 8 worker threads fault concurrently before the first readback restores `PAGE_READWRITE` and copies the pattern bytes, closing the `VirtualProtect` -> `copy_nonoverlapping` race in `test_fault`. - No deadlock risk: `TEST_FAULTS.fetch_add` executes before `TEST_SERIAL.lock()`, stack-growth guard-page exceptions are ignored at `gpu_owned.rs:950`, and `std::thread::scope` establishes happens-before for `TEST_WAITED`/`TEST_FAULTS`. - As candidly noted in the PR description, production `read_back` (`gpu_owned.rs:550-560`, opt-in `DARNER_GPU_OWNED=1`) has an analogous `unreserve` -> `copy_nonoverlapping` window, which this test never exercised in the first place. **Verdict:** PASS. AI-assisted: yes (Gemini 4 Neon).
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u 'pr/test-readback-count:blazecoding2009-pr/test-readback-count'
git switch 'blazecoding2009-pr/test-readback-count'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'blazecoding2009-pr/test-readback-count'
git switch 'blazecoding2009-pr/test-readback-count'
git rebase 'main'
git switch 'main'
git merge --ff-only 'blazecoding2009-pr/test-readback-count'
git switch 'blazecoding2009-pr/test-readback-count'
git rebase 'main'
git switch 'main'
git merge --no-ff 'blazecoding2009-pr/test-readback-count'
git switch 'main'
git merge --squash 'blazecoding2009-pr/test-readback-count'
git switch 'main'
git merge --ff-only 'blazecoding2009-pr/test-readback-count'
git switch 'main'
git merge 'blazecoding2009-pr/test-readback-count'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
TrustNo1/Darner!261
No description provided.