From cfa7715b8d794a1a180af8497de55a06c8445169 Mon Sep 17 00:00:00 2001 From: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com> Date: Sun, 15 Nov 2026 13:31:23 -0500 Subject: [PATCH 1/8] Launcher suite: green on a fresh clone The checks that assumed a release build now follow the build under test: - uninstall.exe is compared byte for byte with the build's WrongGPU-Restore.exe (the size ratio measured the test payload, not which program was installed); - the faked earlier record uses a version below the launcher's own, not 0.5.1; - the RR-free game checks the exact-case WrongGPU folder (the payload's wronggpu\ folder matched the case-insensitive check); - the edition refusals run with a launcher built without the direct route (--no-direct-launcher), and skip with the reason when none is given; - rr-prepare's GPU checks skip with the reason when the installed runtime is the suite's stand-in (moved to launcher_rr_prepare_cases.py: the suite stays below 256 KB). Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com> --- clean/installer/README.md | 6 +- clean/installer/tests/launcher_build_facts.py | 48 +++++++++ .../installer/tests/launcher_edition_cases.py | 35 ++++-- .../tests/launcher_rr_prepare_cases.py | 82 ++++++++++++++ clean/installer/tests/run_installer_tests.py | 9 +- clean/installer/tests/run_launcher_tests.py | 100 ++++-------------- 6 files changed, 194 insertions(+), 86 deletions(-) create mode 100644 clean/installer/tests/launcher_build_facts.py create mode 100644 clean/installer/tests/launcher_rr_prepare_cases.py diff --git a/clean/installer/README.md b/clean/installer/README.md index 33d6be67..99d0e614 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 ]`: 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,10 @@ 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). + Checks that depend on how the launcher was built follow the build under test (`launcher_build_facts.py`). The edition + section's refusals need a launcher without the direct route (`-DWRONGGPU_DIRECT_ROUTE=OFF`, as releases): + `--no-direct-launcher` gives one, otherwise they are skipped with that reason. rr-prepare's GPU checks are skipped, with + the reason, when the installed runtime is the suite's own stand-in. 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 diff --git a/clean/installer/tests/launcher_build_facts.py b/clean/installer/tests/launcher_build_facts.py new file mode 100644 index 00000000..e752d756 --- /dev/null +++ b/clean/installer/tests/launcher_build_facts.py @@ -0,0 +1,48 @@ +# 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 + +from run_installer_tests import read, 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 + + +def has_exact_name(folder, name): + """Whether folder holds an entry spelled exactly name (Windows names are case-insensitive: os.path.exists would also + match a payload's lower-case wronggpu\\ folder for WrongGPU\\).""" + return os.path.isdir(folder) and name in os.listdir(folder) diff --git a/clean/installer/tests/launcher_edition_cases.py b/clean/installer/tests/launcher_edition_cases.py index 384b72e8..fb055891 100644 --- a/clean/installer/tests/launcher_edition_cases.py +++ b/clean/installer/tests/launcher_edition_cases.py @@ -5,14 +5,37 @@ 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 refusals (no OptiScaler at all: exit 2) + need a launcher without the direct route (-DWRONGGPU_DIRECT_ROUTE=OFF, as releases), which then has no other way to + repair: no_direct (--no-direct-launcher) runs the section with such a build when the suite's launcher has the route.""" print("\n[edition] the launcher downloads WrongGPU's edition of OptiScaler: pinned hash, mismatch refused, cache, offline fallback") + saved = t.exe + if no_direct and has_direct_route(t.exe): + 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) + t.exe = no_direct + print(" (this section runs with the launcher without the direct route: %s)" % no_direct) + refuses = not has_direct_route(t.exe) + + def refusal(name, ok, detail): + if refuses: + t.check(name, ok, detail) + else: + print(" skipped: %s (needs a launcher built with -DWRONGGPU_DIRECT_ROUTE=OFF, as releases: this one has the direct " + "route and repairs without OptiScaler; give one with --no-direct-launcher)" % name) + try: + _section(t, opti, game, edition_package, OPTI_INI, refusal) + finally: + t.exe = saved + + +def _section(t, opti, game, edition_package, OPTI_INI, refusal): import http.server import threading import zipfile @@ -69,7 +92,7 @@ def log_message(self, *a): 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)", + refusal("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") @@ -84,11 +107,11 @@ def log_message(self, *a): (rc, t.j.get("message"), t.logtail())) 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"))) + refusal("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"))) # 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())) + refusal("plain http:// to another host is never used", rc == 2 and "only https://" in read(t.log).decode("utf-8", "replace"), (rc, t.logtail())) 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", 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..48b501f9 --- /dev/null +++ b/clean/installer/tests/launcher_rr_prepare_cases.py @@ -0,0 +1,82 @@ +# 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). The section is moved unchanged, except that its GPU checks skip, with the reason, when the installed WrongGPU runtime +is the suite's own stand-in (a fresh clone's test payload), which cannot prepare anything. Written for this project.""" +import os + +import launcher_build_facts as facts +from run_installer_tests import read, write + + +def run(t, exe, b): + """rr-prepare --check, rr-recheck, rr-prepare (the helper under the game's program name) and, with an RDNA 4 card and a + real runtime, 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 + 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) + if gpu and facts.stand_in_runtime(b): # a fresh clone's suite payload: its runtime has no kernels + print(" skipped: rr-prepare's GPU checks (this payload's WrongGPU runtime is the suite's stand-in, which cannot prepare " + "RR's kernels: they need a payload with the real runtime); result %s" % rp.get("result")) + gpu = None + if gpu is not None: + 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) diff --git a/clean/installer/tests/run_installer_tests.py b/clean/installer/tests/run_installer_tests.py index b9c1583e..700feca0 100644 --- a/clean/installer/tests/run_installer_tests.py +++ b/clean/installer/tests/run_installer_tests.py @@ -317,13 +317,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 +339,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..83ec5bf8 100644 --- a/clean/installer/tests/run_launcher_tests.py +++ b/clean/installer/tests/run_launcher_tests.py @@ -23,6 +23,7 @@ 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) @@ -342,7 +343,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 +422,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 +445,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 +466,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") @@ -1068,7 +1070,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 not facts.has_exact_name(bN, "WrongGPU") 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 +1236,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 and 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 +2599,11 @@ 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 + + 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): @@ -3089,12 +3032,15 @@ def main(): 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("--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("--only", nargs="*", default=[], help="development: only these tests (names without test_) after the basics") 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 + global RUN_OLD_BASELINE, NO_DIRECT RUN_OLD_BASELINE = a.run_old_baseline + NO_DIRECT = os.path.abspath(a.no_direct_launcher) if a.no_direct_launcher else None work = 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"): From f5aa7b8ccae0416f2058b23cd28e80a8c07c3e4f Mon Sep 17 00:00:00 2001 From: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com> Date: Sun, 15 Nov 2026 20:53:58 -0500 Subject: [PATCH 2/8] Launcher suite: run only testing builds, keep rr-prepare in the work folder, check both edition routes Review findings on the fresh-clone suite change: - The suite runs only WRONGGPU_TESTING builds with the test isolation hooks (store libraries, access log, edition download, the test Apps & features root). Every launcher it is given, their copies and the uninstall.exe they write are checked before they run; anything else is refused unrun. A self-check runs a program without the hooks and expects the refusal. - A test build's rr-prepare helper keeps the tests' redirected LOCALAPPDATA; the user's real folder only with WRONGGPU_TEST_REAL_DRIVER_CACHE=1 (release builds unchanged). The core tests check the helper's environment in both build types, and CI runs them in a testing build too. The suite asserts the LOCALAPPDATA the helper really started with (WRONGGPU_TEST_HELPER_ENV_LOG). - rr-prepare in the default run: the no-card path with a fresh data folder (the helper's run folder not made: an absent folder counts as empty), and the helper's expected failure to load the suite's stand-in runtime (result 3, exit 1, its code and log in the reason), both under a test driver version (WRONGGPU_TEST_RR_DRIVER), so on any PC. The checks of kernels really prepared need a real runtime and fill the real driver cache: only with --rr-prepare-gpu. - The edition section always runs with --launcher. The download, cache and address rules are checked on both routes; only the end of a repair without any OptiScaler depends on the route (exit 0 through the direct route, exit 2 without it). --no-direct-launcher runs the section again in a pass of its own. - The RR-free check looks for WrongGPU\wronggpu.ini itself and its record line, case-insensitively (the payload's lower-case wronggpu\ folder is the same folder on Windows); a self-check puts the file in that folder. Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com> --- .github/workflows/ci.yml | 6 +- clean/installer/README.md | 19 ++- clean/installer/src/wg_core/rrprep.cpp | 39 ++++-- clean/installer/src/wg_core/rrprep.h | 5 + clean/installer/tests/launcher_build_facts.py | 74 ++++++++++- clean/installer/tests/launcher_core_tests.cpp | 35 +++++ .../installer/tests/launcher_edition_cases.py | 120 +++++++++++------- .../tests/launcher_rr_prepare_cases.py | 99 +++++++++++++-- clean/installer/tests/run_launcher_tests.py | 20 ++- 9 files changed, 331 insertions(+), 86 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 349668e8..4ce913d3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -126,7 +126,11 @@ 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 build with the test isolation hooks (launcher_build_facts.py): this one has them + python -c "import sys; sys.path.insert(0, 'clean/installer/tests'); import launcher_build_facts as f; m = f.missing_test_hooks('out/launcher-mock/WrongGPU.exe'); sys.exit('missing: %s' % m if m 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/README.md b/clean/installer/README.md index 99d0e614..31faff89 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 ] [--no-direct-launcher ]`: 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,10 +929,19 @@ 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). - Checks that depend on how the launcher was built follow the build under test (`launcher_build_facts.py`). The edition - section's refusals need a launcher without the direct route (`-DWRONGGPU_DIRECT_ROUTE=OFF`, as releases): - `--no-direct-launcher` gives one, otherwise they are skipped with that reason. rr-prepare's GPU checks are skipped, with - the reason, when the installed runtime is the suite's own stand-in. + The suite runs only `WRONGGPU_TESTING` builds with the test isolation hooks: every launcher it is given, their copies + and the `uninstall.exe` they write are checked before they run, and anything else is refused unrun (a release launcher + could reach the real download page, the PC's stores and the real Apps & features root). The 0.5.1 baseline predates the + hooks and runs only with `--run-old-baseline`. 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`. Test builds' 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). 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 diff --git a/clean/installer/src/wg_core/rrprep.cpp b/clean/installer/src/wg_core/rrprep.cpp index a0a833cf..3371b2f3 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**); @@ -204,7 +215,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 +286,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/launcher_build_facts.py b/clean/installer/tests/launcher_build_facts.py index e752d756..ca4152bb 100644 --- a/clean/installer/tests/launcher_build_facts.py +++ b/clean/installer/tests/launcher_build_facts.py @@ -4,8 +4,9 @@ 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, STAND_IN_RUNTIME +from run_installer_tests import read, write, STAND_IN_RUNTIME def restorer_ok(un, exe): @@ -42,7 +43,70 @@ def stand_in_runtime(folder): return os.path.isfile(p) and read(p) == STAND_IN_RUNTIME -def has_exact_name(folder, name): - """Whether folder holds an entry spelled exactly name (Windows names are case-insensitive: os.path.exists would also - match a payload's lower-case wronggpu\\ folder for WrongGPU\\).""" - return os.path.isdir(folder) and name in os.listdir(folder) +# 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 = {} + + +def missing_test_hooks(path): + """The test isolation hooks the program at path lacks (UTF-16 strings in its bytes); empty: a testing build with all.""" + try: + data = read(path) + except OSError: + return list(TEST_HOOKS) + return [m for m in TEST_HOOKS if m.encode("utf-16-le") not in data] + + +def require_test_hooks(path, what="the program"): + """Fails closed BEFORE a program runs: the suite runs only WRONGGPU_TESTING builds with the test isolation hooks (every + launcher it is given, their copies and the uninstall.exe they write). Checked once per file (path, size, time).""" + try: + st = os.stat(path) + key = (os.path.abspath(path).lower(), st.st_size, st.st_mtime_ns) + except OSError: + raise SystemExit("%s %s is not there: not run" % (what, path)) + if key not in _hooks_ok: + missing = missing_test_hooks(path) + if missing: + raise SystemExit("%s %s is not a WRONGGPU_TESTING build with the test isolation hooks (missing: %s): the suite never " + "runs it (build it with -DWRONGGPU_TESTING=ON)" % (what, path, ", ".join(missing))) + _hooks_ok[key] = True + + +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") + d = os.path.join(t.work, "self-checks") + shutil.rmtree(d, ignore_errors=True) + fake = os.path.join(d, "release", "WrongGPU.exe") + write(fake, STAND_IN_RUNTIME) # a program without the hooks, as a release launcher is + size = lambda: os.path.getsize(t.log) if os.path.isfile(t.log) else 0 + before, why = size(), "" + try: + t.run("version", exe=fake) + except SystemExit as e: + why = str(e) + t.check("preflight: a program without the test isolation hooks is refused before it runs (a release launcher never reaches the " + "real download page, the PC's stores or the real uninstall registry root)", + "not a WRONGGPU_TESTING build" in why and size() == before and not os.path.exists(t.out), why) + t.check("preflight: the launcher under test is a WRONGGPU_TESTING build with every isolation hook", not missing_test_hooks(t.exe), + missing_test_hooks(t.exe)) + 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..a711bfa2 100644 --- a/clean/installer/tests/launcher_core_tests.cpp +++ b/clean/installer/tests/launcher_core_tests.cpp @@ -26,6 +26,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 +2662,38 @@ int main() { #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] = {}; + const bool had = GetEnvironmentVariableW(L"LOCALAPPDATA", saved, MAX_PATH * 2) > 0; + 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); + } + 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 fb055891..8f25ea85 100644 --- a/clean/installer/tests/launcher_edition_cases.py +++ b/clean/installer/tests/launcher_edition_cases.py @@ -1,7 +1,7 @@ # 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 @@ -11,34 +11,57 @@ 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. The refusals (no OptiScaler at all: exit 2) - need a launcher without the direct route (-DWRONGGPU_DIRECT_ROUTE=OFF, as releases), which then has no other way to - repair: no_direct (--no-direct-launcher) runs the section with such a build when the suite's launcher has the route.""" - print("\n[edition] the launcher downloads WrongGPU's edition of OptiScaler: pinned hash, mismatch refused, cache, offline fallback") - saved = t.exe - if no_direct and has_direct_route(t.exe): - 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) - t.exe = no_direct - print(" (this section runs with the launcher without the direct route: %s)" % no_direct) - refuses = not has_direct_route(t.exe) + release page; the test build never downloads without WRONGGPU_TEST_EDITION. - def refusal(name, ok, detail): - if refuses: - t.check(name, ok, detail) + 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(" skipped: %s (needs a launcher built with -DWRONGGPU_DIRECT_ROUTE=OFF, as releases: this one has the direct " - "route and repairs without OptiScaler; give one with --no-direct-launcher)" % name) + 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: - _section(t, opti, game, edition_package, OPTI_INI, refusal) + 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, refusal): +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) @@ -71,51 +94,52 @@ 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) rc = t.run("install", exe, "--noscan", "--force") log = read(t.log).decode("utf-8", "replace") 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") - refusal("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") - refusal("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") - refusal("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_rr_prepare_cases.py b/clean/installer/tests/launcher_rr_prepare_cases.py index 48b501f9..d482c737 100644 --- a/clean/installer/tests/launcher_rr_prepare_cases.py +++ b/clean/installer/tests/launcher_rr_prepare_cases.py @@ -1,17 +1,31 @@ # 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). The section is moved unchanged, except that its GPU checks skip, with the reason, when the installed WrongGPU runtime -is the suite's own stand-in (a fresh clone's test payload), which cannot prepare anything. Written for this project.""" +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.""" import os +import shutil import launcher_build_facts as facts from run_installer_tests import read, write -def run(t, exe, b): - """rr-prepare --check, rr-recheck, rr-prepare (the helper under the game's program name) and, with an RDNA 4 card and a - real runtime, the prepared state across a driver or runtime change. exe: the RR game's exe, b: its folder.""" +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 @@ -26,19 +40,76 @@ def run(t, exe, b): 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) + + if facts.stand_in_runtime(b): + # 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 (a test build never hands the helper the user's real folder) + envlog = os.path.join(t.work, "rr-helper-env.log") + if os.path.exists(envlog): + os.remove(envlog) + 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", {}) + 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 (never the user's real folder)", + seen == ["LOCALAPPDATA=" + t.env["LOCALAPPDATA"]], (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)") + return + if not gpu_opt_in: + 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 + # opt-in: the real driver cache, as a player's launcher fills it + t.env["WRONGGPU_TEST_REAL_DRIVER_CACHE"] = "1" + try: + _gpu(t, exe, b, prep_dir, glog, glog_before) + finally: + t.env.pop("WRONGGPU_TEST_REAL_DRIVER_CACHE", None) + + +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) - if gpu and facts.stand_in_runtime(b): # a fresh clone's suite payload: its runtime has no kernels - print(" skipped: rr-prepare's GPU checks (this payload's WrongGPU runtime is the suite's stand-in, which cannot prepare " - "RR's kernels: they need a payload with the real runtime); result %s" % rp.get("result")) - gpu = None - if gpu is not None: - 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 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))) + _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", diff --git a/clean/installer/tests/run_launcher_tests.py b/clean/installer/tests/run_launcher_tests.py index 83ec5bf8..84bb340c 100644 --- a/clean/installer/tests/run_launcher_tests.py +++ b/clean/installer/tests/run_launcher_tests.py @@ -64,6 +64,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: @@ -76,7 +77,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: @@ -1070,7 +1073,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 facts.has_exact_name(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) @@ -1236,7 +1239,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) - __import__("launcher_rr_prepare_cases").run(t, exe, b) # rr-prepare and rr-recheck (launcher_rr_prepare_cases.py) + __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") @@ -2600,6 +2603,7 @@ def test_state(t, opti): # #219, in launcher_state_cases.py 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) @@ -3034,13 +3038,18 @@ def main(): 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("--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("--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, NO_DIRECT - RUN_OLD_BASELINE = a.run_old_baseline + 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) work = 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"): @@ -3054,6 +3063,7 @@ def main(): subprocess.run(["reg", "delete", t.uninstall + "\\" + k, "/f"], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) 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: From ced0b06892cf48fbe187d96a821620022f73db72 Mon Sep 17 00:00:00 2001 From: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com> Date: Sun, 15 Nov 2026 21:47:00 -0500 Subject: [PATCH 3/8] Launcher suite: testing builds by their identity, no inherited test overrides, no helper without permission Re-check findings on the fresh-clone suite change: - A WRONGGPU_TESTING build links in a named resource (WRONGGPU_TESTING_BUILD) and, with MSVC, a PE checksum (/RELEASE). The suite's preflight parses the program: the resource in its resource directory, a checksum that matches (a byte changed or data appended after the link fails) and the hooks' strings inside its sections. - Negative controls: wg-test-canary and wg-test-canary-strings (testing-build CMake targets; not testing builds, the second carrying the hooks' strings) leave a start marker. They start when run directly and are refused by a launcher call, --launcher and --no-direct-launcher; changed and appended copies of the launcher are refused too. CI checks the identity of the launcher and restorer and the refusal of both canaries. The junction test's direct calls go through the preflight. - Every launcher call gets TEMP and TMP in the work folder and no inherited WRONGGPU_TEST_* or WG_* variable; the opt-in pass alone sets the real driver cache. The core test clears and restores that variable; the stand-in helper case starts from a caller environment that has it set and still sees the redirected LOCALAPPDATA. - A test build starts no rr-prepare helper unless the test allows it (WRONGGPU_TEST_ALLOW_RR_HELPER=1: the stand-in case and --rr-prepare-gpu). A negative control shows a game the in-game classification does not stop gets no helper. - The launcher logs where it unpacks an OptiScaler archive; the edition passes check that it is the run's own temporary folder. Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com> --- .github/workflows/ci.yml | 7 +- clean/installer/CMakeLists.txt | 19 +++ clean/installer/README.md | 18 +- clean/installer/src/wg_core/optiscaler.cpp | 1 + clean/installer/src/wg_core/rrprep.cpp | 9 + clean/installer/tests/canary.cpp | 26 +++ clean/installer/tests/launcher_build_facts.py | 159 ++++++++++++++++-- clean/installer/tests/launcher_core_tests.cpp | 5 +- .../installer/tests/launcher_edition_cases.py | 6 + .../tests/launcher_rr_prepare_cases.py | 45 +++-- clean/installer/tests/run_launcher_tests.py | 26 ++- 11 files changed, 273 insertions(+), 48 deletions(-) create mode 100644 clean/installer/tests/canary.cpp diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4ce913d3..9f744934 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -126,11 +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 launcher-core-tests + cmake --build out/launcher-mock --target WrongGPU launcher-core-tests wg-test-canary wg-test-canary-strings # 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 build with the test isolation hooks (launcher_build_facts.py): this one has them - python -c "import sys; sys.path.insert(0, 'clean/installer/tests'); import launcher_build_facts as f; m = f.missing_test_hooks('out/launcher-mock/WrongGPU.exe'); sys.exit('missing: %s' % m if m else 0)" + # 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..05d1b26d 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,15 @@ 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) 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 31faff89..231e626b 100644 --- a/clean/installer/README.md +++ b/clean/installer/README.md @@ -929,18 +929,24 @@ 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 with the test isolation hooks: every launcher it is given, their copies - and the `uninstall.exe` they write are checked before they run, and anything else is refused unrun (a release launcher - could reach the real download page, the PC's stores and the real Apps & features root). The 0.5.1 baseline predates the - hooks and runs only with `--run-old-baseline`. Checks that depend on how the launcher was built follow the build under + 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` (CMake targets of a testing build, built next to the launcher; not testing builds, the second + carrying the hooks' strings) start when run directly and are refused through every entry point. The 0.5.1 baseline + predates the hooks and runs only with `--run-old-baseline`. Every launcher call gets the work folder's `tmp` as `TEMP` + and `TMP`, and no inherited test override (`WRONGGPU_TEST_*`, `WG_*`). 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`. Test builds' hooks for this: - `WRONGGPU_TEST_RR_DRIVER` (a driver version, or `none`), `WRONGGPU_TEST_HELPER_ENV_LOG`, and + 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). 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` 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 3371b2f3..02cfee1a 100644 --- a/clean/installer/src/wg_core/rrprep.cpp +++ b/clean/installer/src/wg_core/rrprep.cpp @@ -192,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)); 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/launcher_build_facts.py b/clean/installer/tests/launcher_build_facts.py index ca4152bb..0e346989 100644 --- a/clean/installer/tests/launcher_build_facts.py +++ b/clean/installer/tests/launcher_build_facts.py @@ -51,13 +51,98 @@ def stand_in_runtime(folder): _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(".started when it starts (tests/canary.cpp; built with the + # launcher in a testing build): one plain, one carrying the hooks' strings; first run directly, to show they do start size = lambda: os.path.getsize(t.log) if os.path.isfile(t.log) else 0 - before, why = size(), "" - try: - t.run("version", exe=fake) - except SystemExit as e: - why = str(e) - t.check("preflight: a program without the test isolation hooks is refused before it runs (a release launcher never reaches the " - "real download page, the PC's stores or the real uninstall registry root)", - "not a WRONGGPU_TESTING build" in why and size() == before and not os.path.exists(t.out), why) - t.check("preflight: the launcher under test is a WRONGGPU_TESTING build with every isolation hook", not missing_test_hooks(t.exe), - missing_test_hooks(t.exe)) + for name in ("wg-test-canary.exe", "wg-test-canary-strings.exe"): + built = os.path.join(os.path.dirname(t.exe), name) + if not os.path.isfile(built): + t.check("negative control %s: built next to the launcher (CMake target %s)" % (name, name[:-4]), False, built) + continue + canary = os.path.join(d, name) + shutil.copyfile(built, canary) + started = canary + ".started" + subprocess.run([canary], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, timeout=60) + runs = os.path.isfile(started) + if runs: + os.remove(started) + before, why = size(), "" + try: + t.run("version", exe=canary) + except SystemExit as e: + why = 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; the suite never starts it (a launcher call, --launcher, " + "--no-direct-launcher): refused before it runs, nothing logged" % name, + runs and "not a WRONGGPU_TESTING build" in why and entry == [True, True] and not os.path.exists(started) and size() == before, + (runs, why, 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} + strings = os.path.join(os.path.dirname(t.exe), "wg-test-canary-strings.exe") + if os.path.isfile(strings): # the hooks' strings and a valid checksum, but no identity resource: still not a testing build + import struct + c = bytearray(read(strings)) + at = struct.unpack_from(" 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; @@ -2692,6 +2694,7 @@ int main() { "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); diff --git a/clean/installer/tests/launcher_edition_cases.py b/clean/installer/tests/launcher_edition_cases.py index 8f25ea85..95131b41 100644 --- a/clean/installer/tests/launcher_edition_cases.py +++ b/clean/installer/tests/launcher_edition_cases.py @@ -97,8 +97,14 @@ def log_message(self, *a): 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))] 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 diff --git a/clean/installer/tests/launcher_rr_prepare_cases.py b/clean/installer/tests/launcher_rr_prepare_cases.py index d482c737..74c84f3d 100644 --- a/clean/installer/tests/launcher_rr_prepare_cases.py +++ b/clean/installer/tests/launcher_rr_prepare_cases.py @@ -10,7 +10,9 @@ 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.""" + 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 @@ -60,19 +62,34 @@ def run(t, exe, b, gpu_opt_in=False): 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) + # 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)) + if facts.stand_in_runtime(b): # 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 (a test build never hands the helper the user's real folder) - envlog = os.path.join(t.work, "rr-helper-env.log") - if os.path.exists(envlog): - os.remove(envlog) - t.env["WRONGGPU_TEST_RR_DRIVER"] = "99.0.0.1" - t.env["WRONGGPU_TEST_HELPER_ENV_LOG"] = envlog + # 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.pop("WRONGGPU_TEST_RR_DRIVER", None) - t.env.pop("WRONGGPU_TEST_HELPER_ENV_LOG", None) + 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 " @@ -80,8 +97,9 @@ def run(t, exe, b, gpu_opt_in=False): 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 (never the user's real folder)", - seen == ["LOCALAPPDATA=" + t.env["LOCALAPPDATA"]], (seen, t.env["LOCALAPPDATA"])) + 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))) @@ -92,12 +110,13 @@ def run(t, exe, b, gpu_opt_in=False): 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 - # opt-in: the real driver cache, as a player's launcher fills it - t.env["WRONGGPU_TEST_REAL_DRIVER_CACHE"] = "1" + # opt-in: the helper allowed, with the real driver cache, as a player's launcher fills it + 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) def _gpu(t, exe, b, prep_dir, glog, glog_before): diff --git a/clean/installer/tests/run_launcher_tests.py b/clean/installer/tests/run_launcher_tests.py index 84bb340c..efa629a2 100644 --- a/clean/installer/tests/run_launcher_tests.py +++ b/clean/installer/tests/run_launcher_tests.py @@ -39,18 +39,28 @@ 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 + 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) 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 ("HIP_PATH", "ROCM_PATH", "LLVM_PATH", "HIP_DEVICE_LIB_PATH")]: + env.pop(k) + if self.hip: + env["WRONGGPU_HIP_RUNTIME"] = self.hip + os.makedirs(env["LOCALAPPDATA"], exist_ok=True) + os.makedirs(tmp, exist_ok=True) + return env + def check(self, name, cond, detail=""): if cond: self.passed += 1 @@ -3007,9 +3017,11 @@ def link(): def invoke_without_log(exe, verb): out = os.path.join(work, verb + "-result.json") astart = iso.access_size(t.work) + facts.require_test_hooks(exe) # as every launcher call: a testing build only 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) + log = os.path.join(t.env["TEMP"], "WrongGPU-junction-%d.log" % proc.pid) # TEMP: the work folder's tmp (child_env) + 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) From 8a78fc8afa8a11bfe6dd95c0cf3d371522c31cbe Mon Sep 17 00:00:00 2001 From: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com> Date: Sun, 15 Nov 2026 21:50:26 -0500 Subject: [PATCH 4/8] Launcher suite: the negative controls also go through the junction test's call Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com> --- clean/installer/tests/launcher_build_facts.py | 33 ++++++++++++++++--- clean/installer/tests/run_launcher_tests.py | 14 ++------ 2 files changed, 30 insertions(+), 17 deletions(-) diff --git a/clean/installer/tests/launcher_build_facts.py b/clean/installer/tests/launcher_build_facts.py index 0e346989..6487c454 100644 --- a/clean/installer/tests/launcher_build_facts.py +++ b/clean/installer/tests/launcher_build_facts.py @@ -161,6 +161,25 @@ def require_test_hooks(path, what="the program"): _hooks_ok[key] = True +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.""" @@ -194,21 +213,25 @@ def self_checks(t): runs = os.path.isfile(started) if runs: os.remove(started) - before, why = size(), "" + before, why, jwhy = 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) 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; the suite never starts it (a launcher call, --launcher, " - "--no-direct-launcher): refused before it runs, nothing logged" % name, - runs and "not a WRONGGPU_TESTING build" in why and entry == [True, True] and not os.path.exists(started) and size() == before, - (runs, why, entry)) + 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, --launcher, --no-direct-launcher): refused before it runs, no start marker, nothing logged" % name, + runs and "not a WRONGGPU_TESTING build" in why and "not a WRONGGPU_TESTING build" in jwhy and entry == [True, True] and + not os.path.exists(started) and size() == before, (runs, why, jwhy, 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 diff --git a/clean/installer/tests/run_launcher_tests.py b/clean/installer/tests/run_launcher_tests.py index efa629a2..ac1d0a46 100644 --- a/clean/installer/tests/run_launcher_tests.py +++ b/clean/installer/tests/run_launcher_tests.py @@ -3014,18 +3014,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) - facts.require_test_hooks(exe) # as every launcher call: a testing build only - 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) # TEMP: the work folder's tmp (child_env) - 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 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", From 8467f6db19fde496ba719cabcb54d601c093be04 Mon Sep 17 00:00:00 2001 From: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com> Date: Sun, 15 Nov 2026 22:26:08 -0500 Subject: [PATCH 5/8] Launcher suite: verified canaries, no inherited HIP override, a fresh temporary folder Re-check findings on the fresh-clone suite change: - WRONGGPU_HIP_RUNTIME is stripped from the inherited environment and set only from --hip; a self-check starts with a conflicting inherited value and checks hipcheck's library. - The canaries are built with the testing WrongGPU target (a dependency), which then writes wg-test-build.sha256: the SHA-256 of that WrongGPU.exe and of the canaries. The suite starts only canaries that list verifies as this build's, by full path, with its own child environment; they are also refused through T.raw now. CI builds the launcher target alone. - The helper-permission negative control runs only with the suite's stand-in runtime; with any other runtime, rr-prepare's helper checks are skipped and its GPU checks need --rr-prepare-gpu. - \tmp is removed and made anew at the start; a junction or link in its place or above it stops the run (a self-check puts a junction there). - --run-old-baseline is documented as running the 0.5.1 installer outside the suite's isolation guarantee, and says so when it runs. Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com> --- .github/workflows/ci.yml | 2 +- clean/installer/CMakeLists.txt | 7 + clean/installer/README.md | 15 ++- clean/installer/tests/launcher_build_facts.py | 121 +++++++++++++++--- .../tests/launcher_rr_prepare_cases.py | 77 +++++------ clean/installer/tests/run_launcher_tests.py | 12 +- clean/installer/tools/sha256_list.cmake | 13 ++ 7 files changed, 186 insertions(+), 61 deletions(-) create mode 100644 clean/installer/tools/sha256_list.cmake diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9f744934..f51c91cb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -126,7 +126,7 @@ 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 launcher-core-tests wg-test-canary wg-test-canary-strings + 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 diff --git a/clean/installer/CMakeLists.txt b/clean/installer/CMakeLists.txt index 05d1b26d..67ae2730 100644 --- a/clean/installer/CMakeLists.txt +++ b/clean/installer/CMakeLists.txt @@ -237,6 +237,13 @@ if(WRONGGPU_TESTING) 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) + # 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) + add_custom_command(TARGET WrongGPU POST_BUILD + COMMAND ${CMAKE_COMMAND} -DF1=$ -DF2=$ -DF3=$ + -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 231e626b..4af8ee99 100644 --- a/clean/installer/README.md +++ b/clean/installer/README.md @@ -934,10 +934,14 @@ Windows (the Wine run was not repeated for them): 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` (CMake targets of a testing build, built next to the launcher; not testing builds, the second - carrying the hooks' strings) start when run directly and are refused through every entry point. The 0.5.1 baseline - predates the hooks and runs only with `--run-old-baseline`. Every launcher call gets the work folder's `tmp` as `TEMP` - and `TMP`, and no inherited test override (`WRONGGPU_TEST_*`, `WG_*`). Checks that depend on how the launcher was built follow the build under + `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. Every launcher call gets the work folder's `tmp` (made anew at the start; refused when it or a + folder above it is a junction or link) as `TEMP` and `TMP`, and no inherited test override (`WRONGGPU_TEST_*`, `WG_*`; + `WRONGGPU_HIP_RUNTIME` only from `--hip`). 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 @@ -1013,7 +1017,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/tests/launcher_build_facts.py b/clean/installer/tests/launcher_build_facts.py index 6487c454..5232eadf 100644 --- a/clean/installer/tests/launcher_build_facts.py +++ b/clean/installer/tests/launcher_build_facts.py @@ -161,6 +161,60 @@ def require_test_hooks(path, what="the program"): _hooks_ok[key] = True +def reparse_in_path(path): + """The first folder of path (path itself and every folder above it that exists) that is a junction, a symbolic link or + another reparse point; None when there is none.""" + p = os.path.abspath(path) + while True: + if os.path.lexists(p): + st = os.lstat(p) + if os.path.islink(p) or getattr(st, "st_file_attributes", 0) & 0x400: # FILE_ATTRIBUTE_REPARSE_POINT + return p + up = os.path.dirname(p) + if up == p: + return None + p = up + + +def fresh_temp(work): + """\\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 + + +CANARIES = ("wg-test-canary.exe", "wg-test-canary-strings.exe") +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: + 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).""" @@ -199,21 +253,26 @@ def self_checks(t): 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; first run directly, to show they do start + # 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 - for name in ("wg-test-canary.exe", "wg-test-canary-strings.exe"): - built = os.path.join(os.path.dirname(t.exe), name) - if not os.path.isfile(built): - t.check("negative control %s: built next to the launcher (CMake target %s)" % (name, name[:-4]), False, built) - continue + 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, data in canaries.items(): canary = os.path.join(d, name) - shutil.copyfile(built, canary) + write(canary, data) started = canary + ".started" - subprocess.run([canary], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, timeout=60) + 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 = size(), "", "" + before, why, jwhy, rwhy = size(), "", "", "" try: t.run("version", exe=canary) except SystemExit as e: @@ -222,6 +281,10 @@ def self_checks(t): 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 @@ -229,18 +292,18 @@ def self_checks(t): 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, --launcher, --no-direct-launcher): refused before it runs, no start marker, nothing logged" % name, - runs and "not a WRONGGPU_TESTING build" in why and "not a WRONGGPU_TESTING build" in jwhy and entry == [True, True] and - not os.path.exists(started) and size() == before, (runs, why, jwhy, entry)) + "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} - strings = os.path.join(os.path.dirname(t.exe), "wg-test-canary-strings.exe") - if os.path.isfile(strings): # the hooks' strings and a valid checksum, but no identity resource: still not a testing build + if "wg-test-canary-strings.exe" in canaries: # the hooks' strings and a valid checksum, but no identity resource import struct - c = bytearray(read(strings)) + c = bytearray(canaries["wg-test-canary-strings.exe"]) at = struct.unpack_from("\tmp made anew; refused when it or a folder above it is a junction or link 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) diff --git a/clean/installer/tools/sha256_list.cmake b/clean/installer/tools/sha256_list.cmake new file mode 100644 index 00000000..0840d8ff --- /dev/null +++ b/clean/installer/tools/sha256_list.cmake @@ -0,0 +1,13 @@ +# SPDX-License-Identifier: MIT +# cmake -DF1= [-DF2= -DF3=] -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) + 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}") From ee0222de823831f08e0783e8e533c8202aa20d2b Mon Sep 17 00:00:00 2001 From: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com> Date: Sun, 15 Nov 2026 22:46:58 -0500 Subject: [PATCH 6/8] Launcher suite: no real HIP probe in a default run, the work folder checked first Re-check findings on the fresh-clone suite change: - Every launcher call gets WRONGGPU_TEST_HIP_CANDIDATES (a test build tries only those, never the system's, PATH's or ROCm's runtime): the --hip mock, else a file in the work folder that is not there, so a default run never loads a real HIP runtime. A self-check reads the probe's own lines: only that candidate is tried, never an inherited WRONGGPU_HIP_RUNTIME or candidate list (a safe stand-in file at those paths). - --hip must be an existing plain file, and the suite names it at the start. - --work and the folders above it are checked for junctions and links before the isolation self-test or anything is made or removed; a self-check gives the suite a junction as --work and finds its target untouched. - The canaries link with -municode under MinGW, as the launcher and restorer. - The installer README gives the complete fresh-clone commands: the mock payload, the testing WrongGPU target (with and without the direct route) and the suite. Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com> --- clean/installer/CMakeLists.txt | 4 +++ clean/installer/README.md | 17 ++++++++++ clean/installer/tests/launcher_build_facts.py | 31 +++++++++++++++---- clean/installer/tests/run_launcher_tests.py | 11 +++++++ 4 files changed, 57 insertions(+), 6 deletions(-) diff --git a/clean/installer/CMakeLists.txt b/clean/installer/CMakeLists.txt index 67ae2730..c035cb81 100644 --- a/clean/installer/CMakeLists.txt +++ b/clean/installer/CMakeLists.txt @@ -237,6 +237,10 @@ if(WRONGGPU_TESTING) 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() # 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) diff --git a/clean/installer/README.md b/clean/installer/README.md index 4af8ee99..d2d6ff22 100644 --- a/clean/installer/README.md +++ b/clean/installer/README.md @@ -952,6 +952,23 @@ Windows (the Wine run was not repeated for them): 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 work + 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 diff --git a/clean/installer/tests/launcher_build_facts.py b/clean/installer/tests/launcher_build_facts.py index 5232eadf..839ec925 100644 --- a/clean/installer/tests/launcher_build_facts.py +++ b/clean/installer/tests/launcher_build_facts.py @@ -311,19 +311,38 @@ def self_checks(t): t.check("preflight: a launcher changed after its link (a byte, or the hooks' strings and the identity appended), or a program " "with the strings and a valid checksum but no identity resource, is refused", all(refused.values()), refused) - # WRONGGPU_HIP_RUNTIME only from --hip: an inherited value (another HIP library) is never the launcher's + # the HIP check: only the --hip mock, or in a default run a file that is not there, is ever tried (never the system's, + # PATH's or ROCm's runtime), and an inherited WRONGGPU_HIP_RUNTIME / WRONGGPU_TEST_HIP_CANDIDATES is never tried: a safe + # stand-in file at those paths (the --hip mock's copy, else not a library), and the probe's own log line per candidate conflict = os.path.join(d, "conflict", "amdhip64_7.dll") - env = t.child_env(dict(os.environ, WRONGGPU_HIP_RUNTIME=conflict)) + write(conflict, read(t.hip) if t.hip else b"not a library") + env = t.child_env(dict(os.environ, WRONGGPU_HIP_RUNTIME=conflict, WRONGGPU_TEST_HIP_CANDIDATES=conflict)) saved = t.env t.env = dict(env, **{k: v for k, v in saved.items() if k in ("WRONGGPU_TEST_LIBRARIES", "WRONGGPU_TEST_ACCESS_LOG", "WRONGGPU_TEST_RUN_ID")}) + start = size() try: t.run("hipcheck") finally: t.env = saved - dll = t.j.get("dll", "") - t.check("HIP runtime: an inherited WRONGGPU_HIP_RUNTIME is dropped, only --hip sets it (hipcheck never uses the inherited one)", - env.get("WRONGGPU_HIP_RUNTIME") == t.hip and conflict.lower() not in dll.lower() and (not t.hip or dll.lower() == t.hip.lower()), - (env.get("WRONGGPU_HIP_RUNTIME"), t.hip, t.j)) + tried = [l.split("HIP check: ", 1)[1].rsplit(" -> 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) # 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")) diff --git a/clean/installer/tests/run_launcher_tests.py b/clean/installer/tests/run_launcher_tests.py index 1bafa875..37fc5e2a 100644 --- a/clean/installer/tests/run_launcher_tests.py +++ b/clean/installer/tests/run_launcher_tests.py @@ -59,6 +59,9 @@ def child_env(self, inherited): 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) os.makedirs(tmp, exist_ok=True) return env @@ -3057,7 +3060,15 @@ def main(): 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: # the mock HIP runtime: an existing plain file, named before anything runs + 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 = os.path.abspath(a.work) + bad = facts.reparse_in_path(work) # before the isolation self-test or anything is made or removed in it + if bad: + raise SystemExit("--work %s is not a plain folder (%s is a junction or link): not run" % (work, bad)) 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) From 37566155fadef45815448bc4d6bcb69c830061ee Mon Sep 17 00:00:00 2001 From: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com> Date: Sun, 15 Nov 2026 23:02:42 -0500 Subject: [PATCH 7/8] Launcher suite: a fresh run folder of its own, the HIP candidate list fail-closed Re-check findings on the fresh-clone suite change: - Each run makes a NEW folder of its own in --work (run--, never an existing one) and writes everything there: the isolation self-test's logs, the access log, tmp, the absent HIP candidate; nested test instances (the junction regression, convert-ignore) get new folders of their own with their own fresh tmp. Nothing that was in --work before is written to, followed or loaded: a self-check plants a link at <--work>\library-access.log and a load-marker DLL (tests/canary_dll.cpp, in the build list) at <--work>\no-hip, and finds the target, the link and the DLL unchanged and no load marker. - A test build's WRONGGPU_TEST_HIP_CANDIDATES, once set, is the whole candidate list even when it is empty (no candidate) or longer than EnvVar reads; never the system, PATH or ROCm search. The core tests check both. - --work holding ';' and an explicit empty --hip= are refused before anything is made. Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com> --- clean/installer/CMakeLists.txt | 5 +- clean/installer/README.md | 10 ++- clean/installer/src/wg_core/checks.cpp | 13 ++- clean/installer/tests/canary_dll.cpp | 17 ++++ clean/installer/tests/launcher_build_facts.py | 82 ++++++++++++++++++- clean/installer/tests/launcher_core_tests.cpp | 15 ++++ .../installer/tests/launcher_ignore_cases.py | 6 +- clean/installer/tests/run_launcher_tests.py | 24 +++--- clean/installer/tools/sha256_list.cmake | 4 +- 9 files changed, 149 insertions(+), 27 deletions(-) create mode 100644 clean/installer/tests/canary_dll.cpp diff --git a/clean/installer/CMakeLists.txt b/clean/installer/CMakeLists.txt index c035cb81..aae258d9 100644 --- a/clean/installer/CMakeLists.txt +++ b/clean/installer/CMakeLists.txt @@ -241,11 +241,14 @@ if(WRONGGPU_TESTING) 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) + 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) diff --git a/clean/installer/README.md b/clean/installer/README.md index d2d6ff22..53ffa1a5 100644 --- a/clean/installer/README.md +++ b/clean/installer/README.md @@ -939,9 +939,11 @@ Windows (the Wine run was not repeated for them): 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. Every launcher call gets the work folder's `tmp` (made anew at the start; refused when it or a - folder above it is a junction or link) as `TEMP` and `TMP`, and no inherited test override (`WRONGGPU_TEST_*`, `WG_*`; - `WRONGGPU_HIP_RUNTIME` only from `--hip`). Checks that depend on how the launcher was built follow the build under + 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 @@ -952,7 +954,7 @@ Windows (the Wine run was not repeated for them): 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 work + 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): 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/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 index 839ec925..fa034493 100644 --- a/clean/installer/tests/launcher_build_facts.py +++ b/clean/installer/tests/launcher_build_facts.py @@ -188,7 +188,33 @@ def fresh_temp(work): 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 @@ -206,7 +232,7 @@ def verified_canaries(exe): 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: + 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(): @@ -261,7 +287,8 @@ def self_checks(t): 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, data in canaries.items(): + 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" @@ -343,6 +370,57 @@ def self_checks(t): 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 + entry = {} + 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=dict(os.environ), + 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) + t.check("--work holding ';' (it would split the HIP candidate list) and an explicit empty --hip= are refused before anything " + "is made", all(entry.values()), entry) + # the run's own folder: a link and a load-marker DLL planted where an older run wrote (<--work>\library-access.log, + # <--work>\no-hip\amdhip64_7.dll) are never written, followed or loaded (only when nothing is there already) + root = os.path.dirname(t.work) + user = os.path.join(d, "user-data.txt") + write(user, b"user data") + planted, kind = [], "" + link = os.path.join(root, "library-access.log") + if not os.path.lexists(link): + try: + os.symlink(user, link) + kind = "symbolic link" + except OSError: + os.link(user, link) + kind = "hard link" + planted.append(link) + stand_in = os.path.join(root, "no-hip", "amdhip64_7.dll") + marker_dll = canaries.get(LOAD_MARKER) + loads = False + if marker_dll and not os.path.lexists(os.path.dirname(stand_in)): + 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.append(os.path.dirname(stand_in)) + again = new_run_folder(t.work, "isolation-again") + import launcher_isolation as iso + iso.self_test(again) # the start of a run again, in a fresh folder: the guard's own writes + t.run("version") + t.run("hipcheck") + t.check("the run's own fresh folder: a %s at <--work>\\library-access.log and a load-marker DLL at <--work>\\no-hip are never " + "written, followed or loaded (the target's bytes, the link and the DLL unchanged; no load marker)" % (kind or "file"), + read(user) == b"user data" and (not planted or (loads and os.path.isfile(stand_in) and read(stand_in) == marker_dll and + not os.path.exists(stand_in + ".loaded"))) and + (link not in planted or read(link) == b"user data"), (kind, loads, planted)) + for p in planted: # (only what this check planted) + if os.path.isdir(p) and not os.path.islink(p): + shutil.rmtree(p, ignore_errors=True) + elif os.path.lexists(p): + os.remove(p) # 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")) diff --git a/clean/installer/tests/launcher_core_tests.cpp b/clean/installer/tests/launcher_core_tests.cpp index a4fdfb28..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" @@ -2662,6 +2663,20 @@ 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)"; 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/run_launcher_tests.py b/clean/installer/tests/run_launcher_tests.py index 37fc5e2a..293672c8 100644 --- a/clean/installer/tests/run_launcher_tests.py +++ b/clean/installer/tests/run_launcher_tests.py @@ -40,6 +40,9 @@ def __init__(self, exe, work, model, hip): self.log = os.path.join(work, "launcher-test.log") self.out = os.path.join(work, "out.json") 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) @@ -62,8 +65,7 @@ def child_env(self, inherited): # 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) - os.makedirs(tmp, exist_ok=True) + os.makedirs(env["LOCALAPPDATA"], exist_ok=True) # (in the run's own fresh folder) return env def check(self, name, cond, detail=""): @@ -3003,8 +3005,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") @@ -3060,20 +3061,17 @@ def main(): 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: # the mock HIP runtime: an existing plain file, named before anything runs + 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 = os.path.abspath(a.work) - bad = facts.reparse_in_path(work) # before the isolation self-test or anything is made or removed in it - if bad: - raise SystemExit("--work %s is not a plain folder (%s is a junction or link): not run" % (work, bad)) + # --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) - facts.fresh_temp(work) # \tmp made anew; refused when it or a folder above it is a junction or link 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) diff --git a/clean/installer/tools/sha256_list.cmake b/clean/installer/tools/sha256_list.cmake index 0840d8ff..b7ca7091 100644 --- a/clean/installer/tools/sha256_list.cmake +++ b/clean/installer/tools/sha256_list.cmake @@ -1,9 +1,9 @@ # SPDX-License-Identifier: MIT -# cmake -DF1= [-DF2= -DF3=] -DOUT= -P sha256_list.cmake: one line " " per file +# 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) +foreach(v F1 F2 F3 F4) if(DEFINED ${v}) file(SHA256 "${${v}}" h) get_filename_component(n "${${v}}" NAME) From 518284d6a8767660d78224e4623b87e49f403d3f Mon Sep 17 00:00:00 2001 From: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com> Date: Sun, 15 Nov 2026 23:30:07 -0500 Subject: [PATCH 8/8] Launcher suite: the untouched-target control through a real run start; no bytecode writes Re-check findings on the fresh-clone suite change: - The control plants both fixtures (a link at library-access.log to user data and the load-marker DLL at no-hip\amdhip64_7.dll) in a simulated work root inside the run's own folder, never in the real --work, and checks both work. A child suite run against that root (--startup-only: the run's real start and the HIP check, then stop) makes one new run folder and leaves the link, its target and the DLL unchanged, with no load marker. - run_launcher_tests.py and run_installer_tests.py set sys.dont_write_bytecode before any local import, and the suite's child Python programs get PYTHONDONTWRITEBYTECODE=1: the ';' and empty --hip= refusals change nothing in the tests folder, which the self-check compares. Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com> --- clean/installer/tests/launcher_build_facts.py | 83 ++++++++++--------- clean/installer/tests/run_installer_tests.py | 1 + clean/installer/tests/run_launcher_tests.py | 8 ++ 3 files changed, 55 insertions(+), 37 deletions(-) diff --git a/clean/installer/tests/launcher_build_facts.py b/clean/installer/tests/launcher_build_facts.py index fa034493..ba207a2e 100644 --- a/clean/installer/tests/launcher_build_facts.py +++ b/clean/installer/tests/launcher_build_facts.py @@ -370,34 +370,46 @@ def self_checks(t): 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 - entry = {} + # --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=dict(os.environ), + 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", all(entry.values()), entry) - # the run's own folder: a link and a load-marker DLL planted where an older run wrote (<--work>\library-access.log, - # <--work>\no-hip\amdhip64_7.dll) are never written, followed or loaded (only when nothing is there already) - root = os.path.dirname(t.work) + "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") - planted, kind = [], "" - link = os.path.join(root, "library-access.log") - if not os.path.lexists(link): - try: - os.symlink(user, link) - kind = "symbolic link" - except OSError: - os.link(user, link) - kind = "hard link" - planted.append(link) - stand_in = os.path.join(root, "no-hip", "amdhip64_7.dll") - marker_dll = canaries.get(LOAD_MARKER) - loads = False - if marker_dll and not os.path.lexists(os.path.dirname(stand_in)): + 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 @@ -405,22 +417,19 @@ def self_checks(t): ctypes.windll.kernel32.FreeLibrary(ctypes.c_void_p(h._handle)) loads = os.path.isfile(probe + ".loaded") write(stand_in, marker_dll) - planted.append(os.path.dirname(stand_in)) - again = new_run_folder(t.work, "isolation-again") - import launcher_isolation as iso - iso.self_test(again) # the start of a run again, in a fresh folder: the guard's own writes - t.run("version") - t.run("hipcheck") - t.check("the run's own fresh folder: a %s at <--work>\\library-access.log and a load-marker DLL at <--work>\\no-hip are never " - "written, followed or loaded (the target's bytes, the link and the DLL unchanged; no load marker)" % (kind or "file"), - read(user) == b"user data" and (not planted or (loads and os.path.isfile(stand_in) and read(stand_in) == marker_dll and - not os.path.exists(stand_in + ".loaded"))) and - (link not in planted or read(link) == b"user data"), (kind, loads, planted)) - for p in planted: # (only what this check planted) - if os.path.isdir(p) and not os.path.islink(p): - shutil.rmtree(p, ignore_errors=True) - elif os.path.lexists(p): - os.remove(p) + 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")) diff --git a/clean/installer/tests/run_installer_tests.py b/clean/installer/tests/run_installer_tests.py index 700feca0..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") diff --git a/clean/installer/tests/run_launcher_tests.py b/clean/installer/tests/run_launcher_tests.py index 293672c8..973e5edb 100644 --- a/clean/installer/tests/run_launcher_tests.py +++ b/clean/installer/tests/run_launcher_tests.py @@ -19,6 +19,8 @@ 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) @@ -3052,6 +3054,8 @@ def main(): 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() @@ -3078,6 +3082,10 @@ def main(): 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