From a8b661cf4050c44e96708c23c387ccbf1bab857b Mon Sep 17 00:00:00 2001 From: SkippySteve <69158610+SkippySteve@users.noreply.github.com> Date: Mon, 23 Nov 2026 18:23:17 -0500 Subject: [PATCH] run_wine_session: initialize and stop the prefix with $WINE The session script ran wineboot and wineserver from PATH while run_wine_tests.py runs the tests with $WINE. With WINE set to Proton's or UMU-Proton's files/bin/wine, the prefix was initialized by another Wine, or the script stopped at 'wineboot: command not found' on a host without a system Wine, and the exit trap stopped the wrong wineserver. Run "$WINE" wineboot --init and stop $WINESERVER, else the wineserver next to $WINE, else wineserver on PATH; report a missing $WINE with status 127. --- docs/testing.md | 4 +- scripts/run_wine_session.sh | 18 +++++++- tests/test_run_wine_session.py | 75 ++++++++++++++++++++++++++++++++++ 3 files changed, 94 insertions(+), 3 deletions(-) create mode 100644 tests/test_run_wine_session.py diff --git a/docs/testing.md b/docs/testing.md index 6b65e418a..51a4a0e43 100644 --- a/docs/testing.md +++ b/docs/testing.md @@ -295,7 +295,9 @@ WINE=wine WINEPREFIX="$(mktemp -d)" WINEDLLOVERRIDES="mscoree,mshtml=" WINEDEBUG --require run_tiny_game --require run_tiny_game_exit_code ``` -The session script initializes a dedicated prefix and stops its Wine processes at exit. On a headless host, +The session script initializes a dedicated prefix and stops its Wine processes at exit, with the Wine named by +`WINE` (default `wine`) and the `wineserver` next to it (or `WINESERVER`), so Proton's or UMU-Proton's +`files/bin/wine` works without a system Wine. On a headless host, put `xvfb-run -a` before `bash` so prefix initialization and the tests share one virtual display. The test runner maps the recorded Windows drive to the Linux checkout for shaders referenced by absolute Windows paths. It prints every verdict and returns a failure status if any required test fails, skips or is missing. Check the printed diff --git a/scripts/run_wine_session.sh b/scripts/run_wine_session.sh index 72ace4407..437e18c3c 100755 --- a/scripts/run_wine_session.sh +++ b/scripts/run_wine_session.sh @@ -1,9 +1,23 @@ #!/usr/bin/env bash # Run CI tests on the display that initialized their dedicated Wine prefix. +# +# The prefix is initialized and stopped with the Wine the tests use: $WINE (default: wine), as +# run_wine_tests.py does, so Proton's or UMU-Proton's files/bin/wine also works on a host without a +# system Wine. The wineserver is $WINESERVER, else the one next to $WINE, else wineserver on PATH. set -e : "${WINEPREFIX:?Set WINEPREFIX to a dedicated test prefix}" +wine=${WINE:-wine} +if ! wine_path=$(command -v -- "$wine"); then + echo "run_wine_session.sh: Wine not found: $wine (set WINE to the wine executable)" >&2 + exit 127 +fi +if [[ -z ${WINESERVER:-} ]]; then + WINESERVER=$(dirname -- "$wine_path")/wineserver + [[ -x $WINESERVER ]] || WINESERVER=wineserver +fi + # Stop this prefix's Wine processes before Xvfb tears down the display. -trap 'wineserver -k || true' EXIT -timeout 5m wineboot --init None: + path.mkdir(parents=True, exist_ok=True) + tool = path / name + tool.write_text(f'#!/bin/sh\necho "{tool} $*" >> "{log}"\n', encoding="utf-8", newline="\n") + tool.chmod(0o755) + + +@unittest.skipUnless(shutil.which("bash") and shutil.which("timeout") and os.name == "posix", "needs bash") +class WineSessionTests(unittest.TestCase): + def run_session(self, env: dict[str, str], path: Path) -> subprocess.CompletedProcess: + base = {"PATH": f"{path}:/usr/bin:/bin", "WINEPREFIX": str(path.parent / "prefix")} + return subprocess.run(["bash", str(SCRIPT), "true"], env={**base, **env}, + capture_output=True, text=True, timeout=60) + + def test_uses_wine_and_its_wineserver(self): + with tempfile.TemporaryDirectory() as d: + root, log = Path(d), Path(d) / "log" + system, proton = root / "system bin", root / "Proton 11.0" / "files" / "bin" + for name in ("wine", "wineboot", "wineserver"): + fake(system, name, log) + fake(proton, "wine", log) + fake(proton, "wineserver", log) + r = self.run_session({"WINE": str(proton / "wine")}, system) + self.assertEqual(r.returncode, 0, r.stderr) + self.assertEqual(log.read_text().splitlines(), + [f"{proton / 'wine'} wineboot --init", f"{proton / 'wineserver'} -k"]) + + def test_default_wine_from_path(self): + with tempfile.TemporaryDirectory() as d: + root, log = Path(d), Path(d) / "log" + system = root / "bin" + fake(system, "wine", log) + fake(system, "wineserver", log) + r = self.run_session({}, system) + self.assertEqual(r.returncode, 0, r.stderr) + self.assertEqual(log.read_text().splitlines(), + [f"{system / 'wine'} wineboot --init", f"{system / 'wineserver'} -k"]) + + def test_wineserver_override_and_path_fallback(self): + with tempfile.TemporaryDirectory() as d: + root, log = Path(d), Path(d) / "log" + system, other = root / "bin", root / "other" + fake(system, "wineserver", log) + fake(other, "wine", log) # no wineserver next to it + r = self.run_session({"WINE": str(other / "wine")}, system) + self.assertEqual(r.returncode, 0, r.stderr) + self.assertEqual(log.read_text().splitlines()[-1], f"{system / 'wineserver'} -k") + fake(other, "my-wineserver", log) + r = self.run_session({"WINE": str(other / "wine"), "WINESERVER": str(other / "my-wineserver")}, system) + self.assertEqual(r.returncode, 0, r.stderr) + self.assertEqual(log.read_text().splitlines()[-1], f"{other / 'my-wineserver'} -k") + + def test_missing_wine_is_reported(self): + with tempfile.TemporaryDirectory() as d: + root = Path(d) + (root / "bin").mkdir() + r = self.run_session({"WINE": str(root / "nowhere" / "wine")}, root / "bin") + self.assertEqual(r.returncode, 127) + self.assertIn("Wine not found", r.stderr) + + +if __name__ == "__main__": + unittest.main()