tests: resolve a writable temp dir instead of crashing on C:\Windows #1579

Open
github-bot wants to merge 1 commit from github-bot/gh-1579 into main AGit
Owner

@⁠whoalin1 on GitHub · 2026-11-25 04:57 UTC · original
whoalin1:test-tempdir-robust → main · +375 −81 · 48 files · 1 commits · open

Claimed in the coordination issue: #14

What

With TMP/TEMP/USERPROFILE unset, GetTempPathW returns C:\Windows, which is not writable. Dozens of test binaries then die with 0xc0000409 (uncaught std::filesystem exception) instead of running or skipping — reproduced on main as ctest -R d3d12_mesh → exit 0xc0000409.

runtime/test/test_temp_dir.h gains a writable-dir probe chain (LEONIDA_TEST_DIR → temp_directory_path → current_path, each proven by an actual create/write/delete) and ensure_temp_env(), a pre-main initializer that repairs TMP/TEMP/TMPDIR when the effective temp dir is not writable — which also fixes the loader's own GetTempPathW clone dir, unreachable from test code. scratch_dir()/process_temp_dir() now resolve through it, covering every ScratchDir user (~17 suites), and the ~15 sites that threw directly (create_directories, copy_file, ofstream, _sopen_s capture) get empty → SKIP(77)/loud-failure guards. d3d12_queue_handover_test's stderr capture no longer reads an empty file as "layer was silent".

runtime/shims/d3d12_vulkan_device.cpp default_shader_cache_dir() probes the temp-based dir and falls back to cwd/leonida_shader_cache — without it d3d12_shader_cache reached its disk section and returned E_FAIL under a stripped env. Writable-temp behavior is byte-identical to before.

runtime/CMakeLists.txt: the 14 ctest entries that execute gta6rt/loader guests which the test exes' header cannot reach get ENVIRONMENT "TMP=${CMAKE_CURRENT_BINARY_DIR};TEMP=${CMAKE_CURRENT_BINARY_DIR}" — verified failing before (run_tiny_* "home clone of gta6rt_tls_host.dll cannot be loaded", run_startup_cmdline TLS index) and passing after, with the env stripped. The other gta6rt entries were run under the same stripped env and pass untouched (their guests never touch temp).

Verification (native Windows 11, env stripped of TMP/TEMP/USERPROFILE/ TMPDIR — the failure environment itself)

  • 23/23 GPU d3d12 tests pass (mesh, geometry, state_sweep, shader_cache, queue_handover ×3, conservative ×3+reference+inner_coverage ×2, depth24, depth_resolve, execute_indirect_validation, f16_halves, indirect_dispatch_count, multi_viewport, bindless_churn ×2, stores_atomics, bundle ×2, compute, draw) — zero 0xc0000409.
  • 14/14 run_tiny_* + run_startup_cmdline ctest entries pass (were all failing).
  • 11/11 non-GPU temp users pass (file_system, pipeline_cache_file, shader_fixture_path, xdxr_build_output, module_names ×2, pe_loader_bounds, pe_loader_fuzz, startup_trace, unimplemented_policy, large_module_gate); loader/pe_loader/loader_tls families and 10 GetTempPathW-user + 13 variant tests pass.
  • Spot-check under a normal env: 7/7 pass — no behavior change when temp is writable.
  • GPU runs on the default ICD (NVIDIA RTX 4070 SUPER); LEONIDA_VK_VALIDATION not needed (test-harness-only change plus a fallback path).

