#!/usr/bin/env python3 """Fetch the only machine-readable TMS34010 test corpus that exists. birdybro/TMS34010_sv, sim/vectors/ -- MIT licensed, 137 graphics cases plus 5 TI-binary workload cases, in a plain-text format. Read docs/validation.md before using any of it. In one sentence: its expected values were produced by *running MAME*, at a pinned MAME commit, so it is an **emulator-derived** oracle -- a detector, never a judge -- and it makes no cycle-count claim at all. The corpus is fetched at a pinned commit of the upstream repository and every file is verified against the git blob SHA-1 recorded below, which was read from the GitHub tree API at that commit. A mismatch aborts. Nothing is committed to this repository: the destination is gitignored. python3 scripts/fetch_test_vectors.py # fetch and verify python3 scripts/fetch_test_vectors.py --check # verify what is present python3 scripts/fetch_test_vectors.py --summary # describe the corpus No dependencies beyond the standard library, matching the core's own rule. """ from __future__ import annotations import argparse import hashlib import json import sys import urllib.error import urllib.request from pathlib import Path REPO = "birdybro/TMS34010_sv" # Pinned upstream revision. Read from the GitHub API on 2026-09-12: # commit 94a258e8, 2026-07-30T12:58:16Z, "Record Task 0174 completion commit" COMMIT = "94a258e80a07ceb4303ce0b99818df832e96007f" # git blob SHA-1 of each file at that commit, from the contents API. # `git hash-object` computes the same value: sha1(b"blob %d\0" % len + data). FILES: dict[str, str] = { "mame_graphics_vectors.txt": "704ca87a8c0c12c3e88af4e15d0c649ae22fe0a2", "mame_graphics_expected.txt": "dc276cd7c8e03f0a38bc9e54bf625bdc5af3befa", "mame_graphics_reference.txt": "8e5da9dcc8dd42b1568f290cf45c2a9d867eaafa", "mame_graphics_manifest.json": "bb910f1a6d9ebe083675405da4ffca86e815746b", "mame_graphics_divergences.json": "5bf685a05303873b998a2babca51e2540b67861f", "ti_workload_mame_expected.txt": "af44347089a465e9064aa94d407c4642346f322f", "ti_workload_rtl_expected.txt": "5a77974e6c22b754da09f0aa05acabd3b8d307be", "ti_workload_manifest.json": "a6b2c8218c9b3402ae1e836ac575f3099b240f06", "ti_workload_divergences.json": "4709fbe1dd25975fc5150d12255c4d97dab57194", } RAW = "https://raw.githubusercontent.com/{repo}/{commit}/sim/vectors/{name}" DEST = Path(__file__).resolve().parent.parent / "tests" / "tms34010_sv_vectors" def blob_sha1(data: bytes) -> str: """The git object name of a blob: sha1 over the object header plus data.""" return hashlib.sha1(b"blob %d\0" % len(data) + data).hexdigest() def fetch(name: str) -> bytes: url = RAW.format(repo=REPO, commit=COMMIT, name=name) req = urllib.request.Request(url, headers={"User-Agent": "tms34010-python/fetch"}) with urllib.request.urlopen(req, timeout=120) as response: return response.read() def verify(name: str, data: bytes) -> None: got = blob_sha1(data) want = FILES[name] if got != want: raise SystemExit( f"{name}: git blob SHA-1 mismatch\n expected {want}\n got {got}\n" "Refusing to use it. Either upstream moved or the download is corrupt." ) def do_fetch() -> int: DEST.mkdir(parents=True, exist_ok=True) fetched = skipped = 0 for name in FILES: path = DEST / name if path.exists() and blob_sha1(path.read_bytes()) == FILES[name]: skipped += 1 continue try: data = fetch(name) except urllib.error.URLError as exc: raise SystemExit(f"{name}: {exc}") from exc verify(name, data) path.write_bytes(data) fetched += 1 print(f" {name} {len(data):,} bytes ok") (DEST / "REVISION").write_text( f"{REPO} @ {COMMIT}\nsim/vectors/, MIT\nfetched by scripts/fetch_test_vectors.py\n" ) print(f"{fetched} fetched, {skipped} already present and verified -> {DEST}") return 0 def do_check() -> int: bad = missing = 0 for name, want in FILES.items(): path = DEST / name if not path.exists(): print(f" MISSING {name}") missing += 1 elif blob_sha1(path.read_bytes()) != want: print(f" CORRUPT {name}") bad += 1 if missing or bad: print(f"{missing} missing, {bad} corrupt. Run without --check to fetch.") return 1 print(f"all {len(FILES)} files present and verified against {COMMIT[:8]}") return 0 def do_summary() -> int: manifest = DEST / "mame_graphics_manifest.json" if not manifest.exists(): raise SystemExit("Nothing fetched yet. Run without --summary first.") man = json.loads(manifest.read_text()) by_instruction: dict[str, int] = {} for case in man["cases"]: by_instruction[case["tags"][0]] = by_instruction.get(case["tags"][0], 0) + 1 print(f"{REPO} @ {COMMIT[:8]} (MIT), emulator-derived -- a DETECTOR, not a judge") print(f" graphics cases: {man['case_count']}, generator {man['generator']}") for name, count in sorted(by_instruction.items(), key=lambda kv: -kv[1]): print(f" {name:<10} {count:>4}") div = json.loads((DEST / "mame_graphics_divergences.json").read_text()) print(f" MAME pinned at {div['mame_commit'][:12]}, " f"unexplained mismatches: {div['unexplained_mismatches']}") for cls in div["classes"]: print(f" - {cls['class']}") tidiv = json.loads((DEST / "ti_workload_divergences.json").read_text()) timan = json.loads((DEST / "ti_workload_manifest.json").read_text()) names = ", ".join(c["name"] for c in timan["cases"]) print(f" TI workload cases: {tidiv['case_count']} ({names})") print(" metadata only -- the manifest says the executables are extracted") print(" from do-not-redistribute media, which this project does not have.") return 0 def main(argv: list[str]) -> int: parser = argparse.ArgumentParser(description=__doc__.splitlines()[0]) parser.add_argument("--check", action="store_true", help="verify what is already on disk, fetch nothing") parser.add_argument("--summary", action="store_true", help="describe the fetched corpus and its divergence list") args = parser.parse_args(argv) if args.check: return do_check() if args.summary: return do_summary() return do_fetch() if __name__ == "__main__": sys.exit(main(sys.argv[1:]))