# SPDX-License-Identifier: MIT """Run every SingleStepTests 65816 case through the core, a process per file. python -I scripts/run_single_step.py [--jobs 24] [--limit N] [--json out.json] The same readings as tests/single_step.py (it is imported from there). Prints one line per file with failures and a total; ``--json`` writes per-file counts. The quick check is pytest; this is the whole of rung 1 in minutes instead of hours. """ from __future__ import annotations import argparse import json import multiprocessing import sys from pathlib import Path ROOT = Path(__file__).resolve().parents[1] sys.path.insert(0, str(ROOT / "tests")) sys.path.insert(0, str(ROOT / "src")) import single_step LIMIT: int | None = None def run_file(name: str) -> tuple[str, int, int, int, list[str]]: opcode = int(name[:2], 16) cases = single_step.load_cases(name)[:LIMIT] passed = failed = skipped = 0 first: list[str] = [] for case in cases: if single_step.excluded(opcode, case): skipped += 1 continue problems = single_step.run_case(case) if problems: failed += 1 if not first: first = [case["name"], *problems[:3]] else: passed += 1 return name, passed, failed, skipped, first def init(limit: int | None) -> None: global LIMIT LIMIT = limit def main() -> int: parser = argparse.ArgumentParser(description=__doc__.splitlines()[0]) parser.add_argument("--jobs", type=int, default=24) parser.add_argument("--limit", type=int) parser.add_argument("--json", type=Path) args = parser.parse_args() names = sorted(path.stem for path in single_step.CORPUS.glob("*.json")) totals = [0, 0, 0] results = {} with multiprocessing.Pool(args.jobs, initializer=init, initargs=(args.limit,)) as pool: for name, passed, failed, skipped, first in pool.imap_unordered(run_file, names): totals[0] += passed totals[1] += failed totals[2] += skipped results[name] = {"passed": passed, "failed": failed, "excluded": skipped} if failed: print(f"{name}: {failed} failing; {first}", flush=True) print(f"files {len(names)}, passed {totals[0]}, failed {totals[1]}, excluded (C4) {totals[2]}") if args.json: args.json.write_text(json.dumps(results, indent=1, sort_keys=True)) return 1 if totals[1] else 0 if __name__ == "__main__": sys.exit(main())