#!/usr/bin/env python3 """Run the board's test-ROM judges and print (or write) their verdicts. Suites (docs/validation.md "The plan"): - ``jsmolka``: jsmolka's gba-tests read through r12 (``ppu`` is pictures: rung 3). - ``alyosha``: alyosha-tas's gba-tests read through r12 (ROMs whose folder's source uses ``m_test_eval``; in ``ppu``, the ROMs whose own source does, less two that never finish). - ``hwtest``: NanoBoyAdvance's hw-test, non-PPU, read from the console text. - ``hades``: Hades-Tests' four hardware tests, read from the console text. - ``mgba``: the mGBA suite's 13 non-video groups, read from the debug port. - ``frames``: pictures, each run a fixed number of frames and compared with the frame hash in ``tests/frames_pass.txt`` (frames NanoBoyAdvance and hardware evidence agree on; written by ``scripts/frame_diff.py --write``). ``nointro:NAME.zip`` is a game from the local No-Intro set. - ``ags``: Nintendo's aging cartridges (No-Intro, read in place), their automatic tests on the first result screen. - ``aging``: the same cartridges' settings page kept in their EEPROM across a power cycle, then two rounds of the aging loop (``testrom.run_ags_aging``). - ``armwrestler``: destoer's corrected ARMWrestler, one key per results page, read from its mode 4 text (every row OK). - ``fuzzarm``: DenSinH's five prebuilt FuzzARM ROMs (10,000 random tests each), read from the failure dumps it writes to EWRAM. - ``krom``: krom's (Peter Lemon's) BIOS function tests: results and Timer 0 cycle counts, each line PASS or FAIL on its text screen. - ``retaddr``: GBA-Test-Collection's IRQ return-address test, read from EWRAM. - ``keyirq``: mGBA's gbatests keyirq (built by ``scripts/build_test_roms.py``), one key per step (``#n``). - ``backuplib``: Nintendo's "Backup LIB sample" (No-Intro, read in place), its library's own write-and-verify on each save chip with three patterns (``chip#pattern``). The six above start at 8000000 (``skip_bios``); their verdicts do not depend on the boot, and krom's call the BIOS, whose timing they measure, so they need the retail dump all the same. Every run uses the BIOS ``gba_python.bios.find`` picks (the retail dump by default) and says which. ROMs run in parallel processes (``--jobs``). ``--write`` stores the passing ROMs as the pass list the slow tests keep green (``tests/_pass.txt``; for the mGBA suite, every group's score in ``tests/mgba_scores.txt``). python scripts/run_test_roms.py jsmolka alyosha python scripts/run_test_roms.py mgba --jobs 13 --json runs.json python scripts/run_test_roms.py hwtest --write """ from __future__ import annotations import argparse import json 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")) from gba_python import bios as bios_module # noqa: E402 from gba_python.testrom import ( # noqa: E402 ARMWRESTLER_PAGES, BACKUP_LIB_MENU, BACKUP_LIB_PATTERNS, SUITES, bios_handoff, hades_verdict, hwtest_verdict, keyirq_steps, krom_verdict, read_rom, run_ags, run_ags_aging, run_armwrestler, run_backup_lib, run_frames, run_fuzzarm, run_menu_text, run_r12, run_retaddr, run_suite, run_text, screen_hash, ) SRC = ROOT / "reference" / "src" MGBA_SUITE = ROOT / "tests" / "test_roms" / "mgba-suite" / "suite.gba" HADES = ("bios-openbus", "dma-latch", "dma-start-delay", "timer-basic") HWTEST_FOLDERS = ("bus", "dma", "haltcnt", "irq", "timer") STATUS_IRQ_DMA = "reference/src/hw-test/ppu/status-irq-dma/status-irq-dma.gba" # BIOS-sensitive on NanoBoyAdvance: calibrated on a Game Boy Player (C4, user decision 6). GBP_CALIBRATED = { line for line in (ROOT / "tests" / "alyosha_gbp_calibrated.txt").read_text().splitlines() if line and not line.startswith("#") } #: Nintendo's factory test cartridges in the local No-Intro set (BYOR, read in place) AGING_CARTRIDGES = [ "AGB Aging Cartridge (World) (Test Program).zip", "AGS Aging Cartridge (World) (Rev 1) (v7.0) (Test Program).zip", "AGS Aging Cartridge (World) (v7.1) (Test Program).zip", "AGS Aging Cartridge (World) (Rev 3) (v9.0) (Test Program).zip", "AGS Aging Cartridge (World) (v10.0) (Test Program).zip", ] #: alyosha-tas ppu ROMs that loop for ever drawing (no r12 verdict): judged by eye, not here VISUAL = {"Sprite_Disable_Midline.gba", "Sprite_Disable_on_VRAM_Access.gba"} ARMWRESTLER = SRC / "armwrestler" FUZZARM = ("ARM_DataProcessing", "ARM_Any", "THUMB_DataProcessing", "THUMB_Any", "FuzzARM") KEYIRQ = ROOT / "tests" / "test_roms" / "keyirq" / "keyirq.gba" KEYIRQ_STEPS = 14 RETADDR = "reference/src/GBA-Test-Collection/source/exception/retAddr/retAddr.gba" BACKUP_LIB = "nointro:Backup LIB Sample (Unknown) (v1.04) (Program).zip" def r12_roms(tree: Path) -> list[Path]: roms = [] for rom in sorted(tree.rglob("*.gba")): if "ppu" in rom.relative_to(tree).parts: # the pictures (rung 3) have no verdict; the r12 ones are timing (rung 4) source = rom.with_suffix(".asm") if rom.name not in VISUAL and source.exists() and "m_test_eval" in source.read_text(): roms.append(rom) continue if any("m_test_eval" in s.read_text(errors="replace") for s in rom.parent.glob("*.asm")): roms.append(rom) return roms def jobs_for(suite: str) -> list[tuple[str, str]]: """(suite, key) pairs; the key is a ROM path relative to the repository or a group.""" if suite == "jsmolka": return [(suite, str(r.relative_to(ROOT))) for r in r12_roms(SRC / "gba-tests")] if suite == "alyosha": return [(suite, str(r.relative_to(ROOT))) for r in r12_roms(SRC / "gba-tests-alyosha")] if suite == "hwtest": roms = [] for folder in HWTEST_FOLDERS: roms += sorted((SRC / "hw-test" / folder).rglob("*.gba")) keys = [(suite, str(r.relative_to(ROOT))) for r in roms] # The one PPU hw-test judged by text: line timing, flags, IRQs and DMA requests. return keys + [(suite, f"{STATUS_IRQ_DMA}#{option}") for option in range(4)] if suite == "hades": return [(suite, f"reference/src/Hades-Tests/roms/{name}.gba") for name in HADES] if suite == "mgba": return [(suite, name) for name in SUITES if name != "Video tests"] if suite == "frames": return [(suite, f"{rom}@{frames}") for rom, frames, _ in frame_pass_list()] if suite in ("ags", "aging"): return [(suite, f"nointro:{name}") for name in AGING_CARTRIDGES] if suite == "armwrestler": return [(suite, page) for page in ARMWRESTLER_PAGES] if suite == "fuzzarm": return [(suite, f"reference/src/FuzzARM/{name}.gba") for name in FUZZARM] if suite == "krom": # The BIOS tests print a verdict; the three Sound/ demos only play. roms = sorted((SRC / "PeterLemon-GBA" / "BIOS").rglob("*.gba")) return [(suite, str(r.relative_to(ROOT))) for r in roms] if suite == "retaddr": return [(suite, RETADDR)] if suite == "keyirq": return [(suite, f"{KEYIRQ.relative_to(ROOT)}#{step}") for step in range(KEYIRQ_STEPS)] if suite == "backuplib": return [ (suite, f"{chip}#{pattern}") for chip in BACKUP_LIB_MENU for pattern in BACKUP_LIB_PATTERNS ] raise ValueError(suite) def frame_pass_list() -> list[tuple[str, int, str]]: path = ROOT / "tests" / "frames_pass.txt" rows = ( [line.split("\t") for line in path.read_text().splitlines() if line] if path.exists() else [] ) return [(rom, int(frames), digest) for rom, frames, digest in rows] def rom_path(name: str) -> Path: if name.startswith("nointro:"): return bios_module.nointro_dir() / "Nintendo - Game Boy Advance" / name[8:] return ROOT / name def run_one(job: tuple[str, str], bios_path: str | None, frames: int | None) -> dict: suite, key = job bios = bios_module.find(bios_path) start = time.time() if suite == "mgba": result = run_suite(read_rom(MGBA_SUITE), bios, SUITES.index(key), frames or 4300) passed = result.passes is not None and result.passes == result.total detail = f"{result.passes}/{result.total}" extra = {"fails": result.fails, "passes": result.passes, "total": result.total} elif suite == "frames": name, count = key.rsplit("@", 1) expected = {f"{r}@{f}": d for r, f, d in frame_pass_list()}.get(key) digest = screen_hash(run_frames(read_rom(rom_path(name)), bios, int(count))) passed = digest == expected detail = digest if passed else f"{digest}, expected {expected}" extra = {"hash": digest} elif suite == "ags": result = run_ags(read_rom(rom_path(key)), bios, frames or 1200) passed = bool(result.passed) detail = result.detail extra = {"text": result.text} elif suite == "aging": result = run_ags_aging(read_rom(rom_path(key)), bios) passed = bool(result.passed) detail = result.detail extra = {"text": result.text} elif suite == "handoff": # skip_bios against the retail BIOS's own hand-off to the cartridge (C19). differences = bios_handoff(read_rom(ROOT / key), bios) passed = not differences detail = "skip_bios = BIOS" if passed else f"differ: {sorted(differences)}" extra = {"differences": {k: repr(v) for k, v in differences.items()}} elif suite == "armwrestler": font = (ARMWRESTLER / "data" / "font8x8.pat").read_bytes() rom = read_rom(ARMWRESTLER / "armwrestler-gba-fixed.gba") result = run_armwrestler(rom, bios, font, key) passed = bool(result.passed) detail = result.detail extra = {"text": result.text} elif suite == "fuzzarm": result = run_fuzzarm(read_rom(ROOT / key), bios, frames or 3000) passed = bool(result.passed) detail = result.detail extra = {"text": result.text} elif suite == "krom": rom = read_rom(ROOT / key) result = run_text(rom, bios, frames or 120, krom_verdict, rows=32, skip_bios=True) passed = bool(result.passed) detail = result.detail extra = {"text": result.text} elif suite == "retaddr": result = run_retaddr(read_rom(ROOT / key), bios, frames or 60) passed = bool(result.passed) detail = result.detail extra = {"text": result.text} elif suite == "keyirq": path, step = key.split("#") steps = keyirq_steps(read_rom(ROOT / path), bios, frames or 300) verdict = steps[int(step)] if int(step) < len(steps) else None passed = verdict == "PASS" detail = f"step {step}: {verdict or 'not reached'} ({steps.count('PASS')}/{len(steps)})" extra = {"steps": steps} elif suite == "backuplib": chip, pattern = key.split("#") result = run_backup_lib(read_rom(rom_path(BACKUP_LIB)), bios, chip, pattern, frames or 900) passed = bool(result.passed) detail = f"{chip} {result.detail}" extra = {"text": result.text} elif suite in ("jsmolka", "alyosha"): result = run_r12(read_rom(ROOT / key), bios, frames or 600) passed = result.passed detail = "no result" if result.r12 is None else f"r12={result.r12}" extra = {"r12": result.r12, "frames": result.frames} elif "#" in key: path, option = key.split("#") # Option 3 (DMA) prints no summary: its three PASS/FAIL lines are the verdict. done = (lambda text: sum("DMA:" in row for row in text) == 3) if option == "3" else None result = run_menu_text( read_rom(ROOT / path), bios, int(option), frames or 3000, hwtest_verdict, done=done ) passed = bool(result.passed) detail = result.detail extra = {"text": result.text} else: verdict = hwtest_verdict if suite == "hwtest" else hades_verdict result = run_text(read_rom(ROOT / key), bios, frames or 400, verdict) passed = bool(result.passed) detail = result.detail extra = {"text": result.text} return { "suite": suite, "key": key, "passed": passed, "detail": detail, "bios": bios.label, "seconds": round(time.time() - start, 1), **extra, } def main() -> int: parser = argparse.ArgumentParser(description=__doc__.split("\n\n")[0]) parser.add_argument( "suites", nargs="+", choices=( "jsmolka", "alyosha", "hwtest", "hades", "mgba", "frames", "ags", "aging", "armwrestler", "fuzzarm", "krom", "retaddr", "keyirq", "backuplib", ), ) parser.add_argument("--bios", help="a BIOS file or .zip (default: gba_python.bios.find)") parser.add_argument("--frames", type=int, help="frame budget per ROM (default per suite)") parser.add_argument("--jobs", type=int, default=16) parser.add_argument("--only", help="run only keys containing this text") parser.add_argument("--json", type=Path, help="also write every result here") parser.add_argument("--write", action="store_true", help="write tests/_pass.txt") parser.add_argument("--show", action="store_true", help="print the screen text of failures") args = parser.parse_args() jobs = [job for suite in args.suites for job in jobs_for(suite)] if args.only: jobs = [job for job in jobs if args.only in job[1]] label = bios_module.find(args.bios).label print(f"BIOS: {label}; {len(jobs)} runs", flush=True) results = [] with ProcessPoolExecutor(max_workers=args.jobs) as pool: futures = [pool.submit(run_one, job, args.bios, args.frames) for job in jobs] for future in futures: result = future.result() results.append(result) mark = "pass" if result["passed"] else "FAIL" note = " [GBP-calibrated]" if result["key"] in GBP_CALIBRATED else "" print( f"{mark:4} {result['suite']:8} {result['key']:70} {result['detail']}{note}", flush=True, ) if args.show and not result["passed"] and "text" in result: print(" | " + "\n | ".join(result["text"])) for suite in args.suites: mine = [r for r in results if r["suite"] == suite] calibrated = sum(not r["passed"] and r["key"] in GBP_CALIBRATED for r in mine) extra = f" ({calibrated} of the failures GBP-calibrated)" if calibrated else "" print(f"{suite}: {sum(r['passed'] for r in mine)}/{len(mine)} pass{extra}") if args.write and suite == "mgba": # Every group with its score: the slow test keeps each at or above it. lines = [f"{r['key']}\t{r['passes']}/{r['total']}" for r in mine] (ROOT / "tests" / "mgba_scores.txt").write_text("\n".join(lines) + "\n") elif args.write and suite != "frames": # frames_pass.txt is frame_diff.py's names = sorted(r["key"] for r in mine if r["passed"]) (ROOT / "tests" / f"{suite}_pass.txt").write_text("\n".join(names) + "\n") if args.json: args.json.write_text(json.dumps(results, indent=1) + "\n", encoding="utf-8") return 0 if __name__ == "__main__": sys.exit(main())