OXYGENHUB
# 9120e87480a6 enhanced-x16-emulator / tests / fetch_klaus.py
2.1 KiB · Python · last changed chore(): initial commit 25 days ago source blame history raw
1
#!/usr/bin/env python3
2
"""Fetch Klaus Dormann's 6502/65C02 functional test binaries.
3
4
They are not committed: they are GPL-licensed and 64K each, and this repository
5
is BSD. tests/test_klaus.c reports them skipped when they are absent, so this is
6
optional for a local build and a single step in CI.
7
8
    python tests/fetch_klaus.py
9
10
The listings that come with them (bin_files/*.lst) map an address to the check
11
that stopped there, which is how you read a failure. They are large, so they are
12
not fetched here; look them up in the upstream repository when you need one.
13
"""
14
15
import sys
16
import urllib.request
17
from pathlib import Path
18
19
DEST = Path(__file__).resolve().parent / "klaus"
20
BASE = ("https://raw.githubusercontent.com/Klaus2m5/"
21
        "6502_65C02_functional_tests/master/bin_files")
22
23
BINARIES = (
24
    "6502_functional_test.bin",
25
    "65C02_extended_opcodes_test.bin",
26
)
27
28
# The listings map an address back to the check that stopped there, which is
29
# what turns "trapped at $0ECE" into a line of source. Large, but the difference
30
# between a usable failure and a scavenger hunt.
31
LISTINGS = (
32
    "6502_functional_test.lst",
33
    "65C02_extended_opcodes_test.lst",
34
)
35
36
EXPECTED_SIZE = 65536
37
38
39
def get(name, path, expect_size=None):
40
    if path.exists() and (expect_size is None or path.stat().st_size == expect_size):
41
        print(f"  have {name}")
42
        return True
43
    print(f"  get  {name}")
44
    try:
45
        with urllib.request.urlopen(f"{BASE}/{name}", timeout=180) as r:
46
            data = r.read()
47
    except Exception as exc:
48
        print(f"  FAIL {name}: {exc}")
49
        return False
50
    if expect_size is not None and len(data) != expect_size:
51
        print(f"  FAIL {name}: got {len(data)} bytes, expected {expect_size}")
52
        return False
53
    path.write_bytes(data)
54
    return True
55
56
57
def main():
58
    DEST.mkdir(parents=True, exist_ok=True)
59
    ok = True
60
61
    for name in BINARIES:
62
        ok &= get(name, DEST / name, EXPECTED_SIZE)
63
    for name in LISTINGS:
64
        ok &= get(name, DEST / name)
65
66
    print(f"\ntest images in {DEST}")
67
    return 0 if ok else 1
68
69
70
if __name__ == "__main__":
71
    sys.exit(main())