Merge branch 'claude/amd-fight-crash-ef03a9' into test-all-fixes

This commit is contained in:
chrg6
2026-11-10 15:22:07 -05:00
24 changed files with 745 additions and 37 deletions

View File

@@ -262,6 +262,50 @@ class VersionTest(unittest.TestCase):
versions.parse('banana')
# A player's settings file as a report showed it (an AMD card, 0.7.1): what the game's menu wrote, three lines added by
# hand that are no settings of the game (async_compute, vram_safe_mode, exception_handler: the player took the first for
# the fix of a crash and asked for it as a default, because "the configuration file gets overwritten on updates"), and a
# comment. Saved as an editor on Windows saves it: CRLF line ends, no line end after the last line. Nothing in an
# update may change a byte of it (PlayerIniTest, BackgroundUpdateTest and MakeGameTest each run their part of one).
PLAYER_INI = (
b'# my settings\r\n'
b'[display]\r\n'
b'async_compute = 1\r\n'
b'fullscreen = 1\r\n'
b'window_size = 1920x1080\r\n'
b'gpu_index = 0\r\n'
b'perf_overlay = fps\r\n'
b'vk_present = mailbox\r\n'
b'upscaler = bilinear\r\n'
b'dlaa = 1\r\n'
b'framegen = off\r\n'
b'taa = fsr3\r\n'
b'hdr = 0\r\n'
b'aspect = fit\r\n'
b'game_res = 1800\r\n'
b'sharpness = 80\r\n'
b'aniso = 2\r\n'
b'assume_focus = 1\r\n'
b'texture_detail = auto\r\n'
b'\r\n'
b'[input]\r\n'
b'bind_a = key:default, pad:south\r\n'
b'bind_b = key:default, pad:east\r\n'
b'bind_x = key:default, pad:north\r\n'
b'bind_y = key:default, pad:west\r\n'
b'\r\n'
b'[language]\r\n'
b'operation_mode = docked\r\n'
b'\r\n'
b'[performance]\r\n'
b'wb_lazy = 0\r\n'
b'vram_safe_mode = 1\r\n'
b'exception_handler = 1\r\n'
b'\r\n'
b'[frame rate]\r\n'
b'fps_limit = 120')
class GameIniTest(Tmp):
"""The game settings the launcher switches (launcher/gameini.py), read as runtime/cfg.c reads nx2navi.ini."""
@@ -305,6 +349,45 @@ class GameIniTest(Tmp):
gameini.put(self.tmp, 'discord', 'discord_rpc', '1')
self.assertTrue((self.tmp / 'nx2navi.ini').is_dir())
class PlayerIniTest(Tmp):
"""The settings file of a player (PLAYER_INI) under the two writers outside the game: the launcher's Settings
(launcher/gameini.py) and the older installer's last step (installer/ini.py). Each changes the one line it is
for; the lines that are no settings of the game, the comment and every other byte stay."""
def test_the_launchers_setting_adds_one_line(self):
ini = self.tmp / 'nx2navi.ini'
ini.write_bytes(PLAYER_INI)
self.assertEqual(gameini.get(self.tmp, 'wb_lazy'), '0')
self.assertEqual(gameini.get(self.tmp, 'async_compute'), '1') # read like any line; the game ignores it
gameini.put(self.tmp, 'discord', 'discord_rpc', '0')
self.assertEqual(ini.read_bytes(), PLAYER_INI + b'\r\n\r\n[discord]\r\ndiscord_rpc = 0\r\n')
gameini.put(self.tmp, 'discord', 'discord_rpc', '1')
self.assertEqual(ini.read_bytes(), PLAYER_INI + b'\r\n\r\n[discord]\r\ndiscord_rpc = 1\r\n')
def test_the_older_installer_changes_the_language_line_only(self):
"""installer/ini.py sets the language, in the older installer's last step at every install and update: the
one line goes under [language] with the file's own line ends, and every other byte stays (it used to write
the whole file again with LF line ends, a line end after the last line and no byte order mark). A second run
leaves the file alone; a changed language changes that line; a byte order mark and a line that is not UTF-8
stay too."""
from installer import ini as inst_ini
path = self.tmp / 'nx2navi.ini'
path.write_bytes(PLAYER_INI)
inst_ini.write(self.tmp, 'en-US')
want = PLAYER_INI.replace(b'[language]\r\n', b'[language]\r\nlang = en-US\r\n')
self.assertEqual(path.read_bytes(), want)
self.assertEqual(want.count(b'lang = en-US'), 1)
stamp = path.stat().st_mtime_ns
inst_ini.write(self.tmp, 'en-US')
self.assertEqual((path.read_bytes(), path.stat().st_mtime_ns), (want, stamp))
inst_ini.write(self.tmp, 'de')
self.assertEqual(path.read_bytes(), want.replace(b'lang = en-US', b'lang = de'))
marked = b'\xef\xbb\xbf# caf\xe9\r\nlang = ja\r\nasync_compute = 1'
path.write_bytes(marked)
inst_ini.write(self.tmp, 'fr')
self.assertEqual(path.read_bytes(), marked.replace(b'lang = ja', b'lang = fr'))
self.assertFalse((self.tmp / 'nx2navi.ini.tmp').exists())
class RebuildArgsTest(Tmp):
"""Rebuild the Game compiles the game's code for this processor's level (--retune); an update keeps the level its
@@ -898,6 +981,28 @@ class BackgroundUpdateTest(Tmp):
self.assertEqual(bg.install(self.game, rel), '')
self.assertEqual(len(self.restarts), 1)
def test_an_update_leaves_the_games_settings_file(self):
"""The launcher's part of an update (the release staged beside the running version, the switch to it, the
cleanup after the rebuild) changes nothing in the game folder, also in its default place inside the
launcher's folder: the player's nx2navi.ini is the same bytes afterwards, and an uninstall that keeps the game
does not name it."""
game = self.layout.root / 'game'
(game / 'profile').mkdir(parents=True)
ini = game / 'nx2navi.ini'
ini.write_bytes(PLAYER_INI)
before = sorted(p.relative_to(game).as_posix() for p in game.rglob('*'))
bg = self.background(self.context())
rel = self.publish('0.5.0', runtime='py-2')
self.assertEqual(self.stage(bg, rel), 'staged')
self.assertEqual(ini.read_bytes(), PLAYER_INI)
self.assertEqual(bg.install(str(game), rel, why='the launcher started'), '0.5.0')
self.assertEqual(self.state(), ('0.5.0', '0.4.0', [['--continue-update', '0.4.0']]))
updater.prune(self.layout) # what ContinueUpdateJob ends with
self.assertEqual(ini.read_bytes(), PLAYER_INI)
self.assertEqual(sorted(p.relative_to(game).as_posix() for p in game.rglob('*')), before)
gone, _ = winsys.uninstall_plan(self.layout)
self.assertFalse([p for p in gone if p == game or p in ini.parents])
def test_no_install_while_the_game_runs(self):
"""A copy of the game started elsewhere, the copy the launcher started, and a download under way each hold
the install back, also one the player asked for."""
@@ -1635,6 +1740,75 @@ class MakeGameTest(Tmp):
self.assertEqual(build(), ([], [{'ev': 'step', 'step': 'prompts', 'state': 'skip'}], 4))
self.assertTrue((self.out / 'romfs-patches-xbox' / 'manifest.tsv').is_file())
def test_an_update_keeps_the_settings_file(self):
"""The rebuild an update ends with (make_game.py --rebuild under a newer kit: the lift, the compile, the
shaders step and the button prompts all run again) leaves the game folder's nx2navi.ini as the player has it,
byte for byte. The build reads the file (the bind_ lines for the prompts, shader_carry for the shaders step)
and never writes it; so does a second rebuild that finds nothing to do, and one from the game files again.
The lift and the compile are stand-ins here (the real ones need the game and clang); the check, the ExeFS and
RomFS steps, the shaders step and the prompts step are the real ones."""
from unittest import mock
kit = self.tmp / 'kit'
for d in ('tools', 'bin', 'recomp'):
(kit / d).mkdir(parents=True)
(kit / 'VERSION').write_text('0.7.0\n')
(kit / 'recomp' / 'gen.py').write_text('# the lifter of 0.7.0\n')
(kit / 'bin' / self.mg.XLATE_NAME).write_bytes(b'translator')
(kit / 'bin' / 'nx2navi_xlate.id').write_text('xlate 1\n')
(kit / 'tools' / 'prepare_shaders.py').write_text('print("prepare-shaders: progress build 1 1", flush=True)\n')
for name in ('prompt_art.py', 'button_icons.py'):
shutil.copy2(ROOT / 'tools' / name, kit / 'tools' / name)
(kit / 'tools' / 'pad_prompts.py').write_text(FAKE_PAD_PROMPTS)
art = kit / 'prompt-art' / 'XGamepad' / 'Default'
art.mkdir(parents=True)
(art / 'T_X_A_White.png').write_bytes(b'picture one')
ran = []
def fake(name):
def step(*args, **kw):
ran.append(name)
return step
def build(*source):
"""One run of make_game.py; the steps that ran, in order."""
buf = io.StringIO()
argv = ['make_game.py', *source, '--out', str(self.out), '--msys', str(self.msys), '--events']
with mock.patch.object(sys, 'argv', argv), contextlib.redirect_stdout(buf), \
contextlib.redirect_stderr(io.StringIO()):
self.mg.main()
events = [json.loads(ln[2:]) for ln in buf.getvalue().splitlines() if ln.startswith('@@')]
return [e['step'] for e in events if e['ev'] == 'step' and e['state'] == 'start']
sys.path.insert(0, str(self.layout.pydeps)) # the fake zbic
self.addCleanup(sys.path.remove, str(self.layout.pydeps))
ini = self.out / 'nx2navi.ini'
with mock.patch.multiple(self.mg, KIT=kit, PROMPT_PACKAGES={}, EVENTS=False, step_lift=fake('lift'),
step_compile=fake('compile'), step_scan=fake('scan')):
self.assertEqual(build('--nup', str(self.nup)),
['check', 'exefs', 'romfs', 'lift', 'compile', 'shaders', 'prompts', 'scan'])
self.assertFalse(ini.exists()) # the build makes no settings file: the game's menu does
ini.write_bytes(PLAYER_INI)
names = sorted(p.name for p in self.out.iterdir())
# the update: a kit with another lifter and another version
(kit / 'VERSION').write_text('0.7.1\n')
(kit / 'recomp' / 'gen.py').write_text('# the lifter of 0.7.1\n')
ran.clear()
steps = build('--rebuild')
self.assertEqual(steps, ['check', 'lift', 'compile', 'shaders', 'prompts']) # the bind_ lines are new to it
self.assertEqual(ran, ['lift', 'compile'])
self.assertEqual(ini.read_bytes(), PLAYER_INI)
self.assertEqual(sorted(p.name for p in self.out.iterdir()), names) # no copy, no backup, no temporary file
self.assertEqual(json.loads((self.out / 'build-cache' / 'state.json').read_text())['kit'], '0.7.1')
self.assertEqual(build('--rebuild'), ['check']) # nothing to do
self.assertEqual(ini.read_bytes(), PLAYER_INI)
# from the game files again into the same folder (Rebuild the Game without a build to start from)
st = json.loads((self.out / 'build-cache' / 'state.json').read_text())
st['steps'] = {}
(self.out / 'build-cache' / 'state.json').write_text(json.dumps(st))
self.assertEqual(build('--nup', str(self.nup)),
['check', 'exefs', 'romfs', 'lift', 'compile', 'shaders', 'prompts', 'scan'])
self.assertEqual(ini.read_bytes(), PLAYER_INI)
@unittest.skipIf(os.name == 'nt', 'uses a POSIX script as the compiler')
def test_largest_source_compiles_first(self):
src, obj = self.tmp / 'src', self.tmp / 'obj'

72
tests/wb_lazy_check.c Normal file
View File

@@ -0,0 +1,72 @@
// runtime/wb_lazy_choice.h: whether the lazy write-back runs, by the player's setting, the platform and the GPU driver
// (runtime/vk_memory.c vk_mem_lazy_decide). Built and run by tests/wb_lazy_check.py; prints each failed check and
// exits 1 on any.
#include <stdio.h>
#include <string.h>
#include "wb_lazy_choice.h"
static int fails;
#define CHECK(c, ...) do { if (!(c)) { fails++; printf("FAIL line %d: ", __LINE__); printf(__VA_ARGS__); printf("\n"); } } while (0)
// VkDriverId values (vulkan_core.h)
enum { AMD_PROPRIETARY = 1, AMD_OPEN_SOURCE = 2, MESA_RADV = 3, NVIDIA_PROPRIETARY = 4, INTEL_WINDOWS = 5, MESA_NVK = 24 };
enum { LINUX = 0, WINDOWS = 1 };
static int has(const char *s, const char *part) { return s && strstr(s, part) != NULL; }
int main(void) {
static const unsigned drivers[] = {AMD_PROPRIETARY, AMD_OPEN_SOURCE, MESA_RADV, NVIDIA_PROPRIETARY, INTEL_WINDOWS,
MESA_NVK, 0};
enum { ND = sizeof drivers / sizeof *drivers };
// Nothing set, Windows: on, except on AMD's own driver (both of its branches report this id).
WblChoice nv = wb_lazy_choice(NULL, WINDOWS, NVIDIA_PROPRIETARY);
CHECK(nv.on == 1, "Windows, NVIDIA's driver, nothing set: on");
CHECK(has(nv.why, "default") && has(nv.why, "wb_lazy = 0"), "it says it is the default and how to turn it off: %s", nv.why);
CHECK(wb_lazy_choice(NULL, WINDOWS, INTEL_WINDOWS).on == 1, "Windows, Intel's driver, nothing set: on");
CHECK(wb_lazy_choice(NULL, WINDOWS, 0).on == 1, "Windows, a driver that reports no id: on, as 0.7.1 had it");
WblChoice amd = wb_lazy_choice(NULL, WINDOWS, AMD_PROPRIETARY);
CHECK(amd.on == 0, "Windows, AMD's driver, nothing set: off");
CHECK(has(amd.why, "AMD") && has(amd.why, "wb_lazy = 1"), "it names the driver and how to turn it on: %s", amd.why);
CHECK(has(amd.why, "frame rate"), "it says what off costs: %s", amd.why);
CHECK(has(amd.why, "default"), "it says it is a default: %s", amd.why);
// An empty value is no value (cfg.c add: "key =" leaves the setting at its default).
CHECK(wb_lazy_choice("", WINDOWS, AMD_PROPRIETARY).on == 0, "an empty value on AMD: the default, off");
CHECK(wb_lazy_choice("", WINDOWS, NVIDIA_PROPRIETARY).on == 1, "an empty value on NVIDIA: the default, on");
// Nothing set, elsewhere: off on every driver.
for (int i = 0; i < ND; i++) {
WblChoice c = wb_lazy_choice(NULL, LINUX, drivers[i]);
CHECK(c.on == 0 && has(c.why, "wb_lazy = 1"), "Linux, driver %u, nothing set: off, and how to turn it on: %s",
drivers[i], c.why);
}
// What the player sets wins on every platform and driver, and the reason says it was set.
for (int os = LINUX; os <= WINDOWS; os++)
for (int i = 0; i < ND; i++) {
WblChoice on = wb_lazy_choice("1", os, drivers[i]), off = wb_lazy_choice("0", os, drivers[i]);
CHECK(on.on == 1 && has(on.why, "set"), "os %d driver %u, wb_lazy = 1: on (%s)", os, drivers[i], on.why);
CHECK(off.on == 0 && has(off.why, "set"), "os %d driver %u, wb_lazy = 0: off (%s)", os, drivers[i], off.why);
CHECK(!has(on.why, "default") && !has(off.why, "default"), "os %d driver %u: a set value is not a default", os,
drivers[i]);
}
// Any value but 0 counts as on, as cfg_bool reads it for memory.c mem_init.
CHECK(wb_lazy_choice("on", WINDOWS, AMD_PROPRIETARY).on == 1, "wb_lazy = on: on");
// The exception is the driver, not the vendor: another driver for AMD cards follows its platform's default.
CHECK(wb_lazy_choice(NULL, WINDOWS, AMD_OPEN_SOURCE).on == 1 && wb_lazy_choice(NULL, WINDOWS, MESA_RADV).on == 1,
"the exception is AMD's own driver");
CHECK(WBL_DRIVER_AMD == AMD_PROPRIETARY, "WBL_DRIVER_AMD is VK_DRIVER_ID_AMD_PROPRIETARY");
// The game passes the platform it was built for.
#ifdef _WIN32
CHECK(WBL_ON_WINDOWS == 1, "a Windows build says so");
#else
CHECK(WBL_ON_WINDOWS == 0, "a build elsewhere says so");
#endif
if (!fails) printf("wb lazy choice: all checks passed\n");
return fails != 0;
}

42
tests/wb_lazy_check.py Normal file
View File

@@ -0,0 +1,42 @@
"""Build and run tests/wb_lazy_check.c: runtime/wb_lazy_choice.h, whether the lazy write-back runs, by the player's
setting, the platform and the GPU driver.
Needs a C compiler only: no Vulkan headers, no GPU and no game files.
Usage: wb_lazy_check.py
"""
import os
import shutil
import subprocess
import sys
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
MSYS_BIN = Path(r'C:\msys64\ucrt64\bin')
def compiler():
"""$CC, else MSYS2 UCRT64's clang, else clang on PATH (as tests/diff/common.py picks it, without its Unicorn)."""
if os.environ.get('CC'):
return os.environ['CC']
if os.name == 'nt' and (MSYS_BIN / 'clang.exe').exists():
return str(MSYS_BIN / 'clang.exe')
return shutil.which('clang') or 'clang'
def main():
work = ROOT / 'build' / 'test' / 'wb_lazy'
work.mkdir(parents=True, exist_ok=True)
exe = work / ('wb_lazy_check.exe' if os.name == 'nt' else 'wb_lazy_check')
env = dict(os.environ)
if os.name == 'nt' and MSYS_BIN.exists():
env['PATH'] = str(MSYS_BIN) + os.pathsep + env.get('PATH', '')
# every platform's and driver's choice is checked through wb_lazy_choice's arguments; WBL_ON_WINDOWS on the one
# built for
subprocess.check_call([compiler(), '-std=gnu11', '-O1', '-Wall', '-Werror', '-I', str(ROOT / 'runtime'),
str(ROOT / 'tests' / 'wb_lazy_check.c'), '-o', str(exe)], env=env)
return subprocess.run([str(exe)], env=env).returncode
if __name__ == '__main__':
sys.exit(main())