Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,12 @@ jobs:
$common = @("-G", "Ninja", "-DCMAKE_BUILD_TYPE=Release", "-DCMAKE_POLICY_DEFAULT_CMP0091=NEW", "-DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded",
"-DWRONGGPU_PAYLOAD_DIR=$PWD/out/mock/prepared/payload", "-DWRONGGPU_MAP=$PWD/out/mock/prepared/test-map.json", "-DWRONGGPU_VERSION=0.3.0-test")
cmake -S clean/installer -B out/launcher-mock @common -DWRONGGPU_TESTING=ON
cmake --build out/launcher-mock --target WrongGPU
cmake --build out/launcher-mock --target WrongGPU launcher-core-tests
# the core tests in a WRONGGPU_TESTING build too: its test-only rules (the rr-prepare helper keeps the tests' LOCALAPPDATA)
out/launcher-mock/launcher-core-tests.exe
# the launcher suite runs only a testing build, by its identity (launcher_build_facts.py): this launcher and its restorer
# pass; the negative controls (not testing builds, one carrying the hooks' strings) are refused
python -c "import sys; sys.path.insert(0, 'clean/installer/tests'); import launcher_build_facts as f; ok = [p for p in ('WrongGPU.exe', 'WrongGPU-Restore.exe') if f.missing_test_hooks('out/launcher-mock/' + p)]; bad = [p for p in ('wg-test-canary.exe', 'wg-test-canary-strings.exe') if not f.missing_test_hooks('out/launcher-mock/' + p)]; sys.exit('not accepted: %s; not refused: %s' % (ok, bad) if ok or bad else 0)"
# the negative control: a release build (WRONGGPU_TESTING=OFF) with the same stand-in refuses it at the payload step
cmake -S clean/installer -B out/launcher-mock-release @common -DWRONGGPU_TESTING=OFF
$PSNativeCommandUseErrorActionPreference = $false
Expand Down
33 changes: 33 additions & 0 deletions clean/installer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 $<TARGET_FILE:WrongGPU-Restore> ${GEN}/restorer.bin
DEPENDS WrongGPU-Restore COMMENT "Embedding the restorer")
Expand All @@ -218,6 +228,29 @@ add_executable(WrongGPU WIN32 src/app/main.cpp src/app/wizard.cpp src/app/cli.cp
${GEN}/resources.rc ${GEN}/restore.rc ${GEN}/restorer.bin ${GEN}/payload_table.h ${MANIFEST_SOURCE})
add_dependencies(WrongGPU WrongGPU-Restore)
if(WRONGGPU_TESTING)
target_sources(WrongGPU PRIVATE ${GEN}/testing_identity.rc)
if(MSVC)
target_link_options(WrongGPU PRIVATE /RELEASE)
endif()
# the launcher suite's negative controls: programs that are not testing builds (no identity), one with the hook strings;
# each leaves <program>.started next to itself when it starts, so the suite can prove it never started them
add_executable(wg-test-canary tests/canary.cpp)
add_executable(wg-test-canary-strings tests/canary.cpp)
target_compile_definitions(wg-test-canary-strings PRIVATE WG_CANARY_HOOK_STRINGS)
if(NOT MSVC)
target_link_options(wg-test-canary PRIVATE -municode) # (wmain, as the launcher and restorer)
target_link_options(wg-test-canary-strings PRIVATE -municode)
endif()
add_library(wg-test-canary-dll SHARED tests/canary_dll.cpp) # a load marker: writes <dll>.loaded when loaded
set_target_properties(wg-test-canary-dll PROPERTIES PREFIX "")
# built with the testing launcher (a single-target build has them), and the build list the suite checks before it starts
# one: the SHA-256 of this WrongGPU.exe and of the canaries, written after the launcher's link
add_dependencies(WrongGPU wg-test-canary wg-test-canary-strings wg-test-canary-dll)
add_custom_command(TARGET WrongGPU POST_BUILD
COMMAND ${CMAKE_COMMAND} -DF1=$<TARGET_FILE:WrongGPU> -DF2=$<TARGET_FILE:wg-test-canary> -DF3=$<TARGET_FILE:wg-test-canary-strings>
-DF4=$<TARGET_FILE:wg-test-canary-dll>
-DOUT=$<TARGET_FILE_DIR:WrongGPU>/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()
Expand Down
47 changes: 45 additions & 2 deletions clean/installer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <WrongGPU.exe> --work <dir> [--baseline <0.5.1 WrongGPU-Setup.exe>]
[--hip <mock>]`: the verbs against generated fixture games (names and synthetic bytes only) with a
[--hip <mock>] [--no-direct-launcher <WrongGPU.exe>] [--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\`,
Expand All @@ -929,6 +929,48 @@ Windows (the Wine run was not repeated for them):
the experimental confirmation, the model kept while another managed game uses it, adoption of a real 0.5.1
install (v1 record, settings imported, restorer, entries), self-install / self-uninstall with one Apps & features
entry, portable paths, the update check off, and the window built hidden (`ui-dump`: pages, names, visibility).
The suite runs only `WRONGGPU_TESTING` builds, by their identity: the named resource `WRONGGPU_TESTING_BUILD` only such
a build links in, a PE checksum that matches (MSVC `/RELEASE`: a program changed or appended to after its link fails)
and the test hooks' strings inside its sections. Every launcher it is given, their copies and the `uninstall.exe` they
write are checked before they run; anything else is refused unrun (a release launcher could reach the real download
page, the PC's stores and the real Apps & features root). Negative controls: `wg-test-canary` and
`wg-test-canary-strings` (not testing builds, the second carrying the hooks' strings) are built with a testing
`WrongGPU` target, which then writes `wg-test-build.sha256` (the SHA-256 of that `WrongGPU.exe` and of the canaries)
next to itself. The suite starts only canaries that list verifies as this build's, by their full path and with its own
child environment: they start when run directly and are refused through every launch path. The 0.5.1 baseline predates
the hooks: `--run-old-baseline` runs it OUTSIDE the suite's isolation guarantee, unchecked, and only in a disposable,
fully redirected sandbox. `--work` must be a plain folder (no junction or link in it or above it, no `;`): each run makes
a NEW folder of its own in it (`run-<UTC time>-<pid>`) and writes everything there, nested test instances in new folders of
their own, so nothing that was in `--work` before is written to, followed or loaded. Every launcher call gets its
instance's fresh `tmp` as `TEMP` and `TMP`, and no inherited test override (`WRONGGPU_TEST_*`, `WG_*`;
`WRONGGPU_HIP_RUNTIME` only from `--hip`, which must be an existing plain file; an empty `--hip=` is refused). Checks that depend on how the launcher was built follow the build under
test (`launcher_build_facts.py`). The edition section always runs with `--launcher`: its download, cache and address
rules on either route, and a repair without any OptiScaler ending through the direct route (exit 0) or refused (exit 2)
without it. `--no-direct-launcher` (a testing build with `-DWRONGGPU_DIRECT_ROUTE=OFF`, as releases) runs the section
again in a pass of its own for the exit-2 refusals. rr-prepare stays in the work folder: its no-card path, and with the
suite's stand-in runtime the helper's expected failure to load it (under a test driver version, so on any PC) with the
suite's `LOCALAPPDATA` kept. The checks of RR's kernels really prepared need a payload with the real runtime and fill the
user's real graphics driver cache, so they run only with `--rr-prepare-gpu`. A test build starts no rr-prepare helper
unless the test allows it (`WRONGGPU_TEST_ALLOW_RR_HELPER=1`: the stand-in case and the opt-in pass only). Test builds'
other hooks for this: `WRONGGPU_TEST_RR_DRIVER` (a driver version, or `none`), `WRONGGPU_TEST_HELPER_ENV_LOG`, and
`WRONGGPU_TEST_REAL_DRIVER_CACHE=1` (the helper gets the user's real `LOCALAPPDATA`; release builds always do).
The HIP check only ever tries `--hip` (an existing file, named at the start), or in a default run a file in the run
folder that is not there (`WRONGGPU_TEST_HIP_CANDIDATES`): a default run never loads a real HIP runtime.
On a fresh clone, from the repository root in an x64 Visual Studio developer prompt (PowerShell), with nothing else
needed (a single `WrongGPU` target builds the restorer and the canaries too):

```
python clean/installer/tests/run_installer_tests.py --work out/mock --prepare-only
$common = @("-G", "Ninja", "-DCMAKE_BUILD_TYPE=Release", "-DCMAKE_POLICY_DEFAULT_CMP0091=NEW", "-DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded",
"-DWRONGGPU_PAYLOAD_DIR=$PWD/out/mock/prepared/payload", "-DWRONGGPU_MAP=$PWD/out/mock/prepared/test-map.json",
"-DWRONGGPU_VERSION=0.3.0-test", "-DWRONGGPU_TESTING=ON")
cmake -S clean/installer -B out/launcher-test @common
cmake --build out/launcher-test --target WrongGPU
cmake -S clean/installer -B out/launcher-test-nodirect @common -DWRONGGPU_DIRECT_ROUTE=OFF
cmake --build out/launcher-test-nodirect --target WrongGPU
python clean/installer/tests/run_launcher_tests.py --launcher out/launcher-test/WrongGPU.exe --work out/launcher-suite --no-direct-launcher out/launcher-test-nodirect/WrongGPU.exe
```

Its `[direct-rr]` part: a game that ships the RR library without the game interface's RR plugin (the Unreal Engine
plugin layout of Hogwarts Legacy, LEGO Batman, Borderlands 4) creates Ray Reconstruction itself (`rr.h`
`RrUse::direct`; status `rr_direct`). WrongGPU's RR runs there only through WrongGPU's edition of OptiScaler (plugin
Expand Down Expand Up @@ -994,7 +1036,8 @@ The run stops, loudly, on:

The `[isolation-verbs]` section runs install, repair, update, uninstall, the window's refresh, a batch (a noscan job, then a
normal one) and `/FSR4` / `/LIST`, with and without no-scan, against a non-empty test library. The 0.5.1 baseline installer
predates all this and runs only with `--run-old-baseline`, in a fully redirected sandbox.
predates all this and runs only with `--run-old-baseline`: outside the suite's isolation guarantee, in a disposable, fully
redirected sandbox.

On Windows: `python tests\run_installer_tests.py --prepare-only` writes the mock payload and the synthetic map; build
the installer from them with CMake (`-DWRONGGPU_TESTING=ON -DWRONGGPU_PAYLOAD_DIR=... -DWRONGGPU_MAP=...`) and run
Expand Down
13 changes: 11 additions & 2 deletions clean/installer/src/wg_core/checks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,17 @@ bool VersionLess(const wstring& a, const wstring& b) {
std::vector<wstring> HipCandidates() {
std::vector<wstring> 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));
Expand Down
1 change: 1 addition & 0 deletions clean/installer/src/wg_core/optiscaler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
48 changes: 40 additions & 8 deletions clean/installer/src/wg_core/rrprep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<wchar_t> 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<wchar_t> 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<wchar_t> env;
LPWCH block = GetEnvironmentStringsW();
Expand All @@ -86,9 +94,12 @@ std::vector<wchar_t> 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**);
Expand Down Expand Up @@ -181,6 +192,15 @@ int PrepareRr(Context& ctx, const wstring& dataDir, const wstring& exe, const ws
const wstring driver = RrDriverVersion();
if (driver.empty()) { if (why) *why = L"no AMD graphics card found"; return 2; }
if (!IsFile(runtimeDll)) { if (why) *why = L"the runtime isn't there (" + runtimeDll + L")"; return 3; }
#ifdef WRONGGPU_TESTING
// tests: a test build starts no helper unless the test allows it (WRONGGPU_TEST_ALLOW_RR_HELPER=1): whatever was decided
// above, a default test run never prepares anything on the GPU
if (EnvVar(L"WRONGGPU_TEST_ALLOW_RR_HELPER") != L"1") {
if (why) *why = L"test: the helper may not start (WRONGGPU_TEST_ALLOW_RR_HELPER)";
LogLine(ctx, L"Ray Reconstruction: test: the helper may not start for " + BaseName(exe) + L" (WRONGGPU_TEST_ALLOW_RR_HELPER)");
return 3;
}
#endif
const wstring run = Join(PrepDir(dataDir), L"run");
EnsureDir(run);
const wstring helper = Join(run, BaseName(exe));
Expand All @@ -204,7 +224,7 @@ int PrepareRr(Context& ctx, const wstring& dataDir, const wstring& exe, const ws
wstring cmd = L"\"" + helper + L"\" --rr-prepare \"" + runtimeDll + L"\" " + std::to_wstring(passes);
std::vector<wchar_t> cl(cmd.begin(), cmd.end());
cl.push_back(0);
std::vector<wchar_t> env = HelperEnvironment(log);
std::vector<wchar_t> 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);
Expand Down Expand Up @@ -275,6 +295,18 @@ int PrepareRr(Context& ctx, const wstring& dataDir, const wstring& exe, const ws

int RunRrPrepareHelper(int argc, wchar_t** argv) {
if (argc < 4) return 9;
#ifdef WRONGGPU_TESTING
// tests: the LOCALAPPDATA the helper was started with, appended to this file before the runtime is loaded
if (const wstring f = EnvVar(L"WRONGGPU_TEST_HELPER_ENV_LOG"); !f.empty()) {
const string line = ToUtf8(L"LOCALAPPDATA=" + EnvVar(L"LOCALAPPDATA")) + "\n";
HANDLE h = CreateFileW(f.c_str(), FILE_APPEND_DATA, FILE_SHARE_READ | FILE_SHARE_WRITE, nullptr, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr);
if (h != INVALID_HANDLE_VALUE) {
DWORD w = 0;
WriteFile(h, line.data(), (DWORD)line.size(), &w, nullptr);
CloseHandle(h);
}
}
#endif
HMODULE m = LoadLibraryExW(argv[2], nullptr, LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR | LOAD_LIBRARY_SEARCH_SYSTEM32);
if (!m) return 8;
typedef int (*Cb)(void*, uint32_t, uint32_t, uint32_t, const char*, uint32_t, uint32_t);
Expand Down
5 changes: 5 additions & 0 deletions clean/installer/src/wg_core/rrprep.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "context.h"

#include <functional>
#include <vector>

namespace wg {

Expand Down Expand Up @@ -60,5 +61,9 @@ int PrepareRr(Context& ctx, const wstring& dataDir, const wstring& exe, const ws
const std::function<bool(const RrPrepProgress&)>& progress, wstring* why);
// The helper side: `<exe> --rr-prepare <runtime dll> <passes>` (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<wchar_t> RrHelperEnvironment(const wstring& log);

} // namespace wg
Loading
Loading