#!/usr/bin/env python3 # SPDX-License-Identifier: GPL-3.0-or-later """mgba's smoke test: no ROM or BIOS from anywhere. python3 -I "$EMU_TOOLS_GPL/tools/mgba/tests/smoke.py" Checks build.py's version line and its usage-error exit status (2); then, for each machine that is built, that its build-info.json names the pins; then asks the disassembler for three words of our own (``A e1a00000 0``, ``T 4770 0``, ``A e12fff1e 0``) and checks it answers one line each, naming ``mov``, ``bx`` and ``bx``; and runs the GBA driver with no ROM and checks it refuses. Under a second. The identity runs of 2026-11-25 (CHANGELOG.md) need test ROMs, which the consumers fetch. """ from __future__ import annotations import json import subprocess import sys from pathlib import Path HERE = Path(__file__).resolve().parents[1] sys.path.insert(0, str(HERE)) import build # noqa: E402 failures: list[str] = [] def check(ok: bool, what: str) -> None: print(("ok " if ok else "FAIL ") + what) if not ok: failures.append(what) def main() -> int: script = [sys.executable, "-I", str(HERE / "build.py")] done = subprocess.run([*script, "--version"], capture_output=True, text=True) check(done.returncode == 0 and done.stdout.startswith("mgba-tools 0.1.0 (mGBA fd9dc5c, Lua 5.4.7)"), "--version names the tool and the pins") # fmt: skip done = subprocess.run([*script, "--machine", "gbc"], capture_output=True, text=True) check(done.returncode == 2, "an unknown machine: exit 2") for machine in build.MACHINES: record = build.BUILD / machine / "build-info.json" if not build.program(machine).exists() or not record.exists(): print(f"skip {machine}: not built (build.py --machine {machine})") continue info = json.loads(record.read_text()) check(info["upstream"][0]["commit"] == build.MGBA["commit"] and (machine != "gba" or info["upstream"][1]["sha256"] == build.LUA["sha256"]), f"{machine}: built from the pinned sources") # fmt: skip disasm = build.program("arm-disasm") if disasm.exists(): done = subprocess.run([str(disasm)], input="A e1a00000 0\nT 4770 0\nA e12fff1e 0\n", capture_output=True, text=True, timeout=30, check=False) # fmt: skip lines = done.stdout.splitlines() check(len(lines) == 3 and lines[0].startswith("mov") and lines[1].startswith("bx") and lines[2].startswith("bx"), "arm-disasm: mov r0, r0; bx lr (Thumb); bx lr (ARM)") # fmt: skip driver = build.program("gba") if driver.exists(): done = subprocess.run([str(driver)], capture_output=True, timeout=30, check=False) check(done.returncode != 0, "gba: no ROM is refused") print(f"{len(failures)} failed" if failures else "smoke passed") return 1 if failures else 0 if __name__ == "__main__": raise SystemExit(main())