Files
aji/tools/litmus/run_interp.py
T
dev 4242132b2a Phase 5: atomics through every layer (RFC 0015)
AIR: linear atomic<T> (AtomicScalar), atomic.new/take/load/store/RMW/
cmpxchg (two results)/fence with explicit orderings; feature atomics
published. Verifier: ordering tables (E4201), ordinary access (E4202),
effects [atomic] / [atomic, atomic.weak], linearity, take while lent
(E4101, also for mutex.take). Interpreter: timestamped message machine
(src/interp/weak.zig); views travel through spawn/join, channels, mutexes,
close and cancel; seq_cst reads the latest message and programs without
weak reads make no extra draw (existing records unchanged). aji explore:
exhaustive exploration that branches only before visible operations.
Litmus: 20/20 tests give exactly the oracle's sets; differential test
(1500 random programs) found no unsound outcome. .aji layer 10, Quick
Reference atomics, source coverage 67/67, audit report atomic_operations.
AIR bundle +5.9 %, QUICK.md +0.5k.
2026-10-06 08:05:01 +03:00

77 lines
2.9 KiB
Python

#!/usr/bin/env python3
"""Interpreter conformance on the normative litmus corpus (spec 04 §20.5).
For every test, the outcomes the interpreter produces under exhaustive
exploration (`aji explore`) MUST equal the stated allowed set:
observed_exhaustive == allowed
Usage: python3 tools/litmus/run_interp.py [--aji PATH] [tests/litmus/*.lit]
"""
import glob
import json
import os
import subprocess
import sys
import tempfile
HERE = os.path.dirname(os.path.abspath(__file__))
ROOT = os.path.dirname(os.path.dirname(HERE))
sys.path.insert(0, HERE)
import check # noqa: E402 (stated sets)
import to_air # noqa: E402
def main(argv):
aji = os.path.join(ROOT, "zig-out", "bin", "aji")
if argv[:1] == ["--aji"]:
aji, argv = argv[1], argv[2:]
files = argv or sorted(glob.glob(os.path.join(ROOT, "tests", "litmus", "*.lit")))
failures = 0
with tempfile.TemporaryDirectory() as tmp:
for f in files:
name = os.path.relpath(f, ROOT)
allowed, forbidden = check.stated(f)
air = os.path.join(tmp, os.path.basename(f) + ".air")
prog = to_air.parse(open(f).read())
open(air, "w").write(to_air.translate(open(f).read()))
r = subprocess.run([aji, "explore", "--grant", "heap=mem.alloc:65536", air], capture_output=True, text=True)
lines = [json.loads(l) for l in r.stdout.splitlines() if l.strip()]
result = next((l for l in lines if "outcomes" in l), None)
if result is None:
failures += 1
print(f"ERROR {name}: {r.stdout.strip()[:300]} {r.stderr.strip()[:300]}")
continue
observed = set()
others = []
for o in result["outcomes"]:
out = o["outcome"]
if out.get("status") != "returned":
others.append(out)
continue
observed.add(tuple(out["value"][f"o{i}"] for i in range(len(prog["observe"]))))
problems = []
if not result["complete"]:
problems.append(f"exploration incomplete after {result['runs']} runs")
if others:
problems.append(f"non-returning outcomes {others[:3]}")
if observed - allowed:
problems.append(f"interpreter produced unallowed {sorted(observed - allowed)}")
if allowed - observed:
problems.append(f"interpreter never produced allowed {sorted(allowed - observed)}")
if observed & forbidden:
problems.append(f"interpreter produced forbidden {sorted(observed & forbidden)}")
if problems:
failures += 1
print(f"MISMATCH {name}: " + "; ".join(problems))
else:
print(f"ok {name} ({result['runs']} runs)")
print(f"\n{len(files) - failures} exact, {failures} not")
return 1 if failures else 0
if __name__ == "__main__":
sys.exit(main(sys.argv[1:]))