#!/usr/bin/env python3 """Run the L9 uniform-block proof and L13 route parity audits.""" import os import signal import subprocess import time from pathlib import Path ROOT = Path(__file__).resolve().parents[4] OUT = ROOT / "Saved/Linux/l19-audits" 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", } RECIPES = { "floating-islands": ("-22,-19,-22.8,0,-4", "--recipe=floating-islands"), "surface-world": ("0,-35,-487.94,0,-22", "--recipe=surface-world"), } passed = True for recipe, (camera, recipe_flag) in RECIPES.items(): for compiler, binary in BINARIES.items(): name = f"{recipe}-{compiler}" 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", "--workers=12", f"--camera={camera}", recipe_flag, "--audit-uniform-block-proofs", "--audit-route-parity"] 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 log = logfile.read_text(encoding="utf-8", errors="replace") route_lines = [line for line in log.splitlines() if line.startswith("[RouteParityAudit]")] proof_lines = [line for line in log.splitlines() if line.startswith("[UniformBlockProofAudit]")] route_ok = bool(route_lines) and route_lines[-1].endswith("status=PASS") proof_ok = bool(proof_lines) and "violations=0" in proof_lines[-1] ok = code == 0 and not timed_out and route_ok and proof_ok passed &= ok print(f"[AuditRun] {name} exit={code} seconds={elapsed:.3f} peak_rss_kib={peak_rss} " f"route={route_ok} proofs={proof_ok} status={'PASS' if ok else 'FAIL'}", flush=True) print(f"[AuditSummary] rows={len(RECIPES)*len(BINARIES)} expected=4 " f"result={'PASS' if passed else 'FAIL'} path={OUT}", flush=True) raise SystemExit(0 if passed else 1)