#!/usr/bin/env python3 """Compare every L104 tile hash against its L103 Clang/GCC W1/W8/W12 peer.""" from __future__ import annotations import json import re from pathlib import Path ROOT = Path(__file__).resolve().parents[4] BEFORE = ROOT / "Saved/Linux/l103/hashes" AFTER = ROOT / "Saved/Linux/l104/hashes" TILE = re.compile( r"^\[PipelineTileHash\] lod=(-?\d+) x=(-?\d+) y=(-?\d+) z=(-?\d+) " r"density=(0x[0-9a-f]+) mesh=(0x[0-9a-f]+) payload=(0x[0-9a-f]+) " r"topology=(0x[0-9a-f]+)$", re.M) WHOLE = re.compile( r"^\[PipelineWholeViewHash\] tiles=(\d+) density=(0x[0-9a-f]+) " r"mesh=(0x[0-9a-f]+) payload=(0x[0-9a-f]+) topology=(0x[0-9a-f]+)$", re.M) def parse(path: Path) -> tuple[dict, tuple[str, ...]]: content = path.read_text(encoding="utf-8", errors="replace") tiles = {(int(lod), int(x), int(y), int(z)): values for lod, x, y, z, *values in TILE.findall(content)} whole = WHOLE.search(content) if not tiles or whole is None: raise RuntimeError(f"hash data missing in {path}") return tiles, whole.groups() def main() -> int: runs = json.loads((AFTER / "summary.json").read_text(encoding="utf-8"))["runs"] comparisons = [] for run in runs: stem = f"{run['stratum'].lower()}-{run['compiler'].lower()}-w{run['workers']}.log" old_tiles, old_whole = parse(BEFORE / stem) new_tiles, new_whole = parse(ROOT / run["log"]) keys = set(old_tiles) | set(new_tiles) tile_mismatches = sum(old_tiles.get(key) != new_tiles.get(key) for key in keys) comparisons.append({ "stratum": run["stratum"], "compiler": run["compiler"], "workers": run["workers"], "tiles_before": len(old_tiles), "tiles_after": len(new_tiles), "tile_mismatch_keys": tile_mismatches, "missing_after": len(set(old_tiles) - set(new_tiles)), "extra_after": len(set(new_tiles) - set(old_tiles)), "whole_hash_before": old_whole, "whole_hash_after": new_whole, "whole_hash_match": old_whole == new_whole, }) passed = len(comparisons) == 24 and all( row["tiles_before"] == row["tiles_after"] and row["tile_mismatch_keys"] == 0 and row["missing_after"] == 0 and row["extra_after"] == 0 and row["whole_hash_match"] for row in comparisons) result = {"all_24_l103_peer_comparisons_identical": passed, "comparisons": comparisons} (AFTER / "baseline-comparison.json").write_text( json.dumps(result, indent=2) + "\n", encoding="utf-8") print("[L104HashBaselineComparison] " + json.dumps( {"pass": passed, "comparisons": len(comparisons), "tile_mismatch_keys": sum(r["tile_mismatch_keys"] for r in comparisons), "whole_hash_mismatches": sum(not r["whole_hash_match"] for r in comparisons)}, sort_keys=True), flush=True) return 0 if passed else 1 if __name__ == "__main__": raise SystemExit(main())