#!/usr/bin/env python3 """Rerun the upper-SW fixture's six L34 determinism cases and merge results.""" import csv import re import subprocess import time from pathlib import Path ROOT = Path(__file__).resolve().parents[4] OUT = ROOT / "Saved/Linux/l34" FIXTURE = ROOT / "Saved/Linux/l33/fixtures/sw-upper-tunnel-network-style0.json" BINARIES = { "clang": OUT / "bin/VoxelForgeCoreHeadless-l34-clang", "gcc": OUT / "bin/VoxelForgeCoreHeadless-l34-gcc", } LAYOUT_PATTERN = re.compile( r"^\[ResolvedLayoutSnapshot\] schema=\d+ stable_identity=([^ ]+) strata=\d+ bytes=\d+ round_trip=PASS$", re.M) PLAN_PATTERN = re.compile( r"^\[WorldAssemblerPlanSerialization\].*canonical_round_trip=true .*" r"plan_hash=([0-9a-f]+) manifest_hash=([0-9a-f]+) status=PASS$", re.M) ROUTE_PATTERN = re.compile( r"^\[WorldAssemblerRouteAccepted\] arrival_xy_m=\([^)]*\) " r"departure_xy_m=\([^)]*\) endpoint_proximity_cost=\d+ average_grade_q16=\d+$", re.M) rows = [] failed = False reference = None for compiler, binary in BINARIES.items(): for workers in (1, 8, 12): name = f"upper-fixture-{compiler}-w{workers}" logfile = OUT / f"determinism-{name}.log" command = [ "taskset", "-c", "0-11", "prlimit", "--as=6442450944", "--", "timeout", "1800s", str(binary), str(FIXTURE), f"--workers={workers}", "--world-assembler-prototype", "--stream-benchmark", "--stream-pipeline", "--force-generate", "--clip-radius=3", "--max-clip-level=8", "--max-level=-1", "--recipe=floating-islands", "--audit-resolved-layout-passages", ] started = time.monotonic() try: with logfile.open("w", encoding="utf-8") as stream: result = subprocess.run(command, cwd=ROOT, stdout=stream, stderr=subprocess.STDOUT, timeout=1800, check=False) except subprocess.TimeoutExpired: result = None elapsed = time.monotonic() - started output = logfile.read_text(encoding="utf-8", errors="replace") layouts = LAYOUT_PATTERN.findall(output) plans = PLAN_PATTERN.findall(output) routes = ROUTE_PATTERN.findall(output) stamps = re.findall( r"^\[WorldAssemblerRecipeAudit\] requested=([^ ]+) actual=([^ ]+).*status=([^ ]+)$", output, re.M) passage = re.search(r"^\[ResolvedPassageAuditSummary\].*status=PASS$", output, re.M) signature = (tuple(layouts), tuple(plans), tuple(routes)) stable = reference is None or signature == reference if reference is None and layouts and plans and routes: reference = signature ok = (result is not None and result.returncode == 0 and len(layouts) == 1 and len(plans) == 1 and len(routes) == 1 and stamps == [("floating-islands", "floating-islands", "PASS")] and passage is not None and stable) code = result.returncode if result is not None else "TIMEOUT" rows.append(("upper-fixture", "floating-islands", compiler, workers, elapsed, code, ok)) failed |= not ok print(f"[L34FixtureDeterminism] compiler={compiler} workers={workers} " f"elapsed={elapsed:.1f}s recipe_stamp={stamps[0][1] if stamps else 'MISSING'} " f"layout={layouts[0] if layouts else 'MISSING'} " f"stable_across_matrix={'yes' if stable else 'no'} " f"{'PASS' if ok else 'FAIL'}", flush=True) fixture_summary = OUT / "determinism-upper-fixture-l34.csv" with fixture_summary.open("w", newline="", encoding="utf-8") as stream: writer = csv.writer(stream) writer.writerow(("kind", "recipe", "compiler", "workers", "elapsed_seconds", "exit_code", "status")) for row in rows: writer.writerow((*row[:-1], f"{row[-1] and 'PASS' or 'FAIL'}")) combined = OUT / "determinism-l34.csv" with combined.open("r", newline="", encoding="utf-8") as stream: owner_rows = list(csv.reader(stream)) if owner_rows and owner_rows[0] == ["kind", "recipe", "compiler", "workers", "elapsed_seconds", "exit_code", "status"]: owner_rows = [row for row in owner_rows[1:] if row and row[0] != "upper-fixture"] else: raise SystemExit("owner determinism summary is missing or malformed") if len(owner_rows) != 24: raise SystemExit(f"expected 24 owner rows before fixture merge, found {len(owner_rows)}") with combined.open("w", newline="", encoding="utf-8") as stream: writer = csv.writer(stream) writer.writerow(("kind", "recipe", "compiler", "workers", "elapsed_seconds", "exit_code", "status")) writer.writerows(owner_rows) for row in rows: writer.writerow((*row[:-1], f"{row[-1] and 'PASS' or 'FAIL'}")) print(f"[L34FixtureDeterminismSummary] runs={len(rows)} pass={sum(row[-1] for row in rows)} " f"fail={sum(not row[-1] for row in rows)} combined_runs=30 " f"combined_summary={combined} fixture_summary={fixture_summary}", flush=True) raise SystemExit(1 if failed or len(rows) != 6 else 0)