Independent review: APPROVE after one fix round (the gta6rt ctest gap above was the reviewer's catch; verified and fixed).

AI-assisted (Devin).

**@⁠whoalin1** on GitHub · 2026-11-25 04:57 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1579) `whoalin1:test-tempdir-robust` → `main` · +375 −81 · 48 files · 1 commits · open Claimed in the coordination issue: https://git.gtahub.st/github/ubiquitarianism--leonida/issues/14 ## What With `TMP`/`TEMP`/`USERPROFILE` unset, `GetTempPathW` returns `C:\Windows`, which is not writable. Dozens of test binaries then die with `0xc0000409` (uncaught `std::filesystem` exception) instead of running or skipping — reproduced on `main` as `ctest -R d3d12_mesh` → exit `0xc0000409`. `runtime/test/test_temp_dir.h` gains a writable-dir probe chain (`LEONIDA_TEST_DIR` → `temp_directory_path` → `current_path`, each proven by an actual create/write/delete) and `ensure_temp_env()`, a pre-`main` initializer that repairs `TMP`/`TEMP`/`TMPDIR` when the effective temp dir is not writable — which also fixes the loader's own `GetTempPathW` clone dir, unreachable from test code. `scratch_dir()`/`process_temp_dir()` now resolve through it, covering every `ScratchDir` user (~17 suites), and the ~15 sites that threw directly (`create_directories`, `copy_file`, `ofstream`, `_sopen_s` capture) get `empty → SKIP(77)`/loud-failure guards. `d3d12_queue_handover_test`'s stderr capture no longer reads an empty file as "layer was silent". `runtime/shims/d3d12_vulkan_device.cpp` `default_shader_cache_dir()` probes the temp-based dir and falls back to `cwd/leonida_shader_cache` — without it `d3d12_shader_cache` reached its disk section and returned `E_FAIL` under a stripped env. Writable-temp behavior is byte-identical to before. `runtime/CMakeLists.txt`: the 14 ctest entries that execute `gta6rt`/loader guests which the test exes' header cannot reach get `ENVIRONMENT "TMP=${CMAKE_CURRENT_BINARY_DIR};TEMP=${CMAKE_CURRENT_BINARY_DIR}"` — verified failing before (`run_tiny_*` "home clone of gta6rt_tls_host.dll cannot be loaded", `run_startup_cmdline` TLS index) and passing after, with the env stripped. The other gta6rt entries were run under the same stripped env and pass untouched (their guests never touch temp). ## Verification (native Windows 11, env stripped of TMP/TEMP/USERPROFILE/ TMPDIR — the failure environment itself) - 23/23 GPU d3d12 tests pass (mesh, geometry, state_sweep, shader_cache, queue_handover ×3, conservative ×3+reference+inner_coverage ×2, depth24, depth_resolve, execute_indirect_validation, f16_halves, indirect_dispatch_count, multi_viewport, bindless_churn ×2, stores_atomics, bundle ×2, compute, draw) — zero `0xc0000409`. - 14/14 `run_tiny_*` + `run_startup_cmdline` ctest entries pass (were all failing). - 11/11 non-GPU temp users pass (file_system, pipeline_cache_file, shader_fixture_path, xdxr_build_output, module_names ×2, pe_loader_bounds, pe_loader_fuzz, startup_trace, unimplemented_policy, large_module_gate); loader/pe_loader/loader_tls families and 10 GetTempPathW-user + 13 variant tests pass. - Spot-check under a normal env: 7/7 pass — no behavior change when temp is writable. - GPU runs on the default ICD (NVIDIA RTX 4070 SUPER); `LEONIDA_VK_VALIDATION` not needed (test-harness-only change plus a fallback path). Independent review: APPROVE after one fix round (the gta6rt ctest gap above was the reviewer's catch; verified and fixed). AI-assisted (Devin).
Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:57:09 +00:00
Author
Owner

@⁠Diegobecker07 on GitHub · 2026-11-25 15:53 UTC · original

Reviewed 805acd181, merged with main b0f3d3998, on Windows 11 Pro 26300 with an RTX 5070 Ti (NVIDIA 621.24) and MSVC 19.44. The full ctest passes, 449 of 449.

