#!/usr/bin/env python3 # SPDX-License-Identifier: GPL-2.0-only """winuae's smoke test: two one-instruction cases of our own, no ROM from anywhere. python3 -I "$EMU_TOOLS_GPL2/tools/winuae/tests/smoke.py" Checks build_winuae.py's version line and its usage-error exit status (2); then, if the referee is built (build/winuae_referee), checks that the build and the fetched tree are at the pin (and that the tree carries upstream's COPYING, the GPL-2.0 text), then runs a NOP and a TRAP #15 through it and checks what it prints: the NOP takes 4 clocks and leaves the PC two bytes on, the TRAP raises vector 47 with a six-byte frame and the exception cost the tester adds for it (34). Under a second. """ from __future__ import annotations import subprocess import sys from pathlib import Path HERE = Path(__file__).resolve().parents[1] BINARY = HERE / "build" / "winuae_referee" PIN = "6e0d5ae15a9e7ae071d64fa052a34429ed787476" failures: list[str] = [] def check(ok: bool, what: str) -> None: print(("ok " if ok else "FAIL ") + what) if not ok: failures.append(what) def case(ident: str, program: bytes) -> str: """One case line: D0-D7 and A0-A6 zero, USP 0, SSP $8000, SR $2700, the program at $1000.""" registers = ["0"] * 15 + ["0", "8000", "2700", "1000"] pairs = " ".join(f"{0x1000 + i:x}:{b:x}" for i, b in enumerate(program)) return f"C {ident} {' '.join(registers)} {len(program):x} {pairs}\n" def fields(line: str) -> dict[str, str]: return dict(part.split("=", 1) for part in line.split()[2:] if "=" in part) def main() -> int: script = [sys.executable, "-I", str(HERE / "build_winuae.py")] done = subprocess.run([*script, "--version"], capture_output=True, text=True) check(done.returncode == 0 and done.stdout.startswith("winuae-referee 0.2.0 (WinUAE 6e0d5ae)"), "--version names the tool and the pin") done = subprocess.run([*script, "--bogus"], capture_output=True, text=True) check(done.returncode == 2, "an unknown argument: exit 2") if not BINARY.exists(): print("skip the run: build_winuae.py has not been run") return 1 if failures else 0 pin = (HERE / "build" / "PIN").read_text().strip() if (HERE / "build" / "PIN").exists() else "" check(pin == PIN, f"build/PIN names the pin ({PIN[:7]}): the build is not left from an old pin") tree = HERE / "upstream" / f"winuae-{PIN[:12]}" check((tree / "COPYING").is_file() and "Version 2, June 1991" in (tree / "COPYING").read_text(), "the fetched tree carries upstream's COPYING, the GPL-2.0 text") commands = case("nop", b"\x4e\x71\x4e\x71") + case("trap", b"\x4e\x4f") + "F\nQ\n" done = subprocess.run([str(BINARY)], input=commands, capture_output=True, text=True, timeout=60) check(done.returncode == 0, "the referee exits cleanly on Q") lines = {line.split()[1]: fields(line) for line in done.stdout.splitlines() if line.startswith("R ")} nop, trap = lines.get("nop", {}), lines.get("trap", {}) check(nop.get("exc") == "0" and nop.get("pc") == "1002" and nop.get("cyc") == "4", "NOP: no exception, PC $1002, 4 clocks") check(trap.get("exc") == "47" and trap.get("frame") == "270000001002" and trap.get("excyc") == "34", "TRAP #15: vector 47, frame SR $2700 and PC $1002, exception cost 34") return 1 if failures else 0 if __name__ == "__main__": raise SystemExit(main())