Files
mandy/tests/test_play_linux_defaults.py
Sri Nesan 19d62a98d4 Linux: enable scoped copy and descriptor tracking defaults (#2700)
* Linux: enable scoped copy and descriptor defaults

* Test Linux launcher optimization defaults and opt-outs
2026-12-01 11:52:20 +01:00

70 lines
2.7 KiB
Python

"""Check Linux launcher defaults without Wine, a GPU, or game data."""
import os
from pathlib import Path
import shutil
import subprocess
import tempfile
import unittest
LAUNCHER = Path(__file__).resolve().parents[1] / "scripts" / "play-linux.sh"
SH = shutil.which("sh") if os.name == "posix" else None
FLAGS = ("LEONIDA_COPY_SCOPED", "LEONIDA_PORT_DESCRIPTORS")
@unittest.skipUnless(SH, "POSIX shell required")
class PlayLinuxDefaultsTest(unittest.TestCase):
def run_launcher(self, values):
with tempfile.TemporaryDirectory(prefix="linux-launcher-test-") as directory:
root = Path(directory)
system32 = root / "prefix" / "drive_c" / "windows" / "system32"
system32.mkdir(parents=True)
bin_dir = root / "mock-bin"
bin_dir.mkdir()
wine = bin_dir / "wine"
wine.write_bytes(
b"#!/bin/sh\n"
b'if [ "$1" = --version ]; then echo wine-test; exit 0; fi\n'
b'printf "%s\\n" "${LEONIDA_COPY_SCOPED-unset}" '
b'"${LEONIDA_PORT_DESCRIPTORS-unset}" > "$LAUNCHER_TEST_CAPTURE"\n',
)
wine.chmod(0o755)
game = root / "placeholder-title"
runtime = root / "placeholder-runtime"
for name in (game, runtime, root / "d3d12.dll", root / "dxgi.dll",
root / "d3dcompiler_47.dll"):
name.touch()
(root / "d3d12core.dll").write_bytes(b"legacy_structurizer\n")
capture = root / "capture"
env = {
"PATH": str(bin_dir) + os.pathsep + os.defpath,
"HOME": str(root),
"LEONIDA_WINE": str(wine),
"LEONIDA_WINEPREFIX": str(root / "prefix"),
"LEONIDA_RUNTIME": str(runtime),
"LEONIDA_VKD3D": str(root),
"LEONIDA_DXVK": str(root),
"LEONIDA_D3DCOMPILER": str(root),
"LAUNCHER_TEST_CAPTURE": str(capture),
}
env.update(dict(zip(FLAGS, values)))
result = subprocess.run(
[SH, str(LAUNCHER), str(game)], env=env,
capture_output=True, text=True, timeout=10,
)
self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
return capture.read_text(encoding="utf-8").splitlines()
def test_unset_flags_default_to_enabled(self):
self.assertEqual(self.run_launcher(()), ["1", "1"])
def test_explicit_zero_is_respected(self):
for flags in (("0", "1"), ("1", "0"), ("0", "0")):
with self.subTest(flags=flags):
self.assertEqual(self.run_launcher(flags), list(flags))
if __name__ == "__main__":
unittest.main()