diff options
| author | DadaCap <167002618+DadaCap@users.noreply.github.com> | 2026-11-29 04:38:18 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-11-29 04:38:18 +0100 |
| commit | b6bf3aa0be76d3b90eef9a12e1698f5c1b3b7816 (patch) | |
| tree | 45e7cfec8e134ba24e8a7a0dcd8dbd1fb8fa7e86 /scripts | |
| parent | d50300f15acc152cb54dc7f8e9b74cab3671c280 (diff) | |
| parent | c5a52e67f528844dd11edbc4ef531bf269726d1c (diff) | |
Merge pull request #2254 from kirigayakazima/fix/check-compute-journal-overlay-safety
scripts/check_compute_journal_overlay: validate journal dirs/exe, enforce UTF-8, extract main, add tests
Diffstat (limited to 'scripts')
| -rw-r--r-- | scripts/check_compute_journal_overlay.py | 47 |
1 files changed, 35 insertions, 12 deletions
diff --git a/scripts/check_compute_journal_overlay.py b/scripts/check_compute_journal_overlay.py index 4ea23f84c..1ef6eb501 100644 --- a/scripts/check_compute_journal_overlay.py +++ b/scripts/check_compute_journal_overlay.py | |||
| @@ -25,6 +25,7 @@ def entries(cache): | |||
| 25 | d = cache / "pipeline_cache.d" | 25 | d = cache / "pipeline_cache.d" |
| 26 | if not d.exists(): | 26 | if not d.exists(): |
| 27 | return {} | 27 | return {} |
| 28 | require(d.is_dir(), "pipeline_cache.d is not a directory") | ||
| 28 | out = {} | 29 | out = {} |
| 29 | for p in d.iterdir(): | 30 | for p in d.iterdir(): |
| 30 | require(re.fullmatch(r"cs-[0-9a-f]{16}\.bin", p.name) and p.is_file() and | 31 | require(re.fullmatch(r"cs-[0-9a-f]{16}\.bin", p.name) and p.is_file() and |
| @@ -45,7 +46,10 @@ def run(exe, root, device, strict): | |||
| 45 | if label == "local-B": | 46 | if label == "local-B": |
| 46 | # Bring only B into a fresh process; no session or shared cache crosses this boundary. | 47 | # Bring only B into a fresh process; no session or shared cache crosses this boundary. |
| 47 | (cache / "pipeline_cache.d").mkdir() | 48 | (cache / "pipeline_cache.d").mkdir() |
| 48 | src, = (root / "new-B" / "pipeline_cache.d").iterdir() | 49 | b_dir = root / "new-B" / "pipeline_cache.d" |
| 50 | srcs = list(b_dir.iterdir()) if b_dir.is_dir() else [] | ||
| 51 | require(len(srcs) == 1 and srcs[0].is_file(), "new-B did not leave one journal file to copy") | ||
| 52 | src = srcs[0] | ||
| 49 | shutil.copy2(src, cache / "pipeline_cache.d" / src.name) | 53 | shutil.copy2(src, cache / "pipeline_cache.d" / src.name) |
| 50 | local_before = entries(cache) | 54 | local_before = entries(cache) |
| 51 | env = {k: v for k, v in os.environ.items() if not k.upper().startswith("LEONIDA_")} | 55 | env = {k: v for k, v in os.environ.items() if not k.upper().startswith("LEONIDA_")} |
| @@ -57,7 +61,8 @@ def run(exe, root, device, strict): | |||
| 57 | if label != "cold": | 61 | if label != "cold": |
| 58 | env["LEONIDA_PIPELINE_JOURNAL_SEED_DIR"] = str(seed / "pipeline_cache.d") | 62 | env["LEONIDA_PIPELINE_JOURNAL_SEED_DIR"] = str(seed / "pipeline_cache.d") |
| 59 | p = subprocess.run([str(exe)] + (["--second-shader"] if second else []), | 63 | p = subprocess.run([str(exe)] + (["--second-shader"] if second else []), |
| 60 | stdin=subprocess.DEVNULL, capture_output=True, text=True, errors="replace", | 64 | stdin=subprocess.DEVNULL, capture_output=True, text=True, |
| 65 | encoding="utf-8", errors="replace", | ||
| 61 | cwd=cache, env=env, timeout=60) | 66 | cwd=cache, env=env, timeout=60) |
| 62 | if p.returncode == 77: | 67 | if p.returncode == 77: |
| 63 | print("SKIP: the authored compute fixture is unsupported on this device") | 68 | print("SKIP: the authored compute fixture is unsupported on this device") |
| @@ -77,7 +82,11 @@ def run(exe, root, device, strict): | |||
| 77 | local = entries(cache) | 82 | local = entries(cache) |
| 78 | if label == "cold": | 83 | if label == "cold": |
| 79 | require(len(local) == 1, "cold A was not journaled") | 84 | require(len(local) == 1, "cold A was not journaled") |
| 80 | source, = (seed / "pipeline_cache.d").iterdir() | 85 | seed_dir = seed / "pipeline_cache.d" |
| 86 | seed_entries = list(seed_dir.iterdir()) if seed_dir.is_dir() else [] | ||
| 87 | require(len(seed_entries) == 1 and seed_entries[0].is_file(), | ||
| 88 | "cold A did not leave one seed journal file") | ||
| 89 | source = seed_entries[0] | ||
| 81 | # Make an erroneous hourly LRU touch observable without making the probe depend on system time. | 90 | # Make an erroneous hourly LRU touch observable without making the probe depend on system time. |
| 82 | old = time.time_ns() - 48 * 3600 * 10**9 | 91 | old = time.time_ns() - 48 * 3600 * 10**9 |
| 83 | os.utime(source, ns=(old, old)) | 92 | os.utime(source, ns=(old, old)) |
| @@ -95,17 +104,31 @@ def run(exe, root, device, strict): | |||
| 95 | return 0 | 104 | return 0 |
| 96 | 105 | ||
| 97 | 106 | ||
| 107 | def main(argv=None) -> int: | ||
| 108 | parser = argparse.ArgumentParser(description=__doc__) | ||
| 109 | parser.add_argument("executable", type=Path, help="built d3d12_compute_journal_test.exe") | ||
| 110 | parser.add_argument("--device", help="optional LEONIDA_VK_DEVICE selector") | ||
| 111 | parser.add_argument("--require-hit", action="store_true") | ||
| 112 | args = parser.parse_args(argv) | ||
| 113 | try: | ||
| 114 | exe = args.executable.resolve(strict=True) | ||
| 115 | except OSError as exc: | ||
| 116 | print(f"ERROR: {exc}", file=sys.stderr) | ||
| 117 | return 2 | ||
| 118 | if not exe.is_file() or exe.name.lower() not in ("d3d12_compute_journal_test.exe", "d3d12_compute_journal_test"): | ||
| 119 | print(f"ERROR: expected the compute test executable, not {exe.name}", file=sys.stderr) | ||
| 120 | return 2 | ||
| 121 | try: | ||
| 122 | with tempfile.TemporaryDirectory(prefix="leonida-authored-journal-") as tmp: | ||
| 123 | return run(exe, Path(tmp), args.device, args.require_hit) | ||
| 124 | except (RuntimeError, subprocess.TimeoutExpired, OSError) as exc: | ||
| 125 | print(f"ERROR: {exc}", file=sys.stderr) | ||
| 126 | return 1 | ||
| 127 | |||
| 128 | |||
| 98 | if __name__ == "__main__": | 129 | if __name__ == "__main__": |
| 99 | try: # a redirected stdout is strict ANSI code page under -I; write '?' for what it cannot encode | 130 | try: # a redirected stdout is strict ANSI code page under -I; write '?' for what it cannot encode |
| 100 | sys.stdout.reconfigure(errors="replace") | 131 | sys.stdout.reconfigure(errors="replace") |
| 101 | except (AttributeError, ValueError, OSError): | 132 | except (AttributeError, ValueError, OSError): |
| 102 | pass | 133 | pass |
| 103 | parser = argparse.ArgumentParser(description=__doc__) | 134 | raise SystemExit(main()) |
| 104 | parser.add_argument("executable", type=Path, help="built d3d12_compute_journal_test.exe") | ||
| 105 | parser.add_argument("--device", help="optional LEONIDA_VK_DEVICE selector") | ||
| 106 | parser.add_argument("--require-hit", action="store_true") | ||
| 107 | args = parser.parse_args() | ||
| 108 | exe = args.executable.resolve(strict=True) | ||
| 109 | require(exe.name.lower() == "d3d12_compute_journal_test.exe", "expected the compute test, not the game") | ||
| 110 | with tempfile.TemporaryDirectory(prefix="leonida-authored-journal-") as tmp: | ||
| 111 | raise SystemExit(run(exe, Path(tmp), args.device, args.require_hit)) | ||