Skip to content

tests: nine runtime tests use a temp folder of their own process, and a two-copy test checks it - #8213

Closed
myokex wants to merge 2 commits into
ProjectLeonida:mainfrom
myokex:fix/test-temp-dirs-per-process
Closed

myokex wants to merge 2 commits into
ProjectLeonida:mainfrom
myokex:fix/test-temp-dirs-per-process

Conversation

@myokex

@myokex myokex commented Nov 23, 2026

Copy link
Copy Markdown

Claim: new item in #8047 (comment).

Seven runtime tests wrote their shader library under one fixed %TEMP% name. Two copies at once (ctest -j from two checkouts, or two suites sharing one TMPDIR / Wine prefix) remove or overwrite each other's modules: the race runtime/test/test_temp_dir.h describes, and the one #6221 / #6184 fix for d3d12_bindless_churn (left out here so this doesn't overlap them).

  • d3d12_depth24_draw, d3d12_geometry, d3d12_mesh: they already remove_all the folder at the end, so only the name changes: testfiles::process_temp_dir(<same name>).
  • d3d12_depth_resolve, d3d12_f16_halves, d3d12_state_sweep, d3d12_stores_atomics: they never removed the folder, so a per-process name alone would leave one folder per run. They use testfiles::ScratchDir, which creates it and removes it when main returns. In d3d12_depth_resolve it is declared before the block, because the device reads the library through info.shader_dir after it.
  • bink_audio / bink_decode also use fixed names, but for output files a person may want to look at, and they need a movie from the game; not touched.

Tested on Windows 11, AMD Radeon RX 7800 XT (driver 32.0.32029.2010), MSVC 2022 RelWithDebInfo, Vulkan SDK 1.4.363.0, synthetic only, no game files. 4 copies of each test started at once, 3 rounds (12 runs), main dde82f27e vs this branch:

test main failed this PR failed main failure
d3d12_depth24_draw 9/12 0/12 h.run(...) at lines 348/364/378/413
d3d12_geometry 5/12 0/12 CreateGraphicsPipelineState at lines 129/131
d3d12_mesh 4/12 0/12 create(...) at lines 207/212
d3d12_f16_halves, d3d12_state_sweep, d3d12_stores_atomics 0/12 0/12

Every test passes run alone on both sides, and no leonida_* folder is left in %TEMP% after the branch's runs. d3d12_depth_resolve fails on this card on both sides, alone too, with the same AMD host stencil-resolve differences (63 of 97 match, 18 host quirks against the AMD host, 71 of 71 against WARP): not this change.

🤖 Generated with Claude Code

d3d12_depth24_draw, d3d12_depth_resolve, d3d12_f16_halves, d3d12_geometry,
d3d12_mesh, d3d12_state_sweep and d3d12_stores_atomics wrote their shader
library under one fixed %TEMP% name. Two copies at once (ctest -j with two
checkouts, or two suites sharing one TMPDIR or Wine prefix) then removed or
overwrote each other's modules, the race test_temp_dir.h describes.

- depth24_draw, geometry, mesh (they already remove the folder at the end):
  testfiles::process_temp_dir(<same name>).
- depth_resolve, f16_halves, state_sweep, stores_atomics (they never removed
  it, so a per-process name alone would leave one folder per run):
  testfiles::ScratchDir, which creates the folder and removes it on return.
  In depth_resolve it lives outside the block, because the device reads the
  library through info.shader_dir afterwards.

Measured on Windows 11, RX 7800 XT, 4 copies at once, 3 rounds (12 runs) each,
on main dde82f2 vs this change: depth24_draw 9 -> 0 failed, geometry 5 -> 0,
mesh 4 -> 0 (at PSO creation / h.run); f16_halves, state_sweep, stores_atomics
0 -> 0; no folder left in %TEMP%. depth_resolve fails alone on both sides with
the same AMD host differences, unrelated.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@tupacfan04 tupacfan04 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The seven changed tests are correct, but two other synthetic runtime tests still share one fixed temp folder — and one copy's cleanup deletes another copy's files.

  1. d3d12_shader_cache_test still uses leonida_shader_cache_disk_test. runtime/test/d3d12_shader_cache_test.cpp:289-302 removes and recreates that fixed folder, then current_path(temp_dir); the RestoreCwd destructor (:296-300) removes the same fixed folder. Two copies at once (parallel CTest from two checkouts, or a shared TMPDIR/Wine prefix) race: one startup/teardown remove_all deletes the other's cache and working directory. The PR body excludes only bink_audio/bink_decode, so this one is unmentioned.

  2. xgameruntime_gamesave_test still uses leonida_gamesave_test. runtime/test/xgameruntime_gamesave_test.cpp:125-128 removes that fixed root and sets LEONIDA_SAVE_DIR to it; :371 removes it at the end. Two copies share saves and one cleanup deletes the other's. The same per-process ScratchDir/process_temp_dir fix applies.