What it fixes, confirmed. I ran the nine scratch-folder tests (d3d12_depth24_draw, d3d12_depth_resolve, d3d12_f16_halves, d3d12_geometry, d3d12_mesh, d3d12_shader_cache, d3d12_state_sweep, d3d12_stores_atomics, xgameruntime_gamesave) with TMP, TEMP, USERPROFILE and TMPDIR removed:

  • main's binaries crash with 0xc0000409 in all nine. They were built at 0d80bc5df, and none of these files has changed on main since.
  • With this PR all nine pass.

The per-process folders also fix running two copies at once. I started two copies of d3d12_shader_cache together, five rounds: 3 of 10 copies fail on main and 0 of 10 with this PR.

1. Four of the new per-process folders are never removed. scratch_dir() creates <temp>/<name>_<pid>, and in four tests nothing deletes it: d3d12_depth_resolve_test, d3d12_f16_halves_test, d3d12_state_sweep_test and d3d12_stores_atomics_test. The other four remove theirs. On main these four used one fixed folder that each run overwrote; with this PR each run leaves its own folder behind. One run of the nine tests left four new folders in %TEMP%, holding 2–4 files each (the copied SPIR-V and index.json). With the environment stripped, the folders land in the working directory, which is the build folder under ctest. testfiles::ScratchDir, already in test_temp_dir.h, creates the folder and removes it on exit, so switching these four to it fixes both cases.

2. Three sites keep a fixed name (writable_temp_dir() / "<name>"): bink_audio_test.cpp:426, bink_decode_test.cpp:248 and xgameruntime_gamesave_test.cpp:126. When two copies of xgameruntime_gamesave_test start together, all 10 of 10 copies fail, both on main and with this PR; each copy fails 6 of 76 checks, starting with "seed blobs a and b". One copy on its own passes. This is outside the PR's stated scope (the stripped environment), so it can be a follow-up; the three sites are listed in #1608 (comment 7164348116).

3. Minor, in the runtime. default_shader_cache_dir() now creates the folder whenever the path is requested. clear_all() requests it, so a ClearAll now creates an empty %TEMP%\leonida_shader_cache when there was none. When no temp folder is writable, it falls back to the working directory, which for gta6rt is the directory it was started from rather than the overlay. Neither of these changes a test result.

Overlap: #1600 (TEST-TEMPDIR-STRIPPED-ENV, open, needs rebase) changes the same ~47 files to fix the same stripped-environment crash, so the two can't both land as they are.

Recommendation: merge after fixing 1 (switching four tests to ScratchDir); 2 can be a follow-up.

AI-assisted review.

