"""Rung 2: gilyon's cputest-full and cputest-basic pass in the minimal harness. gilyon/snes-tests v1.4 (validation.md: self-checking, hardware run unstated). Each ROM runs its generated tests in order, checks that none was skipped ("Invalid test order"), and prints its verdict through the PPU: at VRAM word $32 (row 1, column 18) "Success" or "Failed", at word $6E (row 3, column 14) the number of the last test run, in hex. Success at the last test is the pass: 1,610 tests (last $0649) in full, 1,107 ($0452) in basic. """ import re from pathlib import Path import pytest from w65c816.harness import Harness ROMS = Path(__file__).resolve().parents[1] / "reference" / "roms" / "snes-tests-v1.4" / "cputest" LAST_TEST = {"cputest-full.sfc": 0x0649, "cputest-basic.sfc": 0x0452} MAX_CYCLES = 20_000_000 # full needs about 4.9 million def verdict(harness: Harness) -> tuple[str, int | None]: """The ROM's own verdict and test number, as it printed them.""" lines = harness.screen(0, 4) word = lines[1][17:].strip() number = re.fullmatch(r" Test number: ([0-9A-F]{4})", lines[3]) return word, int(number[1], 16) if number else None def failed(harness: Harness) -> bool: return verdict(harness)[0] == "Failed" @pytest.mark.slow @pytest.mark.parametrize("name", LAST_TEST) def test_cputest_succeeds(name: str) -> None: path = ROMS / name if not path.is_file(): pytest.skip("snes-tests v1.4 not fetched: python -I scripts/fetch_references.py") harness = Harness(path.read_bytes()) result = harness.run(MAX_CYCLES, failed) word, number = verdict(harness) screen = "\n".join(line for line in harness.screen(0, 12) if line.strip()) assert result.reason == "spin", f"{result}\n{screen}" assert (word, number) == ("Success", LAST_TEST[name]), screen