diff --git a/docs/testing.md b/docs/testing.md index 6b65e418a7..51a4a0e439 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 72ace4407b..437e18c3cb 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()