diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 349668e8..f51c91cb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -126,7 +126,12 @@ jobs: $common = @("-G", "Ninja", "-DCMAKE_BUILD_TYPE=Release", "-DCMAKE_POLICY_DEFAULT_CMP0091=NEW", "-DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded", "-DWRONGGPU_PAYLOAD_DIR=$PWD/out/mock/prepared/payload", "-DWRONGGPU_MAP=$PWD/out/mock/prepared/test-map.json", "-DWRONGGPU_VERSION=0.3.0-test") cmake -S clean/installer -B out/launcher-mock @common -DWRONGGPU_TESTING=ON - cmake --build out/launcher-mock --target WrongGPU + cmake --build out/launcher-mock --target WrongGPU launcher-core-tests + # the core tests in a WRONGGPU_TESTING build too: its test-only rules (the rr-prepare helper keeps the tests' LOCALAPPDATA) + out/launcher-mock/launcher-core-tests.exe + # the launcher suite runs only a testing build, by its identity (launcher_build_facts.py): this launcher and its restorer + # pass; the negative controls (not testing builds, one carrying the hooks' strings) are refused + python -c "import sys; sys.path.insert(0, 'clean/installer/tests'); import launcher_build_facts as f; ok = [p for p in ('WrongGPU.exe', 'WrongGPU-Restore.exe') if f.missing_test_hooks('out/launcher-mock/' + p)]; bad = [p for p in ('wg-test-canary.exe', 'wg-test-canary-strings.exe') if not f.missing_test_hooks('out/launcher-mock/' + p)]; sys.exit('not accepted: %s; not refused: %s' % (ok, bad) if ok or bad else 0)" # the negative control: a release build (WRONGGPU_TESTING=OFF) with the same stand-in refuses it at the payload step cmake -S clean/installer -B out/launcher-mock-release @common -DWRONGGPU_TESTING=OFF $PSNativeCommandUseErrorActionPreference = $false diff --git a/clean/installer/CMakeLists.txt b/clean/installer/CMakeLists.txt index 82d39b25..aae258d9 100644 --- a/clean/installer/CMakeLists.txt +++ b/clean/installer/CMakeLists.txt @@ -206,6 +206,16 @@ if(MSVC) else() target_link_options(WrongGPU-Restore PRIVATE -municode -static) endif() +# A WRONGGPU_TESTING build's identity, which the launcher suite checks before it runs a program (tests/launcher_build_facts.py): +# a named resource only such a build has, and a PE checksum (MSVC /RELEASE) that a program changed after its link fails. +if(WRONGGPU_TESTING) + file(GENERATE OUTPUT ${GEN}/testing_identity.rc + CONTENT "WRONGGPU_TESTING_BUILD RCDATA\nBEGIN\n \"wg-testing-build 1: store libraries, access log, edition download, uninstall root\\0\"\nEND\n") + target_sources(WrongGPU-Restore PRIVATE ${GEN}/testing_identity.rc) + if(MSVC) + target_link_options(WrongGPU-Restore PRIVATE /RELEASE) + endif() +endif() add_custom_command(OUTPUT ${GEN}/restorer.bin COMMAND ${CMAKE_COMMAND} -E copy $ ${GEN}/restorer.bin DEPENDS WrongGPU-Restore COMMENT "Embedding the restorer") @@ -218,6 +228,29 @@ add_executable(WrongGPU WIN32 src/app/main.cpp src/app/wizard.cpp src/app/cli.cp ${GEN}/resources.rc ${GEN}/restore.rc ${GEN}/restorer.bin ${GEN}/payload_table.h ${MANIFEST_SOURCE}) add_dependencies(WrongGPU WrongGPU-Restore) if(WRONGGPU_TESTING) + target_sources(WrongGPU PRIVATE ${GEN}/testing_identity.rc) + if(MSVC) + target_link_options(WrongGPU PRIVATE /RELEASE) + endif() + # the launcher suite's negative controls: programs that are not testing builds (no identity), one with the hook strings; + # each leaves .started next to itself when it starts, so the suite can prove it never started them + add_executable(wg-test-canary tests/canary.cpp) + add_executable(wg-test-canary-strings tests/canary.cpp) + target_compile_definitions(wg-test-canary-strings PRIVATE WG_CANARY_HOOK_STRINGS) + if(NOT MSVC) + target_link_options(wg-test-canary PRIVATE -municode) # (wmain, as the launcher and restorer) + target_link_options(wg-test-canary-strings PRIVATE -municode) + endif() + add_library(wg-test-canary-dll SHARED tests/canary_dll.cpp) # a load marker: writes .loaded when loaded + set_target_properties(wg-test-canary-dll PROPERTIES PREFIX "") + # built with the testing launcher (a single-target build has them), and the build list the suite checks before it starts + # one: the SHA-256 of this WrongGPU.exe and of the canaries, written after the launcher's link + add_dependencies(WrongGPU wg-test-canary wg-test-canary-strings wg-test-canary-dll) + add_custom_command(TARGET WrongGPU POST_BUILD + COMMAND ${CMAKE_COMMAND} -DF1=$ -DF2=$ -DF3=$ + -DF4=$ + -DOUT=$/wg-test-build.sha256 -P ${CMAKE_CURRENT_SOURCE_DIR}/tools/sha256_list.cmake + VERBATIM) add_executable(wizard-policy-tests tests/wizard_policy_tests.cpp) target_compile_definitions(wizard-policy-tests PRIVATE ${PRESET_K_DEFINITION} ${DIRECT_ROUTE_DEFINITION} ${MODEL_L_DEFINITION} ${MODEL_K_DEFINITION}) endif() diff --git a/clean/installer/README.md b/clean/installer/README.md index 33d6be67..53ffa1a5 100644 --- a/clean/installer/README.md +++ b/clean/installer/README.md @@ -920,7 +920,7 @@ Windows (the Wine run was not repeated for them): the list and line), converted again by a second game's install, a list held open (exit 10), and the last game's uninstall keeping `ignore-files.txt` with the kept line in its result. - `tests/run_launcher_tests.py --launcher --work [--baseline <0.5.1 WrongGPU-Setup.exe>] - [--hip ]`: the verbs against generated fixture games (names and synthetic bytes only) with a + [--hip ] [--no-direct-launcher ] [--rr-prepare-gpu]`: the verbs against generated fixture games (names and synthetic bytes only) with a `WRONGGPU_TESTING` build of the suite's test map: scan statuses, refusals (anti-cheat, DLSS-NR) with nothing changed, install (record v2, owned-files.json, the restorer as uninstall.exe, the managed list), set/get with validation, OptiScaler's FPS key, an outside edit and its revert, the last run from a synthetic log, update with `previous\`, @@ -929,6 +929,48 @@ Windows (the Wine run was not repeated for them): the experimental confirmation, the model kept while another managed game uses it, adoption of a real 0.5.1 install (v1 record, settings imported, restorer, entries), self-install / self-uninstall with one Apps & features entry, portable paths, the update check off, and the window built hidden (`ui-dump`: pages, names, visibility). + The suite runs only `WRONGGPU_TESTING` builds, by their identity: the named resource `WRONGGPU_TESTING_BUILD` only such + a build links in, a PE checksum that matches (MSVC `/RELEASE`: a program changed or appended to after its link fails) + and the test hooks' strings inside its sections. Every launcher it is given, their copies and the `uninstall.exe` they + write are checked before they run; anything else is refused unrun (a release launcher could reach the real download + page, the PC's stores and the real Apps & features root). Negative controls: `wg-test-canary` and + `wg-test-canary-strings` (not testing builds, the second carrying the hooks' strings) are built with a testing + `WrongGPU` target, which then writes `wg-test-build.sha256` (the SHA-256 of that `WrongGPU.exe` and of the canaries) + next to itself. The suite starts only canaries that list verifies as this build's, by their full path and with its own + child environment: they start when run directly and are refused through every launch path. The 0.5.1 baseline predates + the hooks: `--run-old-baseline` runs it OUTSIDE the suite's isolation guarantee, unchecked, and only in a disposable, + fully redirected sandbox. `--work` must be a plain folder (no junction or link in it or above it, no `;`): each run makes + a NEW folder of its own in it (`run--`) and writes everything there, nested test instances in new folders of + their own, so nothing that was in `--work` before is written to, followed or loaded. Every launcher call gets its + instance's fresh `tmp` as `TEMP` and `TMP`, and no inherited test override (`WRONGGPU_TEST_*`, `WG_*`; + `WRONGGPU_HIP_RUNTIME` only from `--hip`, which must be an existing plain file; an empty `--hip=` is refused). Checks that depend on how the launcher was built follow the build under + test (`launcher_build_facts.py`). The edition section always runs with `--launcher`: its download, cache and address + rules on either route, and a repair without any OptiScaler ending through the direct route (exit 0) or refused (exit 2) + without it. `--no-direct-launcher` (a testing build with `-DWRONGGPU_DIRECT_ROUTE=OFF`, as releases) runs the section + again in a pass of its own for the exit-2 refusals. rr-prepare stays in the work folder: its no-card path, and with the + suite's stand-in runtime the helper's expected failure to load it (under a test driver version, so on any PC) with the + suite's `LOCALAPPDATA` kept. The checks of RR's kernels really prepared need a payload with the real runtime and fill the + user's real graphics driver cache, so they run only with `--rr-prepare-gpu`. A test build starts no rr-prepare helper + unless the test allows it (`WRONGGPU_TEST_ALLOW_RR_HELPER=1`: the stand-in case and the opt-in pass only). Test builds' + other hooks for this: `WRONGGPU_TEST_RR_DRIVER` (a driver version, or `none`), `WRONGGPU_TEST_HELPER_ENV_LOG`, and + `WRONGGPU_TEST_REAL_DRIVER_CACHE=1` (the helper gets the user's real `LOCALAPPDATA`; release builds always do). + The HIP check only ever tries `--hip` (an existing file, named at the start), or in a default run a file in the run + folder that is not there (`WRONGGPU_TEST_HIP_CANDIDATES`): a default run never loads a real HIP runtime. + On a fresh clone, from the repository root in an x64 Visual Studio developer prompt (PowerShell), with nothing else + needed (a single `WrongGPU` target builds the restorer and the canaries too): + + ``` + python clean/installer/tests/run_installer_tests.py --work out/mock --prepare-only + $common = @("-G", "Ninja", "-DCMAKE_BUILD_TYPE=Release", "-DCMAKE_POLICY_DEFAULT_CMP0091=NEW", "-DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded", + "-DWRONGGPU_PAYLOAD_DIR=$PWD/out/mock/prepared/payload", "-DWRONGGPU_MAP=$PWD/out/mock/prepared/test-map.json", + "-DWRONGGPU_VERSION=0.3.0-test", "-DWRONGGPU_TESTING=ON") + cmake -S clean/installer -B out/launcher-test @common + cmake --build out/launcher-test --target WrongGPU + cmake -S clean/installer -B out/launcher-test-nodirect @common -DWRONGGPU_DIRECT_ROUTE=OFF + cmake --build out/launcher-test-nodirect --target WrongGPU + python clean/installer/tests/run_launcher_tests.py --launcher out/launcher-test/WrongGPU.exe --work out/launcher-suite --no-direct-launcher out/launcher-test-nodirect/WrongGPU.exe + ``` + Its `[direct-rr]` part: a game that ships the RR library without the game interface's RR plugin (the Unreal Engine plugin layout of Hogwarts Legacy, LEGO Batman, Borderlands 4) creates Ray Reconstruction itself (`rr.h` `RrUse::direct`; status `rr_direct`). WrongGPU's RR runs there only through WrongGPU's edition of OptiScaler (plugin @@ -994,7 +1036,8 @@ The run stops, loudly, on: The `[isolation-verbs]` section runs install, repair, update, uninstall, the window's refresh, a batch (a noscan job, then a normal one) and `/FSR4` / `/LIST`, with and without no-scan, against a non-empty test library. The 0.5.1 baseline installer -predates all this and runs only with `--run-old-baseline`, in a fully redirected sandbox. +predates all this and runs only with `--run-old-baseline`: outside the suite's isolation guarantee, in a disposable, fully +redirected sandbox. On Windows: `python tests\run_installer_tests.py --prepare-only` writes the mock payload and the synthetic map; build the installer from them with CMake (`-DWRONGGPU_TESTING=ON -DWRONGGPU_PAYLOAD_DIR=... -DWRONGGPU_MAP=...`) and run diff --git a/clean/installer/src/wg_core/checks.cpp b/clean/installer/src/wg_core/checks.cpp index 37709316..322fdeb1 100644 --- a/clean/installer/src/wg_core/checks.cpp +++ b/clean/installer/src/wg_core/checks.cpp @@ -156,8 +156,17 @@ bool VersionLess(const wstring& a, const wstring& b) { std::vector HipCandidates() { std::vector c; #ifdef WRONGGPU_TESTING - const wstring mocks = EnvVar(L"WRONGGPU_TEST_HIP_CANDIDATES"); - if (!mocks.empty()) { + // tests: WRONGGPU_TEST_HIP_CANDIDATES set (even empty, or too long to read) is the whole list: never the system's, + // PATH's or ROCm's runtime; set but empty or unreadable: no candidate at all + SetLastError(ERROR_SUCCESS); + const DWORD need = GetEnvironmentVariableW(L"WRONGGPU_TEST_HIP_CANDIDATES", nullptr, 0); + if (need > 0 || GetLastError() != ERROR_ENVVAR_NOT_FOUND) { + wstring mocks; + if (need > 1) { + mocks.resize(need); + const DWORD got = GetEnvironmentVariableW(L"WRONGGPU_TEST_HIP_CANDIDATES", mocks.data(), need); + mocks.resize(got > 0 && got < need ? got : 0); + } for (size_t i = 0; i < mocks.size();) { const size_t end = mocks.find(L';', i); c.push_back(mocks.substr(i, end == wstring::npos ? end : end - i)); diff --git a/clean/installer/src/wg_core/optiscaler.cpp b/clean/installer/src/wg_core/optiscaler.cpp index 2b3b4635..be864e68 100644 --- a/clean/installer/src/wg_core/optiscaler.cpp +++ b/clean/installer/src/wg_core/optiscaler.cpp @@ -48,6 +48,7 @@ OptiPackage PrepareOptiScaler(Context& ctx, const wstring& chosen) { const int code = RunHiddenWait(tar, L"-xf \"" + p.source + L"\" -C \"" + Join(p.tempDir, L"package") + L"\"", 300000); if (code != 0) { p.error = L"Could not unpack " + BaseName(p.source) + L" (tar exit code " + std::to_wstring(code) + L") - unpack it yourself and choose its folder"; return p; } root = Join(p.tempDir, L"package"); + LogLine(ctx, L"OptiScaler: unpacked " + BaseName(p.source) + L" in " + p.tempDir); } else { p.error = L"Choose OptiScaler's release archive (.7z or .zip), the folder you unpacked it to, or the OptiScaler.dll in it"; return p; diff --git a/clean/installer/src/wg_core/rrprep.cpp b/clean/installer/src/wg_core/rrprep.cpp index a0a833cf..02cfee1a 100644 --- a/clean/installer/src/wg_core/rrprep.cpp +++ b/clean/installer/src/wg_core/rrprep.cpp @@ -60,13 +60,21 @@ void WritePrepared(const wstring& dataDir, const PrepLine& now) { WriteFileAtomic(PrepFile(dataDir), text.data(), text.size()); } -// the environment for the helper: this one, with LOCALAPPDATA set to the user's real local app data folder (the driver -// keeps its shader cache there; a launcher started with another LOCALAPPDATA, as the tests' sandbox does, must still -// prepare the cache the game finds) and the runtime's log in the launcher's data folder (never a new file in the game) -std::vector HelperEnvironment(const wstring& log) { +} // namespace + +// the environment for the helper (rrprep.h): this one, with LOCALAPPDATA set to the user's real local app data folder (the +// driver keeps its shader cache there; a launcher started with another LOCALAPPDATA must still prepare the cache the game +// finds) and the runtime's log in the launcher's data folder (never a new file in the game). A WRONGGPU_TESTING build keeps +// the tests' redirected LOCALAPPDATA unless WRONGGPU_TEST_REAL_DRIVER_CACHE=1 (the explicit opt-in of a test that fills the +// real driver cache): the default test run stays in its work folder. +std::vector RrHelperEnvironment(const wstring& log) { wstring local; + bool real = true; +#ifdef WRONGGPU_TESTING + real = EnvVar(L"WRONGGPU_TEST_REAL_DRIVER_CACHE") == L"1"; +#endif PWSTR p = nullptr; - if (SUCCEEDED(SHGetKnownFolderPath(FOLDERID_LocalAppData, KF_FLAG_DONT_VERIFY, nullptr, &p)) && p) local = p; + if (real && SUCCEEDED(SHGetKnownFolderPath(FOLDERID_LocalAppData, KF_FLAG_DONT_VERIFY, nullptr, &p)) && p) local = p; if (p) CoTaskMemFree(p); std::vector env; LPWCH block = GetEnvironmentStringsW(); @@ -86,9 +94,12 @@ std::vector HelperEnvironment(const wstring& log) { return env; } -} // namespace - wstring RrDriverVersion() { +#ifdef WRONGGPU_TESTING + // tests: a driver version of their own ("none": no AMD graphics card), so that rr-prepare's paths run on any PC without + // touching the GPU (the suite sets it only with its stand-in runtime, which the helper cannot load) + if (const wstring t = EnvVar(L"WRONGGPU_TEST_RR_DRIVER"); !t.empty()) return t == L"none" ? wstring() : t; +#endif HMODULE m = LoadSystemDll(L"dxgi.dll"); if (!m) return L""; typedef HRESULT(WINAPI * Create)(REFIID, void**); @@ -181,6 +192,15 @@ int PrepareRr(Context& ctx, const wstring& dataDir, const wstring& exe, const ws const wstring driver = RrDriverVersion(); if (driver.empty()) { if (why) *why = L"no AMD graphics card found"; return 2; } if (!IsFile(runtimeDll)) { if (why) *why = L"the runtime isn't there (" + runtimeDll + L")"; return 3; } +#ifdef WRONGGPU_TESTING + // tests: a test build starts no helper unless the test allows it (WRONGGPU_TEST_ALLOW_RR_HELPER=1): whatever was decided + // above, a default test run never prepares anything on the GPU + if (EnvVar(L"WRONGGPU_TEST_ALLOW_RR_HELPER") != L"1") { + if (why) *why = L"test: the helper may not start (WRONGGPU_TEST_ALLOW_RR_HELPER)"; + LogLine(ctx, L"Ray Reconstruction: test: the helper may not start for " + BaseName(exe) + L" (WRONGGPU_TEST_ALLOW_RR_HELPER)"); + return 3; + } +#endif const wstring run = Join(PrepDir(dataDir), L"run"); EnsureDir(run); const wstring helper = Join(run, BaseName(exe)); @@ -204,7 +224,7 @@ int PrepareRr(Context& ctx, const wstring& dataDir, const wstring& exe, const ws wstring cmd = L"\"" + helper + L"\" --rr-prepare \"" + runtimeDll + L"\" " + std::to_wstring(passes); std::vector cl(cmd.begin(), cmd.end()); cl.push_back(0); - std::vector env = HelperEnvironment(log); + std::vector env = RrHelperEnvironment(log); const BOOL ok = CreateProcessW(helper.c_str(), cl.data(), nullptr, nullptr, TRUE, CREATE_NO_WINDOW | CREATE_UNICODE_ENVIRONMENT | BELOW_NORMAL_PRIORITY_CLASS, env.data(), run.c_str(), &si, &pi); CloseHandle(wr); @@ -275,6 +295,18 @@ int PrepareRr(Context& ctx, const wstring& dataDir, const wstring& exe, const ws int RunRrPrepareHelper(int argc, wchar_t** argv) { if (argc < 4) return 9; +#ifdef WRONGGPU_TESTING + // tests: the LOCALAPPDATA the helper was started with, appended to this file before the runtime is loaded + if (const wstring f = EnvVar(L"WRONGGPU_TEST_HELPER_ENV_LOG"); !f.empty()) { + const string line = ToUtf8(L"LOCALAPPDATA=" + EnvVar(L"LOCALAPPDATA")) + "\n"; + HANDLE h = CreateFileW(f.c_str(), FILE_APPEND_DATA, FILE_SHARE_READ | FILE_SHARE_WRITE, nullptr, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr); + if (h != INVALID_HANDLE_VALUE) { + DWORD w = 0; + WriteFile(h, line.data(), (DWORD)line.size(), &w, nullptr); + CloseHandle(h); + } + } +#endif HMODULE m = LoadLibraryExW(argv[2], nullptr, LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR | LOAD_LIBRARY_SEARCH_SYSTEM32); if (!m) return 8; typedef int (*Cb)(void*, uint32_t, uint32_t, uint32_t, const char*, uint32_t, uint32_t); diff --git a/clean/installer/src/wg_core/rrprep.h b/clean/installer/src/wg_core/rrprep.h index 03ae8b02..35742056 100644 --- a/clean/installer/src/wg_core/rrprep.h +++ b/clean/installer/src/wg_core/rrprep.h @@ -30,6 +30,7 @@ #include "context.h" #include +#include namespace wg { @@ -60,5 +61,9 @@ int PrepareRr(Context& ctx, const wstring& dataDir, const wstring& exe, const ws const std::function& progress, wstring* why); // The helper side: ` --rr-prepare ` (main.cpp, before anything else of the launcher runs). int RunRrPrepareHelper(int argc, wchar_t** argv); +// The helper's environment block (NUL-separated, two NULs at the end): this process's, with WG_RR_LOG=log and LOCALAPPDATA +// set to the user's real local app data folder, where the graphics driver keeps its shader cache. A WRONGGPU_TESTING build +// keeps this process's LOCALAPPDATA (the tests' sandbox) unless WRONGGPU_TEST_REAL_DRIVER_CACHE=1. +std::vector RrHelperEnvironment(const wstring& log); } // namespace wg diff --git a/clean/installer/tests/canary.cpp b/clean/installer/tests/canary.cpp new file mode 100644 index 00000000..ee522884 --- /dev/null +++ b/clean/installer/tests/canary.cpp @@ -0,0 +1,26 @@ +// SPDX-License-Identifier: MIT +// The launcher suite's negative control (tests/launcher_build_facts.py self_checks): a program that is not a WRONGGPU_TESTING +// build. When it starts it writes .started, so the suite can prove its preflight never let it run. +// WG_CANARY_HOOK_STRINGS: it also carries the test hooks' strings, as a program that only looks like a testing build would. +// Written for this project. +#include + +#ifdef WG_CANARY_HOOK_STRINGS +const wchar_t* volatile kStrings[] = {L"WRONGGPU_TEST_LIBRARIES", L"WRONGGPU_TEST_ACCESS_LOG", L"WRONGGPU_TEST_EDITION", + L"WrongGPU-CandidateTests"}; +#endif + +int wmain() { + wchar_t path[MAX_PATH + 16] = {0}; + DWORD n = GetModuleFileNameW(NULL, path, MAX_PATH); + if (n == 0 || n >= MAX_PATH) return 2; + lstrcatW(path, L".started"); + HANDLE h = CreateFileW(path, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); + if (h == INVALID_HANDLE_VALUE) return 3; + CloseHandle(h); +#ifdef WG_CANARY_HOOK_STRINGS + return kStrings[0][0] == L'W' ? 0 : 1; +#else + return 0; +#endif +} diff --git a/clean/installer/tests/canary_dll.cpp b/clean/installer/tests/canary_dll.cpp new file mode 100644 index 00000000..c7372544 --- /dev/null +++ b/clean/installer/tests/canary_dll.cpp @@ -0,0 +1,17 @@ +// SPDX-License-Identifier: MIT +// The launcher suite's load marker (tests/launcher_build_facts.py self_checks): a DLL that writes .loaded when +// it is loaded, so the suite can prove a planted stand-in was never loaded. Not a HIP runtime. Written for this project. +#include + +BOOL WINAPI DllMain(HINSTANCE self, DWORD reason, LPVOID) { + if (reason == DLL_PROCESS_ATTACH) { + wchar_t path[MAX_PATH + 16] = {0}; + const DWORD n = GetModuleFileNameW(self, path, MAX_PATH); + if (n > 0 && n < MAX_PATH) { + lstrcatW(path, L".loaded"); + HANDLE h = CreateFileW(path, GENERIC_WRITE, 0, nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr); + if (h != INVALID_HANDLE_VALUE) CloseHandle(h); + } + } + return TRUE; +} diff --git a/clean/installer/tests/launcher_build_facts.py b/clean/installer/tests/launcher_build_facts.py new file mode 100644 index 00000000..ba207a2e --- /dev/null +++ b/clean/installer/tests/launcher_build_facts.py @@ -0,0 +1,455 @@ +# SPDX-License-Identifier: MIT +"""What the launcher under test was built with, for run_launcher_tests.py: checks that follow the build instead of assuming +a release build (a fresh clone's suite build differs from a release in its version, its payload and its direct route). +Kept out of run_launcher_tests.py, which stays below the 256 KB source limit. Written for this project.""" +import os +import re +import shutil + +from run_installer_tests import read, write, STAND_IN_RUNTIME + + +def restorer_ok(un, exe): + """uninstall.exe is the restorer, not the launcher: byte for byte the restorer built next to the launcher + (WrongGPU-Restore.exe) when that is there, else at least smaller than the launcher and not its bytes.""" + if not os.path.isfile(un): + return False + built = os.path.join(os.path.dirname(exe), "WrongGPU-Restore.exe") + if os.path.isfile(built): + return read(un) == read(built) + return os.path.getsize(un) < os.path.getsize(exe) and read(un) != read(exe) + + +def older_version(version): + """A version below the launcher's own ("0.3.0-test" -> "0.2.9"; "0.6.5" -> "0.6.4"; "1.0.0" -> "0.9.9"), for a faked + record of an earlier install. None when there is none (0.0.0).""" + m = re.match(r"(\d+)\.(\d+)\.(\d+)", version or "") + if not m: + return None + a, b, c = (int(x) for x in m.groups()) + if c: + return "%d.%d.%d" % (a, b, c - 1) + if b: + return "%d.%d.9" % (a, b - 1) + if a: + return "%d.9.9" % (a - 1) + return None + + +def stand_in_runtime(folder): + """Whether the WrongGPU runtime installed in folder is the suite's own stand-in (run_installer_tests payload), which + has no kernels and cannot prepare anything on a GPU.""" + p = os.path.join(folder, "wronggpu_runtime.dll") + return os.path.isfile(p) and read(p) == STAND_IN_RUNTIME + + +# The test isolation hooks a WRONGGPU_TESTING build compiles in (each string is only in such a build, behind #ifdef): its +# store libraries from the test folder only and every store access logged (#243), the edition download from the test server +# only, and an Apps & features root of its own per test run. A release launcher has none of them: run by the suite, it could +# reach the real download page, the PC's own stores and the real uninstall registry root before any check sees it. +TEST_HOOKS = ("WRONGGPU_TEST_LIBRARIES", "WRONGGPU_TEST_ACCESS_LOG", "WRONGGPU_TEST_EDITION", "WrongGPU-CandidateTests") +_hooks_ok = {} + + +IDENTITY_NAME = "WRONGGPU_TESTING_BUILD" # the named RCDATA resource only a WRONGGPU_TESTING build links in (CMakeLists.txt) +IDENTITY_TEXT = b"wg-testing-build 1: store libraries, access log, edition download, uninstall root" + + +def pe_checksum(data, at): + """The PE image checksum of data (the field at offset at counted as 0): what the linker (/RELEASE) writes.""" + import array + body = bytearray(data[:at]) + b"\0\0\0\0" + data[at + 4:] + if len(body) % 2: + body += b"\0" + total = sum(array.array("H", bytes(body))) + s = total % 0xFFFF + if s == 0 and total: + s = 0xFFFF + return (s + len(data)) & 0xFFFFFFFF + + +def testing_identity(data): + """Why data is not a WRONGGPU_TESTING build's program, read from its structure ('' when it is one): a valid PE whose + checksum matches (nothing changed or appended after its link), the identity resource in its resource directory, and the + test hooks' strings inside its sections (not in data appended to it).""" + import struct + try: + if data[:2] != b"MZ": + return "not a program (no MZ header)" + pe = struct.unpack_from("\\tmp, the launcher's TEMP and TMP: refused when it or a folder above it is a reparse point (it could lead + outside the work folder), else removed and made anew, empty.""" + tmp = os.path.join(os.path.abspath(work), "tmp") + bad = reparse_in_path(tmp) + if bad: + raise SystemExit("the suite's temporary folder %s is not a plain folder (%s is a junction or link): not run" % (tmp, bad)) + shutil.rmtree(tmp, ignore_errors=True) + os.makedirs(tmp) + return tmp + + +def new_run_folder(root, prefix="run"): + """A NEW folder of its own in root (--[-n], made with exist_ok off), where a run (or a nested test + instance) writes everything: nothing that was in root before is written to, followed or removed. Refused when root holds + ';' (it would split the HIP candidate list) or it or a folder above it is a junction or link.""" + import time + root = os.path.abspath(root) + if ";" in root: + raise SystemExit("--work %s holds ';': not run" % root) + bad = reparse_in_path(root) + if bad: + raise SystemExit("--work %s is not a plain folder (%s is a junction or link): not run" % (root, bad)) + os.makedirs(root, exist_ok=True) + base = os.path.join(root, "%s-%s-%d" % (prefix, time.strftime("%Y%m%dT%H%M%SZ", time.gmtime()), os.getpid())) + for n in range(100): + run = base if n == 0 else "%s-%d" % (base, n) + try: + os.mkdir(run) + except FileExistsError: + continue + if reparse_in_path(run): + raise SystemExit("the run folder %s is not a plain folder: not run" % run) + return run + raise SystemExit("no new run folder could be made in %s" % root) + + +CANARIES = ("wg-test-canary.exe", "wg-test-canary-strings.exe") +LOAD_MARKER = "wg-test-canary-dll.dll" # writes .loaded when loaded (tests/canary_dll.cpp) +BUILD_LIST = "wg-test-build.sha256" # written by the build next to the launcher: SHA-256 of WrongGPU.exe and the canaries + + +def verified_canaries(exe): + """The canaries built in THIS build: their names in \\wg-test-build.sha256 (written by the testing build + after it links WrongGPU.exe, CMakeLists.txt), whose WrongGPU.exe line is this launcher's SHA-256 and whose canary lines + match the files. Returns ({name: bytes}, why not); a file that is not verified is never started.""" + import hashlib + d = os.path.dirname(os.path.abspath(exe)) + try: + lines = read(os.path.join(d, BUILD_LIST)).decode("ascii").split() + except (OSError, UnicodeDecodeError) as e: + return {}, "no build list %s (%s)" % (BUILD_LIST, e) + listed = dict(zip(lines[1::2], lines[0::2])) + if listed.get("WrongGPU.exe") != hashlib.sha256(read(exe)).hexdigest(): + return {}, "the build list is not this launcher's (another build)" + out = {} + for name in CANARIES + (LOAD_MARKER,): + p = os.path.join(d, name) + data = read(p) if os.path.isfile(p) else b"" + if not data or listed.get(name) != hashlib.sha256(data).hexdigest(): + return {}, "%s is missing or not the one this build made" % name + out[name] = data + return out, "" + + +def junction_call(t, exe, verb, work): + """The data-root junction test's launcher call without --log (its log goes to TEMP\\WrongGPU-junction-.log, TEMP being + the work folder's tmp): the preflight first, as for every launcher call. Returns (exit code, the log's text).""" + import subprocess + import launcher_isolation as iso + out = os.path.join(work, verb + "-result.json") + astart = iso.access_size(t.work) + require_test_hooks(exe) # a testing build only, before it starts + proc = subprocess.Popen([exe, verb, "--out=" + out], env=t.env, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + proc.communicate(timeout=180) + log = os.path.join(t.env["TEMP"], "WrongGPU-junction-%d.log" % proc.pid) + assert os.path.abspath(log).lower().startswith(os.path.abspath(t.work).lower() + os.sep), log + iso.check_isolation(log if os.path.isfile(log) else None, t.work, 0, (verb,), astart) # (#243: every launcher call) + text = read(log).decode("utf-8", "replace") if os.path.isfile(log) else "" + if os.path.isfile(log): + os.remove(log) + return proc.returncode, text + + +def rr_free(folder, record): + """No RR settings file in an RR-free install: neither WrongGPU\\wronggpu.ini on disk (case-insensitively: on Windows the + payload's own lower-case wronggpu\\ folder is the same folder, and its kernels are allowed) nor its record line.""" + return not os.path.isfile(os.path.join(folder, "WrongGPU", "wronggpu.ini")) and "wronggpu\\wronggpu.ini" not in record.lower() + + +def self_checks(t): + """The suite's own guards on synthetic files, before any launcher call: a program without the test isolation hooks is + refused before it runs (nothing started, nothing logged), the launcher under test has the hooks, and the RR-free check + finds an RR settings file that landed in the payload's lower-case wronggpu\\ folder.""" + print("\n[self-checks] the suite's guards: only testing builds run; the RR-free check") + import subprocess + import sys + d = os.path.join(t.work, "self-checks") + shutil.rmtree(d, ignore_errors=True) + os.makedirs(d) + t.check("preflight: the launcher under test is a WRONGGPU_TESTING build (its identity resource, a matching PE checksum, the hooks)", + not missing_test_hooks(t.exe), missing_test_hooks(t.exe)) + # programs that are not testing builds, each leaving .started when it starts (tests/canary.cpp; built with the + # launcher in a testing build): one plain, one carrying the hooks' strings. Only the canaries THIS build made are ever + # started (their SHA-256 in the build list next to the launcher, with this launcher's), by their full path, with the + # suite's own child environment: first directly, to show they do start + import hashlib + size = lambda: os.path.getsize(t.log) if os.path.isfile(t.log) else 0 + canaries, why_not = verified_canaries(t.exe) + t.check("negative controls: the canaries are this build's (wg-test-build.sha256 next to the launcher names this launcher " + "and the canaries' bytes)", bool(canaries), why_not) + for name in [n for n in CANARIES if n in canaries]: + data = canaries[name] + canary = os.path.join(d, name) + write(canary, data) + started = canary + ".started" + if hashlib.sha256(read(canary)).digest() != hashlib.sha256(data).digest(): + t.check("negative control %s: the copy is the verified file" % name, False) + continue + subprocess.run([canary], env=t.env, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, timeout=60) + runs = os.path.isfile(started) + if runs: + os.remove(started) + before, why, jwhy, rwhy = size(), "", "", "" + try: + t.run("version", exe=canary) + except SystemExit as e: + why = str(e) + try: + junction_call(t, canary, "remove-data", d) # the data-root junction test's path + except SystemExit as e: + jwhy = str(e) + try: + t.raw([canary, "/S"]) # a program run as it is (the restorer's path) + except SystemExit as e: + rwhy = str(e) + entry = [] + suite = os.path.join(os.path.dirname(os.path.abspath(__file__)), "run_launcher_tests.py") + for args in (["--launcher", canary], ["--launcher", t.exe, "--no-direct-launcher", canary]): # the suite's entry points + p = subprocess.run([sys.executable, suite] + args + ["--work", os.path.join(d, "entry")], env=dict(os.environ), + stdout=subprocess.PIPE, stderr=subprocess.PIPE, timeout=300) + entry.append(p.returncode != 0 and b"not a WRONGGPU_TESTING build" in p.stderr + p.stdout) + t.check("negative control %s: it starts when run directly (its start marker); the suite never starts it (a launcher call, " + "the junction test's call, a program run as it is, --launcher, --no-direct-launcher): refused before it runs, no start " + "marker, nothing logged" % name, + runs and all("not a WRONGGPU_TESTING build" in w for w in (why, jwhy, rwhy)) and entry == [True, True] and + not os.path.exists(started) and size() == before, (runs, why, jwhy, rwhy, entry)) + # the real launcher changed after its link: one byte, or data appended (the hooks' strings and the identity text) + data = read(t.exe) + mid = len(data) // 2 + mixed = {"one byte changed": data[:mid] + bytes([data[mid] ^ 0xFF]) + data[mid + 1:], + "data appended": data + b"".join(m.encode("utf-16-le") for m in TEST_HOOKS) + IDENTITY_TEXT} + if "wg-test-canary-strings.exe" in canaries: # the hooks' strings and a valid checksum, but no identity resource + import struct + c = bytearray(canaries["wg-test-canary-strings.exe"]) + at = struct.unpack_from(" probe code", 1)[0] for l in read(t.log)[start:].decode("utf-8", "replace").splitlines() + if "HIP check: " in l and " -> probe code" in l] + allowed = os.path.abspath(t.hip or os.path.join(t.work, "no-hip", "amdhip64_7.dll")).lower() + t.check("HIP check: only the --hip mock (a default run: a file in the work folder that is not there) is tried; never a system, " + "PATH or ROCm runtime, nor an inherited WRONGGPU_HIP_RUNTIME or candidate list", + env.get("WRONGGPU_HIP_RUNTIME") == t.hip and len(tried) == 1 and os.path.abspath(tried[0]).lower() == allowed and + conflict.lower() not in " ".join(tried).lower(), (tried, allowed, t.j)) + # --work: a junction (to another folder) is refused before the isolation self-test writes or removes anything in it + target, jroot = os.path.join(d, "work-target"), os.path.join(d, "work-junction") + write(os.path.join(target, "library-access.log"), b"keep") + jlinked = subprocess.run(["cmd.exe", "/d", "/c", "mklink", "/J", jroot, target], stdout=subprocess.PIPE, stderr=subprocess.PIPE).returncode == 0 + suite = os.path.join(os.path.dirname(os.path.abspath(__file__)), "run_launcher_tests.py") + p = subprocess.run([sys.executable, suite, "--launcher", t.exe, "--work", jroot], env=dict(os.environ), + stdout=subprocess.PIPE, stderr=subprocess.PIPE, timeout=300) + t.check("--work: a junction is refused before the isolation self-test or any create or delete in it (its target untouched)", + jlinked and p.returncode != 0 and b"junction or link" in p.stderr + p.stdout and sorted(os.listdir(target)) == ["library-access.log"] and + read(os.path.join(target, "library-access.log")) == b"keep", (jlinked, p.returncode, (p.stderr + p.stdout)[-300:], os.listdir(target))) + if os.path.lexists(jroot): + os.rmdir(jroot) # (the junction only) + # --work holding ';', and an explicit empty --hip=: refused before anything is made, anywhere (the work path stays absent, + # and nothing in the tests folder changes: no bytecode either) + here = os.path.dirname(os.path.abspath(__file__)) + + def tree(top): + out = {} + for dp, dn, fn in os.walk(top): + for f in fn: + st = os.stat(os.path.join(dp, f)) + out[os.path.relpath(os.path.join(dp, f), top)] = (st.st_size, st.st_mtime_ns) + return out + + entry, before_tree = {}, tree(here) + child = dict(os.environ) + child.pop("PYTHONDONTWRITEBYTECODE", None) # (the suite itself must keep its source tree clean) + for name, args, folder in (("--work with ';'", ["--work", os.path.join(d, "semi;colon")], os.path.join(d, "semi;colon")), + ("--hip=", ["--work", os.path.join(d, "hip-empty"), "--hip="], os.path.join(d, "hip-empty"))): + p = subprocess.run([sys.executable, suite, "--launcher", t.exe] + args, env=child, + stdout=subprocess.PIPE, stderr=subprocess.PIPE, timeout=300) + entry[name] = p.returncode != 0 and b"not run" in p.stderr + p.stdout and not os.path.exists(folder) + changed = sorted(k for k in set(before_tree) | set(tree(here)) if before_tree.get(k) != tree(here).get(k)) + t.check("--work holding ';' (it would split the HIP candidate list) and an explicit empty --hip= are refused before anything " + "is made: the work path absent, nothing in the tests folder changed (no bytecode)", all(entry.values()) and not changed, + (entry, changed[:5])) + # the run's own fresh folder: a work root that already holds a link at library-access.log (to user data) and a load-marker + # DLL at no-hip\amdhip64_7.dll, where an older run wrote, gets a run's real start and HIP check (a child suite run, + # --startup-only); both fixtures freshly planted here in a simulated root inside this run folder, and checked to work + sim = new_run_folder(t.work, "simulated-work") + user = os.path.join(d, "user-data.txt") + write(user, b"user data") + link, stand_in, kind = os.path.join(sim, "library-access.log"), os.path.join(sim, "no-hip", "amdhip64_7.dll"), "" + try: + os.symlink(user, link) + kind = "symbolic link" + except OSError: + os.link(user, link) + kind = "hard link" + linked = os.path.lexists(link) and read(link) == b"user data" + marker_dll, loads = canaries.get(LOAD_MARKER), False + if marker_dll: + probe = os.path.join(d, "marker-probe", "amdhip64_7.dll") # the marker works: loaded here, it writes .loaded + write(probe, marker_dll) + import ctypes + h = ctypes.WinDLL(probe) + ctypes.windll.kernel32.FreeLibrary(ctypes.c_void_p(h._handle)) + loads = os.path.isfile(probe + ".loaded") + write(stand_in, marker_dll) + planted = sorted(os.listdir(sim)) + p = subprocess.run([sys.executable, suite, "--launcher", t.exe, "--work", sim, "--startup-only"], env=child, + stdout=subprocess.PIPE, stderr=subprocess.PIPE, timeout=600) + after = sorted(os.listdir(sim)) + runs = [n for n in after if n not in planted] + t.check("the run's own fresh folder: a work root holding a %s at library-access.log (to user data) and a load-marker DLL at " + "no-hip\\amdhip64_7.dll (both planted here and shown to work) gets a run's real start and HIP check (a child suite " + "run): one new run folder, the link, its target and the DLL unchanged, no load marker" % (kind or "link"), + planted == ["library-access.log", "no-hip"] and linked and loads and p.returncode == 0 and + len(runs) == 1 and runs[0].startswith("run-") and read(user) == b"user data" and read(link) == b"user data" and + read(stand_in) == marker_dll and not os.path.exists(stand_in + ".loaded") and sorted(os.listdir(os.path.dirname(stand_in))) == ["amdhip64_7.dll"], + (kind, linked, loads, p.returncode, after, (p.stderr + p.stdout)[-400:])) + os.remove(link) # (the link only, never its target) + # the temporary folder: a junction in its place is refused (fresh_temp), never followed + jw = os.path.join(d, "junction-work") + os.makedirs(os.path.join(d, "elsewhere")) + os.makedirs(jw) + linked = subprocess.run(["cmd.exe", "/d", "/c", "mklink", "/J", os.path.join(jw, "tmp"), os.path.join(d, "elsewhere")], + stdout=subprocess.PIPE, stderr=subprocess.PIPE).returncode == 0 + jwhy = "" + try: + fresh_temp(jw) + except SystemExit as e: + jwhy = str(e) + t.check("the suite's temporary folder: a junction in its place (or above it) is refused, never followed or emptied", + linked and "junction or link" in jwhy and os.path.isdir(os.path.join(d, "elsewhere")), (linked, jwhy)) + if os.path.lexists(os.path.join(jw, "tmp")): + os.rmdir(os.path.join(jw, "tmp")) # (removes the junction only) + b = os.path.join(d, "Game", "bin") + write(os.path.join(b, "wronggpu", "kernels", "enc.hsaco"), b"kernel") + ok_kernels = rr_free(b, "file wronggpu\\kernels\\enc.hsaco") + write(os.path.join(b, "wronggpu", "wronggpu.ini"), b"[wronggpu]\r\n") # WrongGPU\wronggpu.ini, in the lower-case folder + t.check("RR-free check: the payload's wronggpu\\kernels alone is RR-free; WrongGPU\\wronggpu.ini in that lower-case folder, or " + "its record line, is not", ok_kernels and not rr_free(b, "") and not rr_free(os.path.join(d, "empty"), "file WrongGPU\\wronggpu.ini"), + ok_kernels) + shutil.rmtree(d, ignore_errors=True) diff --git a/clean/installer/tests/launcher_core_tests.cpp b/clean/installer/tests/launcher_core_tests.cpp index 768e7ce4..eb3dae9d 100644 --- a/clean/installer/tests/launcher_core_tests.cpp +++ b/clean/installer/tests/launcher_core_tests.cpp @@ -14,6 +14,7 @@ #include #include "app/ui_palette.h" +#include "wg_core/checks.h" #include "wg_core/detect.h" #include "wg_core/gamerules.h" #include "wg_core/install.h" @@ -26,6 +27,9 @@ #include "wg_core/record.h" #include "wg_core/rr.h" #include "wg_core/rrconfig.h" +#include "wg_core/rrprep.h" + +#include #include "wg_core/settings.h" using namespace wg; @@ -2659,6 +2663,55 @@ int main() { #endif } +#ifdef WRONGGPU_TESTING + { // the HIP check's test candidates (checks.cpp HipCandidates): set is the whole list, never the system search + wchar_t savedList[512] = {}; + const bool hadList = GetEnvironmentVariableW(L"WRONGGPU_TEST_HIP_CANDIDATES", savedList, 512) > 0; + SetEnvironmentVariableW(L"WRONGGPU_TEST_HIP_CANDIDATES", L""); + require(HipCandidates().empty(), "WRONGGPU_TEST_HIP_CANDIDATES set but empty: no HIP candidate at all (never the system search)"); + const wstring longPath = L"C:\\x\\" + wstring(20000, L'a') + L"\\amdhip64_7.dll"; + SetEnvironmentVariableW(L"WRONGGPU_TEST_HIP_CANDIDATES", longPath.c_str()); + const auto longList = HipCandidates(); + require(longList.size() == 1 && longList[0] == longPath, + "WRONGGPU_TEST_HIP_CANDIDATES longer than EnvVar reads: still the whole list (that one path), never the system search"); + SetEnvironmentVariableW(L"WRONGGPU_TEST_HIP_CANDIDATES", hadList ? savedList : nullptr); + } +#endif + { // the rr-prepare helper's environment (rrprep.h RrHelperEnvironment): the tests' LOCALAPPDATA is kept in a test build + auto valueOf = [](const std::vector& env, const wstring& key) { + wstring found = L"(none)"; + for (const wchar_t* s = env.data(); *s; s += wcslen(s) + 1) + if (StartsWithI(s, key + L"=")) found = s + key.size() + 1; + return found; + }; + wchar_t saved[MAX_PATH * 2] = {}, savedReal[64] = {}; + const bool had = GetEnvironmentVariableW(L"LOCALAPPDATA", saved, MAX_PATH * 2) > 0; + const bool hadReal = GetEnvironmentVariableW(L"WRONGGPU_TEST_REAL_DRIVER_CACHE", savedReal, 64) > 0; + SetEnvironmentVariableW(L"WRONGGPU_TEST_REAL_DRIVER_CACHE", nullptr); // (whatever the caller had) + const wstring sandbox = Join(dir, L"sandbox-localappdata"); + SetEnvironmentVariableW(L"LOCALAPPDATA", sandbox.c_str()); + wstring real; + PWSTR kp = nullptr; + if (SUCCEEDED(SHGetKnownFolderPath(FOLDERID_LocalAppData, KF_FLAG_DONT_VERIFY, nullptr, &kp)) && kp) real = kp; + if (kp) CoTaskMemFree(kp); + std::vector env = RrHelperEnvironment(L"C:\\log\\prepare.log"); + require(valueOf(env, L"WG_RR_LOG") == L"C:\\log\\prepare.log", "the helper's environment: the runtime log in WG_RR_LOG"); +#ifdef WRONGGPU_TESTING + require(valueOf(env, L"LOCALAPPDATA") == sandbox, + "a test build's rr-prepare helper keeps the tests' redirected LOCALAPPDATA (never the user's real folder)"); + SetEnvironmentVariableW(L"WRONGGPU_TEST_REAL_DRIVER_CACHE", L"1"); + env = RrHelperEnvironment(L"x"); + require(!real.empty() && IEq(valueOf(env, L"LOCALAPPDATA"), real), + "a test build's helper gets the real LOCALAPPDATA only with the explicit opt-in WRONGGPU_TEST_REAL_DRIVER_CACHE=1"); + SetEnvironmentVariableW(L"WRONGGPU_TEST_REAL_DRIVER_CACHE", nullptr); +#else + require(!real.empty() && IEq(valueOf(env, L"LOCALAPPDATA"), real), + "a release build's rr-prepare helper gets the user's real LOCALAPPDATA (where the driver keeps the game's shader cache)"); +#endif + SetEnvironmentVariableW(L"LOCALAPPDATA", had ? saved : nullptr); + SetEnvironmentVariableW(L"WRONGGPU_TEST_REAL_DRIVER_CACHE", hadReal ? savedReal : nullptr); + } + RemoveTree(dir); std::printf("launcher-core: %d checks passed\n", checks); return 0; diff --git a/clean/installer/tests/launcher_edition_cases.py b/clean/installer/tests/launcher_edition_cases.py index 384b72e8..95131b41 100644 --- a/clean/installer/tests/launcher_edition_cases.py +++ b/clean/installer/tests/launcher_edition_cases.py @@ -1,21 +1,67 @@ # SPDX-License-Identifier: MIT """The download of WrongGPU's edition of OptiScaler, for run_launcher_tests.py (which calls run() in its place in the suite; -this file keeps that suite below the 256 KB source limit, as launcher_ignore_cases.py does). The section is moved unchanged: -run()'s arguments are the suite's own helpers it used as module names. Written for this project.""" +this file keeps that suite below the 256 KB source limit, as launcher_ignore_cases.py does). run()'s arguments are the +suite's own helpers it used as module names. Written for this project.""" import os import shutil -from run_installer_tests import read, sha, snapshot, diff, write +from run_installer_tests import read, sha, snapshot, diff, write, has_direct_route -def run(t, opti, game, edition_package, OPTI_INI): +def run(t, opti, game, edition_package, OPTI_INI, no_direct=None): """WrongGPU's edition of OptiScaler, downloaded by the launcher (optiedition.h): pinned size + SHA-256, a mismatch refused, the cache reused, offline falls back to the player's own download. A local test server (127.0.0.1) stands in for the - release page; the test build never downloads without WRONGGPU_TEST_EDITION.""" + release page; the test build never downloads without WRONGGPU_TEST_EDITION. + + The section always runs with the launcher under test (--launcher). The download, cache and address rules are checked + on both routes; only how a repair without any OptiScaler ends depends on the route: a launcher without the direct route + (-DWRONGGPU_DIRECT_ROUTE=OFF, as releases) has nothing left to repair with (exit 2, said in words), one with it repairs + through it (exit 0). When the launcher under test has the direct route, no_direct (--no-direct-launcher, a testing build + without it) runs the section again in a pass of its own, for the exit-2 refusals.""" print("\n[edition] the launcher downloads WrongGPU's edition of OptiScaler: pinned hash, mismatch refused, cache, offline fallback") + passes = [(t.exe, "")] + if has_direct_route(t.exe): + if no_direct: + if has_direct_route(no_direct): + raise SystemExit("--no-direct-launcher %s has the direct route: build it with -DWRONGGPU_DIRECT_ROUTE=OFF" % no_direct) + passes.append((no_direct, "without the direct route: ")) + else: + print(" note: this launcher has the direct route, so a repair without any OptiScaler goes on through it (exit 0); the " + "exit-2 refusals need a testing launcher built with -DWRONGGPU_DIRECT_ROUTE=OFF, as releases: give one with " + "--no-direct-launcher") + saved = t.exe + try: + for exe, tag in passes: + t.exe = exe + if tag: + print(" (again, in a pass of its own, with the launcher without the direct route: %s)" % exe) + _section(t, opti, game, edition_package, OPTI_INI, tag, not has_direct_route(exe)) + finally: + t.exe = saved + + +def _section(t, opti, game, edition_package, OPTI_INI, tag, refuses): import http.server import threading import zipfile + + def check(name, ok, detail=""): + t.check(tag + name, ok, detail) + + def ends(name, rc, rules, words, detail): + """A repair without any OptiScaler: the download, cache and address rules (rules) hold on both routes; without the + direct route it is refused (exit 2) with the words (words), with it the repair goes on through the direct route.""" + if refuses: + check(name + "; nothing else to repair with: refused (exit 2), said in words", rc == 2 and rules and words, detail) + else: + check(name + "; the repair goes on through the direct route (exit 0)", rc == 0 and rules, detail) + + def repair(): + """A repair; returns its exit code and the log lines it wrote (this run's only).""" + start = os.path.getsize(t.log) if os.path.isfile(t.log) else 0 + rc = t.run("repair", exe, "--noscan", "--force") + return rc, read(t.log)[start:].decode("utf-8", "replace") + ed_pkg, dll = edition_package(t, "edition-src") srv_dir = os.path.join(t.work, "edition-server") shutil.rmtree(srv_dir, ignore_errors=True) @@ -48,51 +94,58 @@ def log_message(self, *a): t.env["WRONGGPU_TEST_EDITION"] = pin("http://127.0.0.1:%d/edition.zip" % port) if os.path.exists(cache): os.remove(cache) + t.run("set", "--global", "optiscaler=") # no player's own download (an earlier pass may have set one) root, b, exe = game(t, "Edition Game", validated=True) before = snapshot(root) + start = os.path.getsize(t.log) if os.path.isfile(t.log) else 0 rc = t.run("install", exe, "--noscan", "--force") log = read(t.log).decode("utf-8", "replace") + unpack = [l.split(" in ", 1)[1].strip() for l in read(t.log)[start:].decode("utf-8", "replace").splitlines() + if "OptiScaler: unpacked edition-test.zip in " in l] + check("the edition archive is unpacked in the run's own temporary folder (TEMP in the work folder), nowhere else", + len(unpack) == 1 and os.path.abspath(unpack[0]).lower().startswith(os.path.join(t.work, "tmp").lower() + os.sep) and + t.env.get("TEMP") == os.path.join(t.work, "tmp"), (unpack, t.env.get("TEMP"))) proxy = [n for n in ("dxgi.dll", "winmm.dll", "version.dll") if os.path.isfile(os.path.join(b, n))] - t.check("no OptiScaler chosen: the launcher downloads its edition (one GET), checks it (sha256), caches it in its data folder and installs it", - rc == 0 and len(hits) == 1 and read(cache) == zbytes and "downloaded and checked" in log and proxy and read(os.path.join(b, proxy[0])) == dll and - "(WrongGPU edition, plugin interface 5)" in log, (rc, t.j.get("message"), hits, proxy, t.logtail())) - rc = t.run("repair", exe, "--noscan", "--force") - log = read(t.log).decode("utf-8", "replace") - t.check("the next install / repair reuses the cached, checked copy (no second download)", - rc == 0 and len(hits) == 1 and "from the launcher's cache" in log, (rc, hits, t.logtail())) + check("no OptiScaler chosen: the launcher downloads its edition (one GET), checks it (sha256), caches it in its data folder and installs it", + rc == 0 and len(hits) == 1 and read(cache) == zbytes and "downloaded and checked" in log and proxy and read(os.path.join(b, proxy[0])) == dll and + "(WrongGPU edition, plugin interface 5)" in log, (rc, t.j.get("message"), hits, proxy, t.logtail())) + rc, seg = repair() + check("the next install / repair reuses the cached, checked copy (no second download)", + rc == 0 and len(hits) == 1 and "from the launcher's cache" in seg, (rc, hits, seg[-1500:])) # the cached copy changed on disk: not used, downloaded again write(cache, zbytes[:-1] + b"X") - rc = t.run("repair", exe, "--noscan", "--force") - t.check("a cached copy that doesn't match is never used: downloaded again and checked", rc == 0 and len(hits) == 2 and read(cache) == zbytes, (rc, hits)) + rc, seg = repair() + check("a cached copy that doesn't match is never used: downloaded again and checked", rc == 0 and len(hits) == 2 and read(cache) == zbytes, (rc, hits)) # a download that isn't the pinned file: refused, deleted, never used; the player's own download (Settings) instead os.remove(cache) t.env["WRONGGPU_TEST_EDITION"] = pin("http://127.0.0.1:%d/edition.zip" % port, "0" * 64) - rc = t.run("repair", exe, "--noscan", "--force") - log = read(t.log).decode("utf-8", "replace") - t.check("hash mismatch: refused with the plain words, nothing cached, no OptiScaler without the player's own download (exit 2)", - rc == 2 and "download refused" in log and not os.path.exists(cache) and not os.path.exists(cache + ".part"), (rc, t.j.get("message"), t.logtail())) - rc = t.run("set", "--global", "optiscaler=" + opti) - rc = t.run("repair", exe, "--noscan", "--force") - log = read(t.log).decode("utf-8", "replace") - t.check("hash mismatch with the player's own OptiScaler download set: that one is used", rc == 0 and "mock OptiScaler" in read(os.path.join(b, proxy[0])).decode("latin-1") if proxy else False, - (rc, t.j.get("message"), t.logtail())) + rc, seg = repair() + ends("hash mismatch: the download refused with the plain words, nothing cached, no partial file", rc, + "download refused" in seg and len(hits) == 3 and not os.path.exists(cache) and not os.path.exists(cache + ".part"), + True, (rc, t.j.get("message"), hits, seg[-1500:])) + t.run("set", "--global", "optiscaler=" + opti) + rc, seg = repair() + check("hash mismatch with the player's own OptiScaler download set: that one is used, nothing cached", + rc == 0 and bool(proxy) and "mock OptiScaler" in read(os.path.join(b, proxy[0])).decode("latin-1") and not os.path.exists(cache), + (rc, t.j.get("message"), seg[-1500:])) # offline (nothing answers): the player's own download t.env["WRONGGPU_TEST_EDITION"] = pin("http://127.0.0.1:9/edition.zip") - rc = t.run("repair", exe, "--noscan", "--force") - log = read(t.log).decode("utf-8", "replace") - t.check("offline: the player's own OptiScaler download is used (fallback), nothing cached", rc == 0 and "download failed" in log and not os.path.exists(cache), - (rc, t.j.get("message"), t.logtail())) + rc, seg = repair() + check("offline: the player's own OptiScaler download is used (fallback), nothing cached", rc == 0 and "download failed" in seg and not os.path.exists(cache), + (rc, t.j.get("message"), seg[-1500:])) t.run("set", "--global", "optiscaler=") - rc = t.run("repair", exe, "--noscan", "--force") - t.check("offline without the player's own download: refused (exit 2), said in words", rc == 2 and "OptiScaler" in t.j.get("message", ""), (rc, t.j.get("message"))) + rc, seg = repair() + ends("offline without the player's own download: the download failed, nothing cached", rc, + "download failed" in seg and not os.path.exists(cache), "OptiScaler" in t.j.get("message", ""), (rc, t.j.get("message"), seg[-1500:])) # only https:// outside 127.0.0.1 (a test build allows the local test server only) t.env["WRONGGPU_TEST_EDITION"] = pin("http://example.invalid/edition.zip") - rc = t.run("repair", exe, "--noscan", "--force") - t.check("plain http:// to another host is never used", rc == 2 and "only https://" in read(t.log).decode("utf-8", "replace"), (rc, t.logtail())) + rc, seg = repair() + ends("plain http:// to another host is never used (only https://), nothing cached", rc, + "only https://" in seg and not os.path.exists(cache), True, (rc, seg[-1500:])) t.env["WRONGGPU_TEST_EDITION"] = pin("http://127.0.0.1:%d/edition.zip" % port) rc = t.run("uninstall", exe) - t.check("uninstall: the game folder back byte for byte", - rc == 0 and snapshot(root) == before, (rc, diff(before, snapshot(root)))) + check("uninstall: the game folder back byte for byte", + rc == 0 and snapshot(root) == before, (rc, diff(before, snapshot(root)))) shutil.rmtree(root, ignore_errors=True) finally: httpd.shutdown() diff --git a/clean/installer/tests/launcher_ignore_cases.py b/clean/installer/tests/launcher_ignore_cases.py index 7456c5f5..b5602faa 100644 --- a/clean/installer/tests/launcher_ignore_cases.py +++ b/clean/installer/tests/launcher_ignore_cases.py @@ -38,9 +38,9 @@ def run(T, base, opti, game): print("\n[convert-ignore] the ignore lists on the install path: a listed model source, a list held open, the last uninstall") import hashlib from run_installer_tests import read, write - work = os.path.join(base.work, "convert-ignore") - shutil.rmtree(work, ignore_errors=True) - t = T(base.exe, work, base.model, base.env.get("WRONGGPU_HIP_RUNTIME")) + import launcher_build_facts as facts + work = facts.new_run_folder(base.work, "convert-ignore") # a new folder of its own, with its own fresh tmp (T) + t = T(base.exe, work, base.model, base.hip) t.check = base.check # one count, one list of failures shared = os.path.join(t.env["LOCALAPPDATA"], "WrongGPU") lst = os.path.join(shared, "ignore-files.txt") diff --git a/clean/installer/tests/launcher_rr_prepare_cases.py b/clean/installer/tests/launcher_rr_prepare_cases.py new file mode 100644 index 00000000..412d96df --- /dev/null +++ b/clean/installer/tests/launcher_rr_prepare_cases.py @@ -0,0 +1,175 @@ +# SPDX-License-Identifier: MIT +"""rr-prepare and rr-recheck (RR's kernels prepared for a game ahead of its start), for run_launcher_tests.py's RR section +(which calls run() in its place; this file keeps that suite below the 256 KB source limit, as launcher_edition_cases.py +does). Written for this project. + +The default run stays inside its work folder and never prepares anything on the GPU: +- the no-card path runs with a fresh data folder (the helper's run folder not made yet) and a test build's driver answer + "none" (WRONGGPU_TEST_RR_DRIVER); +- with the suite's stand-in runtime (a fresh clone's test payload: no kernels), the helper really runs, under a test driver + version, and must fail to load that runtime: the expected result, with its diagnostic. The helper must keep the suite's + redirected LOCALAPPDATA (a test build's rule, rrprep.h RrHelperEnvironment); +- the checks that need RR's kernels really prepared (a payload with the real runtime and an RDNA 4 card) fill the user's + real graphics driver cache, so they run only with the opt-in --rr-prepare-gpu. +A test build starts no helper at all unless the test allows it (WRONGGPU_TEST_ALLOW_RR_HELPER=1, rrprep.cpp): only the +stand-in case and the opt-in pass do; a negative control shows a game the classification does not stop gets no helper.""" +import os +import shutil + +import launcher_build_facts as facts +from run_installer_tests import read, write + + +def _helper_gone(run_dir): + """No helper left in the helper's run folder; an absent folder is empty (the no-card path never makes it).""" + return not os.path.isdir(run_dir) or not os.listdir(run_dir) + + +def run(t, exe, b, gpu_opt_in=False): + """rr-prepare --check, rr-recheck, rr-prepare's no-card path, the helper with the stand-in runtime and, with the opt-in, a + real runtime and an RDNA 4 card, the prepared state across a driver or runtime change. exe: the RR game's exe, b: its folder.""" + # release 0.6.0 (owner: RR's kernels pre-compiled inside the launcher, rrprep.h): rr-prepare runs the launcher as a helper + # under the game's program name, which loads the installed wronggpu_runtime.dll (the real runtime of this payload, RR + # built in) and creates RR's pipelines on the GPU; the driver keeps them per program name, so the game finds them ready + prep_dir = os.path.join(t.data, "rr-prepare") # the launcher data folder (the suite runs with --data) + rc = t.run("rr-prepare", exe, "--check") + t.check("rr-prepare --check before: not prepared yet", rc == 0 and t.j.get("rr_prepare", {}).get("ready") is False and + "not prepared yet" in t.j.get("rr_prepare", {}).get("not_ready_why", ""), t.j) + # release 0.6.0 polish: the window's start prepares again only games prepared before (never prepared: Play's job) + rc = t.run("rr-recheck", exe) + rq = t.j.get("rr_recheck", {}) + t.check("rr-recheck before any prepare: not stale (state not-prepared), the start leaves it to Play", + rc == 0 and rq.get("stale") is False and rq.get("state_before") == "not-prepared", t.j) + glog = os.path.join(b, "wronggpu-rr.log") # the RR log an earlier case wrote (Last run): prepare must not touch it + glog_before = read(glog) if os.path.exists(glog) else None + game_before = sorted(os.listdir(b)) + + # no AMD graphics card, a fresh data folder: result 2, exit 0, no helper, no run folder made + saved = t.data + t.data = os.path.join(t.work, "data-rr-nocard") + shutil.rmtree(t.data, ignore_errors=True) + t.env["WRONGGPU_TEST_RR_DRIVER"] = "none" + try: + rc = t.run("rr-prepare", exe, "--passes=1") + finally: + t.env.pop("WRONGGPU_TEST_RR_DRIVER", None) + nocard_dir = os.path.join(t.data, "rr-prepare") + t.data = saved + rp = t.j.get("rr_prepare", {}) + t.check("rr-prepare without an AMD graphics card (fresh data folder): result 2, exit 0, the reason in words, no helper run, " + "nothing in the game's folder", rc == 0 and rp.get("result") == 2 and "no AMD graphics card" in rp.get("why", "") and + _helper_gone(os.path.join(nocard_dir, "run")) and not os.path.isfile(os.path.join(nocard_dir, "prepared.txt")) and + sorted(os.listdir(b)) == game_before, (rc, rp, os.listdir(b))) + shutil.rmtree(os.path.join(t.work, "data-rr-nocard"), ignore_errors=True) + + envlog = os.path.join(t.work, "rr-helper-env.log") + if os.path.exists(envlog): + os.remove(envlog) + if not facts.stand_in_runtime(b): + print(" skipped: rr-prepare's helper checks (they run only with the suite's stand-in runtime, which a helper cannot " + "load; this payload's runtime is another)") + if not gpu_opt_in and not facts.stand_in_runtime(b): + print(" skipped: rr-prepare's GPU checks (a real runtime prepares RR's kernels into the user's real graphics driver " + "cache: only with the opt-in --rr-prepare-gpu)") + return + if gpu_opt_in and not facts.stand_in_runtime(b): + t.env.update(WRONGGPU_TEST_REAL_DRIVER_CACHE="1", WRONGGPU_TEST_ALLOW_RR_HELPER="1") + try: + _gpu(t, exe, b, prep_dir, glog, glog_before) + finally: + t.env.pop("WRONGGPU_TEST_REAL_DRIVER_CACHE", None) + t.env.pop("WRONGGPU_TEST_ALLOW_RR_HELPER", None) + return + # the stand-in runtime from here on (a helper could not load it, whatever happens) + # the negative control: a game the in-game classification does not stop, a driver, no permission: no helper starts + t.env["WRONGGPU_TEST_RR_DRIVER"] = "99.0.0.1" + t.env["WRONGGPU_TEST_HELPER_ENV_LOG"] = envlog + try: + rc = t.run("rr-prepare", exe, "--passes=1") + finally: + t.env.pop("WRONGGPU_TEST_RR_DRIVER", None) + t.env.pop("WRONGGPU_TEST_HELPER_ENV_LOG", None) + rp = t.j.get("rr_prepare", {}) + t.check("rr-prepare without the test's permission: no helper starts, whatever the classification (result 3, exit 1, said why)", + rc == 1 and rp.get("result") == 3 and "WRONGGPU_TEST_ALLOW_RR_HELPER" in rp.get("why", "") and not os.path.exists(envlog) and + _helper_gone(os.path.join(prep_dir, "run")), (rc, rp)) + + # the suite's stand-in runtime: the helper really runs (a test driver version, so on any PC) and cannot load it; it + # must keep the suite's LOCALAPPDATA even when the caller's environment asks for the real one (the suite strips that) + saved_env = t.env + t.env = t.child_env(dict(os.environ, WRONGGPU_TEST_REAL_DRIVER_CACHE="1")) + t.env.update({k: v for k, v in saved_env.items() if k in ("WRONGGPU_TEST_LIBRARIES", "WRONGGPU_TEST_ACCESS_LOG", "WRONGGPU_TEST_RUN_ID")}) + stripped = "WRONGGPU_TEST_REAL_DRIVER_CACHE" not in t.env + t.env.update(WRONGGPU_TEST_RR_DRIVER="99.0.0.1", WRONGGPU_TEST_HELPER_ENV_LOG=envlog, WRONGGPU_TEST_ALLOW_RR_HELPER="1") + try: + rc = t.run("rr-prepare", exe, "--passes=1") + finally: + t.env = saved_env + rp = t.j.get("rr_prepare", {}) + why = rp.get("why", "") + t.check("rr-prepare with the suite's stand-in runtime: the helper ran and could not load it (result 3, exit 1, the helper's " + "code and the log in the reason), nothing recorded as prepared", + rc == 1 and rp.get("result") == 3 and ("the helper ended with 7" in why or "the helper ended with 8" in why) and + "prepare.log" in why and rp.get("ready") is False and not os.path.isfile(os.path.join(prep_dir, "prepared.txt")), (rc, rp)) + seen = read(envlog).decode("utf-8", "replace").splitlines() if os.path.isfile(envlog) else [] + t.check("rr-prepare: the helper kept the suite's redirected LOCALAPPDATA, also when the caller's environment had " + "WRONGGPU_TEST_REAL_DRIVER_CACHE=1 (stripped before any launcher call)", + stripped and seen == ["LOCALAPPDATA=" + t.env["LOCALAPPDATA"]], (stripped, seen, t.env["LOCALAPPDATA"])) + t.check("rr-prepare: the helper copy is gone, nothing new in the game's folder (the runtime log went to the data folder)", + _helper_gone(os.path.join(prep_dir, "run")) and (read(glog) if os.path.exists(glog) else None) == glog_before and + sorted(os.listdir(b)) == game_before, (os.listdir(prep_dir) if os.path.isdir(prep_dir) else None, os.listdir(b))) + print(" skipped: rr-prepare's checks of RR's kernels really prepared (this payload's WrongGPU runtime is the suite's " + "stand-in: they need a payload with the real runtime, an RDNA 4 card and --rr-prepare-gpu)") + + +def _gpu(t, exe, b, prep_dir, glog, glog_before): + """--rr-prepare-gpu: a payload with the real runtime; an RDNA 4 card prepares, another PC answers result 2.""" + rc = t.run("rr-prepare", exe, "--passes=1") + rp = t.j.get("rr_prepare", {}) + gpu = rp.get("result") != 2 # 2: no RDNA 4 graphics card on this PC (nothing to prepare) + t.check("rr-prepare: the helper prepared the default mode's kernels (result 0, ready, every kernel reported), or no RDNA 4 card", + rc == 0 and (not gpu or (rp.get("result") == 0 and rp.get("ready") is True and rp.get("kernels", 0) >= 50)), rp) + t.check("rr-prepare: the helper copy is gone, nothing new in the game's folder (the runtime log went to the data folder)", + _helper_gone(os.path.join(prep_dir, "run")) and (read(glog) if os.path.exists(glog) else None) == glog_before and + (not gpu or os.path.isfile(os.path.join(prep_dir, "prepare.log"))), (os.listdir(prep_dir) if os.path.isdir(prep_dir) else None, os.listdir(b))) + if gpu: + ptxt = read(os.path.join(prep_dir, "prepared.txt")).decode("utf-8", "replace") + t.check("rr-prepare: prepared.txt keeps the game's program name, the driver's version, the runtime's SHA-256, the passes", + ptxt.lower().startswith(os.path.basename(exe).lower() + "\t" + rp.get("driver", "?").lower() + "\t") and ptxt.rstrip().endswith("\t1"), ptxt) + plog = read(os.path.join(prep_dir, "prepare.log")).decode("utf-8", "replace") + t.check("rr-prepare: the runtime ran as the game's program name (the driver's cache key)", + ("as " + os.path.join(prep_dir, "run", os.path.basename(exe))).lower() in plog.lower() and "prepare: done" in plog, plog[-1500:]) + rc = t.run("rr-prepare", exe, "--passes=1") + rp2 = t.j.get("rr_prepare", {}) + t.check("rr-prepare again: the driver had every kernel (quick: under 15 s, was %s ms)" % rp.get("ms"), + rc == 0 and rp2.get("result") == 0 and rp2.get("ms", 99999) < 15000, rp2) + rc = t.run("rr-prepare", exe, "--check", "--passes=2") + t.check("rr-prepare --check for the other modes (pass 2): not prepared (default mode only)", rc == 0 and t.j.get("rr_prepare", {}).get("ready") is False, t.j) + write(os.path.join(prep_dir, "prepared.txt"), ptxt.replace("\t" + rp.get("driver", "?") + "\t", "\t1.2.3.4\t", 1).encode("utf-8")) + rc = t.run("rr-prepare", exe, "--check") + t.check("rr-prepare --check after a driver change: not prepared, the reason in words", rc == 0 and t.j.get("rr_prepare", {}).get("ready") is False and + "driver changed" in t.j.get("rr_prepare", {}).get("not_ready_why", ""), t.j) + # release 0.6.0 polish (owner 2026-11-02): the launcher's start prepares again after a driver / WrongGPU update + rc = t.run("rr-recheck", exe) + rq = t.j.get("rr_recheck", {}) + t.check("rr-recheck after a driver change: stale (driver-changed), the reason names the old driver, nothing run without --run", + rc == 0 and rq.get("stale") is True and rq.get("state_before") == "driver-changed" and "1.2.3.4" in rq.get("why", "") and rq.get("result") == -1, t.j) + rc = t.run("rr-recheck", exe, "--run") + rq = t.j.get("rr_recheck", {}) + p2 = read(os.path.join(prep_dir, "prepared.txt")).decode("utf-8", "replace") + t.check("rr-recheck --run: prepared again (result 0), ready, prepared.txt names this driver again", + rc == 0 and rq.get("result") == 0 and rq.get("state") == "ready" and + p2.lower().startswith(os.path.basename(exe).lower() + "\t" + rp.get("driver", "?").lower() + "\t"), (t.j, p2)) + cols = p2.splitlines()[0].split("\t") + if len(cols) >= 4: + cols[2] = "0" * 64 # another WrongGPU runtime (an update): its SHA-256 differs + write(os.path.join(prep_dir, "prepared.txt"), ("\t".join(cols) + "\r\n").encode("utf-8")) + rc = t.run("rr-recheck", exe) + rq = t.j.get("rr_recheck", {}) + t.check("rr-recheck after a WrongGPU runtime change: stale (runtime-changed)", + rc == 0 and rq.get("stale") is True and rq.get("state_before") == "runtime-changed", t.j) + write(os.path.join(prep_dir, "prepared.txt"), p2.encode("utf-8")) + rc = t.run("rr-recheck", exe) + rq = t.j.get("rr_recheck", {}) + t.check("rr-recheck with the same driver and runtime: not stale (ready), nothing run", + rc == 0 and rq.get("stale") is False and rq.get("state_before") == "ready" and rq.get("result") == -1, t.j) diff --git a/clean/installer/tests/run_installer_tests.py b/clean/installer/tests/run_installer_tests.py index b9c1583e..8576309d 100644 --- a/clean/installer/tests/run_installer_tests.py +++ b/clean/installer/tests/run_installer_tests.py @@ -22,6 +22,7 @@ import time import zipfile +sys.dont_write_bytecode = True # before any local module: no __pycache__ in the source tree (also as the launcher suite's module) HERE = os.path.dirname(os.path.abspath(__file__)) INSTALLER = os.path.dirname(HERE) CONVERTER_TESTS = os.path.join(INSTALLER, "..", "converter", "tests") @@ -317,13 +318,18 @@ def model_ok(self, case=None): FSR3UP_V2 = mockpe.make_dll(None, extra=b"game-built upscaler v2 (game update)" * 10, exports=mockpe.FSR3UPSCALER_EXPORTS, dll_name=SLOTS[2]) FOREIGN_FSR3 = mockpe.make_dll(None, extra=b"some other mod", exports=["ModInit", "ModHook"], dll_name=SLOTS[1]) OLD_DLSS = mockpe.make_dll({"CompanyName": "Mock", "ProductName": "Mock DLSS"}, (310, 1, 0, 0), extra=random.Random(5).randbytes(200_000)) +# the release marker the payload gate looks for in a runtime (tools/make_payload.py) +RELEASE_MARKER = b"\0wg-build dev-diagnostics=0\0" +# the test payload's WrongGPU runtime as installed: a stand-in without kernels (it cannot prepare anything on a GPU), with +# the marker (stand_in_runtime) +STAND_IN_RUNTIME = mockpe.make_dll({"ProductName": "WrongGPU", "FileDescription": "WrongGPU runtime"}, (0, 3, 0, 0)) + RELEASE_MARKER def stand_in_runtime(folder, data, name="wronggpu_runtime.dll"): """The test payload's WrongGPU runtime, a stand-in without kernels: its bytes carry the release marker ("wg-build dev-diagnostics=0"), and its build manifest (.build.json, as clean/runner/build.py writes one) is for these exact bytes and says stand_in, so the payload gate (tools/make_payload.py) embeds it only in a WRONGGPU_TESTING build.""" - data = data + b"\0wg-build dev-diagnostics=0\0" + data = data if data.endswith(RELEASE_MARKER) else data + RELEASE_MARKER write(os.path.join(folder, name), data) manifest = {"format": 1, "file": name, "sha256": hashlib.sha256(data).hexdigest(), "size": len(data), "dev_diagnostics": False, "stand_in": True} @@ -334,7 +340,7 @@ def payload(root): exports = {SLOTS[0]: mockpe.FFX_API_EXPORTS, SLOTS[1]: mockpe.FSR3_EXPORTS, SLOTS[2]: mockpe.FSR3UPSCALER_EXPORTS} for name in SLOTS: # WrongGPU's three FSR DLLs (front end, spec 20) write(os.path.join(root, name), mockpe.make_dll(mockpe.FRONT_END, (0, 3, 0, 0), extra=("front end " + name).encode(), exports=exports[name], dll_name=name)) - stand_in_runtime(root, mockpe.make_dll({"ProductName": "WrongGPU", "FileDescription": "WrongGPU runtime"}, (0, 3, 0, 0))) + stand_in_runtime(root, STAND_IN_RUNTIME) rng = random.Random(11) for k in ("enc", "swin", "dec"): write(os.path.join(root, "wronggpu", "kernels", k + ".hsaco"), rng.randbytes(3000)) diff --git a/clean/installer/tests/run_launcher_tests.py b/clean/installer/tests/run_launcher_tests.py index cebd7b6c..973e5edb 100644 --- a/clean/installer/tests/run_launcher_tests.py +++ b/clean/installer/tests/run_launcher_tests.py @@ -19,10 +19,13 @@ import sys import time +sys.dont_write_bytecode = True # before any local module: the suite writes nothing outside its run folder (no __pycache__) +os.environ["PYTHONDONTWRITEBYTECODE"] = "1" # (and the Python programs it starts) os.environ["WRONGGPU_TESTING"] = "1" HERE = os.path.dirname(os.path.abspath(__file__)) sys.path.insert(0, HERE) import mockpe # noqa: E402 (synthetic PE files with a version resource) +import launcher_build_facts as facts # noqa: E402 (what the launcher under test was built with) import run_installer_tests as suite # noqa: E402 (mock content, snapshots, the synthetic model case) from run_installer_tests import read, sha, snapshot, diff, write, kept_runtime, unrecorded_wronggpu_files # noqa: E402 import launcher_isolation as iso # noqa: E402 (#243: no search of the PC's own game folders) @@ -38,18 +41,35 @@ def __init__(self, exe, work, model, hip): self.data = os.path.join(work, "data") self.log = os.path.join(work, "launcher-test.log") self.out = os.path.join(work, "out.json") - self.env = dict(os.environ, LOCALAPPDATA=os.path.join(work, "localappdata"), ProgramData=os.path.join(work, "programdata")) - if hip: - self.env["WRONGGPU_HIP_RUNTIME"] = hip - for k in [k for k in self.env if k.upper().startswith("WG_") or k.upper() in ("HIP_PATH", "ROCM_PATH", "LLVM_PATH", "HIP_DEVICE_LIB_PATH")]: - self.env.pop(k) - os.makedirs(self.env["LOCALAPPDATA"], exist_ok=True) + self.hip = hip + facts.fresh_temp(work) # its own tmp, made here (refused when it or a folder above it is a junction or link) + if os.path.lexists(os.path.join(work, "no-hip")): + raise SystemExit("%s already holds no-hip: not a fresh run folder" % work) + self.env = self.child_env(os.environ) # the store libraries: \libraries only; every store access logged and checked after each call (launcher_isolation) iso.test_env(self.env, work) self.expect_scan = False # set by a test whose next call must search the test libraries (the guard's sensitivity) self.uninstall = suite.uninstall_root(self.env["LOCALAPPDATA"]) # this run's Apps & features root (the build's own) self.j = {} + def child_env(self, inherited): + """The launcher's environment from the caller's: LOCALAPPDATA, ProgramData, TEMP and TMP in the work folder, and no + inherited test override (WRONGGPU_TEST_*, WG_*: a test sets its own for one call; WRONGGPU_HIP_RUNTIME only from --hip) + or HIP path.""" + tmp = os.path.join(self.work, "tmp") + env = dict(inherited, LOCALAPPDATA=os.path.join(self.work, "localappdata"), ProgramData=os.path.join(self.work, "programdata"), + TEMP=tmp, TMP=tmp) + for k in [k for k in env if k.upper().startswith(("WG_", "WRONGGPU_TEST_")) or + k.upper() in ("WRONGGPU_HIP_RUNTIME", "HIP_PATH", "ROCM_PATH", "LLVM_PATH", "HIP_DEVICE_LIB_PATH")]: + env.pop(k) + if self.hip: + env["WRONGGPU_HIP_RUNTIME"] = self.hip + # the HIP check tries these candidates only, never the system's, PATH's or ROCm's runtime (checks.cpp HipCandidates): + # the --hip mock, else a file that is not there (a default run never loads a real HIP runtime) + env["WRONGGPU_TEST_HIP_CANDIDATES"] = self.hip or os.path.join(self.work, "no-hip", "amdhip64_7.dll") + os.makedirs(env["LOCALAPPDATA"], exist_ok=True) # (in the run's own fresh folder) + return env + def check(self, name, cond, detail=""): if cond: self.passed += 1 @@ -63,6 +83,7 @@ def run(self, *args, exe=None, data=True, timeout=600, cwd=None): if os.path.exists(self.out): os.remove(self.out) cmd = [exe or self.exe] + list(args) + ["--log=" + self.log, "--out=" + self.out] + (["--data=" + self.data] if data else []) + facts.require_test_hooks(cmd[0]) # fails closed before it runs: a testing build with the isolation hooks only start, astart = os.path.getsize(self.log) if os.path.isfile(self.log) else 0, iso.access_size(self.work) p = subprocess.run(cmd, env=self.env, stdout=subprocess.PIPE, stderr=subprocess.PIPE, timeout=timeout, cwd=cwd) try: @@ -75,7 +96,9 @@ def run(self, *args, exe=None, data=True, timeout=600, cwd=None): def raw(self, cmd, timeout=600, guard=True): """A program run as it is (no --log/--out added); its store accesses checked as for run() (guard=False only for the old - baseline installer, which predates the access log: --run-old-baseline).""" + baseline installer, which predates the access log and the hooks: the opt-in --run-old-baseline).""" + if guard: + facts.require_test_hooks(cmd[0]) start, astart = os.path.getsize(self.log) if os.path.isfile(self.log) else 0, iso.access_size(self.work) rc = subprocess.run(cmd, env=self.env, stdout=subprocess.PIPE, stderr=subprocess.PIPE, timeout=timeout).returncode if guard: @@ -342,7 +365,7 @@ def test_install_settings_uninstall(t, opti): t.check("owned-files.json: valid JSON, every recorded file with its owner", owned.get("format") == "wronggpu-owned-files/1" and any(f["path"] == "wronggpu_runtime.dll" and f["owner"] == "wg" for f in owned.get("files", [])), owned) un = os.path.join(b, "wronggpu-setup", "uninstall.exe") - t.check("uninstall.exe is the small restorer, not the launcher", os.path.isfile(un) and os.path.getsize(un) < os.path.getsize(t.exe) // 4, + t.check("uninstall.exe is the restorer (the build's WrongGPU-Restore.exe), not the launcher", facts.restorer_ok(un, t.exe), (os.path.getsize(un) if os.path.isfile(un) else None, os.path.getsize(t.exe))) t.check("profile.ini written", os.path.isfile(os.path.join(b, "wronggpu-setup", "profile.ini"))) t.check("the game is on the managed list", b.lower() in managed_list(t), managed_list(t)) @@ -421,9 +444,10 @@ def test_install_settings_uninstall(t, opti): write(rec_path, rec_same) rc = t.run("status", exe) t.check("the record back as installed: installed again", rc == 0 and t.j.get("game", {}).get("status") == "installed", t.j.get("game", {}).get("status")) - # update from an older version, then roll back and forward + # update from an older version (below this build's own), then roll back and forward lines = read(rec_path).decode("utf-8").split("\r\n") - lines = ["version\t0.5.1" if l.startswith("version\t") else l for l in lines] + old = facts.older_version(next((l[8:] for l in lines if l.startswith("version\t")), "")) + lines = ["version\t" + old if l.startswith("version\t") else l for l in lines] write(rec_path, "\r\n".join(lines)) rc = t.run("status", exe) t.check("an older record: update available", rc == 0 and t.j.get("game", {}).get("status") == "update-available", t.j.get("game", {}).get("status")) @@ -443,17 +467,17 @@ def test_install_settings_uninstall(t, opti): any(w.startswith("Left in place (the plugin's settings file selects an entry this version lacks)") for w in t.j.get("warnings", [])), (rc, options_line(eff_ini(b)), t.j.get("warnings"), t.logtail(1500))) prev_txt = os.path.join(b, "wronggpu-setup", "previous", "previous.txt") - t.check("update: exit 0; the earlier version kept in previous\\", rc == 0 and os.path.isfile(prev_txt) and "version=0.5.1" in read(prev_txt).decode(), (rc, t.j.get("message"), t.logtail())) + t.check("update: exit 0; the earlier version kept in previous\\", rc == 0 and os.path.isfile(prev_txt) and "version=" + old in read(prev_txt).decode(), (rc, t.j.get("message"), t.logtail())) rec = record_text(b) t.check("update: the settings survive (profile re-applied)", "output_filter=quality9" in (options_line(eff_ini(b)) or "") and "ShowFps=true" in ini(b, "OptiScaler.ini"), (options_line(eff_ini(b)), ini(b, "OptiScaler.ini"))) - t.check("update: record at this version", "\nversion\t0.5.1" not in rec, rec[:300]) + t.check("update: record at this version", "\nversion\t" + old not in rec, rec[:300]) rc = t.run("rollback", exe) rec = record_text(b) - t.check("roll back: exit 0, record says 0.5.1, the newer version kept for later", rc == 0 and "\nversion\t0.5.1\r\n" in rec and - "version=" in read(prev_txt).decode() and "version=0.5.1" not in read(prev_txt).decode(), (rc, t.j.get("message"))) + t.check("roll back: exit 0, record says the older version, the newer one kept for later", rc == 0 and "\nversion\t%s\r\n" % old in rec and + "version=" in read(prev_txt).decode() and "version=" + old not in read(prev_txt).decode(), (rc, t.j.get("message"))) rc = t.run("rollback", exe) - t.check("roll back again: back to the newer version", rc == 0 and "\nversion\t0.5.1\r\n" not in record_text(b), t.j.get("message")) + t.check("roll back again: back to the newer version", rc == 0 and "\nversion\t%s\r\n" % old not in record_text(b), t.j.get("message")) rc = t.run("repair", exe, "--opti=" + opti, "--noscan", "--force") t.check("repair: exit 0, settings kept", rc == 0 and "output_filter=quality9" in (options_line(eff_ini(b)) or ""), (rc, t.j.get("message"))) # a missing settings file is one problem, said once (the record lists wronggpu.ini as a file of the install too) @@ -464,10 +488,10 @@ def test_install_settings_uninstall(t, opti): g.get("problems") == ["wronggpu.ini is missing"], g.get("problems")) # Repair on an older WrongGPU puts this release's files back: an update too, and its message says so lines = read(rec_path).decode("utf-8").split("\r\n") - write(rec_path, "\r\n".join("version\t0.5.1" if l.startswith("version\t") else l for l in lines)) + write(rec_path, "\r\n".join("version\t" + old if l.startswith("version\t") else l for l in lines)) rc = t.run("repair", exe, "--opti=" + opti, "--noscan", "--force") - t.check("repair of an older version: wronggpu.ini back with the settings, the message says it updated from 0.5.1", - rc == 0 and "output_filter=quality9" in (options_line(eff_ini(b)) or "") and "updated from 0.5.1 to" in t.j.get("message", ""), (rc, t.j.get("message"))) + t.check("repair of an older version: wronggpu.ini back with the settings, the message says it updated from the older version", + rc == 0 and "output_filter=quality9" in (options_line(eff_ini(b)) or "") and "updated from %s to" % old in t.j.get("message", ""), (rc, t.j.get("message"))) # the elevated worker's job (run here without elevation: the same code path) job = os.path.join(t.work, "job.txt") result = os.path.join(t.work, "result.txt") @@ -790,6 +814,7 @@ def test_adopt_and_self_install(t, opti, baseline): print(" skipped: the 0.5.1 installer predates the test isolation (it may read the PC's own libraries); --run-old-baseline " "runs it, only in a fully redirected sandbox") return + print(" WARNING: --run-old-baseline: the 0.5.1 installer runs OUTSIDE the suite's isolation guarantee (not preflighted)") root, b, exe = game(t, "Old Game", exe="Old.exe") before = snapshot(root) rc = t.raw([baseline, "/S", "/LOG=" + t.log, "/NOSCAN", "/FORCE", "/EXPERIMENTAL", "/DIR=" + root, "/OPTISCALER=" + opti], guard=False) @@ -1068,7 +1093,7 @@ def test_rr(t, opti, synth_f): rc = t.run("install", exeN, "--opti=" + opti, "--noscan", "--force", "--experimental") rec = record_text(bN) if rc == 0 else "" t.check("a game without RR: installed without any RR file or record line", rc == 0 and "WrongGPU-RR.asi" not in rec and "wronggpu-rr.ini" not in rec and - not os.path.exists(os.path.join(bN, "wronggpu_rr_runtime.dll")) and not os.path.exists(os.path.join(bN, "WrongGPU")) and + not os.path.exists(os.path.join(bN, "wronggpu_rr_runtime.dll")) and facts.rr_free(bN, rec) and not os.path.exists(os.path.join(bN, "wronggpu-rr.ini")) and not os.path.exists(os.path.join(bN, "plugins", "WrongGPU-RR.asi")), (rc, t.j.get("message"), rec[:800])) # a game that ships the RR model file (a stand-in WrongGPU cannot convert: the RR data is not ready yet) @@ -1234,69 +1259,7 @@ def test_rr(t, opti, synth_f): st = [c["text"] for c in d.get("settings", {}).get("controls", [])] t.check("window: Settings has the Ray Reconstruction data row and the Exact mode switch (off)", any(x.startswith("Ray Reconstruction data") for x in st) and any(c["text"] == "Exact mode" and c.get("checked") is False for c in d.get("settings", {}).get("controls", [])), st) - # release 0.6.0 (owner: RR's kernels pre-compiled inside the launcher, rrprep.h): rr-prepare runs the launcher as a helper - # under the game's program name, which loads the installed wronggpu_runtime.dll (the real runtime of this payload, RR - # built in) and creates RR's pipelines on the GPU; the driver keeps them per program name, so the game finds them ready - prep_dir = os.path.join(t.data, "rr-prepare") # the launcher data folder (the suite runs with --data) - rc = t.run("rr-prepare", exe, "--check") - t.check("rr-prepare --check before: not prepared yet", rc == 0 and t.j.get("rr_prepare", {}).get("ready") is False and - "not prepared yet" in t.j.get("rr_prepare", {}).get("not_ready_why", ""), t.j) - # release 0.6.0 polish: the window's start prepares again only games prepared before (never prepared: Play's job) - rc = t.run("rr-recheck", exe) - rq = t.j.get("rr_recheck", {}) - t.check("rr-recheck before any prepare: not stale (state not-prepared), the start leaves it to Play", - rc == 0 and rq.get("stale") is False and rq.get("state_before") == "not-prepared", t.j) - glog = os.path.join(b, "wronggpu-rr.log") # the RR log an earlier case wrote (Last run): prepare must not touch it - glog_before = read(glog) if os.path.exists(glog) else None - rc = t.run("rr-prepare", exe, "--passes=1") - rp = t.j.get("rr_prepare", {}) - gpu = rp.get("result") != 2 # 2: no RDNA 4 graphics card on this PC (nothing to prepare) - t.check("rr-prepare: the helper prepared the default mode's kernels (result 0, ready, every kernel reported), or no RDNA 4 card", - rc == 0 and (not gpu or (rp.get("result") == 0 and rp.get("ready") is True and rp.get("kernels", 0) >= 50)), rp) - t.check("rr-prepare: the helper copy is gone, nothing new in the game's folder (the runtime log went to the data folder)", - not os.listdir(os.path.join(prep_dir, "run")) and (read(glog) if os.path.exists(glog) else None) == glog_before and - (not gpu or os.path.isfile(os.path.join(prep_dir, "prepare.log"))), (os.listdir(prep_dir), os.listdir(b))) - if gpu: - ptxt = read(os.path.join(prep_dir, "prepared.txt")).decode("utf-8", "replace") - t.check("rr-prepare: prepared.txt keeps the game's program name, the driver's version, the runtime's SHA-256, the passes", - ptxt.lower().startswith(os.path.basename(exe).lower() + "\t" + rp.get("driver", "?").lower() + "\t") and ptxt.rstrip().endswith("\t1"), ptxt) - plog = read(os.path.join(prep_dir, "prepare.log")).decode("utf-8", "replace") - t.check("rr-prepare: the runtime ran as the game's program name (the driver's cache key)", - ("as " + os.path.join(prep_dir, "run", os.path.basename(exe))).lower() in plog.lower() and "prepare: done" in plog, plog[-1500:]) - rc = t.run("rr-prepare", exe, "--passes=1") - rp2 = t.j.get("rr_prepare", {}) - t.check("rr-prepare again: the driver had every kernel (quick: under 15 s, was %s ms)" % rp.get("ms"), - rc == 0 and rp2.get("result") == 0 and rp2.get("ms", 99999) < 15000, rp2) - rc = t.run("rr-prepare", exe, "--check", "--passes=2") - t.check("rr-prepare --check for the other modes (pass 2): not prepared (default mode only)", rc == 0 and t.j.get("rr_prepare", {}).get("ready") is False, t.j) - write(os.path.join(prep_dir, "prepared.txt"), ptxt.replace("\t" + rp.get("driver", "?") + "\t", "\t1.2.3.4\t", 1).encode("utf-8")) - rc = t.run("rr-prepare", exe, "--check") - t.check("rr-prepare --check after a driver change: not prepared, the reason in words", rc == 0 and t.j.get("rr_prepare", {}).get("ready") is False and - "driver changed" in t.j.get("rr_prepare", {}).get("not_ready_why", ""), t.j) - # release 0.6.0 polish (owner 2026-11-02): the launcher's start prepares again after a driver / WrongGPU update - rc = t.run("rr-recheck", exe) - rq = t.j.get("rr_recheck", {}) - t.check("rr-recheck after a driver change: stale (driver-changed), the reason names the old driver, nothing run without --run", - rc == 0 and rq.get("stale") is True and rq.get("state_before") == "driver-changed" and "1.2.3.4" in rq.get("why", "") and rq.get("result") == -1, t.j) - rc = t.run("rr-recheck", exe, "--run") - rq = t.j.get("rr_recheck", {}) - p2 = read(os.path.join(prep_dir, "prepared.txt")).decode("utf-8", "replace") - t.check("rr-recheck --run: prepared again (result 0), ready, prepared.txt names this driver again", - rc == 0 and rq.get("result") == 0 and rq.get("state") == "ready" and - p2.lower().startswith(os.path.basename(exe).lower() + "\t" + rp.get("driver", "?").lower() + "\t"), (t.j, p2)) - cols = p2.splitlines()[0].split("\t") - if len(cols) >= 4: - cols[2] = "0" * 64 # another WrongGPU runtime (an update): its SHA-256 differs - write(os.path.join(prep_dir, "prepared.txt"), ("\t".join(cols) + "\r\n").encode("utf-8")) - rc = t.run("rr-recheck", exe) - rq = t.j.get("rr_recheck", {}) - t.check("rr-recheck after a WrongGPU runtime change: stale (runtime-changed)", - rc == 0 and rq.get("stale") is True and rq.get("state_before") == "runtime-changed", t.j) - write(os.path.join(prep_dir, "prepared.txt"), p2.encode("utf-8")) - rc = t.run("rr-recheck", exe) - rq = t.j.get("rr_recheck", {}) - t.check("rr-recheck with the same driver and runtime: not stale (ready), nothing run", - rc == 0 and rq.get("stale") is False and rq.get("state_before") == "ready" and rq.get("result") == -1, t.j) + __import__("launcher_rr_prepare_cases").run(t, exe, b, RR_PREPARE_GPU) # rr-prepare, rr-recheck (launcher_rr_prepare_cases.py) # the player edited both RR settings files by hand; the state folder holds the saved settings (#219) write(files["ini"], read(files["ini"]) + b"rr_plugin_key=1\r\n") write(files["settings"], read(files["settings"]) + b"rr_last_seen=1\r\n") @@ -2659,8 +2622,12 @@ def test_state(t, opti): # #219, in launcher_state_cases.py __import__("launcher_state_cases").run(t, opti, sys.modules[__name__]) +NO_DIRECT = None # --no-direct-launcher +RR_PREPARE_GPU = False # --rr-prepare-gpu (opt-in: rr-prepare with a real runtime fills the user's real driver cache) + + def test_edition_download(t, opti): # in launcher_edition_cases.py (this file stays below the 256 KB source limit) - __import__("launcher_edition_cases").run(t, opti, game, edition_package, OPTI_INI) + __import__("launcher_edition_cases").run(t, opti, game, edition_package, OPTI_INI, NO_DIRECT) def test_ui_dump(t, opti): @@ -3040,8 +3007,7 @@ def rr_dump(tag): def test_data_root_junctions(parent): """A junction at the data root must be unlinked without modifying anything in its target.""" - work = os.path.join(parent.work, "junction-regression") - os.makedirs(work, exist_ok=True) + work = facts.new_run_folder(parent.work, "junction-regression") # a new folder of its own, with its own fresh tmp (T) t = T(parent.exe, work, parent.model, None) shared = os.path.join(t.env["LOCALAPPDATA"], "WrongGPU") target = os.path.join(work, "junction-target") @@ -3057,16 +3023,8 @@ def test_data_root_junctions(parent): def link(): return subprocess.run(["cmd.exe", "/d", "/c", "mklink", "/J", shared, target], stdout=subprocess.PIPE, stderr=subprocess.PIPE).returncode == 0 - def invoke_without_log(exe, verb): - out = os.path.join(work, verb + "-result.json") - astart = iso.access_size(t.work) - proc = subprocess.Popen([exe, verb, "--out=" + out], env=t.env, stdout=subprocess.PIPE, stderr=subprocess.PIPE) - proc.communicate(timeout=180) - log = os.path.join(t.env.get("TEMP", ""), "WrongGPU-junction-%d.log" % proc.pid) - iso.check_isolation(log if os.path.isfile(log) else None, t.work, 0, (verb,), astart) # (#243: every launcher call) - text = read(log).decode("utf-8", "replace") if os.path.isfile(log) else "" - if os.path.isfile(log): os.remove(log) - return proc.returncode, text + def invoke_without_log(exe, verb): # (launcher_build_facts.junction_call: also the negative controls' path) + return facts.junction_call(t, exe, verb, work) linked = link() rc2, log = invoke_without_log(os.path.join(program, "WrongGPU.exe"), "self-uninstall") if linked else (-1, "") parent.check("self-uninstall: data-root junction unlinked, target unchanged, and link removal logged", @@ -3088,26 +3046,49 @@ def main(): ap.add_argument("--work", required=True) ap.add_argument("--baseline", help="the 0.5.1 installer (WRONGGPU_TESTING build, same test map) for the adoption cases") ap.add_argument("--hip", help="mock amdhip64_7.dll (WRONGGPU_HIP_RUNTIME)") - ap.add_argument("--run-old-baseline", action="store_true", help="also run --baseline (it predates the test isolation: only in a fully redirected sandbox)") + ap.add_argument("--run-old-baseline", action="store_true", help="also run --baseline: OUTSIDE the suite's isolation guarantee (the " + "0.5.1 installer predates the test hooks and is not preflighted; it may read the PC's own libraries): only in a " + "disposable, fully redirected sandbox") + ap.add_argument("--no-direct-launcher", help="a testing launcher built with -DWRONGGPU_DIRECT_ROUTE=OFF (as releases) for the edition " + "refusals, when --launcher has the direct route") + ap.add_argument("--rr-prepare-gpu", action="store_true", help="opt-in: rr-prepare's GPU checks with a payload's real runtime " + "(they fill the user's real graphics driver cache; never in the default run)") ap.add_argument("--only", nargs="*", default=[], help="development: only these tests (names without test_) after the basics") + ap.add_argument("--startup-only", action="store_true", help="the run's start (its own run folder, the isolation self-test) " + "and the HIP check, then stop (the self-checks' untouched-target control)") ap.add_argument("--synth-f", default=os.environ.get("WGC_SYNTH_BINS", ""), help="folder with the spec team's synthetic preset-F file synth-common-v0.bin (the test build's F map is synth-r0)") a = ap.parse_args() - global RUN_OLD_BASELINE - RUN_OLD_BASELINE = a.run_old_baseline - work = os.path.abspath(a.work) + global RUN_OLD_BASELINE, NO_DIRECT, RR_PREPARE_GPU + RUN_OLD_BASELINE, RR_PREPARE_GPU = a.run_old_baseline, a.rr_prepare_gpu + NO_DIRECT = os.path.abspath(a.no_direct_launcher) if a.no_direct_launcher else None + for what, p in (("--launcher", a.launcher), ("--no-direct-launcher", NO_DIRECT)): # before anything runs + if p: + facts.require_test_hooks(p, what) + if a.hip is not None: # the mock HIP runtime: an existing plain file (an empty --hip= too is refused), named first + if not a.hip or ";" in a.hip: + raise SystemExit("--hip %r is empty or holds ';': not run" % a.hip) + a.hip = os.path.abspath(a.hip) + if not os.path.isfile(a.hip) or facts.reparse_in_path(a.hip): + raise SystemExit("--hip %s is not an existing plain file: not run" % a.hip) + print("HIP runtime for the tests (--hip): %s" % a.hip) + # --work: a plain folder (no junction or link in it or above it, no ';' that would split the HIP candidate list); the + # run gets a NEW folder of its own in it, and everything the run writes is in that folder (nothing that was there before) + work = facts.new_run_folder(os.path.abspath(a.work)) iso.self_test(work) # (#243) first: no launcher call with a broken guard - for d in ("games", "data", "localappdata", "programs", "startmenu"): - shutil.rmtree(os.path.join(work, d), ignore_errors=True) - os.makedirs(work, exist_ok=True) model = suite.cases.f_mini_case(present=0) # the synthetic source of the test map the launcher was built with t = T(os.path.abspath(a.launcher), work, model, a.hip) # registry entries of an earlier run (test root only) for k, v in t.reg_keys().items(): if (k.startswith("WrongGPU-") and v.get("InstallLocation", "").lower().startswith(work.lower())) or (k == "WrongGPU" and work.lower() in v.get("InstallLocation", "").lower()): subprocess.run(["reg", "delete", t.uninstall + "\\" + k, "/f"], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) + if a.startup_only: # the start of a run and the HIP check only + rc = t.run("hipcheck") + print("startup-only: run folder %s; hipcheck exit %d" % (work, rc)) + return 0 if rc == 0 else 1 opti = opti_package(t) t0 = time.time() + facts.self_checks(t) # the suite's own guards (launcher_build_facts.py), before any launcher call test_basics(t) if a.only: # development: only the tests named (after the basics) for name in a.only: diff --git a/clean/installer/tools/sha256_list.cmake b/clean/installer/tools/sha256_list.cmake new file mode 100644 index 00000000..b7ca7091 --- /dev/null +++ b/clean/installer/tools/sha256_list.cmake @@ -0,0 +1,13 @@ +# SPDX-License-Identifier: MIT +# cmake -DF1= [-DF2= ... -DF4=] -DOUT= -P sha256_list.cmake: one line " " per file +# (the testing build's list of WrongGPU.exe and the launcher suite's canaries, tests/launcher_build_facts.py +# verified_canaries). +set(out "") +foreach(v F1 F2 F3 F4) + if(DEFINED ${v}) + file(SHA256 "${${v}}" h) + get_filename_component(n "${${v}}" NAME) + string(APPEND out "${h} ${n}\n") + endif() +endforeach() +file(WRITE "${OUT}" "${out}")