#!/usr/bin/env python3 """Run the L19 24 m SurfaceWorld crossing hash matrix.""" import os import re import signal import subprocess import time from pathlib import Path ROOT = Path(__file__).resolve().parents[4] OUT = ROOT / "Saved/Linux/l19-crossing" OUT.mkdir(parents=True, exist_ok=True) if not os.sched_getaffinity(0).issubset(set(range(12))): raise SystemExit("run under taskset -c 0-11") BINARIES = { "clang-off": ROOT / "Standalone/bin/linux/VoxelForgeCoreHeadless-linux19-clang", "gcc-default": ROOT / "Standalone/bin/linux/VoxelForgeCoreHeadless-linux19-gcc", } PATTERN = re.compile(r"^\[Pipeline(?:FullDetailHash|WholeViewHash|LODHash|ExactQueryHash)\].*$", re.M) RUNS = [(1, 1), (8, 1), (12, 1), (12, 2), (12, 3), (12, 4), (12, 5)] passed = True for compiler, binary in BINARIES.items(): reference = None for workers, repeat in RUNS: name = f"{compiler}-w{workers}-r{repeat}" logfile = OUT / f"{name}.log" command = ["prlimit", "--as=6442450944", "--", str(binary), str(ROOT / "Standalone/data/owner_world.json"), "--world-assembler-prototype", "--stream-benchmark", "--stream-pipeline", "--stream-hash", "--force-generate", "--clip-radius=3", "--max-clip-level=8", f"--workers={workers}", "--camera=0,-35,-487.94,0,-22", "--camera-step=24,0,0", "--region-crossing", "--recipe=surface-world"] started = time.monotonic() peak_rss = 0 timed_out = False with logfile.open("w", encoding="utf-8") as stream: process = subprocess.Popen(command, stdout=stream, stderr=subprocess.STDOUT, start_new_session=True) while process.poll() is None: pending, seen = [process.pid], set() while pending: pid = pending.pop() if pid in seen: continue seen.add(pid) try: pending.extend(int(value) for value in Path(f"/proc/{pid}/task/{pid}/children").read_text().split()) for line in Path(f"/proc/{pid}/status").read_text().splitlines(): if line.startswith("VmRSS:"): peak_rss = max(peak_rss, int(line.split()[1])) break except (FileNotFoundError, PermissionError, ProcessLookupError, ValueError): pass if time.monotonic() - started > 900: os.killpg(process.pid, signal.SIGTERM) try: process.wait(timeout=5) except subprocess.TimeoutExpired: os.killpg(process.pid, signal.SIGKILL) process.wait() timed_out = True passed = False break time.sleep(0.1) code = process.wait() elapsed = time.monotonic() - started hashes = PATTERN.findall(logfile.read_text(encoding="utf-8", errors="replace")) ok = code == 0 and not timed_out and len(hashes) == 12 if reference is None: reference = hashes elif hashes != reference: ok = False print(f"[CrossingMismatch] {name}", flush=True) passed &= ok print(f"[CrossingRun] {name} exit={code} seconds={elapsed:.3f} " f"peak_rss_kib={peak_rss} hash_rows={len(hashes)} " f"status={'PASS' if ok else 'FAIL'}", flush=True) print(f"[CrossingSummary] rows={len(BINARIES)*len(RUNS)} expected=14 " f"result={'PASS' if passed else 'FAIL'} path={OUT}", flush=True) raise SystemExit(0 if passed else 1)