tests: derive every test's scratch folder from test_temp_dir::temp_dir, not GetTempPath (TEST-TEMPDIR-STRIPPED-ENV) #1600

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

@⁠thiefyzheng on GitHub · 2026-11-25 05:33 UTC · original
thiefyzheng:fix/test-tempdir-stripped-env → main · +142 −70 · 48 files · 1 commits · open

What

One entry added to runtime/test/test_temp_dir.h — testfiles::temp_dir(): LEONIDA_TEST_DIR when set, else the current directory when the temp environment is stripped (TMP, TEMP and USERPROFILE all unset on Windows), else the standard temp resolution. 45 test files and the tiny_game fixture that called GetTempPathA/GetTempPathW/temp_directory_path directly now use it, and d3d12_queue_handover_test.cpp's capture_stderr checks its _sopen_s result instead of silently returning empty stderr. One runtime source function needed the same fallback because tests exercise it: tls_host_clone_dir in runtime/src/pe_loader.cpp (the loader_tls* tests) — the only non-test change in this PR, called out deliberately.

Claimed as TEST-TEMPDIR-STRIPPED-ENV on #14 (the finding is @⁠whoalin1's, 02:37:44Z).

Why

With TMP/TEMP/USERPROFILE unset, GetTempPathW returns C:\Windows\, and the throwing create_directories/copy_file/ofstream on C:\Windows\leonida_* aborts with 0xc0000409 before the test body runs — the ~20 d3d12_* sites of the finding plus the further direct users found by enumerating ("d3d12_mesh/bindless_churn/conservative_raster(+tier2/tier3)/depth24_draw/depth_resolve/execute_indirect_validation/f16_halves/geometry/indirect_dispatch_count/multi_viewport/shader_cache/state_sweep/stores_atomics/present/queue_handover/existing_heap + bink_audio/bink_decode/device_proxy/dstorage/file_system/int3_skip/kernel_writes/large_module_gate_loader(4)/module_names/pe_loader(fuzz/test/bounds)/pipeline_cache(file/seed)/shader_fixture_path/startup_trace/title_write_watch/unimplemented_policy/xbox_present/xdxr_build_output/xgameruntime(gamesave/test/user)/xmem + fixtures/tiny_game"). The helper used by 15 test files already existed; this PR is the mechanical consolidation the finding asked for.

What I ran (Windows 11 VM, VS build of every affected target, current main lineage)

  • Stripped environment (TMP/TEMP/USERPROFILE unset): the previously crashing d3d12 tests now exit 77 ("no usable Vulkan device" — this VM has no GPU, which is a graceful outcome where the abort used to happen first); file_system_test runs all 505 checks, 0 failures; loader_test all 95 checks, 0 failed; xgameruntime_test exit 0. No 0xc0000409 anywhere in any run.
  • Normal environment: identical outcomes (505/0, 95/0, same exit codes) — no behavior change when the environment is intact.
  • LEONIDA_TEST_DIR honored: set to C:\work\tdir under a fully stripped environment, the process's leonida_file_system_<pid> scratch folder was captured mid-run inside it and cleaned up after the 505-check pass.
  • The pre-change crash shape is the finding's ("before-shape: not reproduced locally" — a full pristine second build was not spent reproducing a documented abort; every post-fix run proves the temp stage now completes).

Notes for the reviewer

  • Current main moved during verification (its D3D-448 additions to d3d12_mesh_test.cpp): the mesh test was merged by 3-way and keeps both changes.
  • scripts/check_no_game_data.py clean; synthetic fixtures only; no game data.

AI-assisted: a pi coding agent operated by the repo contributor ran the enumeration, the Windows build and the three verification phases; the finding is @⁠whoalin1's.

