#!/usr/bin/env python3 # SPDX-License-Identifier: MIT """Run SingleStepTests 65x02 through the core, each CMOS set on its row: rung 1. python -I scripts/run_single_step.py # all 7,660,000 cases python -I scripts/run_single_step.py --limit 100 # the smoke run: 100 per file python -I scripts/run_single_step.py --set wdc65c02 --opcode 6d The readings and the named known-contradiction classes are tests/single_step.py's. Prints one line per file with failures, then per set: cases, passed, failed, and how many were counted in each named class. The exit status is 1 if any case failed outside the named classes. Run it from the project's venv (PyPy for the whole corpus). At most ``--jobs`` processes (default 4: the machine is shared). """ from __future__ import annotations import argparse import json import multiprocessing import sys from collections import Counter from pathlib import Path ROOT = Path(__file__).resolve().parents[1] sys.path.insert(0, str(ROOT / "tests")) import single_step def run_file(task: tuple[str, int, int | None]) -> tuple[str, int, int, int, Counter, list[str]]: set_name, opcode, limit = task passed = failed = 0 classes: Counter = Counter() first: list[str] = [] for case in single_step.load_cases(set_name, opcode, limit): problems, names = single_step.run_case(case, set_name) if problems: failed += 1 if not first: first = [case["name"], *problems[:4]] elif names: classes["counted"] += 1 classes.update(names) # a case can be in two classes (a decimal ADC zp,X) else: passed += 1 return set_name, opcode, passed, failed, classes, first def main() -> int: parser = argparse.ArgumentParser(description=__doc__.split("\n\n")[0]) parser.add_argument("--jobs", type=int, default=4) parser.add_argument("--limit", type=int, help="cases per file (default: all 10,000)") parser.add_argument("--set", choices=sorted(single_step.SETS), action="append") parser.add_argument("--opcode", type=lambda text: int(text, 16), action="append") parser.add_argument("--json", type=Path, help="write the per-file results here") args = parser.parse_args() if not single_step.corpus_present(): raise SystemExit(single_step.FETCH_HINT) sets = args.set or list(single_step.SETS) tasks = [(name, opcode, args.limit) for name in sets for opcode in (args.opcode or range(256))] totals = {name: Counter() for name in sets} results: dict[str, dict] = {} with multiprocessing.Pool(args.jobs) as pool: for name, opcode, ok, bad, classes, first in pool.imap_unordered(run_file, tasks): total = totals[name] total["cases"] += ok + bad + classes["counted"] total["passed"] += ok total["failed"] += bad total.update(classes) results[f"{name}/{opcode:02x}"] = {"passed": ok, "failed": bad, **classes} if bad: print(f"{name} {opcode:02X}: {bad} failing; {first}", flush=True) failed = 0 for name in sets: total = totals[name] failed += total["failed"] row = single_step.SETS[name].__name__ named = sorted((key for key in total if key[1:].isdigit()), key=lambda key: int(key[1:])) counted = ", ".join(f"{key} {total[key]:,}" for key in named) print( f"{name} on {row}: {total['cases']:,} cases, {total['passed']:,} pass in full, " f"{total['counted']:,} counted under a named contradiction, {total['failed']:,} fail; " f"by name (a case can be in two): {counted or 'none'}" ) if args.json: args.json.write_text(json.dumps(results, indent=1, sort_keys=True)) return 1 if failed else 0 if __name__ == "__main__": sys.exit(main())