The bink_audio/bink_decode exclusions are reasonable (inspection output/movie input), but these two are synthetic and unconstrained.

Test gap: no committed two-copy test. The PR body's manual table is useful, but three of the seven (d3d12_f16_halves, d3d12_state_sweep, d3d12_stores_atomics) were 0/12 on main as well, so their two-copy case was never reproduced, and d3d12_depth_resolve fails on the author's card on both sides. Add a two-copy test (shared temp dir, both must pass) to catch a future fixed-path regression.

Minor: the three process_temp_dir tests rely on remove_all(library) at the end, so an early return/crash leaves a per-PID folder; d3d12_mesh handles its early skip, the other two may not. ScratchDir for all seven would make cleanup uniform. Correct: per-PID paths, no cross-process deletion in the changed tests, no path escape. Synthetic/code-read only; no game files. AI-assisted (OpenCode).

…y test

d3d12_shader_cache_test (leonida_shader_cache_disk_test) and
xgameruntime_gamesave_test (leonida_gamesave_test) still used one fixed
folder under the temp directory, so one copy's remove_all deleted the
other copy's cache or saves. Both now use testfiles::process_temp_dir.

d3d12_depth24_draw, d3d12_geometry and d3d12_mesh use ScratchDir instead
of process_temp_dir plus a final remove_all, so an early return no longer
leaves a per-process folder behind.

test/run_two_copies.cmake starts two copies of a test at once (the
commands of one execute_process run concurrently) and fails unless both
exit 0. Registered for xgameruntime_gamesave, d3d12_shader_cache and
d3d12_geometry. With the game save folder put back to the fixed name,
xgameruntime_gamesave_two_copies failed 19 of 20 runs; with this change
it passed 20 of 20 (RX 7800 XT, Windows 11).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@myokex

myokex commented Nov 23, 2026

Copy link
Copy Markdown
Author

Thanks @tupacfan04, all four points are in c61f86e1e:

  1. d3d12_shader_cache_test: the disk-mode folder is now testfiles::process_temp_dir("leonida_shader_cache_disk_test"), so the RestoreCwd cleanup only removes this process's folder.
  2. xgameruntime_gamesave_test: LEONIDA_SAVE_DIR is now process_temp_dir("leonida_gamesave_test").
  3. Two-copy test: new runtime/test/run_two_copies.cmake starts two copies of a test at once (the commands of one execute_process run concurrently) and fails unless both exit 0. It is registered as xgameruntime_gamesave_two_copies, d3d12_shader_cache_two_copies and d3d12_geometry_two_copies. Sabotage check: with the save folder put back to the fixed name, xgameruntime_gamesave_two_copies failed 19 of 20 runs. With the fix it passed 20 of 20.
  4. Cleanup: d3d12_depth24_draw, d3d12_geometry and d3d12_mesh now use ScratchDir too, so the trailing remove_all(library) calls are gone and an early return cleans up as well.

Tested on Windows 11 Pro 10.0.26300, RX 7800 XT (32.0.32029.2010), MSVC 19.44 RelWithDebInfo: the 9 touched tests plus the 3 new *_two_copies give 11 of 12 passing. The failing one is d3d12_depth_resolve, and it fails the same way on main a91049014 on this card, as you noted. d3d12_f16_halves, d3d12_state_sweep and d3d12_stores_atomics pass here, but I did not add two-copy entries for them. The one race that reproduced on demand is covered by the gamesave test.

AI-assisted (Claude Code).

@myokex myokex changed the title tests: seven runtime tests use a temp folder of their own process (two copies at once no longer race) tests: nine runtime tests use a temp folder of their own process, and a two-copy test checks it Nov 23, 2026
@MartinIndra02

Copy link
Copy Markdown
Contributor

Independent build + test: PASS (one already-failing test unchanged)

AI-assisted (Claude Code). Windows 11 x64, MSVC 19.44.35220, Ninja RelWithDebInfo, NVIDIA GeForce RTX 3080 driver 621.24 / 32.0.16.2124 (Vulkan layer).

Head c61f86e1e, merged locally with current main 867d922f0 (CMakeLists.txt auto-merged). Reconfigured for the three new _two_copies tests.

ctest Result
xgameruntime_gamesave, xgameruntime_gamesave_two_copies Passed
d3d12_shader_cache, d3d12_shader_cache_two_copies Passed
d3d12_geometry, d3d12_geometry_two_copies Passed
d3d12_depth24_draw, d3d12_f16_halves, d3d12_mesh, d3d12_state_sweep, d3d12_stores_atomics Passed
d3d12_depth_resolve Failed: the same refused D24S8/D32S8 ... Close 0x80070057, destination changed lines that main has had since #6610. #7905 / #7930 (still open) fix that. Not caused by this PR

