#!/usr/bin/env python3 # SPDX-License-Identifier: MIT """Rung 1: run the whole SingleStepTests ARM7TDMI corpus against the core, one process per file. The corpus is emulator-derived (an NBA fork), so this is a detector (user decision 2). Excluded cases (tests/sst_overrides.json) are counted, never passed. python scripts/sst_gate.py # every file, every case python scripts/sst_gate.py --limit 2000 # the first 2,000 cases of each file python scripts/sst_gate.py --files arm_swp thumb_bx --examples 5 python scripts/sst_gate.py --json out.json """ from __future__ import annotations import argparse import json import os import sys import time from collections import Counter from concurrent.futures import ProcessPoolExecutor from pathlib import Path ROOT = Path(__file__).resolve().parents[1] sys.path[:0] = [str(ROOT / "src"), str(ROOT)] from tests.sst_runner import CORPUS, corpus_files, run_file # noqa: E402 def job(args: tuple[str, int | None, int]): path, limit, examples = args start = time.perf_counter() result = run_file(Path(path), limit, examples) return result, time.perf_counter() - start def main() -> int: parser = argparse.ArgumentParser(description=__doc__.splitlines()[0]) parser.add_argument("--limit", type=int, help="cases per file") parser.add_argument("--files", nargs="*", help="corpus file names without .json.bin") parser.add_argument("--examples", type=int, default=2) parser.add_argument("--jobs", type=int, default=os.cpu_count()) parser.add_argument("--json", type=Path) args = parser.parse_args() paths = [CORPUS / f"{n}.json.bin" for n in args.files] if args.files else corpus_files() start = time.perf_counter() totals = Counter() excluded, overridden, report = Counter(), Counter(), {} with ProcessPoolExecutor(args.jobs) as pool: work = [(str(p), args.limit, args.examples) for p in paths] for result, seconds in pool.map(job, work): totals.update(cases=result.cases, passed=result.passed, failed=result.failed) excluded += result.excluded overridden += result.overridden ex = ",".join(f"{k}={v}" for k, v in sorted(result.excluded.items())) print( f"{result.name:32} {result.passed:6}/{result.cases:<6} failed={result.failed:<6}" f" excluded[{ex}] {seconds:6.1f}s" ) for line in result.examples: print(" ", line) report[result.name] = { "cases": result.cases, "passed": result.passed, "failed": result.failed, "excluded": dict(result.excluded), "overridden": dict(result.overridden), "mapped": result.mapped, "fields": dict(result.fields), } gated = totals["cases"] - sum(excluded.values()) print( f"\nall: {totals['passed']:,} of {gated:,} gated cases pass, {totals['failed']:,} fail;" f" excluded {dict(excluded)} ({sum(excluded.values()):,});" f" overridden {dict(overridden)}; {time.perf_counter() - start:.0f} s wall" ) if args.json: args.json.write_text(json.dumps(report, indent=1) + "\n", encoding="utf-8") return 0 if totals["failed"] == 0 else 1 if __name__ == "__main__": sys.exit(main())