diff options
Diffstat (limited to 'scripts/run_wine_tests.py')
| -rw-r--r-- | scripts/run_wine_tests.py | 70 |
1 files changed, 62 insertions, 8 deletions
diff --git a/scripts/run_wine_tests.py b/scripts/run_wine_tests.py index b2736982f..b55ea9b91 100644 --- a/scripts/run_wine_tests.py +++ b/scripts/run_wine_tests.py | |||
| @@ -8,6 +8,10 @@ Usage: | |||
| 8 | made in (forward slashes, as `cygpath -m` prints it). Paths under it are mapped to --root, the Linux checkout (default: | 8 | made in (forward slashes, as `cygpath -m` prints it). Paths under it are mapped to --root, the Linux checkout (default: |
| 9 | this repository), which must hold the Windows build's runtime/build folder at the same place. | 9 | this repository), which must hold the Windows build's runtime/build folder at the same place. |
| 10 | 10 | ||
| 11 | Some tests open files through absolute paths compiled into them (the GLSL test shaders, LEONIDA_TEST_*_SPV under | ||
| 12 | runtime/build/generated). For those, the drive of --windows-root is pointed at --root in the Wine prefix for the run | ||
| 13 | ($WINEPREFIX, else ~/.wine), unless that drive is already in use there. | ||
| 14 | |||
| 11 | Every test is run and reported. The exit code is 1 if a test named by --require fails or is missing, else 0: the | 15 | Every test is run and reported. The exit code is 1 if a test named by --require fails or is missing, else 0: the |
| 12 | others show what does and doesn't work under Wine yet without failing the job. | 16 | others show what does and doesn't work under Wine yet without failing the job. |
| 13 | """ | 17 | """ |
| @@ -17,8 +21,10 @@ import math | |||
| 17 | import os | 21 | import os |
| 18 | import re | 22 | import re |
| 19 | import shlex | 23 | import shlex |
| 24 | import shutil | ||
| 20 | import subprocess | 25 | import subprocess |
| 21 | import sys | 26 | import sys |
| 27 | import tempfile | ||
| 22 | import time | 28 | import time |
| 23 | 29 | ||
| 24 | ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | 30 | ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) |
| @@ -46,6 +52,51 @@ def map_path(arg: str, windows_root: str, root: str) -> str | None: | |||
| 46 | return None | 52 | return None |
| 47 | 53 | ||
| 48 | 54 | ||
| 55 | class DriveMap: | ||
| 56 | """Points the drive of the Windows checkout at the Linux one inside the Wine prefix, for the run. | ||
| 57 | |||
| 58 | A test that opens D:/a/Leonida/Leonida/runtime/build/generated/x.spv (a path compiled into it) then reads | ||
| 59 | <root>/runtime/build/generated/x.spv. The drive is a dosdevices link to a scratch folder holding a/Leonida/Leonida | ||
| 60 | as a link to the root; both are removed afterwards. A drive the prefix already has (c:, z:, or one set up by | ||
| 61 | hand) is left alone, and so is a root without a drive letter. | ||
| 62 | """ | ||
| 63 | |||
| 64 | def __init__(self, windows_root: str, root: str, prefix: str): | ||
| 65 | self.windows_root, self.root, self.prefix = norm(windows_root), os.path.abspath(root), prefix | ||
| 66 | self.link = self.scratch = None | ||
| 67 | self.note = "" | ||
| 68 | |||
| 69 | def __enter__(self): | ||
| 70 | m = re.fullmatch(r"([A-Za-z]):/(.+)", self.windows_root) | ||
| 71 | if not m: | ||
| 72 | self.note = f"{self.windows_root} has no drive letter: no drive mapped" | ||
| 73 | return self | ||
| 74 | drive, rest = m.group(1).lower(), [p for p in m.group(2).split("/") if p] | ||
| 75 | dosdevices = os.path.join(self.prefix, "dosdevices") | ||
| 76 | link = os.path.join(dosdevices, drive + ":") | ||
| 77 | if not os.path.isdir(dosdevices): | ||
| 78 | self.note = f"no Wine prefix at {self.prefix}: drive {drive}: not mapped" | ||
| 79 | return self | ||
| 80 | if os.path.lexists(link): | ||
| 81 | self.note = f"drive {drive}: is already set in {dosdevices}: left as it is" | ||
| 82 | return self | ||
| 83 | self.scratch = tempfile.mkdtemp(prefix="wine-drive-") | ||
| 84 | parent = os.path.join(self.scratch, *rest[:-1]) | ||
| 85 | os.makedirs(parent, exist_ok=True) | ||
| 86 | os.symlink(self.root, os.path.join(parent, rest[-1])) | ||
| 87 | os.symlink(self.scratch, link) | ||
| 88 | self.link = link | ||
| 89 | self.note = f"drive {drive}: maps {self.windows_root} to {self.root} for this run" | ||
| 90 | return self | ||
| 91 | |||
| 92 | def __exit__(self, *exc): | ||
| 93 | if self.link and os.path.islink(self.link): | ||
| 94 | os.unlink(self.link) | ||
| 95 | if self.scratch: | ||
| 96 | shutil.rmtree(self.scratch, ignore_errors=True) # removes the links, never what they point to | ||
| 97 | return False | ||
| 98 | |||
| 99 | |||
| 49 | def wine_path(path: str) -> str: | 100 | def wine_path(path: str) -> str: |
| 50 | """Wine's Z: drive is the Unix root, so a Windows program reads /x/y as Z:\\x\\y.""" | 101 | """Wine's Z: drive is the Unix root, so a Windows program reads /x/y as Z:\\x\\y.""" |
| 51 | return "Z:" + os.path.abspath(path).replace("/", "\\") | 102 | return "Z:" + os.path.abspath(path).replace("/", "\\") |
| @@ -175,14 +226,17 @@ def main() -> int: | |||
| 175 | return 2 | 226 | return 2 |
| 176 | wine = args.wine | 227 | wine = args.wine |
| 177 | results = {} | 228 | results = {} |
| 178 | for test in tests: | 229 | prefix = os.environ.get("WINEPREFIX") or os.path.join(os.path.expanduser("~"), ".wine") |
| 179 | name = test.get("name", "?") | 230 | with DriveMap(args.windows_root, args.root, prefix) as drive: |
| 180 | status, detail = run_test(test, args, wine) | 231 | print(drive.note, flush=True) |
| 181 | results[name] = status | 232 | for test in tests: |
| 182 | print(f"[{status.upper()}] {name}", flush=True) | 233 | name = test.get("name", "?") |
| 183 | if status != "pass": | 234 | status, detail = run_test(test, args, wine) |
| 184 | for line in detail.rstrip().splitlines()[-40:]: | 235 | results[name] = status |
| 185 | print(f" {line}") | 236 | print(f"[{status.upper()}] {name}", flush=True) |
| 237 | if status != "pass": | ||
| 238 | for line in detail.rstrip().splitlines()[-40:]: | ||
| 239 | print(f" {line}") | ||
| 186 | 240 | ||
| 187 | missing = [n for n in args.require if n not in results] | 241 | missing = [n for n in args.require if n not in results] |
| 188 | failed_required = [n for n in args.require if results.get(n) != "pass"] | 242 | failed_required = [n for n in args.require if results.get(n) != "pass"] |