**@⁠Diegobecker07** on GitHub · 2026-11-25 15:53 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1579#issuecomment-7167400086) Reviewed 805acd181, merged with main b0f3d3998, on Windows 11 Pro 26300 with an RTX 5070 Ti (NVIDIA 621.24) and MSVC 19.44. The full ctest passes, 449 of 449. **What it fixes, confirmed.** I ran the nine scratch-folder tests (`d3d12_depth24_draw`, `d3d12_depth_resolve`, `d3d12_f16_halves`, `d3d12_geometry`, `d3d12_mesh`, `d3d12_shader_cache`, `d3d12_state_sweep`, `d3d12_stores_atomics`, `xgameruntime_gamesave`) with TMP, TEMP, USERPROFILE and TMPDIR removed: - main's binaries crash with `0xc0000409` in all nine. They were built at 0d80bc5df, and none of these files has changed on main since. - With this PR all nine pass. The per-process folders also fix running two copies at once. I started two copies of `d3d12_shader_cache` together, five rounds: 3 of 10 copies fail on main and 0 of 10 with this PR. **1. Four of the new per-process folders are never removed.** `scratch_dir()` creates `<temp>/<name>_<pid>`, and in four tests nothing deletes it: `d3d12_depth_resolve_test`, `d3d12_f16_halves_test`, `d3d12_state_sweep_test` and `d3d12_stores_atomics_test`. The other four remove theirs. On main these four used one fixed folder that each run overwrote; with this PR each run leaves its own folder behind. One run of the nine tests left four new folders in `%TEMP%`, holding 2–4 files each (the copied SPIR-V and `index.json`). With the environment stripped, the folders land in the working directory, which is the build folder under ctest. `testfiles::ScratchDir`, already in `test_temp_dir.h`, creates the folder and removes it on exit, so switching these four to it fixes both cases. **2. Three sites keep a fixed name** (`writable_temp_dir() / "<name>"`): `bink_audio_test.cpp:426`, `bink_decode_test.cpp:248` and `xgameruntime_gamesave_test.cpp:126`. When two copies of `xgameruntime_gamesave_test` start together, all 10 of 10 copies fail, both on main and with this PR; each copy fails 6 of 76 checks, starting with "seed blobs a and b". One copy on its own passes. This is outside the PR's stated scope (the stripped environment), so it can be a follow-up; the three sites are listed in #1608 (comment 7164348116). **3. Minor, in the runtime.** `default_shader_cache_dir()` now creates the folder whenever the path is requested. `clear_all()` requests it, so a `ClearAll` now creates an empty `%TEMP%\leonida_shader_cache` when there was none. When no temp folder is writable, it falls back to the working directory, which for gta6rt is the directory it was started from rather than the overlay. Neither of these changes a test result. **Overlap:** #1600 (TEST-TEMPDIR-STRIPPED-ENV, open, needs rebase) changes the same ~47 files to fix the same stripped-environment crash, so the two can't both land as they are. **Recommendation:** merge after fixing 1 (switching four tests to `ScratchDir`); 2 can be a follow-up. AI-assisted review.
Author
Owner

@⁠Diegobecker07 on GitHub · 2026-11-25 17:47 UTC · original

Checked edd15f364, merged with main 863c1616a, on the same machine as before (Windows 11 Pro 26300, RTX 5070 Ti, NVIDIA 621.24, MSVC 19.44). Point 1 is fixed. I built the four tests and ran each one three times normally and three times with TMP, TEMP, USERPROFILE and TMPDIR removed. All 24 runs exit 0, and none leaves a <name>_<pid> folder in %TEMP% or in the build folder.

Heads-up: #1952 changes the same lines in bink_audio_test.cpp, bink_decode_test.cpp and xgameruntime_gamesave_test.cpp, so whichever of the two lands second will conflict. The details are on #1952.

AI-assisted.

**@⁠Diegobecker07** on GitHub · 2026-11-25 17:47 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1579#issuecomment-7169998173) Checked edd15f364, merged with main 863c1616a, on the same machine as before (Windows 11 Pro 26300, RTX 5070 Ti, NVIDIA 621.24, MSVC 19.44). Point 1 is fixed. I built the four tests and ran each one three times normally and three times with TMP, TEMP, USERPROFILE and TMPDIR removed. All 24 runs exit 0, and none leaves a `<name>_<pid>` folder in `%TEMP%` or in the build folder. Heads-up: #1952 changes the same lines in `bink_audio_test.cpp`, `bink_decode_test.cpp` and `xgameruntime_gamesave_test.cpp`, so whichever of the two lands second will conflict. The details are on #1952. AI-assisted.
Author
Owner

@⁠whoalin1 on GitHub · 2026-11-25 18:31 UTC · original

Thanks for the thorough review, @⁠Diegobecker07 — especially the concurrent-copy experiment. Pushed edd15f364 addressing point 1: all four tests (d3d12_depth_resolve_test, d3d12_f16_halves_test, d3d12_state_sweep_test, d3d12_stores_atomics_test) now use testfiles::ScratchDir, which removes the per-process folder on every way out of main — the same pattern the other scratch-library tests use. The no-writable-dir case still SKIPs with 77 (checked via is_directory after construction, since ScratchDir always falls back to a path). Syntax-checked each translation unit with MSVC cl /Zs (NOMINMAX + the test-shader defines); a full ctest run on both GPUs follows once the shared GPU lock cycles free, and I'll post the result here.

