#!/usr/bin/env python3 # SPDX-License-Identifier: MIT """Run the smoke list (docs/handoff-brief.md, 29 games) headless and save pictures. Each title is found under ``$NO_INTRO_DIR`` by name prefix, read in place, booted through the real boot ROM and run; the frame at each named point is saved as a PNG under ``tests/runs/smoke/`` (gitignored). Whether a picture is a title screen is judged by a person looking at it (docs/validation.md records who looked and what). python -I scripts/smoke.py [--frames 600,1200] [--jobs 3] [--list FILE] [TITLE ...] ``--list scripts/smoke-next.txt`` runs the next smoke group (a full sweep's failures plus classics, as the methodology says). """ from __future__ import annotations import argparse import sys import time from concurrent.futures import ProcessPoolExecutor from pathlib import Path ROOT = Path(__file__).resolve().parents[1] sys.path.insert(0, str(ROOT / "src")) SMOKE = [ # Classics. "California Games", "Chip's Challenge", "Blue Lightning", "Electrocop", "Todd's Adventures in Slime World", "Xenophobe", "Ms. Pac-Man", "Shanghai", "Robotron 2084", "Joust", "Rampart", "Warbirds", "Checkered Flag", # Known-hard, with the reason in docs/undocumented-behavior.md. "S.T.U.N. Runner", "Hard Drivin'", "Dirty Larry", "Steel Talons", "QIX", "Fat Bobby", "Block Out", "Lemmings", "Batman Returns", "Krazy Ace", "Crystal Mines II", "Awesome Golf", "Scrapyard Dog", "Klax", "Gauntlet - The Third Encounter", "NFL Football", ] # fmt: skip OUT = ROOT / "tests" / "runs" / "smoke" def job(item: tuple[str, list[int]]) -> str: from lynx_python import romsets from lynx_python.__main__ import boot, run_frames from lynx_python.cart import load from lynx_python.picture import save title, points = item # "SET/FILE" names one file of one set under $NO_INTRO_DIR (a BLL twin of a cart, say). root = romsets.no_intro_dir() if "/" in title: cart = root / title if root is not None and (root / title).is_file() else None else: cart = romsets.find_cart(title) if cart is None: return f"{title}: not found under $NO_INTRO_DIR" started = time.process_time() try: description = load(cart) board = boot(cart, description=description) done = 0 names = [] for point in points: run_frames(board, point - done) done = point name = f"{title.replace(' ', '_').replace(chr(39), '').replace('/', '_')}-{point}.png" save(OUT / name, board.mikey.display.rgb(), description.rotation) names.append(name) except Exception as error: # noqa: BLE001 (a crash is a smoke result, reported) return f"{title}: {type(error).__name__}: {error}" spent = time.process_time() - started seconds = board.tick / 16_000_000 return f"{title}: {seconds:.1f} emulated s, {spent:.0f} s CPU; {', '.join(names)}" def main(argv: list[str]) -> int: parser = argparse.ArgumentParser() parser.add_argument("titles", nargs="*") parser.add_argument("--frames", default="600,1200") parser.add_argument("--jobs", type=int, default=3) parser.add_argument("--list", type=Path, help="titles from a file, one per line (# comments)") args = parser.parse_args(argv) points = sorted(int(v) for v in args.frames.split(",")) OUT.mkdir(parents=True, exist_ok=True) listed = [] if args.list: for line in args.list.read_text().splitlines(): line = line.split("#")[0].strip() if line: listed.append(line) titles = args.titles or listed or SMOKE with ProcessPoolExecutor(args.jobs) as pool: for line in pool.map(job, [(t, points) for t in titles]): print(line, flush=True) return 0 if __name__ == "__main__": sys.exit(main(sys.argv[1:]))