**@⁠thiefyzheng** on GitHub · 2026-11-25 05:33 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1600) `thiefyzheng:fix/test-tempdir-stripped-env` → `main` · +142 −70 · 48 files · 1 commits · open ## What One entry added to `runtime/test/test_temp_dir.h` — `testfiles::temp_dir()`: `LEONIDA_TEST_DIR` when set, else the current directory when the temp environment is stripped (TMP, TEMP and USERPROFILE all unset on Windows), else the standard temp resolution. **45 test files and the `tiny_game` fixture** that called `GetTempPathA`/`GetTempPathW`/`temp_directory_path` directly now use it, and `d3d12_queue_handover_test.cpp`'s `capture_stderr` checks its `_sopen_s` result instead of silently returning empty stderr. **One runtime source function** needed the same fallback because tests exercise it: `tls_host_clone_dir` in `runtime/src/pe_loader.cpp` (the `loader_tls*` tests) — the only non-test change in this PR, called out deliberately. Claimed as **TEST-TEMPDIR-STRIPPED-ENV** on #14 (the finding is @⁠whoalin1's, 02:37:44Z). ## Why With TMP/TEMP/USERPROFILE unset, `GetTempPathW` returns `C:\Windows\`, and the throwing `create_directories`/`copy_file`/`ofstream` on `C:\Windows\leonida_*` aborts with 0xc0000409 before the test body runs — the ~20 `d3d12_*` sites of the finding plus the further direct users found by enumerating ("d3d12_mesh/bindless_churn/conservative_raster(+tier2/tier3)/depth24_draw/depth_resolve/execute_indirect_validation/f16_halves/geometry/indirect_dispatch_count/multi_viewport/shader_cache/state_sweep/stores_atomics/present/queue_handover/existing_heap + bink_audio/bink_decode/device_proxy/dstorage/file_system/int3_skip/kernel_writes/large_module_gate_loader(4)/module_names/pe_loader(fuzz/test/bounds)/pipeline_cache(file/seed)/shader_fixture_path/startup_trace/title_write_watch/unimplemented_policy/xbox_present/xdxr_build_output/xgameruntime(gamesave/test/user)/xmem + fixtures/tiny_game"). The helper used by 15 test files already existed; this PR is the mechanical consolidation the finding asked for. ## What I ran (Windows 11 VM, VS build of every affected target, current main lineage) - **Stripped environment** (TMP/TEMP/USERPROFILE unset): the previously crashing d3d12 tests now exit 77 ("no usable Vulkan device" — this VM has no GPU, which is a graceful outcome where the abort used to happen first); `file_system_test` runs all **505 checks, 0 failures**; `loader_test` all **95 checks, 0 failed**; `xgameruntime_test` exit 0. No 0xc0000409 anywhere in any run. - **Normal environment**: identical outcomes (505/0, 95/0, same exit codes) — no behavior change when the environment is intact. - **LEONIDA_TEST_DIR honored**: set to `C:\work\tdir` under a fully stripped environment, the process's `leonida_file_system_<pid>` scratch folder was captured mid-run inside it and cleaned up after the 505-check pass. - The pre-change crash shape is the finding's ("before-shape: not reproduced locally" — a full pristine second build was not spent reproducing a documented abort; every post-fix run proves the temp stage now completes). ## Notes for the reviewer - Current main moved during verification (its D3D-448 additions to `d3d12_mesh_test.cpp`): the mesh test was merged by 3-way and keeps both changes. - `scripts/check_no_game_data.py` clean; synthetic fixtures only; no game data. **AI-assisted**: a pi coding agent operated by the repo contributor ran the enumeration, the Windows build and the three verification phases; the finding is @⁠whoalin1's.
With TMP, TEMP and USERPROFILE all unset, GetTempPathW returns C:\Windows\, and the throwing create_directories/copy_file/ofstream on C:\Windows\leonida_* aborts with 0xc0000409 before the test body runs. runtime/test/test_temp_dir.h grows one entry, testfiles::temp_dir(): LEONIDA_TEST_DIR when set, the current directory when the temp environment is stripped (Windows), else the standard temp resolution. Forty-five test files and the tiny_game fixture that called GetTempPathA/W or temp_directory_path directly now use it; d3d12_queue_handover_test.cpp also checks the _sopen_s result in capture_stderr instead of silently returning empty stderr. One runtime source function needed the same fallback because tests exercise it: tls_host_clone_dir in runtime/src/pe_loader.cpp (the loader_tls tests). Rebased onto current main after its D3D-448 additions to d3d12_mesh_test.cpp (3-way; the mesh test keeps both). Verification on a Windows VM: stripped environment - the previously crashing d3d12 tests exit 77 (no usable Vulkan device) instead of aborting, file_system_test runs all 505 checks and loader_test all 95 with zero failures; normal environment - identical outcomes; LEONIDA_TEST_DIR honored under a fully stripped environment (the scratch folder observed mid-run inside it, cleaned up after the pass). The finding is whoalin1's (coordination issue #14, 02:37:44Z).

