# SPDX-License-Identifier: MIT """Rung 2: gilyon's spctest in the harness (validation.md). Hardware-run, author's expectations: the ROM's hand-written values, with hardware runs in its history but no per-test statement. Test numbers are printed in hexadecimal, so the last, "0557", is the 1,368th. A test program is cut from the ROM by scripts/build_referees.py. """ from pathlib import Path import pytest from spc700_python import SPC700 from spc700_python.harness import run_spctest BUILD = Path(__file__).resolve().parents[1] / "reference" / "build" / "spctest" TESTS = 1368 # $558: tests.txt holds Test 0000 to Test 0557, numbered in hex pytestmark = pytest.mark.skipif( not (BUILD / "spc_tests0.bin").exists(), reason="run scripts/build_referees.py first" ) def programs() -> list[bytes]: return [(BUILD / f"spc_tests{n}.bin").read_bytes() for n in range(3)] def test_all_pass(): report = run_spctest(programs()) assert report.failure is None assert report.programs == 3 assert report.tests == list(range(TESTS)) def test_the_driver_sees_a_wrong_result(monkeypatch): """The gate can fail: a DAA that ignores H is caught, with the failing test's registers.""" def wrong_daa(self, op): self._read_dummy(self.pc) self._idle() monkeypatch.setattr(SPC700, "_op_daa", wrong_daa) report = run_spctest(programs()) assert report.failure is not None assert not report.passed assert report.failure[0] < TESTS