On point 2 (the three fixed-name sites in bink_audio_test.cpp:426, bink_decode_test.cpp:248, xgameruntime_gamesave_test.cpp:126): agreed, follow-up material — they're outside the stripped-environment scope and already tracked in #1608. On point 3: noted; clear_all() creating an empty cache dir is harmless in practice, but I'll look at it if it ever surfaces in a test. On the #1600 overlap: agreed they can't both land as-is; this branch is the superset (stripped-env + per-process isolation + cleanup), happy to rebase whichever way the maintainer prefers.

AI-assisted (Devin).

**@⁠whoalin1** on GitHub · 2026-11-25 18:31 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1579#issuecomment-7171014814) Thanks for the thorough review, @⁠Diegobecker07 — especially the concurrent-copy experiment. Pushed `edd15f364` addressing point 1: all four tests (`d3d12_depth_resolve_test`, `d3d12_f16_halves_test`, `d3d12_state_sweep_test`, `d3d12_stores_atomics_test`) now use `testfiles::ScratchDir`, which removes the per-process folder on every way out of main — the same pattern the other scratch-library tests use. The no-writable-dir case still SKIPs with 77 (checked via `is_directory` after construction, since `ScratchDir` always falls back to a path). Syntax-checked each translation unit with MSVC `cl /Zs` (`NOMINMAX` + the test-shader defines); a full ctest run on both GPUs follows once the shared GPU lock cycles free, and I'll post the result here. On point 2 (the three fixed-name sites in `bink_audio_test.cpp:426`, `bink_decode_test.cpp:248`, `xgameruntime_gamesave_test.cpp:126`): agreed, follow-up material — they're outside the stripped-environment scope and already tracked in #1608. On point 3: noted; `clear_all()` creating an empty cache dir is harmless in practice, but I'll look at it if it ever surfaces in a test. On the #1600 overlap: agreed they can't both land as-is; this branch is the superset (stripped-env + per-process isolation + cleanup), happy to rebase whichever way the maintainer prefers. AI-assisted (Devin).
Author
Owner

@⁠whoalin1 on GitHub · 2026-11-25 20:02 UTC · original

Rebased onto current main (db1a22d29) as f4a906884 and squashed the four ScratchDir commits into one for a single conflict-resolution pass. The only textual conflict was run_tiny_first_run_ui in runtime/CMakeLists.txt; resolution unions main's LEONIDA_KEYBOARD_PAD reset with this PR's TMP/TEMP redirect. The overlapping bink/gamesave hunks auto-merged and retain the current-main code with only the temp-root substitution. git diff --check is clean; a fresh MSVC runtime build is running locally as a sanity check, and CI will provide the full matrix. AI-assisted with Devin.

**@⁠whoalin1** on GitHub · 2026-11-25 20:02 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1579#issuecomment-7173098896) Rebased onto current main (`db1a22d29`) as `f4a906884` and squashed the four ScratchDir commits into one for a single conflict-resolution pass. The only textual conflict was `run_tiny_first_run_ui` in `runtime/CMakeLists.txt`; resolution unions main's `LEONIDA_KEYBOARD_PAD` reset with this PR's TMP/TEMP redirect. The overlapping bink/gamesave hunks auto-merged and retain the current-main code with only the temp-root substitution. `git diff --check` is clean; a fresh MSVC runtime build is running locally as a sanity check, and CI will provide the full matrix. AI-assisted with Devin.
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 origin '+refs/pull/1579/head:github-bot/gh-1579'
git switch 'github-bot/gh-1579'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1579'
git switch 'github-bot/gh-1579'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1579'
git switch 'github-bot/gh-1579'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1579'
git switch 'main'
git merge --squash 'github-bot/gh-1579'
git switch 'main'
git merge --ff-only 'github-bot/gh-1579'
git switch 'main'
git merge 'github-bot/gh-1579'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.