#!/usr/bin/env python3 """Compare L137 Clang/GCC composed hashes at W1, W8, and W12.""" from __future__ import annotations import json import re import subprocess import time from pathlib import Path ROOT = Path(__file__).resolve().parents[4] OUT = ROOT / "Saved/Linux/l137/determinism" DATA = ROOT / "Standalone/data/regression/owner_world_2strate_l61.json" BINARIES = { "clang": ROOT / "Saved/Linux/l137/fast/bin/VoxelForgeCoreHeadless-fast-clang", "gcc": ROOT / "Saved/Linux/l137/fast/bin/VoxelForgeCoreHeadless-fast-gcc", } STAMP = "dcf2ffa55fd6d62b3c7faf76229c3b99c635868dc1b694fc6e8f39e738775a4e" CAMERA = "-4.688214,38.662384,-505.781342,-28.446,0" HASH_RE = re.compile( r"^\[Pipeline(?:FullDetailHash|WholeViewHash|MaterialHash|LODHash|ExactQueryHash)\].*$", re.M) STAMP_RE = re.compile(r"^\[VoxelForgeSourceStamp\] sha256=([0-9a-f]+)$", re.M) def main() -> int: if any(not path.is_file() for path in (DATA, *BINARIES.values())): raise SystemExit("missing L137 determinism binary or owner fixture") OUT.mkdir(parents=True, exist_ok=True) rows = [] baseline: tuple[str, ...] | None = None for compiler, binary in BINARIES.items(): for workers in (1, 8, 12): label = f"determinism-{compiler}-w{workers}" log = OUT / f"{label}.log" command = ["taskset", "-c", "0-11", "prlimit", "--as=6442450944", "--", "timeout", "1740s", str(binary), str(DATA), "--world-assembler-prototype", "--stream-benchmark", "--stream-pipeline", f"--workers={workers}", "--clip-radius=3", "--max-clip-level=0", "--max-level=0", f"--camera={CAMERA}", "--stream-hash-tiles", "--force-generate", "--recipe=surface-world", "--render-distance-chunks=0", "--landmark-chamber-demo", "--ore-veins-demo"] started = time.monotonic() with log.open("w", encoding="utf-8") as output: result = subprocess.run(command, cwd=ROOT, stdout=output, stderr=subprocess.STDOUT, check=False, timeout=1740) content = log.read_text(encoding="utf-8", errors="replace") stamp = STAMP_RE.search(content) hashes = tuple(HASH_RE.findall(content)) passed = (result.returncode == 0 and stamp is not None and stamp.group(1) == STAMP and len(hashes) >= 4) if baseline is None and passed: baseline = hashes elif baseline is not None: passed &= hashes == baseline row = {"compiler": compiler, "workers": workers, "exit": result.returncode, "stamp": stamp.group(1) if stamp else None, "hash_lines": len(hashes), "hashes_match_first": hashes == baseline, "passed": bool(passed), "elapsed_s": round(time.monotonic() - started, 3), "log": str(log.relative_to(ROOT))} rows.append(row) print("[L137DeterminismRun] " + json.dumps(row, sort_keys=True), flush=True) if not passed: (OUT / "summary.json").write_text(json.dumps( {"status": "FAIL", "stamp": STAMP, "runs": rows}, indent=2) + "\n") raise SystemExit(f"determinism mismatch; see {log}") (OUT / "summary.json").write_text(json.dumps( {"status": "PASS", "stamp": STAMP, "runs": rows}, indent=2) + "\n") print(f"[L137DeterminismSummary] runs={len(rows)} stamp={STAMP} status=PASS") return 0 if __name__ == "__main__": raise SystemExit(main())