#!/usr/bin/env python3
# SPDX-License-Identifier: GPL-3.0-or-later
"""Build and run the real-core observation probe; no ROMs, audio device, or network."""
import argparse
import datetime
import hashlib
import json
from pathlib import Path
import platform
import subprocess
import tempfile
HERE = Path(__file__).resolve().parent
SOURCE_FILES = [
"src/core/MachineSession.h", "src/core/MachineSession.cpp", "src/core/MachineDefs.h",
"src/core/tcc1014mmu.h", "src/core/tcc1014mmu.cpp", "src/core/tcc1014graphics.cpp",
"src/core/mc6809.cpp", "src/core/hd6309.cpp", "src/core/FrameRunner.cpp",
]
def digest(path):
return hashlib.sha256(path.read_bytes()).hexdigest()
def checked(arguments):
return subprocess.run(arguments, check=True, text=True, capture_output=True).stdout.strip()
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--source", type=Path, required=True)
parser.add_argument("--library", type=Path, required=True)
parser.add_argument("--output", type=Path)
parser.add_argument("--architectures", nargs="+", choices=["arm64", "x86_64"], default=["arm64", "x86_64"])
args = parser.parse_args()
if args.output and args.output.exists(): parser.error("Choose a new result JSON path")
source, library = args.source.resolve(), args.library.resolve()
compiler = checked(["xcrun", "--find", "clang++"])
source_hashes = {name: digest(source / name) for name in SOURCE_FILES}
receipt = {
"schema_version": 1,
"experiment": "observer_invariants_real_core",
"observed_utc": datetime.datetime.now(datetime.timezone.utc).isoformat(),
"source_repository_url": "https://vccplus-git.brianholman.com/VCCPlus/VCCPlusOSS/src/branch/main/",
"source_files_sha256": source_hashes,
"probe_sha256": digest(HERE / "probe.cpp"),
"runner_sha256": digest(Path(__file__)),
"library_sha256": digest(library),
"library_architectures": checked(["xcrun", "lipo", "-archs", str(library)]).split(),
"compiler": checked([compiler, "--version"]).splitlines()[0],
"host": {"system": platform.system(), "release": platform.release(), "machine": platform.machine()},
"dependencies": "Python standard library, Apple C++ toolchain, prebuilt real VCCCore static library",
"privacy": "No private ROMs/media/settings, network, normal application, audio output or desktop access",
"runs": [],
}
all_passed = True
with tempfile.TemporaryDirectory(prefix="vccplus-observer-probe-") as build:
for arch in args.architectures:
binary = Path(build) / ("probe-" + arch)
flags = ["-std=c++17", "-O2", "-Wall", "-Wextra", "-Werror", "-mmacosx-version-min=14.0", "-arch", arch]
command = [compiler, *flags, "-I", str(source / "src/core"), str(HERE / "probe.cpp"), str(library), "-o", str(binary)]
built = subprocess.run(command, text=True, capture_output=True)
run = {"architecture": arch, "execution": "native" if platform.machine() == arch else "Rosetta_translation",
"compiler_flags": flags, "build_exit_code": built.returncode}
if built.returncode:
run["build_error"] = built.stderr.replace(str(source), "<source>").replace(str(library), "<library>").replace(build, "<temporary-build>").replace(str(HERE), "<experiment>")
all_passed = False
else:
run["executable_sha256"] = digest(binary)
executed = subprocess.run(["/usr/bin/arch", "-" + arch, str(binary)], text=True, capture_output=True)
run["exit_code"] = executed.returncode
try: run["result"] = json.loads(executed.stdout)
except json.JSONDecodeError:
run["result"] = {"passed": False, "error": "probe did not emit JSON"}
run["stdout"] = executed.stdout
if executed.stderr: run["stderr"] = executed.stderr.replace(str(source), "<source>").replace(build, "<temporary-build>")
all_passed = all_passed and executed.returncode == 0 and run["result"].get("passed") is True
receipt["runs"].append(run)
unchanged = {name: digest(source / name) == expected for name, expected in source_hashes.items()}
receipt["source_inputs_unchanged_during_measurement"] = unchanged
receipt["passed"] = all_passed and all(unchanged.values())
encoded = json.dumps(receipt, indent=2) + "\n"
if args.output:
args.output.parent.mkdir(parents=True, exist_ok=True)
args.output.write_text(encoded)
print(encoded, end="")
return 0 if all_passed else 1
if __name__ == "__main__":
raise SystemExit(main())
Evidence record
experiments/observer-invariants/run.py
From Windows Application to Portable Emulation Platform
4,770 bytes
SHA-25614fbcdf41ee6cdcf99d772317b114f92f3784ef82c828e976687dcfd79fe9968