"""Exercise the packaged release PID 1 with the native Vinix first-boot desktop.""" import argparse import hashlib import os import shutil import subprocess import tarfile from pathlib import Path # Published November 28 release, checked against each architecture's ISO. INITRAMFS = { "x86_64": "8be0f76685936c66d40609f62ad7ad5d2b231e6778678618a445e7fe83ce54da", "aarch64": "a32afaa82a33096256280086bacbc39873e36a2e3ecd81c5504960b9034ec4f9", } PROGRAMS = ("usr/bin/vinix-desktop", "usr/sbin/vinix-session", "usr/sbin/vinix-account", "usr/sbin/vinix-authd", "usr/sbin/vinix-system") def digest(path): with path.open("rb") as stream: return hashlib.file_digest(stream, "sha256").hexdigest() def native_overlay(archive, arch, root): if digest(archive) != INITRAMFS[arch]: raise ValueError("release initramfs checksum mismatch") copies = set() with tarfile.open(archive, "r|gz") as members: for item in members: name = item.name.removeprefix("./") if name not in PROGRAMS: continue if not item.isfile() or not item.mode & 0o111: raise ValueError(f"expected a native executable at {name}") target = root / name with members.extractfile(item) as source, target.open("xb") as output: shutil.copyfileobj(source, output) target.chmod(0o755) copies.add(name) if copies != set(PROGRAMS): raise ValueError(f"missing release programs: {set(PROGRAMS) - copies}") manifest = root / "desktop-programs.sha256" with manifest.open("x") as output: for name in ("sbin/init", *PROGRAMS): output.write(f"{digest(root / name)} /{name}\n") def run(args): work = args.work work.mkdir() client = work / "client" tests = Path(__file__).resolve().parent def log(name, argv, **kwargs): with (work / (name + ".log")).open("x") as output: subprocess.run(argv, stdout=output, stderr=subprocess.STDOUT, check=True, **kwargs) log("install", ["feed", "install", args.keys, args.repo, args.arch, client, "--fakeroot", "vinix-desktop-init", "vinix-accounts", "vinix-release", "netbase"]) log("audit", [args.auditor, args.arch, client]) root = work / "root" shutil.copytree(client / "root", root, symlinks=True) native_overlay(args.initramfs, args.arch, root) shutil.copyfile(root / "desktop-programs.sha256", work / "desktop-programs.sha256") log("compile", ["vinix-cc", "-Wall", "-Wextra", "-Werror", "-O2", tests / "userland/framebuffer.c", "-o", root / "framebuffer-check"], env={**os.environ, "VPAC_MAKEPKG_ROOT": str(args.sdk)}) helper = root / "usr/libexec/vinix-version-check" helper.parent.mkdir(exist_ok=True) with helper.open("x") as output: output.write("#!/bin/sh\nexec /bin/sh /userland-check.sh\n") helper.chmod(0o755) mode = "--aarch64-fixture" if args.arch == "aarch64" else "--fixture" log("boot", [args.boot, root, args.iso, work / "guest", mode, tests / "userland/desktop.sh"]) with (work / "receipts.sha256").open("x") as output: for file in sorted([*work.glob("*.log"), work / "guest/serial.log", work / "desktop-programs.sha256"]): output.write(f"{digest(file)} {file.relative_to(work)}\n") if __name__ == "__main__": parser = argparse.ArgumentParser(description=__doc__) parser.add_argument("arch", choices=INITRAMFS) for name in ("keys", "repo", "auditor", "sdk", "initramfs", "boot", "iso", "work"): parser.add_argument(name, type=lambda path: Path(path).resolve()) run(parser.parse_args())