diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0623badf..75b1adf0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -117,6 +117,23 @@ jobs: cmake -S clean/installer -B out/launcher-tests -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_POLICY_DEFAULT_CMP0091=NEW -DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded -DWRONGGPU_PAYLOAD_DIR="$PWD/out/no-payload" -DWRONGGPU_TESTING=OFF -DWRONGGPU_PRESET_K=OFF -DWRONGGPU_DIRECT_ROUTE=OFF cmake --build out/launcher-tests --target wg-core-tests launcher-core-tests coexist-core-tests convert-ignore-tests model-choice-tests model-choice-k-tests model-choice-k-only-tests ctest --test-dir out/launcher-tests --output-on-failure -R "^(wg-core|launcher-core|coexist-core|convert-ignore|model-choice|model-choice-k|model-choice-k-only|source-size|wording)$" + - name: Test launcher from the test suite's stand-in payload (and a release build refusing it) + run: | + $PSNativeCommandUseErrorActionPreference = $true + 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") + cmake -S clean/installer -B out/launcher-mock @common -DWRONGGPU_TESTING=ON + cmake --build out/launcher-mock --target WrongGPU + # 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 + cmake --build out/launcher-mock-release --target gen/payload_table.h *> out/mock-release.log + $refused = $LASTEXITCODE -ne 0 + Get-Content out/mock-release.log | Select-Object -Last 15 + if (-not $refused) { throw "a release build embedded the test suite's stand-in runtime" } + if (-not (Select-String -Path out/mock-release.log -SimpleMatch "test suite's stand-in runtime" -Quiet)) { throw "the release build failed for another reason" } + $global:LASTEXITCODE = 0 # the refused build above was the expected result; the step's exit code is the last native one release-models: # The front end and launcher with the release's model flags (BUILDING.md 4.1 and 5.2: Model L and Model K on), so a diff --git a/clean/installer/CMakeLists.txt b/clean/installer/CMakeLists.txt index b7bea24a..82d39b25 100644 --- a/clean/installer/CMakeLists.txt +++ b/clean/installer/CMakeLists.txt @@ -177,12 +177,19 @@ else() set(MANIFEST_ARGS --manifest ${MANIFEST}) set(MANIFEST_SOURCE) endif() +# A WRONGGPU_TESTING build may embed the test suite's stand-in runtime (tests/run_installer_tests.py --prepare-only: the +# marker and a build manifest that says stand_in); any other build refuses it at this step (make_payload.py --testing). +if(WRONGGPU_TESTING) + set(TESTING_PAYLOAD_ARGS --testing) +else() + set(TESTING_PAYLOAD_ARGS) +endif() add_custom_command( OUTPUT ${GEN}/payload_table.h ${GEN}/resources.rc ${GEN}/app.ico COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/tools/make_payload.py --payload ${WRONGGPU_PAYLOAD_DIR} --map ${WRONGGPU_MAP} ${PRESET_K_MAP_ARGS} --version ${WRONGGPU_VERSION} --build-id=${WRONGGPU_BUILD_ID} --payload-name=${WRONGGPU_PAYLOAD_NAME} - ${DIRECT_ROUTE_PAYLOAD_ARGS} ${RR_PAYLOAD_ARGS} ${MAP_F_ARGS} ${MAP_L_ARGS} ${MANIFEST_ARGS} --out ${GEN} + ${DIRECT_ROUTE_PAYLOAD_ARGS} ${RR_PAYLOAD_ARGS} ${MAP_F_ARGS} ${MAP_L_ARGS} ${MANIFEST_ARGS} ${TESTING_PAYLOAD_ARGS} --out ${GEN} DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/tools/make_payload.py ${MANIFEST} ${WRONGGPU_MAP} ${PRESET_K_MAP_FILE} ${MAP_F_FILE} ${MAP_L_FILE} ${WRONGGPU_PAYLOAD_FILES} ${WRONGGPU_RR_FILES} COMMENT "Embedding the payload and the converter map") diff --git a/clean/installer/README.md b/clean/installer/README.md index 94f011ca..10117e38 100644 --- a/clean/installer/README.md +++ b/clean/installer/README.md @@ -820,7 +820,9 @@ player guide), `/UNINSTALL` (with `/OUT=`: collect logs first), `/COLLECT [ build time (`tools/make_payload.py` embeds the payload and the map, writes the resource script and draws the icon). The application manifest is a CMake source under MSVC (the linker embeds it once, `/MANIFESTUAC:NO`); MinGW gets it through the resource script. -- Linux, MinGW-w64: `./build-mingw.sh [map] [version] [out dir]`, or CMake with a MinGW toolchain file. +- Linux, MinGW-w64: `./build-mingw.sh [map] [version] [out dir]` makes a `WRONGGPU_TESTING` build (the Wine + test runner's, from the test suite's stand-in payload); `RELEASE=1 ./build-mingw.sh ...` makes a release-type build, which + needs a real payload (the stand-in is refused), as does CMake with a MinGW toolchain file without `-DWRONGGPU_TESTING=ON`. ## Tests @@ -994,8 +996,11 @@ normal one) and `/FSR4` / `/LIST`, with and without no-scan, against a non-empty predates all this and runs only with `--run-old-baseline`, in a 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_PAYLOAD_DIR=... -DWRONGGPU_MAP=...`) and run -`python tests\run_installer_tests.py --setup `. Natively it points `LOCALAPPDATA` and +the installer from them with CMake (`-DWRONGGPU_TESTING=ON -DWRONGGPU_PAYLOAD_DIR=... -DWRONGGPU_MAP=...`) and run +`python tests\run_installer_tests.py --setup `. The mock payload's runtime is a stand-in: it carries the +release marker and a build manifest that says `stand_in`, so only a `WRONGGPU_TESTING` build embeds it (`make_payload.py +--testing`); a release build refuses it at the payload step, as it refuses any runtime without a release build's manifest. +CI builds the testing launcher from it and checks that a release build refuses it. Natively it points `LOCALAPPDATA` and `ProgramData` at its work folder, always passes `/NOSCAN`, touches only "Apps & features" entries that point into its work folder, and skips the Steam/GOG library tests (they need registry keys of their own; run them under Wine) and the ROCm search-order test (it would write to `C:\Program Files`). The HIP mocks are built with MinGW `gcc` or, from diff --git a/clean/installer/build-mingw.sh b/clean/installer/build-mingw.sh index 9987fdfa..8e61b02e 100755 --- a/clean/installer/build-mingw.sh +++ b/clean/installer/build-mingw.sh @@ -4,6 +4,9 @@ # with the restorer and the payload embedded. Usage: # ./build-mingw.sh [map.json] [version] [out dir] # Default map: data/preset-M.v1.map.json; default out dir: build-mingw/. +# A WRONGGPU_TESTING build (the Wine test runner's: tests/run_installer_tests.py builds it from the test suite's stand-in +# payload, which only a testing build embeds: make_payload.py --testing). RELEASE=1 ./build-mingw.sh ... makes a release-type +# build instead: no WRONGGPU_TESTING, and the payload step refuses the stand-in (it needs a real runtime with its manifest). set -e cd "$(dirname "$0")" PAYLOAD="${1:?payload folder}" @@ -14,11 +17,12 @@ CXX="${CXX:-x86_64-w64-mingw32-g++}" WINDRES="${WINDRES:-x86_64-w64-mingw32-windres}" GEN="$OUT/gen" mkdir -p "$GEN" -python3 tools/make_payload.py --payload "$PAYLOAD" --map "$MAP" --version "$VERSION" --manifest src/setup.manifest --out "$GEN" +if [ "${RELEASE:-0}" = "1" ]; then TESTING_DEFINE=""; TESTING_PAYLOAD=""; else TESTING_DEFINE="-DWRONGGPU_TESTING"; TESTING_PAYLOAD="--testing"; fi +python3 tools/make_payload.py --payload "$PAYLOAD" --map "$MAP" --version "$VERSION" --manifest src/setup.manifest $TESTING_PAYLOAD --out "$GEN" "$WINDRES" -O coff -i "$GEN/resources.rc" -o "$GEN/resources.o" CONV=../converter/src CONV_SRC="$CONV/sha256.cpp $CONV/json.cpp $CONV/numeric.cpp $CONV/map.cpp $CONV/locate.cpp $CONV/lz4block.cpp $CONV/convert.cpp $CONV/output.cpp $CONV/pe_version.cpp $CONV/api.cpp" -FLAGS="-std=c++17 -O2 -Wall -Wextra -ffp-contract=off -municode -mwindows -static -I$GEN -I$CONV -Isrc" +FLAGS="-std=c++17 -O2 -Wall -Wextra -ffp-contract=off -municode -mwindows -static -I$GEN -I$CONV -Isrc $TESTING_DEFINE" LIBS="-lcomctl32 -lshell32 -lole32 -luuid -ladvapi32 -luser32 -lgdi32 -lgdiplus -ldwmapi -luxtheme -lwinhttp" # the restorer: wg_core without payload or UI printf '1 ICON "app.ico"\n' > "$GEN/restore_app.rc" diff --git a/clean/installer/tests/run_installer_tests.py b/clean/installer/tests/run_installer_tests.py index 27bb74bd..b9c1583e 100644 --- a/clean/installer/tests/run_installer_tests.py +++ b/clean/installer/tests/run_installer_tests.py @@ -161,14 +161,15 @@ def __init__(self, work): # Native Windows: never touch the tester's own WrongGPU data, store registry keys or libraries. self.env = dict(os.environ, LOCALAPPDATA=os.path.join(work, "localappdata"), ProgramData=os.path.join(work, "programdata")) os.makedirs(self.env["LOCALAPPDATA"], exist_ok=True) - # a test build takes its store libraries from this folder only (empty: none) and never reads the PC's own stores - # (detect.h TestLibraries) + # natively, a test build takes its store libraries from this folder only (empty: none) and never reads the PC's own + # stores (detect.h TestLibraries); under Wine the prefix is the program's own world and its store tests read the + # prefix's own registry and folders, so these are not set there libs = os.path.join(work, "libraries") os.makedirs(libs, exist_ok=True) - self.env["WRONGGPU_TEST_LIBRARIES"] = self.win(libs) self.access = os.path.join(work, "library-access.log") # every store access of the program, checked after each run (#243) - self.env["WRONGGPU_TEST_ACCESS_LOG"] = self.win(self.access) # (written by the program itself, never created here) if self.native: + self.env["WRONGGPU_TEST_LIBRARIES"] = self.win(libs) + self.env["WRONGGPU_TEST_ACCESS_LOG"] = self.win(self.access) # (written by the program itself, never created here) if os.environ.get("WRONGGPU_TESTING") != "1": raise SystemExit("native Windows runs need an installer built with WRONGGPU_TESTING (and WRONGGPU_TESTING=1 set): " "only a test build keeps to the test libraries and logs every store access (#243)") @@ -318,11 +319,22 @@ def model_ok(self, case=None): OLD_DLSS = mockpe.make_dll({"CompanyName": "Mock", "ProductName": "Mock DLSS"}, (310, 1, 0, 0), extra=random.Random(5).randbytes(200_000)) +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" + 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} + write(os.path.join(folder, os.path.splitext(name)[0] + ".build.json"), json.dumps(manifest, indent=1).encode()) + + 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)) - write(os.path.join(root, "wronggpu_runtime.dll"), mockpe.make_dll({"ProductName": "WrongGPU", "FileDescription": "WrongGPU runtime"}, (0, 3, 0, 0))) + stand_in_runtime(root, mockpe.make_dll({"ProductName": "WrongGPU", "FileDescription": "WrongGPU runtime"}, (0, 3, 0, 0))) rng = random.Random(11) for k in ("enc", "swin", "dec"): write(os.path.join(root, "wronggpu", "kernels", k + ".hsaco"), rng.randbytes(3000)) @@ -1934,14 +1946,15 @@ def tail(rc, log, root=None, want=None): all(not os.path.isfile(os.path.join(payload_dir, n)) or read(os.path.join(payload_dir, n)) not in read(t.setup) for n in COMPONENTS)) full = os.path.join(t.work, "payload-with-fsr30") shutil.rmtree(full, ignore_errors=True) - for n in SLOTS + ["wronggpu_runtime.dll"]: + for n in SLOTS: write(os.path.join(full, n), mockpe.make_dll(mockpe.FRONT_END, (0, 4, 5, 0), extra=n.encode())) + stand_in_runtime(full, mockpe.make_dll(mockpe.FRONT_END, (0, 4, 5, 0), extra=b"wronggpu_runtime.dll")) tables = {} for flag in ("", "--hosted-only"): out = os.path.join(t.work, "payload-table" + flag) shutil.rmtree(out, ignore_errors=True) p = subprocess.run([sys.executable, os.path.join(INSTALLER, "tools", "make_payload.py"), "--payload", full, "--map", os.path.join(t.work, "prepared", "test-map.json"), - "--version", "0.0.0", "--out", out] + ([flag] if flag else []), stdout=subprocess.PIPE, stderr=subprocess.STDOUT) + "--version", "0.0.0", "--out", out, "--testing"] + ([flag] if flag else []), stdout=subprocess.PIPE, stderr=subprocess.STDOUT) tables[flag] = (read(os.path.join(out, "payload_table.h")) + read(os.path.join(out, "resources.rc"))).decode() if p.returncode == 0 else "" t.check("make_payload.py --hosted-only (what this build passes): the FSR 3.0 DLLs of a payload folder are left out, the rest is built in", all(n in tables[""] for n in SLOTS) and SLOTS[0] in tables["--hosted-only"] and "wronggpu_runtime.dll" in tables["--hosted-only"] and @@ -2263,6 +2276,7 @@ def main(): out = os.path.join(work, "build") subprocess.run([os.path.join(INSTALLER, "build-mingw.sh"), os.path.join(prep, "payload"), os.path.join(prep, "test-map.json"), "0.3.0-test", out], check=True) setup = os.path.join(out, "WrongGPU.exe") # the launcher; its /switches are the installer's + os.environ["WRONGGPU_TESTING"] = "1" # (build-mingw.sh makes a WRONGGPU_TESTING build: its Apps & features root, its tests) env = Env(work) for d in ("games", "steam", "epic", "gog", "elsewhere"): shutil.rmtree(os.path.join(work, d), ignore_errors=True) diff --git a/clean/installer/tools/make_payload.py b/clean/installer/tools/make_payload.py index 550dace7..b0225eff 100644 --- a/clean/installer/tools/make_payload.py +++ b/clean/installer/tools/make_payload.py @@ -70,11 +70,15 @@ def fail(msg): import check_no_dev_diagnostics as devcheck # noqa: E402 +TESTING = False # --testing: a WRONGGPU_TESTING build (CMake), which may embed the test suite's stand-in runtime + + def refuse_developer_runtime(rel, data, full=None): """A runtime library is accepted only with its build manifest (clean/runner/build.py writes .build.json next to it): the SHA-256 of the library must match a manifest that says dev_diagnostics = false, as well as the marker and the negative scan; anything else refuses the payload (failing closed). Other embedded files must not carry a developer - runtime.""" + runtime. The test suite's stand-in runtime (tests/run_installer_tests.py payload: its manifest says "stand_in": true) + passes the same checks and is embedded only by a WRONGGPU_TESTING build (--testing); any other build refuses it.""" if devcheck.is_runtime_name(rel): manifest = None mpath = os.path.splitext(full)[0] + ".build.json" if full else None @@ -82,6 +86,14 @@ def refuse_developer_runtime(rel, data, full=None): with open(mpath, "rb") as f: manifest = f.read() ok, text = devcheck.check_runtime_with_manifest(rel, data, manifest) + if ok: + try: + stand_in = json.loads(manifest.decode("utf-8")).get("stand_in") is True + except Exception: + stand_in = False + if stand_in and not TESTING: + fail("%s: the test suite's stand-in runtime (its build manifest says stand_in): only a WRONGGPU_TESTING build " + "embeds it; a release build needs the real runtime built with clean/runner/build.py" % rel) else: ok, text, _ = devcheck.check_artifact(rel, data) if not ok: @@ -225,8 +237,12 @@ def main(): "installer without them") ap.add_argument("--map-f", help="the RR converter map (preset F); omit for an installer without it") ap.add_argument("--map-l", help="Model L's converter map (preset L); omit for an installer without Model L") + ap.add_argument("--testing", action="store_true", help="a WRONGGPU_TESTING build (CMake passes it): it may embed the test " + "suite's stand-in runtime (its build manifest says stand_in); any other build refuses that runtime") ap.add_argument("--out", required=True) a = ap.parse_args() + global TESTING + TESTING = a.testing root = os.path.abspath(a.payload) if not os.path.isdir(root): fail("payload folder not found: " + root) diff --git a/clean/tests/test_dev_diagnostics_off.py b/clean/tests/test_dev_diagnostics_off.py index d2ba4549..b3c64743 100644 --- a/clean/tests/test_dev_diagnostics_off.py +++ b/clean/tests/test_dev_diagnostics_off.py @@ -155,6 +155,25 @@ def test_a_release_runtime_with_its_manifest_is_packaged(self): self.assertIn("wronggpu_runtime.dll", table) self.assertNotIn("build.json", table, "the manifest is read for the gate and is not shipped") + def test_the_test_suites_stand_in_only_in_a_testing_build(self): + lib = self._release() + stand_in = {"wronggpu_runtime.dll": manifest_for("wronggpu_runtime.dll", lib, stand_in=True)} + r, out = self._pack({"wronggpu_runtime.dll": lib}, stand_in) + self.assertNotEqual(r.returncode, 0, "a release build (no --testing) never embeds the test stand-in") + self.assertIn("stand-in runtime", r.stderr + r.stdout) + self.assertFalse(os.path.isfile(os.path.join(out, "payload_table.h"))) + r, out = self._pack({"wronggpu_runtime.dll": lib}, stand_in, extra_args=("--testing",)) + self.assertEqual(r.returncode, 0, r.stdout + r.stderr) + self.assertIn("wronggpu_runtime.dll", open(os.path.join(out, "payload_table.h"), encoding="utf-8").read()) + # --testing changes nothing else: a stand-in still needs the marker and its own bytes' manifest + r, _ = self._pack({"wronggpu_runtime.dll": b"MZ no marker"}, {"wronggpu_runtime.dll": manifest_for("wronggpu_runtime.dll", b"MZ no marker", stand_in=True)}, + extra_args=("--testing",)) + self.assertNotEqual(r.returncode, 0) + r, _ = self._pack({"wronggpu_runtime.dll": lib + b"changed"}, stand_in, extra_args=("--testing",)) + self.assertNotEqual(r.returncode, 0) + r, _ = self._pack({"wronggpu_runtime.dll": lib}, extra_args=("--testing",)) + self.assertNotEqual(r.returncode, 0, "a testing build still needs a manifest") + def test_no_manifest_refuses_the_payload(self): r, out = self._pack({"wronggpu_runtime.dll": self._release()}) self.assertNotEqual(r.returncode, 0)