diff options
| author | Jan Trencansky <jan.trencansky@protonmail.com> | 2026-11-24 18:34:25 -0500 |
|---|---|---|
| committer | Jan Trencansky <jan.trencansky@protonmail.com> | 2026-11-24 18:34:52 -0500 |
| commit | 70d615b3bbdfa255118810eba1f7a9e6434d1ab7 (patch) | |
| tree | 3ee3ec30db85b5d6991c76b2fd69643fec1ccaeb /scripts | |
| parent | 0d666fcf4f3f7e3b209c6b35c55de199633c5f15 (diff) | |
| parent | 3a0af1f1503307570d998cfe609a70a16c5bbad2 (diff) | |
Merge main into OLD-7084, pe_inspect Linux classes (#653)
No conflicts. Brings in main's owns_dll host list with ws2_32.dll and wsock32.dll (the
ws2_offline shim), which the next commit mirrors in pe_inspect.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'scripts')
| -rw-r--r-- | scripts/bench_wave64.py | 8 | ||||
| -rw-r--r-- | scripts/build_runtime.ps1 | 4 | ||||
| -rw-r--r-- | scripts/check_no_game_data.py | 20 | ||||
| -rw-r--r-- | scripts/ci_expected_failures.py | 18 | ||||
| -rw-r--r-- | scripts/merge_check.py | 7 | ||||
| -rw-r--r-- | scripts/run_gpu_tests.py | 67 | ||||
| -rw-r--r-- | scripts/run_semantic_tests.py | 68 | ||||
| -rw-r--r-- | scripts/run_wine_tests.py | 228 |
8 files changed, 362 insertions, 58 deletions
diff --git a/scripts/bench_wave64.py b/scripts/bench_wave64.py index e6fd59737..57253cb57 100644 --- a/scripts/bench_wave64.py +++ b/scripts/bench_wave64.py | |||
| @@ -44,7 +44,13 @@ def build(work, name, emulate, llvm_mc): | |||
| 44 | r = subprocess.run([sys.executable, "-I", BUILD_PY, out, name], env=env, capture_output=True, text=True) | 44 | r = subprocess.run([sys.executable, "-I", BUILD_PY, out, name], env=env, capture_output=True, text=True) |
| 45 | if r.returncode: | 45 | if r.returncode: |
| 46 | sys.exit(r.stdout + r.stderr) | 46 | sys.exit(r.stdout + r.stderr) |
| 47 | return os.path.join(out, "spirv", name + ".spv") | 47 | spv = os.path.join(out, "spirv", name + ".spv") |
| 48 | if not os.path.isfile(spv): | ||
| 49 | mode = "emulated" if emulate else "native" | ||
| 50 | message = f"{name}: {mode} build did not produce a SPIR-V module" | ||
| 51 | reason = (r.stdout + r.stderr).strip() | ||
| 52 | sys.exit(f"{message}\n{reason}" if reason else message) | ||
| 53 | return spv | ||
| 48 | 54 | ||
| 49 | 55 | ||
| 50 | def segments(spv: str) -> tuple[int, int] | None: | 56 | def segments(spv: str) -> tuple[int, int] | None: |
diff --git a/scripts/build_runtime.ps1 b/scripts/build_runtime.ps1 index 63acb7ce3..f24cc073f 100644 --- a/scripts/build_runtime.ps1 +++ b/scripts/build_runtime.ps1 | |||
| @@ -83,10 +83,10 @@ $build || exit /b 1 | |||
| 83 | } else { | 83 | } else { |
| 84 | # Keep this list in step with runtime\CMakeLists.txt. Optional parts that need a dependency are left out here: | 84 | # Keep this list in step with runtime\CMakeLists.txt. Optional parts that need a dependency are left out here: |
| 85 | # the GameInput shim (SDL3), so controllers go through the host's GameInput.dll, if any, as without the shim. | 85 | # the GameInput shim (SDL3), so controllers go through the host's GameInput.dll, if any, as without the shim. |
| 86 | Write-Warning "CMake and Ninja weren't found (neither VS C++ CMake tools nor native PATH tools): building with cl.exe directly, without the GameInput shim (SDL3). Install CMake + Ninja or VS's CMake tools component to get it." | 86 | Write-Warning "CMake and Ninja weren't found (neither VS C++ CMake tools nor native PATH tools): building with cl.exe directly, without the GameInput shim (SDL3) and without the Rust XMA2 decoder (XMA voices are silent). Install CMake + Ninja or VS's CMake tools component to get it." |
| 87 | $xtaskqueueDir = Join-Path $root "third_party\xtaskqueue" | 87 | $xtaskqueueDir = Join-Path $root "third_party\xtaskqueue" |
| 88 | $xtaskqueueFiles = "Source\Task\TaskQueue.cpp", "Source\Task\AsyncLib.cpp", "Source\Task\ThreadPool_win32.cpp", "Source\Task\WaitTimer_win32.cpp" | ForEach-Object { "`"$xtaskqueueDir\$_`"" } | 88 | $xtaskqueueFiles = "Source\Task\TaskQueue.cpp", "Source\Task\AsyncLib.cpp", "Source\Task\ThreadPool_win32.cpp", "Source\Task\WaitTimer_win32.cpp" | ForEach-Object { "`"$xtaskqueueDir\$_`"" } |
| 89 | $files = "src\main.cpp", "src\host_cpu.cpp", "src\pe_loader.cpp", "shims\registry.cpp", "shims\file_system.cpp", "shims\xmem.cpp", "shims\xg_xs.cpp", "shims\acphal.cpp", "shims\d3d12_xs.cpp", "shims\d3d12_xs_device.cpp", "shims\d3d12_xs_rootsig.cpp", "shims\xgameruntime.cpp", "shims\xgameruntime_user.cpp", "shims\xgameruntime_gamesave.cpp", "shims\xgameruntime_store.cpp", "shims\xgameruntime_offline.cpp", "shims\winhttp_offline.cpp", "shims\library_loader.cpp", "shims\process.cpp", "shims\com_shim.cpp", "shims\bcrypt_rng.cpp", "shims\xapu_chad.cpp", "shims\dstorage.cpp" | ForEach-Object { "`"$src\$_`"" } | 89 | $files = "src\main.cpp", "src\host_cpu.cpp", "src\pe_loader.cpp", "shims\registry.cpp", "shims\file_system.cpp", "shims\xmem.cpp", "shims\xg_xs.cpp", "shims\acphal.cpp", "shims\d3d12_xs.cpp", "shims\d3d12_xs_device.cpp", "shims\d3d12_xs_rootsig.cpp", "shims\xgameruntime.cpp", "shims\xgameruntime_user.cpp", "shims\xgameruntime_gamesave.cpp", "shims\xgameruntime_store.cpp", "shims\xgameruntime_offline.cpp", "shims\winhttp_offline.cpp", "shims\ws2_offline.cpp", "shims\library_loader.cpp", "shims\process.cpp", "shims\com_shim.cpp", "shims\bcrypt_rng.cpp", "shims\xapu_chad.cpp", "shims\dstorage.cpp" | ForEach-Object { "`"$src\$_`"" } |
| 90 | $includes = "/I `"$src\src`" /I `"$src\shims`" /I `"$src\shims\xtaskqueue`" /I `"$xtaskqueueDir\Include`" /I `"$xtaskqueueDir\Source\Task`" /I `"$xtaskqueueDir\Source\Common`"" | 90 | $includes = "/I `"$src\src`" /I `"$src\shims`" /I `"$src\shims\xtaskqueue`" /I `"$xtaskqueueDir\Include`" /I `"$xtaskqueueDir\Source\Task`" /I `"$xtaskqueueDir\Source\Common`"" |
| 91 | $opt = if ($Debug) { "/Od /MDd" } else { "/O2 /MD" } | 91 | $opt = if ($Debug) { "/Od /MDd" } else { "/O2 /MD" } |
| 92 | $body = @" | 92 | $body = @" |
diff --git a/scripts/check_no_game_data.py b/scripts/check_no_game_data.py index a5b65e242..bccee5e68 100644 --- a/scripts/check_no_game_data.py +++ b/scripts/check_no_game_data.py | |||
| @@ -21,7 +21,8 @@ under a budget per checked file (64 MiB expanded, 10,000 members), so a zip bomb | |||
| 21 | reported as archives that can't be checked. | 21 | reported as archives that can't be checked. |
| 22 | 22 | ||
| 23 | Prints one line per match, `<path>: <format>` (`<format> in <archive> (<member>)` for a match inside an archive), and | 23 | Prints one line per match, `<path>: <format>` (`<format> in <archive> (<member>)` for a match inside an archive), and |
| 24 | exits 1 if there is any. Standard library only, no game files. | 24 | exits 1 if there is any. It exits 2 when a file cannot be read or git cannot list the tracked files (outside a |
| 25 | repository, or git not installed). Standard library only, no game files. | ||
| 25 | """ | 26 | """ |
| 26 | import bz2 | 27 | import bz2 |
| 27 | import gzip | 28 | import gzip |
| @@ -257,6 +258,14 @@ def tracked_files(root): | |||
| 257 | return [os.path.join(root, p) for p in out.decode("utf-8", "surrogateescape").split("\0") if p] | 258 | return [os.path.join(root, p) for p in out.decode("utf-8", "surrogateescape").split("\0") if p] |
| 258 | 259 | ||
| 259 | 260 | ||
| 261 | def git_error(e): | ||
| 262 | """One line on why git could not list the files: the first line git printed, or the OS error.""" | ||
| 263 | if isinstance(e, subprocess.CalledProcessError): | ||
| 264 | lines = (e.stderr or b"").decode("utf-8", "replace").splitlines() | ||
| 265 | return next((line.strip() for line in lines if line.strip()), f"exit status {e.returncode}") | ||
| 266 | return e.strerror or str(e) | ||
| 267 | |||
| 268 | |||
| 260 | def check(paths, unreadable=None): | 269 | def check(paths, unreadable=None): |
| 261 | """[(path, format)] for every regular file in `paths` that starts like game data. | 270 | """[(path, format)] for every regular file in `paths` that starts like game data. |
| 262 | 271 | ||
| @@ -285,7 +294,14 @@ def display(path): | |||
| 285 | 294 | ||
| 286 | 295 | ||
| 287 | def main(argv): | 296 | def main(argv): |
| 288 | paths = argv or tracked_files(os.getcwd()) | 297 | if argv: |
| 298 | paths = argv | ||
| 299 | else: | ||
| 300 | try: | ||
| 301 | paths = tracked_files(os.getcwd()) | ||
| 302 | except (OSError, subprocess.CalledProcessError) as e: | ||
| 303 | print(f"check_no_game_data: cannot list the tracked files with git: {git_error(e)}", file=sys.stderr) | ||
| 304 | return 2 # not 1: that is the 'game data found' code | ||
| 289 | unreadable = [] | 305 | unreadable = [] |
| 290 | found = check(paths, unreadable) | 306 | found = check(paths, unreadable) |
| 291 | for path, name in found: | 307 | for path, name in found: |
diff --git a/scripts/ci_expected_failures.py b/scripts/ci_expected_failures.py index 8112dcf4b..f398020f7 100644 --- a/scripts/ci_expected_failures.py +++ b/scripts/ci_expected_failures.py | |||
| @@ -2,11 +2,13 @@ | |||
| 2 | 2 | ||
| 3 | python -I scripts/ci_expected_failures.py FAILED_LIST EXIT_STATUS [EXPECTED ...] | 3 | python -I scripts/ci_expected_failures.py FAILED_LIST EXIT_STATUS [EXPECTED ...] |
| 4 | 4 | ||
| 5 | FAILED_LIST is a file with one failed test name per line, EXIT_STATUS the test runner's exit status, and each | 5 | FAILED_LIST is a UTF-8 file with one failed test name per line and an optional BOM. |
| 6 | EXPECTED argument one or more whitespace-separated test names (so a workflow can pass one quoted list). Exits 1 when a | 6 | EXIT_STATUS is the test runner's exit status. Each EXPECTED argument is one or more whitespace-separated |
| 7 | test outside EXPECTED failed, the runner failed without naming a test, or the runner was terminated by a signal | 7 | test names, so a workflow can pass one quoted list. |
| 8 | (its failure list can be incomplete); 2 on a usage error. `--help` prints this text. An expected failure absent | 8 | |
| 9 | from a completed run gets a GitHub Actions notice so the list in the workflow can shrink. | 9 | Exits 1 when an unexpected test failed, the runner failed without naming a test, or a signal terminated the runner. |
| 10 | Exits 2 on a usage error. `--help` prints this text. An expected failure absent from a completed run gets a GitHub | ||
| 11 | Actions notice so the list in the workflow can shrink. | ||
| 10 | """ | 12 | """ |
| 11 | 13 | ||
| 12 | import sys | 14 | import sys |
| @@ -43,10 +45,10 @@ def main(argv: list[str]) -> int: | |||
| 43 | print(f"ci_expected_failures: EXIT_STATUS {argv[1]!r} is not an integer", file=sys.stderr) | 45 | print(f"ci_expected_failures: EXIT_STATUS {argv[1]!r} is not an integer", file=sys.stderr) |
| 44 | return 2 | 46 | return 2 |
| 45 | try: | 47 | try: |
| 46 | with open(argv[0], encoding="utf-8") as f: | 48 | with open(argv[0], encoding="utf-8-sig") as f: |
| 47 | failed = [line.strip() for line in f if line.strip()] | 49 | failed = [line.strip() for line in f if line.strip()] |
| 48 | except OSError as e: | 50 | except (OSError, UnicodeDecodeError) as e: |
| 49 | print(f"ci_expected_failures: {argv[0]}: {e.strerror or e}", file=sys.stderr) | 51 | print(f"ci_expected_failures: {argv[0]}: {getattr(e, 'strerror', None) or e}", file=sys.stderr) |
| 50 | return 2 | 52 | return 2 |
| 51 | expected = [name for arg in argv[2:] for name in arg.split()] | 53 | expected = [name for arg in argv[2:] for name in arg.split()] |
| 52 | code, lines = judge(failed, status, expected) | 54 | code, lines = judge(failed, status, expected) |
diff --git a/scripts/merge_check.py b/scripts/merge_check.py index c4cbdceca..81bb3368a 100644 --- a/scripts/merge_check.py +++ b/scripts/merge_check.py | |||
| @@ -42,7 +42,10 @@ class GitError(Exception): | |||
| 42 | 42 | ||
| 43 | 43 | ||
| 44 | def git(repo, *args, check=True): | 44 | def git(repo, *args, check=True): |
| 45 | r = subprocess.run(["git", "-C", repo, *args], capture_output=True) | 45 | try: |
| 46 | r = subprocess.run(["git", "-C", repo, *args], capture_output=True) | ||
| 47 | except OSError as e: # git is not on PATH, or cannot be executed: a usage error (exit 2), not a traceback | ||
| 48 | raise GitError(f"cannot run git: {e.strerror or e}") from None | ||
| 46 | # Decode without universal-newline translation: a bare CR inside a Git line is content. | 49 | # Decode without universal-newline translation: a bare CR inside a Git line is content. |
| 47 | r.stdout = r.stdout.decode("utf-8", "replace") | 50 | r.stdout = r.stdout.decode("utf-8", "replace") |
| 48 | r.stderr = r.stderr.decode("utf-8", "replace") | 51 | r.stderr = r.stderr.decode("utf-8", "replace") |
| @@ -64,7 +67,7 @@ def _merged_pr_number(subject): | |||
| 64 | def prior_merges(repo, main, numbers, depth): | 67 | def prior_merges(repo, main, numbers, depth): |
| 65 | out = git(repo, "log", main, "--first-parent", f"-n{depth}", "--format=%H%x09%s").stdout | 68 | out = git(repo, "log", main, "--first-parent", f"-n{depth}", "--format=%H%x09%s").stdout |
| 66 | hits = {number: [] for number in numbers} | 69 | hits = {number: [] for number in numbers} |
| 67 | for line in out.splitlines(): | 70 | for line in out.split("\n"): |
| 68 | sha, _, subject = line.partition("\t") | 71 | sha, _, subject = line.partition("\t") |
| 69 | number = _merged_pr_number(subject) | 72 | number = _merged_pr_number(subject) |
| 70 | if number in hits: | 73 | if number in hits: |
diff --git a/scripts/run_gpu_tests.py b/scripts/run_gpu_tests.py index a075c876a..fef03e9c9 100644 --- a/scripts/run_gpu_tests.py +++ b/scripts/run_gpu_tests.py | |||
| @@ -36,6 +36,10 @@ from check import (CMPX_CLASS_WORDS, CVT_F32_SAT_CASES, CVT_PK_U8_WORDS, PK_MUL_ | |||
| 36 | from check import SIGNED_MIP_TEST, UINT_MIP_TEST | 36 | from check import SIGNED_MIP_TEST, UINT_MIP_TEST |
| 37 | from check import cbv_modulate_test | 37 | from check import cbv_modulate_test |
| 38 | from check import HEAP_INIT_EXPECTED, heap_init_env # cs_heap_init: vk_compute_test's VKC_HEAP_INIT | 38 | from check import HEAP_INIT_EXPECTED, heap_init_env # cs_heap_init: vk_compute_test's VKC_HEAP_INIT |
| 39 | from check import shift64_test # dynamic 64-bit vector shifts and overlapping destinations | ||
| 40 | from check import cmp_f64_test # the 32 binary64 vector compares on memory-fed operands | ||
| 41 | from check import round_f64_test # the four binary64 roundings on memory-fed inputs | ||
| 42 | from check import frexp_ldexp_test # binary32 and binary64 frexp, and v_ldexp_f32, on memory-fed records | ||
| 39 | from check import judged_words, words_match # dump words not judged on some devices (cs_signed_zero_nan) | 43 | from check import judged_words, words_match # dump words not judged on some devices (cs_signed_zero_nan) |
| 40 | from check import TEXOFF_ARGS, texoff_problem # ps_texoff's expected words and arguments live in check.py | 44 | from check import TEXOFF_ARGS, texoff_problem # ps_texoff's expected words and arguments live in check.py |
| 41 | from check import TEXOFF_FALLBACK, texoff_env # LEONIDA_TEXOFF_FALLBACK=1: texel offsets without maintenance8 | 45 | from check import TEXOFF_FALLBACK, texoff_env # LEONIDA_TEXOFF_FALLBACK=1: texel offsets without maintenance8 |
| @@ -93,10 +97,23 @@ def make_ms_psv0(threads_x: int, maxv: int, maxp: int, topology: int = 2, group_ | |||
| 93 | return struct.pack("<I", len(r)) + bytes(r) | 97 | return struct.pack("<I", len(r)) + bytes(r) |
| 94 | 98 | ||
| 95 | 99 | ||
| 100 | # A comment line a .asm carries when llvm-mc cannot assemble it (cs_dpp_cmp.asm: a VOPC compare in DPP form). | ||
| 101 | TEXT_ONLY_MARK = "; run_gpu_tests: text only, llvm-mc has no gfx1013 encoding for an instruction here" | ||
| 102 | |||
| 103 | |||
| 96 | def assemble_to_s(llvm_mc: str, asm_path: str, s_path: str, name: str) -> None: | 104 | def assemble_to_s(llvm_mc: str, asm_path: str, s_path: str, name: str) -> None: |
| 97 | """Assemble raw RDNA2 .asm with llvm-mc -show-encoding into .s format for rdna2spirv.py.""" | 105 | """Assemble raw RDNA2 .asm with llvm-mc -show-encoding into .s format for rdna2spirv.py.""" |
| 98 | with open(asm_path, encoding="utf-8") as source: | 106 | with open(asm_path, encoding="utf-8") as source: |
| 99 | raw = source.read() | 107 | raw = source.read() |
| 108 | if any(ln.strip() == TEXT_ONLY_MARK for ln in raw.splitlines()): | ||
| 109 | # The source holds an instruction llvm-mc has no gfx1013 encoding for. The translator reads straight-line | ||
| 110 | # code from its text alone (tests/semantic/regen_fixtures.py writes such listings), so the lines go through | ||
| 111 | # as they are. | ||
| 112 | lines = [f"; {name} code 0x0..0x0 (synthetic), gfx1013, 0 invalid words"] | ||
| 113 | lines += ["\t" + ln.strip() for ln in raw.splitlines() if ln.strip() and not ln.lstrip().startswith(";")] | ||
| 114 | with open(s_path, "w", encoding="utf-8", newline="\n") as f: | ||
| 115 | f.write("\n".join(lines) + "\n") | ||
| 116 | return | ||
| 100 | cmd = mc_command.mc_command(llvm_mc) + ["-triple=amdgcn--amdpal", "-mcpu=gfx1013"] | 117 | cmd = mc_command.mc_command(llvm_mc) + ["-triple=amdgcn--amdpal", "-mcpu=gfx1013"] |
| 101 | for ln in raw.splitlines(): | 118 | for ln in raw.splitlines(): |
| 102 | s = ln.strip() | 119 | s = ln.strip() |
| @@ -149,8 +166,13 @@ def spirv_as(asm_text: str, out_spv: str, assembler: str = "spirv-as") -> None: | |||
| 149 | with open(out_spv, "wb") as f: | 166 | with open(out_spv, "wb") as f: |
| 150 | f.write(spv_bytes) | 167 | f.write(spv_bytes) |
| 151 | return | 168 | return |
| 152 | p = subprocess.run(["spirv-as", "--target-env", "vulkan1.2", "-o", out_spv, "-"], | 169 | try: |
| 153 | input=asm_text, capture_output=True, text=True) | 170 | p = subprocess.run(["spirv-as", "--target-env", "vulkan1.2", "-o", out_spv, "-"], |
| 171 | input=asm_text, capture_output=True, text=True) | ||
| 172 | except FileNotFoundError: | ||
| 173 | raise RuntimeError("spirv-as not found on PATH (use --assembler python to assemble with tools/spirv_asm.py)") from None | ||
| 174 | except OSError as exc: | ||
| 175 | raise RuntimeError(f"spirv-as could not be started: {exc.strerror or exc}") from None | ||
| 154 | if p.returncode != 0: | 176 | if p.returncode != 0: |
| 155 | raise RuntimeError(f"spirv-as failed for {out_spv}:\n{p.stderr}") | 177 | raise RuntimeError(f"spirv-as failed for {out_spv}:\n{p.stderr}") |
| 156 | 178 | ||
| @@ -258,6 +280,8 @@ def read_raw_u32(path: str) -> list[tuple[int, int, int, int]]: | |||
| 258 | return [struct.unpack_from("<4I", data, 16 * i) for i in range(n)] | 280 | return [struct.unpack_from("<4I", data, 16 * i) for i in range(n)] |
| 259 | 281 | ||
| 260 | 282 | ||
| 283 | # cs_div_fmas_f64_rt's operands a = 1 + 2^-30, c = -(1 + 2^-29) as s4..s7 (low word first). | ||
| 284 | DIV_FMAS_F64_SGPRS = "0x00400000,0x3ff00000,0x00800000,0xbff00000" | ||
| 261 | UNSUPPORTED = 77 # vk_harness: the device lacks a stage the test draws with (geometry or mesh shaders) | 285 | UNSUPPORTED = 77 # vk_harness: the device lacks a stage the test draws with (geometry or mesh shaders) |
| 262 | 286 | ||
| 263 | 287 | ||
| @@ -423,8 +447,10 @@ def judge_cs_dump(rc: int, msg: str, want: list[int], *, wave64: bool, partial: | |||
| 423 | return None, "SKIP (no 64-wide compute subgroup on this device)" | 447 | return None, "SKIP (no 64-wide compute subgroup on this device)" |
| 424 | if rc == 0 and wave64 and "compute subgroup size: 64" not in msg.splitlines(): | 448 | if rc == 0 and wave64 and "compute subgroup size: 64" not in msg.splitlines(): |
| 425 | return False, "64-wide subgroup was not confirmed (rebuild vk_compute_test)" | 449 | return False, "64-wide subgroup was not confirmed (rebuild vk_compute_test)" |
| 450 | if rc != 0: | ||
| 451 | return False, f"exit {rc}: {msg or 'no test output'}" | ||
| 426 | words = dump_words(msg) | 452 | words = dump_words(msg) |
| 427 | if rc != 0 or words is None: | 453 | if words is None: |
| 428 | return False, msg | 454 | return False, msg |
| 429 | vals = words[:len(want)] | 455 | vals = words[:len(want)] |
| 430 | return words_match(vals, want), " ".join((hex if hexwords else str)(x) for x in vals) | 456 | return words_match(vals, want), " ".join((hex if hexwords else str)(x) for x in vals) |
| @@ -975,6 +1001,22 @@ def run_suite(a, work: str) -> int: | |||
| 975 | if name in CLIP_CASES: | 1001 | if name in CLIP_CASES: |
| 976 | detail = clip_test(a.build, spirv_dir, name) | 1002 | detail = clip_test(a.build, spirv_dir, name) |
| 977 | results.append((name, None if isinstance(detail, Skip) else not detail, detail or "four pixel masks exact")) | 1003 | results.append((name, None if isinstance(detail, Skip) else not detail, detail or "four pixel masks exact")) |
| 1004 | elif name == "cs_w32_frexp_ldexp": | ||
| 1005 | detail = frexp_ldexp_test(a.build, spirv_dir, cs_env) | ||
| 1006 | results.append((name, None if isinstance(detail, Skip) else not detail, | ||
| 1007 | detail or "768 words exact (64 records, eight results each, and unchanged inputs)")) | ||
| 1008 | elif name == "cs_w32_shift64": | ||
| 1009 | detail = shift64_test(a.build, spirv_dir, cs_env) | ||
| 1010 | results.append((name, None if isinstance(detail, Skip) else not detail, | ||
| 1011 | detail or "640 words exact (64 shift cases and unchanged inputs)")) | ||
| 1012 | elif name == "cs_w32_cmp_f64": | ||
| 1013 | detail = cmp_f64_test(a.build, spirv_dir, cs_env) | ||
| 1014 | results.append((name, None if isinstance(detail, Skip) else not detail, | ||
| 1015 | detail or "1536 words exact (256 operand pairs and unchanged inputs)")) | ||
| 1016 | elif name == "cs_w32_round_f64": | ||
| 1017 | detail = round_f64_test(a.build, spirv_dir, cs_env) | ||
| 1018 | results.append((name, None if isinstance(detail, Skip) else not detail, | ||
| 1019 | detail or "1152 words exact (64 inputs, eight roundings each, and unchanged inputs)")) | ||
| 978 | elif name == "cs_workgroup_yz": | 1020 | elif name == "cs_workgroup_yz": |
| 979 | rc, msg = run_cmd([vk_compute, spv, "2x3x4", "workgroup_yz"], env=cs_env) | 1021 | rc, msg = run_cmd([vk_compute, spv, "2x3x4", "workgroup_yz"], env=cs_env) |
| 980 | results.append((name,) + compute_result(rc, msg, rc == 0 and "2x3x4 workgroup Y/Z: 0 mismatches" | 1022 | results.append((name,) + compute_result(rc, msg, rc == 0 and "2x3x4 workgroup Y/Z: 0 mismatches" |
| @@ -1092,10 +1134,12 @@ def run_suite(a, work: str) -> int: | |||
| 1092 | ok, detail = judge_cs_dump(rc, msg, [0, 0x40040000], wave64=False, partial=False, emulated=False, | 1134 | ok, detail = judge_cs_dump(rc, msg, [0, 0x40040000], wave64=False, partial=False, emulated=False, |
| 1093 | hexwords=True) | 1135 | hexwords=True) |
| 1094 | results.append((name, ok, detail)) | 1136 | results.append((name, ok, detail)) |
| 1095 | elif name == "cs_div_fmas_f64": | 1137 | elif name in ("cs_div_fmas_f64", "cs_div_fmas_f64_rt"): |
| 1096 | # One-rounding binary64 FMA: strict where the translator emitted OpFmaKHR on doubles (shaderFmaFloat64, | 1138 | # One-rounding binary64 FMA: strict where the translator emitted OpFmaKHR on doubles (shaderFmaFloat64, |
| 1097 | # --fma khr); under the default GLSL Fma the split result (0) is allowed, as cs_fma_fused allows it. | 1139 | # --fma khr); under the default GLSL Fma the split result (0) is allowed, as cs_fma_fused allows it. |
| 1098 | rc, msg = run_cmd([vk_compute, spv, "1", "dump"], env=cs_env) | 1140 | # The _rt fixture reads the same operands from s4..s7, so the driver cannot fold the Fma at compile time. |
| 1141 | env = dict(cs_env or os.environ, VKC_SGPRS=DIV_FMAS_F64_SGPRS) if name.endswith("_rt") else cs_env | ||
| 1142 | rc, msg = run_cmd([vk_compute, spv, "1", "dump"], env=env) | ||
| 1099 | if rc == UNSUPPORTED: # no shaderFloat64, or (--fma khr) no shaderFmaFloat64 | 1143 | if rc == UNSUPPORTED: # no shaderFloat64, or (--fma khr) no shaderFmaFloat64 |
| 1100 | results.append((name, None, unsupported_skip(msg))) | 1144 | results.append((name, None, unsupported_skip(msg))) |
| 1101 | else: | 1145 | else: |
| @@ -1105,7 +1149,8 @@ def run_suite(a, work: str) -> int: | |||
| 1105 | ok = rc == 0 and (words == fused or (not strict and words == split)) | 1149 | ok = rc == 0 and (words == fused or (not strict and words == split)) |
| 1106 | detail = " ".join(hex(x) for x in words) if words else msg | 1150 | detail = " ".join(hex(x) for x in words) if words else msg |
| 1107 | if ok and words == split: | 1151 | if ok and words == split: |
| 1108 | detail += " (split: the driver rounds GLSL Fma on doubles twice; --fma khr fixes it)" | 1152 | detail += (" (split: the driver rounded GLSL Fma on doubles twice%s; --fma khr fixes it)" |
| 1153 | % ("" if name.endswith("_rt") else " when folding the constants")) | ||
| 1109 | results.append((name, ok, detail)) | 1154 | results.append((name, ok, detail)) |
| 1110 | elif name == "cs_cvt_f32_sat": | 1155 | elif name == "cs_cvt_f32_sat": |
| 1111 | # #300's saturating float -> int conversions: one dispatch per input word in s4 (VKC_SGPRS). | 1156 | # #300's saturating float -> int conversions: one dispatch per input word in s4 (VKC_SGPRS). |
| @@ -1152,7 +1197,7 @@ def run_suite(a, work: str) -> int: | |||
| 1152 | results.append((name,) + wavemask_check(vk_compute, spv, cs_env, w64_emulated())) | 1197 | results.append((name,) + wavemask_check(vk_compute, spv, cs_env, w64_emulated())) |
| 1153 | elif name in ("cs_store", "cs_signed_zero_nan", "cs_smem_soffset_imm", "cs_w32_lane_wrap", "cs_movrelsd_2", "cs_w32_permute", "cs_w32_sincos", "cs_w32_buffer_sub16", "cs_w32_buffer_store_sub", "cs_w32_fcmpswap", "cs_w32_permlane_fi", "cs_exec_const", "cs_w32_mask_imm", "cs_w64_mask_imm", "cs_w32_lds_u8_d16", "cs_w32_lds_subdword", "cs_w32_lds_wide", "cs_w32_int_ext", "cs_w32_salu64", "cs_w32_misc_ext", "cs_w32_new_ops", "cs_wave64_ballot", "cs_wm_half_ops", "cs_wm_half_cmp", "cs_wm_bfm64", "cs_wm_scc_rfl", "cs_wqm_w64", "cs_wqm_w32", "cs_wqm_w64_half", | 1198 | elif name in ("cs_store", "cs_signed_zero_nan", "cs_smem_soffset_imm", "cs_w32_lane_wrap", "cs_movrelsd_2", "cs_w32_permute", "cs_w32_sincos", "cs_w32_buffer_sub16", "cs_w32_buffer_store_sub", "cs_w32_fcmpswap", "cs_w32_permlane_fi", "cs_exec_const", "cs_w32_mask_imm", "cs_w64_mask_imm", "cs_w32_lds_u8_d16", "cs_w32_lds_subdword", "cs_w32_lds_wide", "cs_w32_int_ext", "cs_w32_salu64", "cs_w32_misc_ext", "cs_w32_new_ops", "cs_wave64_ballot", "cs_wm_half_ops", "cs_wm_half_cmp", "cs_wm_bfm64", "cs_wm_scc_rfl", "cs_wqm_w64", "cs_wqm_w32", "cs_wqm_w64_half", |
| 1154 | "cs_dpp", "cs_dpp_row", "cs_dpp_mask", "cs_dpp8", "cs_dpp_ops", "cs_dpp_bank", "cs_dpp_fi", | 1199 | "cs_dpp", "cs_dpp_row", "cs_dpp_mask", "cs_dpp8", "cs_dpp_ops", "cs_dpp_bank", "cs_dpp_fi", |
| 1155 | "cs_dpp_bound", "cs_dpp_w64", | 1200 | "cs_dpp_bound", "cs_dpp_cmp", "cs_dpp_w64", |
| 1156 | "cs_w64_mask_detect", | 1201 | "cs_w64_mask_detect", |
| 1157 | "cs_w64x_readlane", "cs_w64x_writelane", "cs_w64x_readfirstlane", "cs_w64x_bpermute", "cs_w64x_permute", | 1202 | "cs_w64x_readlane", "cs_w64x_writelane", "cs_w64x_readfirstlane", "cs_w64x_bpermute", "cs_w64x_permute", |
| 1158 | "cs_w64x_branch", "cs_w64x_ballot", "cs_w64x_wg128_branches", "cs_w64x_lds_raw", | 1203 | "cs_w64x_branch", "cs_w64x_ballot", "cs_w64x_wg128_branches", "cs_w64x_lds_raw", |
| @@ -1213,6 +1258,7 @@ def run_suite(a, work: str) -> int: | |||
| 1213 | "cs_dpp_bound": [10, 10, 11, 12, 13, 14, 15, 16], | 1258 | "cs_dpp_bound": [10, 10, 11, 12, 13, 14, 15, 16], |
| 1214 | "cs_dpp_bank": [0xFFFFFFFF, 0xFFFFFFFE, 0xFFFFFFFD, 0xFFFFFFFC, 7, 7, 7, 7], | 1259 | "cs_dpp_bank": [0xFFFFFFFF, 0xFFFFFFFE, 0xFFFFFFFD, 0xFFFFFFFC, 7, 7, 7, 7], |
| 1215 | "cs_dpp_fi": [1, 2, 3, 0x7777, 5, 6, 7, 0x7777], | 1260 | "cs_dpp_fi": [1, 2, 3, 0x7777, 5, 6, 7, 0x7777], |
| 1261 | "cs_dpp_cmp": [3, 2, 3, 2, 1, 0, 1, 0], | ||
| 1216 | "cs_dpp_w64": [1, 0, 3, 2, 5, 4, 7, 6], | 1262 | "cs_dpp_w64": [1, 0, 3, 2, 5, 4, 7, 6], |
| 1217 | # SHADER-99: -0 and NaN survive (SignedZeroInfNanPreserve, cs_signed_zero_nan.asm); 0 in out[4..7] | 1263 | # SHADER-99: -0 and NaN survive (SignedZeroInfNanPreserve, cs_signed_zero_nan.asm); 0 in out[4..7] |
| 1218 | # without it | 1264 | # without it |
| @@ -1287,7 +1333,7 @@ def run_suite(a, work: str) -> int: | |||
| 1287 | "cs_bpermute32", "cs_w32_partial_scmp", "cs_w32_partial_permute", "cs_w32_permlane_fi", "cs_w32_sincos", "cs_w32_buffer_sub16", "cs_w32_buffer_store_sub", "cs_w32_fcmpswap", | 1333 | "cs_bpermute32", "cs_w32_partial_scmp", "cs_w32_partial_permute", "cs_w32_permlane_fi", "cs_w32_sincos", "cs_w32_buffer_sub16", "cs_w32_buffer_store_sub", "cs_w32_fcmpswap", |
| 1288 | "cs_lds_b64_cmpst", "cs_lds_xchg64_ext", "cs_lds_atomics_ext", "cs_exec_const", "cs_w32_mask_imm", "cs_mask_vgpr_exec", | 1334 | "cs_lds_b64_cmpst", "cs_lds_xchg64_ext", "cs_lds_atomics_ext", "cs_exec_const", "cs_w32_mask_imm", "cs_mask_vgpr_exec", |
| 1289 | "cs_dpp", "cs_dpp_row", "cs_dpp_mask", "cs_dpp8", | 1335 | "cs_dpp", "cs_dpp_row", "cs_dpp_mask", "cs_dpp8", |
| 1290 | "cs_dpp_ops", "cs_dpp_bound", "cs_dpp_bank", "cs_dpp_fi", "cs_w32_andn2_exec", | 1336 | "cs_dpp_ops", "cs_dpp_bound", "cs_dpp_bank", "cs_dpp_fi", "cs_dpp_cmp", "cs_w32_andn2_exec", |
| 1291 | "cs_w32_exec_computed") and not emulated and not partial | 1337 | "cs_w32_exec_computed") and not emulated and not partial |
| 1292 | if partial and not emulated: | 1338 | if partial and not emulated: |
| 1293 | cs_env = dict(os.environ, VKC_SUBGROUP_SIZE="64") | 1339 | cs_env = dict(os.environ, VKC_SUBGROUP_SIZE="64") |
| @@ -1301,7 +1347,7 @@ def run_suite(a, work: str) -> int: | |||
| 1301 | continue | 1347 | continue |
| 1302 | if rc == 0: | 1348 | if rc == 0: |
| 1303 | skip = wave32_lane_skip(msg) | 1349 | skip = wave32_lane_skip(msg) |
| 1304 | if skip is None and name in WAVE32_PIN_DUMPS: | 1350 | if rc == 0 and skip is None and name in WAVE32_PIN_DUMPS: |
| 1305 | # the device may not be able to run the wave size this fixture was written for (a 64-only device | 1351 | # the device may not be able to run the wave size this fixture was written for (a 64-only device |
| 1306 | # can't pin 32, so cs_barrier_loop's words mean nothing); check.py skips it too | 1352 | # can't pin 32, so cs_barrier_loop's words mean nothing); check.py skips it too |
| 1307 | skip = subgroup_pin_skip(msg, cs_env) | 1353 | skip = subgroup_pin_skip(msg, cs_env) |
| @@ -1320,6 +1366,9 @@ def run_suite(a, work: str) -> int: | |||
| 1320 | elif name == "cs_imgstore": | 1366 | elif name == "cs_imgstore": |
| 1321 | rc, msg = run_cmd([vk_store, spv]) | 1367 | rc, msg = run_cmd([vk_store, spv]) |
| 1322 | results.append((name, *helper_result(rc, msg))) | 1368 | results.append((name, *helper_result(rc, msg))) |
| 1369 | elif name == "cs_imgstore_cube": # GPU-CUBE-STORE: six-layer 2D-array views at bindings 11/12/13 | ||
| 1370 | rc, msg = run_cmd([vk_store, spv, "cube"]) | ||
| 1371 | results.append((name, *helper_result(rc, msg))) | ||
| 1323 | elif name in ("cs_imgload", "cs_imgload_tfe", "cs_imgload_d16", "cs_imgload_d16_tfe", "cs_sample_lz_int_d16"): | 1372 | elif name in ("cs_imgload", "cs_imgload_tfe", "cs_imgload_d16", "cs_imgload_d16_tfe", "cs_sample_lz_int_d16"): |
| 1324 | rc, msg = run_cmd([vk_store, spv, "load" if name in ("cs_imgload", "cs_imgload_tfe") else "load-d16"]) | 1373 | rc, msg = run_cmd([vk_store, spv, "load" if name in ("cs_imgload", "cs_imgload_tfe") else "load-d16"]) |
| 1325 | results.append((name, *helper_result(rc, msg))) | 1374 | results.append((name, *helper_result(rc, msg))) |
diff --git a/scripts/run_semantic_tests.py b/scripts/run_semantic_tests.py index c364bb35d..03e0ddab4 100644 --- a/scripts/run_semantic_tests.py +++ b/scripts/run_semantic_tests.py | |||
| @@ -12,12 +12,14 @@ the pattern matches their basenames, not directory paths. Package `__init__.py` | |||
| 12 | because discover imports them and runs any TestCase they define regardless of the pattern. No matching files is an | 12 | because discover imports them and runs any TestCase they define regardless of the pattern. No matching files is an |
| 13 | error in serial and parallel runs. | 13 | error in serial and parallel runs. |
| 14 | 14 | ||
| 15 | It runs the files `python -m unittest discover -s tests/semantic` finds (`test*.py` by default, and packages below it), each as | 15 | It runs the files `python -m unittest discover -s tests/semantic` finds (`test*.py` by default, and packages below it), each in its own process from that folder, so a file sees the same import path as under discover. |
| 16 | `python -m unittest <module>` from that folder, so a file sees the same import path as under discover. The files can | 16 | |
| 17 | run side by side because each one writes only into its own temporary folder; a new test must do the same. With -j 1, | 17 | The files can run side by side because each one writes only into its own temporary folder; a new test must do the same. With -j 1, |
| 18 | or on a single core, it runs that discover command itself. Prints the output of every failing file and one summary | 18 | or on a single core, it runs that discover command itself. Prints the output of every failing file and one summary |
| 19 | line, and exits 1 if a file fails, none is found, or no test ran. Standard library only. | 19 | line, and exits 1 if a file fails, none is found, or no test ran. Standard library only. |
| 20 | 20 | ||
| 21 | The count of tests comes from unittest's own result object, not from its output: a module that writes a line shaped like unittest's summary to stderr - a nested runner, or an atexit handler that runs after unittest's own summary - cannot change it. | ||
| 22 | |||
| 21 | `--timeout SECONDS` limits each module subprocess in parallel mode, or the entire discover subprocess with | 23 | `--timeout SECONDS` limits each module subprocess in parallel mode, or the entire discover subprocess with |
| 22 | `-j 1`. The value must be positive and at most 86400 seconds (24 hours), keeping it within platform wait limits. | 24 | `-j 1`. The value must be positive and at most 86400 seconds (24 hours), keeping it within platform wait limits. |
| 23 | A timeout fails the run and reports any output already produced; other parallel modules keep running. | 25 | A timeout fails the run and reports any output already produced; other parallel modules keep running. |
| @@ -26,16 +28,34 @@ The default has no time limit. This stops the direct test subprocess, not any de | |||
| 26 | import argparse | 28 | import argparse |
| 27 | import concurrent.futures | 29 | import concurrent.futures |
| 28 | import fnmatch | 30 | import fnmatch |
| 31 | import json | ||
| 29 | import locale | 32 | import locale |
| 30 | import math | 33 | import math |
| 31 | import os | 34 | import os |
| 32 | import re | 35 | import re |
| 33 | import subprocess | 36 | import subprocess |
| 34 | import sys | 37 | import sys |
| 38 | import tempfile | ||
| 35 | import time | 39 | import time |
| 36 | 40 | ||
| 37 | MAX_TIMEOUT_SECONDS = 24 * 60 * 60 | 41 | MAX_TIMEOUT_SECONDS = 24 * 60 * 60 |
| 38 | 42 | ||
| 43 | # The child runs the module through unittest's own program and writes the result to a file, so the count of tests | ||
| 44 | # comes from the result object and nothing the module writes can change it. The exit codes are unittest's own: 1 | ||
| 45 | # when a test failed, 5 when nothing ran at all, 0 otherwise. The module is left unset, as `python -m unittest` leaves it, so | ||
| 46 | # the name is imported and not looked up as an attribute of the program itself. | ||
| 47 | CHILD_PROGRAM = ( | ||
| 48 | "import json, os, sys, unittest\n" | ||
| 49 | "program = unittest.TestProgram(module=None, argv=['unittest'] + sys.argv[1:], exit=False)\n" | ||
| 50 | "result = program.result\n" | ||
| 51 | "with open(os.environ['LEONIDA_TEST_COUNT'], 'w', encoding='utf-8') as handle:\n" | ||
| 52 | " json.dump({'testsRun': result.testsRun}, handle)\n" | ||
| 53 | "if not result.wasSuccessful():\n" | ||
| 54 | " sys.exit(1)\n" | ||
| 55 | "elif result.testsRun == 0 and len(result.skipped) == 0:\n" | ||
| 56 | " sys.exit(5)\n" | ||
| 57 | "sys.exit(0)\n") | ||
| 58 | |||
| 39 | 59 | ||
| 40 | def module_path(directory, module): | 60 | def module_path(directory, module): |
| 41 | """Source path of a dotted module name, including a package's `__init__.py`.""" | 61 | """Source path of a dotted module name, including a package's `__init__.py`.""" |
| @@ -73,28 +93,42 @@ def positive_seconds(value): | |||
| 73 | return seconds | 93 | return seconds |
| 74 | 94 | ||
| 75 | 95 | ||
| 96 | def read_count(path): | ||
| 97 | """The number of tests the child ran, as unittest's own result object reported it.""" | ||
| 98 | try: | ||
| 99 | with open(path, encoding="utf-8") as handle: | ||
| 100 | return int(json.load(handle)["testsRun"]) | ||
| 101 | except (OSError, ValueError, KeyError, TypeError): | ||
| 102 | # The child wrote no result: it did not finish, so no test is known to have run. | ||
| 103 | return 0 | ||
| 104 | |||
| 105 | |||
| 76 | def run_module(directory, module, verbose, timeout=None): | 106 | def run_module(directory, module, verbose, timeout=None): |
| 77 | """(return code, tests run, output) of `python -m unittest <target>` run from `directory`.""" | 107 | """(return code, tests run, output) of `python -m unittest <target>` run from `directory`.""" |
| 78 | # `python -m unittest pkg.__init__` imports pkg and then runs the same file again as pkg.__init__, so a | 108 | # `python -m unittest pkg.__init__` imports pkg and then runs the same file again as pkg.__init__, so a |
| 79 | # registration in the initializer happens twice. Running the package itself imports it once; module_path() is | 109 | # registration in the initializer happens twice. Running the package itself imports it once; module_path() is |
| 80 | # still the initializer's path, so the jobs stay sorted by the file they run. | 110 | # still the initializer's path, so the jobs stay sorted by the file they run. |
| 81 | target = module[:-len(".__init__")] if module.endswith(".__init__") else module | 111 | target = module[:-len(".__init__")] if module.endswith(".__init__") else module |
| 82 | cmd = [sys.executable, "-m", "unittest", *(["-v"] if verbose else []), target] | 112 | cmd = [sys.executable, "-c", CHILD_PROGRAM, *(["-v"] if verbose else []), target] |
| 83 | try: | 113 | with tempfile.TemporaryDirectory() as scratch: |
| 84 | p = subprocess.run(cmd, cwd=directory, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True, | 114 | count_path = os.path.join(scratch, "count.json") |
| 85 | errors="replace", timeout=timeout) | 115 | env = dict(os.environ, LEONIDA_TEST_COUNT=count_path) |
| 86 | except subprocess.TimeoutExpired as exc: | 116 | try: |
| 87 | out = exc.stdout or "" | 117 | p = subprocess.run(cmd, cwd=directory, env=env, stdout=subprocess.PIPE, stderr=subprocess.PIPE, |
| 88 | if isinstance(out, bytes): # TimeoutExpired retains bytes even when text=True. | 118 | text=True, errors="replace", timeout=timeout) |
| 89 | out = out.decode(locale.getpreferredencoding(False), errors="replace") | 119 | except subprocess.TimeoutExpired as exc: |
| 90 | return 1, 0, out + f"\nTIMED OUT after {timeout:g} s: {module}\n" | 120 | # TimeoutExpired retains bytes even when text=True. |
| 91 | ran = re.search(r"^Ran (\d+) tests? in", p.stdout, re.M) | 121 | parts = [chunk.decode(locale.getpreferredencoding(False), errors="replace") if isinstance(chunk, bytes) |
| 92 | count = int(ran.group(1)) if ran else 0 | 122 | else chunk for chunk in (exc.stdout, exc.stderr) if chunk] |
| 123 | out = "".join(parts) | ||
| 124 | return 1, 0, out + f"\nTIMED OUT after {timeout:g} s: {module}\n" | ||
| 125 | count = read_count(count_path) | ||
| 126 | out = p.stdout + p.stderr | ||
| 93 | # Discover imports every package initializer, but an empty one has no tests to run. It is included in the | 127 | # Discover imports every package initializer, but an empty one has no tests to run. It is included in the |
| 94 | # module list so parallel runs see TestCase classes when there are any; without them, it is not a failure. | 128 | # module list so parallel runs see TestCase classes when there are any; without them, it is not a failure. |
| 95 | if p.returncode == 5 and count == 0 and module.endswith(".__init__") and "NO TESTS RAN" in p.stdout: | 129 | if p.returncode == 5 and count == 0 and module.endswith(".__init__") and "NO TESTS RAN" in p.stderr: |
| 96 | return 0, 0, p.stdout | 130 | return 0, 0, out |
| 97 | return p.returncode, count, p.stdout | 131 | return p.returncode, count, out |
| 98 | 132 | ||
| 99 | 133 | ||
| 100 | def main(argv=None): | 134 | def main(argv=None): |
diff --git a/scripts/run_wine_tests.py b/scripts/run_wine_tests.py index 8435f7fb9..d36011430 100644 --- a/scripts/run_wine_tests.py +++ b/scripts/run_wine_tests.py | |||
| @@ -2,7 +2,7 @@ | |||
| 2 | 2 | ||
| 3 | Usage: | 3 | Usage: |
| 4 | python -I scripts/run_wine_tests.py --tests ctest.json --windows-root D:/a/Leonida/Leonida | 4 | python -I scripts/run_wine_tests.py --tests ctest.json --windows-root D:/a/Leonida/Leonida |
| 5 | [--root DIR] [--wine CMD] [--require NAME ...] [--timeout SECONDS] [--summary FILE] [--label TEXT] | 5 | [--root DIR] [--wine CMD] [--require NAME ...] [--timeout SECONDS] [--jobs N] [--summary FILE] [--label TEXT] |
| 6 | 6 | ||
| 7 | --tests is the output of `ctest --show-only=json-v1` from the Windows build, and --windows-root the checkout it was | 7 | --tests is the output of `ctest --show-only=json-v1` from the Windows build, and --windows-root the checkout it was |
| 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: |
| @@ -16,8 +16,16 @@ Every test is reported. The exit code is 1 if a test named by --require fails or | |||
| 16 | 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. |
| 17 | --timeout caps each process; a shorter positive CTest TIMEOUT takes precedence for that test. | 17 | --timeout caps each process; a shorter positive CTest TIMEOUT takes precedence for that test. |
| 18 | Relative executable paths in --wine or WINE are read from the directory where you start this runner. | 18 | Relative executable paths in --wine or WINE are read from the directory where you start this runner. |
| 19 | |||
| 20 | Each test gets WINEDLLOVERRIDES with winedbg.exe and winemenubuilder.exe disabled, so a crash fails at once instead of | ||
| 21 | waiting in the debugger until the timeout; an entry of the caller's or the test's for the same program wins. One | ||
| 22 | wineserver is kept alive for the whole run (`wineserver -p`: $WINESERVER, else the one next to the --wine command, | ||
| 23 | else the one on PATH) and stopped at the end, instead of a new one starting for every test. | ||
| 24 | --jobs N runs N tests at a time. Tests marked RUN_SERIAL run alone, tests sharing a RESOURCE_LOCK never overlap, and | ||
| 25 | DEPENDS and fixtures are kept; the report is in the same order as with --jobs 1 (the default). | ||
| 19 | """ | 26 | """ |
| 20 | import argparse | 27 | import argparse |
| 28 | from concurrent.futures import FIRST_COMPLETED, ThreadPoolExecutor, wait | ||
| 21 | from graphlib import CycleError, TopologicalSorter | 29 | from graphlib import CycleError, TopologicalSorter |
| 22 | import json | 30 | import json |
| 23 | import math | 31 | import math |
| @@ -30,6 +38,7 @@ import signal | |||
| 30 | import subprocess | 38 | import subprocess |
| 31 | import sys | 39 | import sys |
| 32 | import tempfile | 40 | import tempfile |
| 41 | import threading | ||
| 33 | import time | 42 | import time |
| 34 | 43 | ||
| 35 | ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | 44 | ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) |
| @@ -120,6 +129,97 @@ class DriveMap: | |||
| 120 | return False | 129 | return False |
| 121 | 130 | ||
| 122 | 131 | ||
| 132 | # A crashed test would wait in winedbg until the timeout; winemenubuilder writes file associations and menu entries | ||
| 133 | # into the user's profile when a fresh prefix is set up. | ||
| 134 | DEFAULT_DLL_OVERRIDES = ("winedbg.exe=d", "winemenubuilder.exe=d") | ||
| 135 | |||
| 136 | |||
| 137 | def _override_names(entry: str) -> set[str]: | ||
| 138 | """The programs one WINEDLLOVERRIDES entry ("a,b.exe=n") names, lower case and without .dll/.exe.""" | ||
| 139 | names = set() | ||
| 140 | for name in entry.partition("=")[0].split(","): | ||
| 141 | name = name.strip().lower() | ||
| 142 | for suffix in (".dll", ".exe"): | ||
| 143 | if name.endswith(suffix): | ||
| 144 | name = name[:-len(suffix)] | ||
| 145 | if name: | ||
| 146 | names.add(name) | ||
| 147 | return names | ||
| 148 | |||
| 149 | |||
| 150 | def merge_dll_overrides(given: str | None) -> str: | ||
| 151 | """WINEDLLOVERRIDES with the defaults added, leaving out a default for a program the given value already names.""" | ||
| 152 | entries = [e for e in (given or "").split(";") if e.strip()] | ||
| 153 | named = set().union(*(_override_names(e) for e in entries)) | ||
| 154 | return ";".join([d for d in DEFAULT_DLL_OVERRIDES if not _override_names(d) & named] + entries) | ||
| 155 | |||
| 156 | |||
| 157 | def find_wineserver(wine: list[str]) -> str | None: | ||
| 158 | """The wineserver the --wine command uses: $WINESERVER, else the one next to it, else the one on PATH.""" | ||
| 159 | given = os.environ.get("WINESERVER") | ||
| 160 | if given and shutil.which(given): | ||
| 161 | return shutil.which(given) | ||
| 162 | for part in wine: | ||
| 163 | resolved = shutil.which(part) | ||
| 164 | if resolved and os.path.basename(resolved).lower() in ("wine", "wine64"): | ||
| 165 | for folder in (os.path.dirname(resolved), os.path.dirname(os.path.realpath(resolved))): | ||
| 166 | sibling = shutil.which(os.path.join(folder, "wineserver")) | ||
| 167 | if sibling: | ||
| 168 | return sibling | ||
| 169 | return shutil.which("wineserver") | ||
| 170 | |||
| 171 | |||
| 172 | class KeptServer: | ||
| 173 | """Keeps one wineserver alive for the run instead of one starting and stopping for every test. | ||
| 174 | |||
| 175 | `wineserver -p` starts a persistent server for $WINEPREFIX; `wineserver -k` stops it and the prefix's Wine | ||
| 176 | processes at the end, also after a failure or Ctrl+C. A server still shutting down (wineboot's lingers a few | ||
| 177 | seconds) is waited for first; one that stays (started by hand with -p) is used and left running. | ||
| 178 | The first Wine program a server runs starts the prefix's services, which inherit its output and live as long as | ||
| 179 | the server: `wine wineboot` starts them with no output, or the first test would wait for the end of its output | ||
| 180 | until the timeout. | ||
| 181 | """ | ||
| 182 | |||
| 183 | def __init__(self, command: str | None, wine: list[str]): | ||
| 184 | self.command, self.wine, self.started, self.note = command, wine, False, "" | ||
| 185 | |||
| 186 | def _run(self, *flags, timeout=30.0) -> int | None: | ||
| 187 | try: | ||
| 188 | return subprocess.run([self.command, *flags], stdin=subprocess.DEVNULL, stdout=subprocess.DEVNULL, | ||
| 189 | stderr=subprocess.DEVNULL, timeout=timeout).returncode | ||
| 190 | except (OSError, subprocess.TimeoutExpired): | ||
| 191 | return None | ||
| 192 | |||
| 193 | def __enter__(self): | ||
| 194 | if not self.command: | ||
| 195 | self.note = "no wineserver found: each test starts its own" | ||
| 196 | return self | ||
| 197 | code = self._run("-p") | ||
| 198 | if code == 2: # one is already running for this prefix | ||
| 199 | if self._run("-w", timeout=15.0) == 0: | ||
| 200 | code = self._run("-p") | ||
| 201 | else: | ||
| 202 | self.note = "a wineserver already runs for this prefix: used and left running" | ||
| 203 | return self | ||
| 204 | self.started = code == 0 | ||
| 205 | if not self.started: | ||
| 206 | self.note = f"could not start {self.command} -p: each test starts its own server" | ||
| 207 | return self | ||
| 208 | self.note = "wineserver kept alive for the run" | ||
| 209 | env = dict(os.environ, WINEDLLOVERRIDES=merge_dll_overrides(os.environ.get("WINEDLLOVERRIDES"))) | ||
| 210 | try: | ||
| 211 | subprocess.run(self.wine + ["wineboot"], stdin=subprocess.DEVNULL, stdout=subprocess.DEVNULL, | ||
| 212 | stderr=subprocess.DEVNULL, env=env, timeout=120) | ||
| 213 | except (OSError, subprocess.TimeoutExpired): | ||
| 214 | pass # the tests start the services then, as without a kept server | ||
| 215 | return self | ||
| 216 | |||
| 217 | def __exit__(self, *exc): | ||
| 218 | if self.started: | ||
| 219 | self._run("-k") | ||
| 220 | return False | ||
| 221 | |||
| 222 | |||
| 123 | def wine_path(path: str) -> str: | 223 | def wine_path(path: str) -> str: |
| 124 | """Wine's Z: drive is the Unix root, so a Windows program reads /x/y as Z:\\x\\y.""" | 224 | """Wine's Z: drive is the Unix root, so a Windows program reads /x/y as Z:\\x\\y.""" |
| 125 | return "Z:" + os.path.abspath(path).replace("/", "\\") | 225 | return "Z:" + os.path.abspath(path).replace("/", "\\") |
| @@ -194,6 +294,7 @@ def run_test(test: dict, args, wine: list[str], *, failed_setups: tuple[str, ... | |||
| 194 | if not key or not equals or "\0" in assignment: | 294 | if not key or not equals or "\0" in assignment: |
| 195 | return "fail", "invalid CTest ENVIRONMENT entry: expected NAME=value" | 295 | return "fail", "invalid CTest ENVIRONMENT entry: expected NAME=value" |
| 196 | env[key] = value | 296 | env[key] = value |
| 297 | env["WINEDLLOVERRIDES"] = merge_dll_overrides(env.get("WINEDLLOVERRIDES")) | ||
| 197 | timeout = args.timeout | 298 | timeout = args.timeout |
| 198 | if "TIMEOUT" in props: | 299 | if "TIMEOUT" in props: |
| 199 | try: | 300 | try: |
| @@ -257,19 +358,42 @@ def run_test_process(argv: list[str], *, cwd: str, env: dict[str, str], | |||
| 257 | 358 | ||
| 258 | # Wine's Windows children and launcher wrappers can outlive the immediate child. | 359 | # Wine's Windows children and launcher wrappers can outlive the immediate child. |
| 259 | with subprocess.Popen(argv, **options, start_new_session=True) as proc: | 360 | with subprocess.Popen(argv, **options, start_new_session=True) as proc: |
| 361 | with _running_lock: | ||
| 362 | _running.add(proc.pid) | ||
| 260 | try: | 363 | try: |
| 261 | out, _ = proc.communicate(timeout=timeout) | 364 | out, _ = proc.communicate(timeout=timeout) |
| 262 | except (subprocess.TimeoutExpired, KeyboardInterrupt): | 365 | except (subprocess.TimeoutExpired, KeyboardInterrupt): |
| 263 | # The launcher may have exited while a helper still holds the output pipe. | 366 | # The launcher may have exited while a helper still holds the output pipe. |
| 264 | try: | 367 | _kill_group(proc.pid) |
| 265 | os.killpg(proc.pid, signal.SIGKILL) | ||
| 266 | except ProcessLookupError: | ||
| 267 | pass | ||
| 268 | proc.wait() | 368 | proc.wait() |
| 269 | raise | 369 | raise |
| 370 | finally: | ||
| 371 | with _running_lock: | ||
| 372 | _running.discard(proc.pid) | ||
| 270 | return subprocess.CompletedProcess(argv, proc.returncode, out) | 373 | return subprocess.CompletedProcess(argv, proc.returncode, out) |
| 271 | 374 | ||
| 272 | 375 | ||
| 376 | # The process groups of the tests running now: with --jobs, Ctrl+C reaches only the main thread, which stops them. | ||
| 377 | _running: set[int] = set() | ||
| 378 | _running_lock = threading.Lock() | ||
| 379 | |||
| 380 | |||
| 381 | def _kill_group(pid: int) -> None: | ||
| 382 | try: | ||
| 383 | os.killpg(pid, signal.SIGKILL) | ||
| 384 | except (ProcessLookupError, PermissionError): | ||
| 385 | pass | ||
| 386 | |||
| 387 | |||
| 388 | def stop_running_tests() -> None: | ||
| 389 | if os.name != "posix": | ||
| 390 | return | ||
| 391 | with _running_lock: | ||
| 392 | pids = list(_running) | ||
| 393 | for pid in pids: | ||
| 394 | _kill_group(pid) | ||
| 395 | |||
| 396 | |||
| 273 | def positive_seconds(text: str) -> float: | 397 | def positive_seconds(text: str) -> float: |
| 274 | """--timeout: a finite value greater than 0, so subprocess.run never gets a bad timeout to raise on.""" | 398 | """--timeout: a finite value greater than 0, so subprocess.run never gets a bad timeout to raise on.""" |
| 275 | try: | 399 | try: |
| @@ -283,6 +407,17 @@ def positive_seconds(text: str) -> float: | |||
| 283 | return value | 407 | return value |
| 284 | 408 | ||
| 285 | 409 | ||
| 410 | def positive_int(text: str) -> int: | ||
| 411 | """--jobs: a whole number of at least 1.""" | ||
| 412 | try: | ||
| 413 | value = int(text) | ||
| 414 | except ValueError: | ||
| 415 | raise argparse.ArgumentTypeError(f"invalid int value: {text!r}") from None | ||
| 416 | if value < 1: | ||
| 417 | raise argparse.ArgumentTypeError("must be at least 1") | ||
| 418 | return value | ||
| 419 | |||
| 420 | |||
| 286 | def wine_command(text: str) -> list[str]: | 421 | def wine_command(text: str) -> list[str]: |
| 287 | """--wine: split into a command the way a shell would, refusing blank or malformed values up front.""" | 422 | """--wine: split into a command the way a shell would, refusing blank or malformed values up front.""" |
| 288 | try: | 423 | try: |
| @@ -331,6 +466,48 @@ def read_tests(path: str) -> list[dict] | None: | |||
| 331 | return tests | 466 | return tests |
| 332 | 467 | ||
| 333 | 468 | ||
| 469 | def run_parallel(tests: list[dict], order: list[int], before: dict[int, set[int]], jobs: int, run_one, outcomes: dict, | ||
| 470 | results_by_index: dict, report) -> None: | ||
| 471 | """Run up to `jobs` tests at a time and report them in `order`, as the serial loop does. | ||
| 472 | |||
| 473 | A test starts once the tests it depends on have finished. A RUN_SERIAL test runs alone, and two tests that share | ||
| 474 | a RESOURCE_LOCK never run at the same time. | ||
| 475 | """ | ||
| 476 | serial = {index for index, test in enumerate(tests) if truthy(properties(test).get("RUN_SERIAL"))} | ||
| 477 | locks = {index: set(regex_list(properties(test).get("RESOURCE_LOCK", []))) for index, test in enumerate(tests)} | ||
| 478 | waiting, running, held = list(order), {}, set() | ||
| 479 | next_report = 0 | ||
| 480 | with ThreadPoolExecutor(max_workers=jobs) as pool: | ||
| 481 | try: | ||
| 482 | while waiting or running: | ||
| 483 | for index in list(waiting): | ||
| 484 | if len(running) >= jobs or any(r in serial for r in running.values()): | ||
| 485 | break | ||
| 486 | if before[index] - results_by_index.keys() or locks[index] & held: | ||
| 487 | continue | ||
| 488 | if index in serial and running: | ||
| 489 | continue | ||
| 490 | waiting.remove(index) | ||
| 491 | held |= locks[index] | ||
| 492 | running[pool.submit(run_one, index)] = index | ||
| 493 | if index in serial: | ||
| 494 | break | ||
| 495 | done, _ = wait(running, return_when=FIRST_COMPLETED) | ||
| 496 | for future in done: | ||
| 497 | index = running.pop(future) | ||
| 498 | outcomes[index] = future.result() | ||
| 499 | results_by_index[index] = outcomes[index][0] | ||
| 500 | held -= locks[index] | ||
| 501 | while next_report < len(order) and order[next_report] in outcomes: | ||
| 502 | report(order[next_report]) | ||
| 503 | next_report += 1 | ||
| 504 | except BaseException: | ||
| 505 | # Ctrl+C reaches this thread only: stop the tests the workers are waiting on, start no more. | ||
| 506 | pool.shutdown(wait=False, cancel_futures=True) | ||
| 507 | stop_running_tests() | ||
| 508 | raise | ||
| 509 | |||
| 510 | |||
| 334 | def main() -> int: | 511 | def main() -> int: |
| 335 | ap = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter) | 512 | ap = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter) |
| 336 | ap.add_argument("--tests", required=True, help="ctest --show-only=json-v1 output from the Windows build") | 513 | ap.add_argument("--tests", required=True, help="ctest --show-only=json-v1 output from the Windows build") |
| @@ -341,6 +518,8 @@ def main() -> int: | |||
| 341 | ap.add_argument("--require", action="append", default=[], help="a test that must pass (repeatable)") | 518 | ap.add_argument("--require", action="append", default=[], help="a test that must pass (repeatable)") |
| 342 | ap.add_argument("--timeout", type=positive_seconds, default=120.0, | 519 | ap.add_argument("--timeout", type=positive_seconds, default=120.0, |
| 343 | help="maximum seconds per test; a shorter CTest TIMEOUT applies (default 120)") | 520 | help="maximum seconds per test; a shorter CTest TIMEOUT applies (default 120)") |
| 521 | ap.add_argument("--jobs", type=positive_int, default=1, | ||
| 522 | help="tests run at a time; RUN_SERIAL and RESOURCE_LOCK are kept (default 1)") | ||
| 344 | ap.add_argument("--summary", help="append a Markdown table to this file (e.g. $GITHUB_STEP_SUMMARY)") | 523 | ap.add_argument("--summary", help="append a Markdown table to this file (e.g. $GITHUB_STEP_SUMMARY)") |
| 345 | ap.add_argument("--label", help="named in the summary's heading, e.g. the Wine version") | 524 | ap.add_argument("--label", help="named in the summary's heading, e.g. the Wine version") |
| 346 | args = ap.parse_args() | 525 | args = ap.parse_args() |
| @@ -352,9 +531,12 @@ def main() -> int: | |||
| 352 | indices = {name: index for index, name in enumerate(names)} | 531 | indices = {name: index for index, name in enumerate(names)} |
| 353 | setups = fixture_dependencies(tests) | 532 | setups = fixture_dependencies(tests) |
| 354 | sorter = TopologicalSorter(setups) | 533 | sorter = TopologicalSorter(setups) |
| 534 | before = {index: set(setups[index]) for index in range(len(tests))} | ||
| 355 | for index, test in enumerate(tests): | 535 | for index, test in enumerate(tests): |
| 356 | # DEPENDS controls order. Only failed fixture setups block a consumer. | 536 | # DEPENDS controls order. Only failed fixture setups block a consumer. |
| 357 | sorter.add(index, *(indices[name] for name in properties(test).get("DEPENDS", []) if name in indices)) | 537 | depends = [indices[name] for name in properties(test).get("DEPENDS", []) if name in indices] |
| 538 | sorter.add(index, *depends) | ||
| 539 | before[index].update(depends) | ||
| 358 | try: | 540 | try: |
| 359 | order = list(sorter.static_order()) | 541 | order = list(sorter.static_order()) |
| 360 | except CycleError: | 542 | except CycleError: |
| @@ -367,18 +549,30 @@ def main() -> int: | |||
| 367 | results = {} | 549 | results = {} |
| 368 | results_by_index: dict[int, str] = {} | 550 | results_by_index: dict[int, str] = {} |
| 369 | prefix = os.environ.get("WINEPREFIX") or os.path.join(os.path.expanduser("~"), ".wine") | 551 | prefix = os.environ.get("WINEPREFIX") or os.path.join(os.path.expanduser("~"), ".wine") |
| 370 | with DriveMap(args.windows_root, args.root, prefix) as drive: | 552 | outcomes: dict[int, tuple[str, str]] = {} |
| 553 | |||
| 554 | def run_one(index: int) -> tuple[str, str]: | ||
| 555 | failed_setups = tuple(names[setup] for setup in setups[index] if results_by_index[setup] == "fail") | ||
| 556 | return run_test(tests[index], args, wine, failed_setups=failed_setups) | ||
| 557 | |||
| 558 | def report(index: int) -> None: | ||
| 559 | status, detail = outcomes[index] | ||
| 560 | results[names[index]] = status | ||
| 561 | print(f"[{status.upper()}] {names[index]}", flush=True) | ||
| 562 | if status != "pass": | ||
| 563 | for line in detail.rstrip().splitlines()[-40:]: | ||
| 564 | print(f" {line}") | ||
| 565 | |||
| 566 | with DriveMap(args.windows_root, args.root, prefix) as drive, KeptServer(find_wineserver(wine), wine) as server: | ||
| 371 | print(drive.note, flush=True) | 567 | print(drive.note, flush=True) |
| 372 | for index in order: | 568 | print(server.note, flush=True) |
| 373 | name = names[index] | 569 | if args.jobs == 1: |
| 374 | failed_setups = tuple(names[setup] for setup in setups[index] if results_by_index[setup] == "fail") | 570 | for index in order: |
| 375 | status, detail = run_test(tests[index], args, wine, failed_setups=failed_setups) | 571 | outcomes[index] = run_one(index) |
| 376 | results_by_index[index] = status | 572 | results_by_index[index] = outcomes[index][0] |
| 377 | results[name] = status | 573 | report(index) |
| 378 | print(f"[{status.upper()}] {name}", flush=True) | 574 | else: |
| 379 | if status != "pass": | 575 | run_parallel(tests, order, before, args.jobs, run_one, outcomes, results_by_index, report) |
| 380 | for line in detail.rstrip().splitlines()[-40:]: | ||
| 381 | print(f" {line}") | ||
| 382 | 576 | ||
| 383 | missing = list(dict.fromkeys(n for n in args.require if n not in results)) | 577 | missing = list(dict.fromkeys(n for n in args.require if n not in results)) |
| 384 | failed_required = [n for n in args.require if results.get(n) != "pass"] | 578 | failed_required = [n for n in args.require if results.get(n) != "pass"] |