Files
aji/tools/litmus/check.py
dev f8d2a99249 P5-1a: independent axiomatic oracle and the litmus corpus (20 tests agree)
tools/litmus/enumerate.py was written by an independent author from spec 04
§20 alone, with the programs blind (outcome sets removed). check.py compares
its allowed sets with tests/litmus/*.lit: 20/20 equal. 21 self-tests derived
from the axioms. Both run in CI. The author's spec findings are Q-024.
2026-10-06 00:40:09 +03:00

74 lines
2.5 KiB
Python

#!/usr/bin/env python3
"""Compare the axiomatic oracle with the stated outcome sets of the litmus corpus.
Usage: python3 tools/litmus/check.py [tests/litmus/*.lit]
For every test the oracle's allowed set (tools/litmus/enumerate.py) MUST equal the
stated `allowed:` set, and no stated `forbidden:` outcome may be allowed
(spec 04 §20.5). A mismatch is a finding to diagnose, never a reason to edit
the stated set to match (docs/reference/concurrency-litmus.md).
"""
import glob
import json
import os
import re
import subprocess
import sys
HERE = os.path.dirname(os.path.abspath(__file__))
ROOT = os.path.dirname(os.path.dirname(HERE))
def outcomes(line):
return {tuple(int(v) for v in m.split(",")) for m in re.findall(r"\(([^)]*)\)", line)}
def stated(path):
allowed, forbidden = set(), set()
for line in open(path):
line = line.split("#", 1)[0].strip()
if line.startswith("allowed:"):
allowed |= outcomes(line)
elif line.startswith("forbidden:"):
forbidden |= outcomes(line)
return allowed, forbidden
def main(argv):
files = argv or sorted(glob.glob(os.path.join(ROOT, "tests", "litmus", "*.lit")))
out = subprocess.run([sys.executable, os.path.join(HERE, "enumerate.py"), *files], capture_output=True, text=True, check=True).stdout
computed = {}
for line in out.splitlines():
if line.strip():
r = json.loads(line)
computed[os.path.abspath(r["file"])] = {tuple(o) for o in r["allowed"]}
failures = 0
for f in files:
allowed, forbidden = stated(f)
got = computed.get(os.path.abspath(f))
name = os.path.relpath(f, ROOT)
problems = []
if allowed & forbidden:
problems.append(f"stated sets overlap: {sorted(allowed & forbidden)}")
if got is None:
problems.append("no oracle result")
else:
if got - allowed:
problems.append(f"oracle allows unstated {sorted(got - allowed)}")
if allowed - got:
problems.append(f"oracle forbids stated-allowed {sorted(allowed - got)}")
if got & forbidden:
problems.append(f"oracle allows stated-forbidden {sorted(got & forbidden)}")
if problems:
failures += 1
print(f"MISMATCH {name}: " + "; ".join(problems))
else:
print(f"ok {name}")
print(f"\n{len(files) - failures} agree, {failures} disagree")
return 1 if failures else 0
if __name__ == "__main__":
sys.exit(main(sys.argv[1:]))