Notes:

  • run_two_copies.cmake pipes the first copy's stdout into the second copy's stdin, so the first copy's output never reaches the ctest log; only its exit code does. When a two-copy run fails, you can't tell which copy printed what. Running each COMMAND with its own OUTPUT_FILE would keep both.
  • A mixed result (77;0 or 0;77) counts as a failure. That's probably intended, but the comment only mentions "77 from both".

@rideinstead

Copy link
Copy Markdown

✅ Automated security review: CLEAN (commit c61f86e1)

  • No findings.

Scope: static analysis of added diff lines only; no code was executed. Please review findings manually.

@ddaikodaiko

Copy link
Copy Markdown

Windows check of c61f86e: Windows 10 Pro 10.0.19045, MSVC 19.44.35229, Windows SDK 10.0.26100, CMake 3.31 + Ninja. No game files.

cmake --build runtime\build --target xgameruntime_gamesave_test d3d12_shader_cache_test d3d12_f16_halves_test -j 10
ctest -R "two_copies|^d3d12_f16_halves$|^d3d12_shader_cache$|^xgameruntime_gamesave$" --output-on-failure
1/5 Test  #81: xgameruntime_gamesave ..............   Passed    0.18 sec
2/5 Test  #82: xgameruntime_gamesave_two_copies ...   Passed    0.12 sec
3/5 Test #178: d3d12_shader_cache .................   Passed    1.85 sec
4/5 Test #179: d3d12_shader_cache_two_copies ......   Passed    2.63 sec
5/5 Test #201: d3d12_f16_halves ...................   Passed    0.55 sec
100% tests passed, 0 tests failed out of 5

Both new two-copy tests pass on this machine, so the per-process folders work for the gamesave and shader-cache paths at least (the ones that build here). d3d12_state_sweep, d3d12_stores_atomics, d3d12_depth24_draw, d3d12_geometry and d3d12_mesh are not in this build (glslangValidator and the llvm-mc-gated fixtures are absent), so their part of the change could not be run; d3d12_depth_resolve is the known failure on this host.

I did not run four copies in three rounds; this is one ctest pass, not a stress run.

@comtek21516

Copy link
Copy Markdown

Tested c61f86e1e on main at 867d922f0, in one tree with #9480, #9486, #9492, #9328, #9467 (six clean merges): pass.

For this change. On the GPU under Wine the tests it moves to a temp folder of their own process pass: d3d12_depth24_draw, d3d12_f16_halves, d3d12_geometry, d3d12_mesh and d3d12_shader_cache (d3d12_depth_resolve fails there with and without the change, d3d12_state_sweep skips as on main). Of the new two-copy tests, xgameruntime_gamesave_two_copies passes natively; d3d12_geometry_two_copies and d3d12_shader_cache_two_copies skip natively (no Vulkan driver) and are not started by the Wine runner (they are cmake scripts), so the two-copies-at-once case for the GPU tests was not exercised anywhere in this run.

#9370 could not be put in the same tree: it conflicts with this PR in runtime/test/d3d12_mesh_test.cpp; #9083 conflicts with it in runtime/CMakeLists.txt.

Setup. Built with MSVC 14.52 (Visual Studio 18), Windows SDK 10.0.26100, Vulkan SDK 1.4.363.1, Ninja RelWithDebInfo on Windows Server 2025 (no Vulkan driver there), then the same binaries run through scripts/run_wine_tests.py under wine-11.0 (WineHQ stable, xvfb-run) on a Quadro RTX 4000 (Turing), NVIDIA 615.71.09, Ubuntu 22.04.5, where the layer tests report device: Quadro RTX 4000.

passed failed skipped
native Windows, this tree 149 4 129
Wine on the GPU, main 867d922f0 210 12 54
Wine on the GPU, this tree 214 12 57

Against main under Wine the only differences are the seven tests this tree adds (four pass, three are skipped because the Wine runner does not start cmake-driven tests); every test that exists on main has the status it has there. The four native failures are gameinput_host, d3d12_sparse_queue_family, vk_bindless_ps_tex and vk_bindless_ps_imgatomic, which fail the same way on main on that machine (#7452). The 12 under Wine are the same 12 as on main (host comparisons Wine cannot answer, and d3d12_xdxr_rt, d3d12_indirect_rt, d3d12_indirect_dispatch_count).

This was a combined run: the six PRs were built into one tree, so it is weaker evidence than a run of this PR alone, and there is no per-PR negative control. A regression would have shown as a difference from main, and there is none. No game files used. AI-assisted (Claude Code).

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants