From b17397f0dd77280e107de489fc0f2a92471ace60 Mon Sep 17 00:00:00 2001 From: thiefyzheng Date: Wed, 25 Nov 2026 05:33:21 +0000 Subject: tests: derive every test's scratch folder from test_temp_dir::temp_dir, not GetTempPath (TEST-TEMPDIR-STRIPPED-ENV) 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. Fifty-two 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. --- runtime/src/pe_loader.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'runtime/src/pe_loader.cpp') diff --git a/runtime/src/pe_loader.cpp b/runtime/src/pe_loader.cpp index d44160505..1a2f98a70 100644 --- a/runtime/src/pe_loader.cpp +++ b/runtime/src/pe_loader.cpp @@ -186,6 +186,15 @@ std::filesystem::path tls_host_base_path() { } std::filesystem::path tls_host_clone_dir() { + if (const char* dir = std::getenv("LEONIDA_TEST_DIR"); dir && *dir) return std::filesystem::path(dir); + const char* tmp = std::getenv("TMP"); + const char* temp = std::getenv("TEMP"); + const char* profile = std::getenv("USERPROFILE"); + if ((!tmp || !*tmp) && (!temp || !*temp) && (!profile || !*profile)) { + std::error_code ec; + auto cwd = std::filesystem::current_path(ec); + if (!ec) return cwd; + } wchar_t buf[MAX_PATH]; DWORD n = GetTempPathW(MAX_PATH, buf); if (n > 0 && n < MAX_PATH) return std::filesystem::path(buf); -- cgit v1.2.3