71 lines
3.1 KiB
Python
71 lines
3.1 KiB
Python
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
"""Build and run the C SDC interface against disposable cards on both guest CPUs."""
|
|
import argparse
|
|
import hashlib
|
|
import os
|
|
from pathlib import Path
|
|
import shutil
|
|
import subprocess
|
|
import tempfile
|
|
|
|
|
|
def contents(card):
|
|
return {p.relative_to(card): hashlib.sha256(p.read_bytes()).digest()
|
|
for p in card.rglob("*") if p.is_file()}
|
|
|
|
|
|
def main():
|
|
parser = argparse.ArgumentParser(description=__doc__)
|
|
for name in ("runtime", "core", "roms"):
|
|
parser.add_argument(name, type=Path)
|
|
args = parser.parse_args()
|
|
runtime, core, roms = [p.resolve(strict=True) for p in (args.runtime, args.core, args.roms)]
|
|
fixture = Path(__file__).resolve().parent
|
|
root = fixture.parents[2]
|
|
env = dict(os.environ, VCC_CMOC_COMPAT="1", PATH=str(runtime / "bin") + os.pathsep + os.environ["PATH"])
|
|
with tempfile.TemporaryDirectory(prefix="vcc-sdc-sdk-") as temp:
|
|
work = Path(temp)
|
|
|
|
def run(*cmd):
|
|
subprocess.run(cmd, cwd=work, env=env, check=True)
|
|
|
|
card = work / "card"
|
|
survey = card / "SURVEY"
|
|
survey.mkdir(parents=True)
|
|
# More than one hardware directory page. An additional pattern matches
|
|
# exactly 16 entries, requiring an empty final block to detect the end.
|
|
group = card / "GROUP"
|
|
group.mkdir()
|
|
(group / "CHILD").mkdir()
|
|
for i in range(17):
|
|
extension = "TXT" if i < 16 else "BIN"
|
|
(group / f"A{i:02}.{extension}").write_bytes(bytes(i + 1))
|
|
(group / "A00.TXT").chmod(0o444)
|
|
(card / "BAD.DSK").write_bytes(b"bad geometry")
|
|
(card / "startup.cfg").write_text("0=BOOT.DSK\n", encoding="ascii")
|
|
blank = root / "docs/manuals/software-storage-and-peripherals/media/BLANK.DSK"
|
|
for image, name, data in ((card / "BOOT.DSK", "BOOTMAP.DAT", b"B"),
|
|
(survey / "EARTH.DSK", "ROVER.DAT", b"E"),
|
|
(survey / "MARS.DSK", "ROVER.DAT", b"M")):
|
|
shutil.copyfile(blank, image)
|
|
(work / name).write_bytes(data)
|
|
run(runtime / "bin/writecocofile", "--binary", image, name)
|
|
# The M: firmware command also mounts disk sets when given a directory.
|
|
# The C API promises a named image even if a directory has a .DSK suffix.
|
|
(card / "BUNDLE.DSK").mkdir()
|
|
shutil.copyfile(blank, card / "BUNDLE.DSK/DISK1.DSK")
|
|
initial = contents(card)
|
|
run("xcrun", "clang++", "-std=c++17", "-O2", "-mmacosx-version-min=14.0",
|
|
"-I", root / "src", fixture / "run.cpp", core, "-o", "run")
|
|
for opt in ("-O0", "-O2"):
|
|
run(runtime / "bin/cmoc", "--coco", opt, "-Werror", "--org=2800", "-o", "SDCTEST.BIN",
|
|
fixture / "qualification.c", "-lsdc", "-lvcccompat", "-ldecbfile")
|
|
run("./run", roms, card / "BOOT.DSK", "SDCTEST.BIN")
|
|
if contents(card) != initial:
|
|
raise AssertionError(f"{opt}: card content changed")
|
|
print(f"PASS {opt}: both guest CPUs, original card and floppy bytes verified", flush=True)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|