Skip to content
Closed
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
4 changes: 3 additions & 1 deletion docs/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 16 additions & 2 deletions scripts/run_wine_session.sh
Original file line number Diff line number Diff line change
@@ -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 </dev/null
trap '"$WINESERVER" -k || true' EXIT
timeout 5m "$wine_path" wineboot --init </dev/null
"$@" </dev/null
75 changes: 75 additions & 0 deletions tests/test_run_wine_session.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
"""Check that scripts/run_wine_session.sh initializes and stops the prefix with the Wine named by WINE."""

import os
from pathlib import Path
import shutil
import subprocess
import tempfile
import unittest

SCRIPT = Path(__file__).resolve().parents[1] / "scripts" / "run_wine_session.sh"


def fake(path: Path, name: str, log: Path) -> 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()
Loading