feat(testing): pin public ARM fixture and document compatibility baseline
Add a standard-library Python adapter and SHA-256/size lock for jsmolka/gba-tests ARM at a7113b67e63f83a9b321696ddd7042ccfad6c881. Retain sources and license locally, refuse tracked output paths or overwrites, verify offline inputs, and generate the source-verified eval/r12 suite checkpoint without patching the ROM. Add Python to the pinned Nix shell, offline adapter regressions, and public-test provenance/results documentation. Verified on Darwin arm64: Rust debug/release workspace tests, adapter tests, Clippy, rustdoc, native ROM and all demo window checks. The public test remains a failing baseline at instruction 0xe5b00004, PC 0x0800132c, in test 360.
This commit is contained in:
parent
75fb98bc55
commit
a28b830b38
13 changed files with 460 additions and 8 deletions
91
tools/gba-tests-arm.lock.json
Normal file
91
tools/gba-tests-arm.lock.json
Normal file
|
|
@ -0,0 +1,91 @@
|
|||
{
|
||||
"repository": "jsmolka/gba-tests",
|
||||
"revision": "a7113b67e63f83a9b321696ddd7042ccfad6c881",
|
||||
"license": "MIT",
|
||||
"rom": "arm/arm.gba",
|
||||
"completion_pc": "0x08001d4c",
|
||||
"result_register": 12,
|
||||
"files": {
|
||||
"LICENSE": {
|
||||
"sha256": "b59a9ed235d76752c977f04116bc72155a14af48176bdbf50d7e5c29fca35aa7",
|
||||
"bytes": 1070
|
||||
},
|
||||
"README.md": {
|
||||
"sha256": "488f50d9d9031c88cea4161fad69f6460209dd54d965645fa45cf5e972cc9062",
|
||||
"bytes": 434
|
||||
},
|
||||
"arm/arm.asm": {
|
||||
"sha256": "eb708021f0bc77e022516e5770862c267a54513b45a4b0c81eae921b4a582283",
|
||||
"bytes": 1070
|
||||
},
|
||||
"arm/arm.gba": {
|
||||
"sha256": "77ee88662552bdc885c1080c0172ff119d54db791bd73b21808cf1ff1fe5b40e",
|
||||
"bytes": 8824
|
||||
},
|
||||
"arm/block_transfer.asm": {
|
||||
"sha256": "0e6483405a80b6d36b6ac6bbe0543fe42822cc42bc288b96f64b45aae1676ccf",
|
||||
"bytes": 9888
|
||||
},
|
||||
"arm/branches.asm": {
|
||||
"sha256": "92ac6cd8ff9532c2cb0e5ccff183558e0ae5bc63eee6e2e0ad86af3ec0138786",
|
||||
"bytes": 910
|
||||
},
|
||||
"arm/conditions.asm": {
|
||||
"sha256": "3f4c5835bca66647d45b2f7573bab80b64fb132334c67f97a11e892efefd1a62",
|
||||
"bytes": 1992
|
||||
},
|
||||
"arm/data_processing.asm": {
|
||||
"sha256": "19fa7c26807bf83dababe46c76b120bc0f20adbb6c7fbf60fd900c6391698a0d",
|
||||
"bytes": 8712
|
||||
},
|
||||
"arm/data_swap.asm": {
|
||||
"sha256": "f7280d42f8a8533143b90ca1ffd5aa5cc689cc2dadd60010278e602ecf1ecb8e",
|
||||
"bytes": 1474
|
||||
},
|
||||
"arm/flags.asm": {
|
||||
"sha256": "99721b1054668061c1287ff93479829bdd2ebffb706f6aed9200270457434f46",
|
||||
"bytes": 2639
|
||||
},
|
||||
"arm/halfword_transfer.asm": {
|
||||
"sha256": "79a6e93c07c68ad1c8d23c72f08e6ddca7aac805a496770169fc859a34e8177f",
|
||||
"bytes": 4293
|
||||
},
|
||||
"arm/multiply.asm": {
|
||||
"sha256": "8d751321327ba6104e94c1804f8976dbe126b14025d72a5b2f58a08facf2694a",
|
||||
"bytes": 4803
|
||||
},
|
||||
"arm/psr_transfer.asm": {
|
||||
"sha256": "d60520c2c3b104a009881bdc597b255af460a667b6fccf801a24aab5986b453c",
|
||||
"bytes": 1431
|
||||
},
|
||||
"arm/shifts.asm": {
|
||||
"sha256": "ebfb709bbb4e21273f067f510b8cb536a5df67701599fecbca10960ffcb2b8f0",
|
||||
"bytes": 4473
|
||||
},
|
||||
"arm/single_transfer.asm": {
|
||||
"sha256": "b2ce52f89735c5571a41d0561f44fb908e927357a6e6228acc24119e21fc2a90",
|
||||
"bytes": 3863
|
||||
},
|
||||
"lib/constants.inc": {
|
||||
"sha256": "b4dd3f4760ac1ae7e99cdc7e255f8220eed666e1ab821b150561db58e5d3b7ea",
|
||||
"bytes": 900
|
||||
},
|
||||
"lib/macros.inc": {
|
||||
"sha256": "25b0ff553c4ca99d76ec82c8c9db874e25d6eed58e2e69fa27f1a0fe7a8c46d4",
|
||||
"bytes": 2864
|
||||
},
|
||||
"lib/header.asm": {
|
||||
"sha256": "e9d1e8c7b6382eeb1b7059423ec365e32911f702eadfa51804a2119438a87357",
|
||||
"bytes": 1720
|
||||
},
|
||||
"lib/text.asm": {
|
||||
"sha256": "77e579d6cf0db182fd24e8d420c8c0a81592d78197e8fb06accc8bcfb43db17e",
|
||||
"bytes": 2288
|
||||
},
|
||||
"lib/glyphs.asm": {
|
||||
"sha256": "538beb37f40b1fd56beed9253e0e9eab25444c748adba7440a2093f49e3cbcc9",
|
||||
"bytes": 2545
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
112
tools/prepare_gba_tests.py
Normal file
112
tools/prepare_gba_tests.py
Normal file
|
|
@ -0,0 +1,112 @@
|
|||
#!/usr/bin/env python3
|
||||
"""Prepare a hash-verified, pinned public ARM test outside tracked source paths.
|
||||
|
||||
This adapter is original. Upstream sources, license, and ROM bytes are downloaded
|
||||
only to the requested local directory. They are not embedded in this repository.
|
||||
"""
|
||||
|
||||
import argparse
|
||||
import hashlib
|
||||
import json
|
||||
from pathlib import Path
|
||||
import struct
|
||||
import sys
|
||||
from urllib.request import Request, urlopen
|
||||
|
||||
ROOT = Path(__file__).resolve().parent.parent
|
||||
LOCK = Path(__file__).with_name("gba-tests-arm.lock.json")
|
||||
MAX_FILE_BYTES = 1024 * 1024
|
||||
|
||||
|
||||
def fetch(url):
|
||||
request = Request(url, headers={"User-Agent": "gameboy-rust-public-test-adapter"})
|
||||
with urlopen(request, timeout=30) as response:
|
||||
return response.read(MAX_FILE_BYTES + 1)
|
||||
|
||||
|
||||
def verify(name, data, expected):
|
||||
if len(data) > MAX_FILE_BYTES or len(data) != expected["bytes"]:
|
||||
raise ValueError(f"size mismatch for {name}")
|
||||
if hashlib.sha256(data).hexdigest() != expected["sha256"]:
|
||||
raise ValueError(f"SHA-256 mismatch for {name}")
|
||||
|
||||
|
||||
def destination(path):
|
||||
path = Path(path).resolve()
|
||||
# Public ROM headers can contain third-party assets. Keep them untracked.
|
||||
if path.is_relative_to(ROOT) and not path.is_relative_to(ROOT / "roms"):
|
||||
raise ValueError("output must be outside the repository or inside ignored roms/")
|
||||
if path.exists():
|
||||
raise ValueError(f"output directory already exists: {path}")
|
||||
if not path.parent.is_dir():
|
||||
raise ValueError("output parent directory must already exist")
|
||||
return path
|
||||
|
||||
|
||||
def prepare(output, source=None, download=fetch):
|
||||
output = destination(output)
|
||||
lock = json.loads(LOCK.read_text(encoding="utf-8"))
|
||||
base = f"https://raw.githubusercontent.com/{lock['repository']}/{lock['revision']}/"
|
||||
files = {}
|
||||
for name, expected in lock["files"].items():
|
||||
if source is None:
|
||||
data = download(base + name)
|
||||
else:
|
||||
path = Path(source) / name
|
||||
if not path.is_file() or path.stat().st_size > MAX_FILE_BYTES:
|
||||
raise ValueError(f"source must be a bounded regular file: {name}")
|
||||
with path.open("rb") as stream:
|
||||
data = stream.read(MAX_FILE_BYTES + 1)
|
||||
verify(name, data, expected)
|
||||
files[name] = data
|
||||
|
||||
# The source-defined eval label starts with m_vsync's register save. All
|
||||
# failure exits branch here with r12 set; successful fallthrough keeps r12=0.
|
||||
# Hash pinning is authoritative; this check also catches adapter-offset mistakes.
|
||||
pc = int(lock["completion_pc"], 16)
|
||||
offset = pc - 0x08000000
|
||||
rom = files[lock["rom"]]
|
||||
if offset < 0 or offset + 4 > len(rom) or struct.unpack_from("<I", rom, offset)[0] != 0xE92D0003:
|
||||
raise ValueError("pinned evaluation checkpoint does not match the ROM")
|
||||
manifest = {
|
||||
"version": 1,
|
||||
"cases": [{
|
||||
"name": "jsmolka-arm",
|
||||
"rom": lock["rom"],
|
||||
"step_limit": 1_000_000,
|
||||
"completion": {"pc": lock["completion_pc"], "instruction_set": "arm"},
|
||||
"checks": [{"kind": "register", "index": lock["result_register"], "equals": 0}],
|
||||
}],
|
||||
}
|
||||
# Validate every file before creating output. Existing destinations are never
|
||||
# reused, and file creation is exclusive. Disk errors can leave partial output.
|
||||
output.mkdir()
|
||||
for name, data in files.items():
|
||||
target = output / name
|
||||
target.parent.mkdir(parents=True, exist_ok=True)
|
||||
with target.open("xb") as stream:
|
||||
stream.write(data)
|
||||
for name, value in [("suite.json", manifest), ("source-lock.json", lock)]:
|
||||
with (output / name).open("x", encoding="utf-8") as stream:
|
||||
json.dump(value, stream, indent=2)
|
||||
stream.write("\n")
|
||||
return output / "suite.json"
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument("output", type=Path, help="new directory outside the repository or under roms/")
|
||||
parser.add_argument("--source-dir", type=Path, help="offline upstream tree; every selected file must match the lock")
|
||||
args = parser.parse_args()
|
||||
try:
|
||||
manifest = prepare(args.output, args.source_dir)
|
||||
except (OSError, ValueError) as error:
|
||||
print(f"cannot prepare public ARM test: {error}", file=sys.stderr)
|
||||
return 1
|
||||
print(f"Prepared pinned public ARM suite: {manifest}")
|
||||
print("Run with gameboy-rust --test-suite PATH. Preparation does not mean the CPU tests passed.")
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
128
tools/test_prepare_gba_tests.py
Normal file
128
tools/test_prepare_gba_tests.py
Normal file
|
|
@ -0,0 +1,128 @@
|
|||
"""Adapter regressions with original synthetic bytes; no network or public ROMs."""
|
||||
import hashlib
|
||||
import json
|
||||
from pathlib import Path
|
||||
import struct
|
||||
import tempfile
|
||||
import unittest
|
||||
from unittest import mock
|
||||
|
||||
import prepare_gba_tests as adapter
|
||||
|
||||
|
||||
class PreparationTests(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.temp = tempfile.TemporaryDirectory()
|
||||
self.addCleanup(self.temp.cleanup)
|
||||
self.root = Path(self.temp.name).resolve()
|
||||
self.output = self.root / "prepared"
|
||||
self.files = {
|
||||
"arm/arm.gba": struct.pack("<II", 0xEAFFFFFE, 0xE92D0003),
|
||||
"LICENSE": b"Original fixture, not upstream license content.\n",
|
||||
"arm/arm.asm": b"Original fixture source marker.\n",
|
||||
}
|
||||
self.lock = {
|
||||
"repository": "original/test-fixture",
|
||||
"revision": "0" * 40,
|
||||
"license": "fixture",
|
||||
"rom": "arm/arm.gba",
|
||||
"completion_pc": "0x08000004",
|
||||
"result_register": 12,
|
||||
"files": {name: {"bytes": len(data), "sha256": hashlib.sha256(data).hexdigest()}
|
||||
for name, data in self.files.items()},
|
||||
}
|
||||
self.lock_path = self.root / "lock.json"
|
||||
self.save_lock()
|
||||
patch = mock.patch.object(adapter, "LOCK", self.lock_path)
|
||||
patch.start()
|
||||
self.addCleanup(patch.stop)
|
||||
|
||||
def save_lock(self):
|
||||
self.lock_path.write_text(json.dumps(self.lock), encoding="utf-8")
|
||||
|
||||
def download(self, url):
|
||||
prefix = "https://raw.githubusercontent.com/original/test-fixture/" + "0" * 40 + "/"
|
||||
self.assertTrue(url.startswith(prefix))
|
||||
return self.files[url[len(prefix):]]
|
||||
|
||||
def prepare(self):
|
||||
return adapter.prepare(self.output, download=self.download)
|
||||
|
||||
def test_verified_bytes_license_and_provenance_are_retained(self):
|
||||
manifest_path = self.prepare()
|
||||
for name, expected in self.files.items():
|
||||
self.assertEqual((self.output / name).read_bytes(), expected)
|
||||
self.assertEqual(json.loads((self.output / "source-lock.json").read_text()), self.lock)
|
||||
manifest = json.loads(manifest_path.read_text())
|
||||
case = manifest["cases"][0]
|
||||
self.assertEqual(case["completion"], {"pc": "0x08000004", "instruction_set": "arm"})
|
||||
self.assertEqual(case["checks"], [{"kind": "register", "index": 12, "equals": 0}])
|
||||
self.assertEqual(case["rom"], "arm/arm.gba")
|
||||
self.assertEqual(case["step_limit"], 1_000_000)
|
||||
|
||||
def test_existing_directory_is_rejected_before_fetching(self):
|
||||
self.output.mkdir()
|
||||
sentinel = self.output / "keep"
|
||||
sentinel.write_text("unchanged")
|
||||
with self.assertRaisesRegex(ValueError, "already exists"):
|
||||
adapter.prepare(self.output, download=lambda _: self.fail("unexpected download"))
|
||||
self.assertEqual(sentinel.read_text(), "unchanged")
|
||||
|
||||
def test_failed_hash_or_size_leaves_no_output(self):
|
||||
for replacement in [b"short", b"x" * len(self.files["arm/arm.gba"])]:
|
||||
with self.subTest(replacement=replacement):
|
||||
self.files["arm/arm.gba"] = replacement
|
||||
with self.assertRaisesRegex(ValueError, "mismatch"):
|
||||
self.prepare()
|
||||
self.assertFalse(self.output.exists())
|
||||
|
||||
def test_bad_checkpoint_is_rejected_even_with_matching_hash(self):
|
||||
self.lock["completion_pc"] = "0x08000000"
|
||||
self.save_lock()
|
||||
with self.assertRaisesRegex(ValueError, "checkpoint"):
|
||||
self.prepare()
|
||||
self.assertFalse(self.output.exists())
|
||||
|
||||
def test_offline_tree_gets_the_same_checks_and_no_network(self):
|
||||
source = self.root / "source"
|
||||
for name, data in self.files.items():
|
||||
target = source / name
|
||||
target.parent.mkdir(parents=True, exist_ok=True)
|
||||
target.write_bytes(data)
|
||||
adapter.prepare(self.output, source, download=lambda _: self.fail("unexpected network"))
|
||||
self.assertEqual((self.output / "arm/arm.gba").read_bytes(), self.files["arm/arm.gba"])
|
||||
(source / "LICENSE").write_bytes(b"modified")
|
||||
with self.assertRaisesRegex(ValueError, "mismatch"):
|
||||
adapter.prepare(self.root / "second", source)
|
||||
self.assertFalse((self.root / "second").exists())
|
||||
|
||||
def test_download_failure_does_not_publish_partial_fixture(self):
|
||||
calls = 0
|
||||
def download(url):
|
||||
nonlocal calls
|
||||
calls += 1
|
||||
if calls == 2:
|
||||
raise OSError("network unavailable")
|
||||
return self.download(url)
|
||||
with self.assertRaisesRegex(OSError, "network unavailable"):
|
||||
adapter.prepare(self.output, download=download)
|
||||
self.assertFalse(self.output.exists())
|
||||
|
||||
def test_tracked_repository_paths_are_rejected(self):
|
||||
fake_repo = self.root / "repo"
|
||||
fake_repo.mkdir()
|
||||
(fake_repo / "roms").mkdir()
|
||||
with mock.patch.object(adapter, "ROOT", fake_repo):
|
||||
with self.assertRaisesRegex(ValueError, "outside the repository"):
|
||||
adapter.destination(fake_repo / "assets")
|
||||
self.assertEqual(adapter.destination(fake_repo / "roms" / "local"), fake_repo / "roms" / "local")
|
||||
|
||||
def test_file_capacity_is_independent_of_declared_size(self):
|
||||
data = b"x" * (adapter.MAX_FILE_BYTES + 1)
|
||||
expected = {"bytes": len(data), "sha256": hashlib.sha256(data).hexdigest()}
|
||||
with self.assertRaisesRegex(ValueError, "size mismatch"):
|
||||
adapter.verify("fixture", data, expected)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Loading…
Add table
Add a link
Reference in a new issue