"""Rung 3: ZEXDOC and ZEXALL in lockstep with the reference, segment by segment. The reference's ``conformance checkpoints`` subcommand cuts each exerciser into 116 manifests of 50,000,000 boundaries (examples/conformance/zex/README.md; check them against the committed SHA256SUMS first). Each segment starts from the state the previous one ended in, so a clean result on every segment is a clean result for the whole run. This runs ``validation/lockstep.py`` on every segment, ``--jobs`` at a time, and writes one ``.lockstep`` result file beside each manifest, so an interrupted run resumes where it stopped. pypy3 scripts/rung3.py examples/conformance/zex/zexall-segments --jobs 20 Exit status 0 when every segment is identical, 1 otherwise. """ from __future__ import annotations import argparse import subprocess import sys import time from concurrent.futures import ThreadPoolExecutor from pathlib import Path ROOT = Path(__file__).resolve().parents[1] def _run(manifest: Path) -> tuple[Path, int, str]: result = manifest.with_suffix(".lockstep") if result.exists() and result.read_text().startswith("identical"): return manifest, 0, result.read_text().strip() proc = subprocess.run( [sys.executable, str(ROOT / "validation" / "lockstep.py"), str(manifest)], capture_output=True, text=True, ) text = (proc.stdout + proc.stderr).strip() result.write_text(text + "\n") return manifest, proc.returncode, text def main(argv: list[str] | None = None) -> int: parser = argparse.ArgumentParser(description=__doc__.split("\n\n")[0]) parser.add_argument("directories", nargs="+", type=Path) parser.add_argument("--jobs", type=int, default=8) args = parser.parse_args(argv) manifests = sorted(m for d in args.directories for m in d.glob("*.json")) if not manifests: print("no manifests found", file=sys.stderr) return 2 started = time.perf_counter() failures = 0 with ThreadPoolExecutor(args.jobs) as pool: for done, (_manifest, status, text) in enumerate(pool.map(_run, manifests), 1): elapsed = time.perf_counter() - started if status != 0: failures += 1 line = text.splitlines()[0] if text else f"exit {status}, no output" print(f"[{done}/{len(manifests)} {elapsed:6.0f} s] {line}", flush=True) verdict = "every segment identical" if failures == 0 else f"{failures} segment(s) FAILED" print(f"{len(manifests)} segments, {verdict}, {time.perf_counter() - started:.0f} s") return 0 if failures == 0 else 1 if __name__ == "__main__": raise SystemExit(main())