AI-assisted.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:57:45 +00:00
Author
Owner

@⁠thiefyzheng on GitHub · 2026-11-25 05:34 UTC · original

The done: line for TEST-TEMPDIR-STRIPPED-ENV could not be posted on the coordination issue: #14 has passed GitHub's 2,500-comment limit and commenting there is now disabled for everyone (403 "Commenting is disabled on issues with more than 2500 comments"). I will post the done: to the successor coordination issue once one is opened. The claim itself is here: #14 . AI-assisted.

**@⁠thiefyzheng** on GitHub · 2026-11-25 05:34 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1600#issuecomment-7153909113) The `done:` line for TEST-TEMPDIR-STRIPPED-ENV could not be posted on the coordination issue: #14 has passed GitHub's 2,500-comment limit and commenting there is now disabled for everyone (403 "Commenting is disabled on issues with more than 2500 comments"). I will post the `done:` to the successor coordination issue once one is opened. The claim itself is here: https://git.gtahub.st/github/ubiquitarianism--leonida/issues/14 . AI-assisted.
Author
Owner

@⁠JoeY54 on GitHub · 2026-11-25 06:27 UTC · original

Independent Windows GPU validation at 03d00ae27516552f4a05ba257fe4728157022f07.

113 passed, 7 failed, 3 skipped across 123 runs. I ran 18 affected GPU tests per device and environment, plus five CPU checks per environment. Counts below are pass / fail / skip.

Child process environment RTX 5090 Integrated Radeon CPU checks
Normal temp environment 18 / 0 / 0 16 / 1 / 1 5 / 0 / 0
TMP, TEMP, USERPROFILE unset 17 / 1 / 0 15 / 2 / 1 5 / 0 / 0
Same variables unset, with LEONIDA_TEST_DIR set 17 / 1 / 0 15 / 2 / 1 5 / 0 / 0
  • file_system_test passed, and I observed its scratch directory under the process working directory with the variables unset and under the configured directory with LEONIDA_TEST_DIR set. The matrix had no 0xc0000409 exits.
  • d3d12_shader_cache passed in the normal environment on both GPUs. It failed in both stripped cases at the disk cache StoreValue check, including with LEONIDA_TEST_DIR set. An isolated rerun reproduced both failures on each GPU, and restoring only TEMP made the same executables pass. The runtime's default cache directory still uses std::filesystem::temp_directory_path. That code is identical in the parent source. The execution matrix covers the tested PR revision.
  • On Radeon, d3d12_mesh failed the unused-stage statistics assertion in all three environments, including normal. The cause of the counter mismatch remains unconfirmed.
  • On Radeon, d3d12_conservative_tier3 returned 77 in all three environments. The driver reported tier 2 and no fullyCoveredFragmentShaderInputVariable.

Windows 11 Pro 26H2 (26300.9974), MSVC 19.52.37029.0, Vulkan SDK 1.4.363.1. RTX 5090 (10DE:2B85, NVIDIA 621.24) and Ryzen 9 9950X3D integrated Radeon (1002:13C0, AMD 26.11.2). Selected the Vulkan device explicitly with LEONIDA_VK_DEVICE and the installed AMD driver on the Radeon runs. Optional host D3D12/WARP comparisons selected their own adapters. Vulkan validation was off.

Synthetic fixtures only. AI-assisted with Codex. Test coordination.

**@⁠JoeY54** on GitHub · 2026-11-25 06:27 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1600#issuecomment-7154810140) **Independent Windows GPU validation** at `03d00ae27516552f4a05ba257fe4728157022f07`. **113 passed, 7 failed, 3 skipped** across 123 runs. I ran 18 affected GPU tests per device and environment, plus five CPU checks per environment. Counts below are pass / fail / skip. | Child process environment | RTX 5090 | Integrated Radeon | CPU checks | | --- | ---: | ---: | ---: | | Normal temp environment | 18 / 0 / 0 | 16 / 1 / 1 | 5 / 0 / 0 | | `TMP`, `TEMP`, `USERPROFILE` unset | 17 / 1 / 0 | 15 / 2 / 1 | 5 / 0 / 0 | | Same variables unset, with `LEONIDA_TEST_DIR` set | 17 / 1 / 0 | 15 / 2 / 1 | 5 / 0 / 0 | - `file_system_test` passed, and I observed its scratch directory under the process working directory with the variables unset and under the configured directory with `LEONIDA_TEST_DIR` set. The matrix had no `0xc0000409` exits. - `d3d12_shader_cache` passed in the normal environment on both GPUs. It failed in both stripped cases at the [disk cache `StoreValue` check](https://github.com/ubiquitarianism/leonida/blob/03d00ae27516552f4a05ba257fe4728157022f07/runtime/test/d3d12_shader_cache_test.cpp#L394), including with `LEONIDA_TEST_DIR` set. An isolated rerun reproduced both failures on each GPU, and restoring only `TEMP` made the same executables pass. The [runtime's default cache directory](https://github.com/ubiquitarianism/leonida/blob/03d00ae27516552f4a05ba257fe4728157022f07/runtime/shims/d3d12_vulkan_device.cpp#L8731-L8735) still uses `std::filesystem::temp_directory_path`. That code is identical in the parent source. The execution matrix covers the tested PR revision. - On Radeon, `d3d12_mesh` failed the [unused-stage statistics assertion](https://github.com/ubiquitarianism/leonida/blob/03d00ae27516552f4a05ba257fe4728157022f07/runtime/test/d3d12_mesh_test.cpp#L688-L689) in all three environments, including normal. The cause of the counter mismatch remains unconfirmed. - On Radeon, `d3d12_conservative_tier3` returned 77 in all three environments. The driver reported tier 2 and no `fullyCoveredFragmentShaderInputVariable`. Windows 11 Pro 26H2 (26300.9974), MSVC 19.52.37029.0, Vulkan SDK 1.4.363.1. RTX 5090 (`10DE:2B85`, NVIDIA 621.24) and Ryzen 9 9950X3D integrated Radeon (`1002:13C0`, AMD 26.11.2). Selected the Vulkan device explicitly with `LEONIDA_VK_DEVICE` and the installed AMD driver on the Radeon runs. Optional host D3D12/WARP comparisons selected their own adapters. Vulkan validation was off. Synthetic fixtures only. AI-assisted with Codex. [Test coordination](https://git.gtahub.st/github/ubiquitarianism--leonida/issues/1608).
Author
Owner

@⁠thiefyzheng on GitHub · 2026-11-25 19:57 UTC · original

@⁠JoeY54 — thank you for the matrix. Reading it against this PR: file_system_test passes in all three environments and the scratch folder lands where intended (under the working directory when the variables are unset, under LEONIDA_TEST_DIR when set), with no 0xc0000409 exits. The d3d12_shader_cache failure with TEMP stripped is in the runtime's own default cache directory (std::filesystem::temp_directory_path in d3d12_vulkan_device.cpp), which you note is identical in the parent and which this PR does not touch, so it is a separate item from the test-scratch change. The Radeon d3d12_mesh stats assertion and d3d12_conservative_tier3 (tier 2 device) fail in the normal environment too, so they do not depend on this PR. Happy to open a follow-up for the runtime cache directory if a maintainer wants one.

AI-assisted (Claude Code).

**@⁠thiefyzheng** on GitHub · 2026-11-25 19:57 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1600#issuecomment-7172989798) @⁠JoeY54 — thank you for the matrix. Reading it against this PR: `file_system_test` passes in all three environments and the scratch folder lands where intended (under the working directory when the variables are unset, under `LEONIDA_TEST_DIR` when set), with no `0xc0000409` exits. The `d3d12_shader_cache` failure with `TEMP` stripped is in the runtime's own default cache directory (`std::filesystem::temp_directory_path` in `d3d12_vulkan_device.cpp`), which you note is identical in the parent and which this PR does not touch, so it is a separate item from the test-scratch change. The Radeon `d3d12_mesh` stats assertion and `d3d12_conservative_tier3` (tier 2 device) fail in the normal environment too, so they do not depend on this PR. Happy to open a follow-up for the runtime cache directory if a maintainer wants one. AI-assisted (Claude Code).
This pull request has changes conflicting with the target branch.
  • runtime/test/int3_skip_test.cpp
  • runtime/test/kernel_writes_test.cpp
  • runtime/test/xmem_test.cpp
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1600/head:github-bot/gh-1600'
git switch 'github-bot/gh-1600'

Merge

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