vinix-ports / tests / desktop-guest.py
86 lines · 74 sloc · 3.63 KB · cbd2d400e82f75db02a0f223d93c518821a6638d
Raw
1"""Exercise the packaged release PID 1 with the native Vinix first-boot desktop."""
2import argparse
3import hashlib
4import os
5import shutil
6import subprocess
7import tarfile
8from pathlib import Path
9
10
11# Published November 28 release, checked against each architecture's ISO.
12INITRAMFS = {
13 "x86_64": "8be0f76685936c66d40609f62ad7ad5d2b231e6778678618a445e7fe83ce54da",
14 "aarch64": "a32afaa82a33096256280086bacbc39873e36a2e3ecd81c5504960b9034ec4f9",
15}
16PROGRAMS = ("usr/bin/vinix-desktop", "usr/sbin/vinix-session", "usr/sbin/vinix-account",
17 "usr/sbin/vinix-authd", "usr/sbin/vinix-system")
18
19
20def digest(path):
21 with path.open("rb") as stream:
22 return hashlib.file_digest(stream, "sha256").hexdigest()
23
24
25def native_overlay(archive, arch, root):
26 if digest(archive) != INITRAMFS[arch]:
27 raise ValueError("release initramfs checksum mismatch")
28 copies = set()
29 with tarfile.open(archive, "r|gz") as members:
30 for item in members:
31 name = item.name.removeprefix("./")
32 if name not in PROGRAMS:
33 continue
34 if not item.isfile() or not item.mode & 0o111:
35 raise ValueError(f"expected a native executable at {name}")
36 target = root / name
37 with members.extractfile(item) as source, target.open("xb") as output:
38 shutil.copyfileobj(source, output)
39 target.chmod(0o755)
40 copies.add(name)
41 if copies != set(PROGRAMS):
42 raise ValueError(f"missing release programs: {set(PROGRAMS) - copies}")
43 manifest = root / "desktop-programs.sha256"
44 with manifest.open("x") as output:
45 for name in ("sbin/init", *PROGRAMS):
46 output.write(f"{digest(root / name)} /{name}\n")
47
48
49def run(args):
50 work = args.work
51 work.mkdir()
52 client = work / "client"
53 tests = Path(__file__).resolve().parent
54
55 def log(name, argv, **kwargs):
56 with (work / (name + ".log")).open("x") as output:
57 subprocess.run(argv, stdout=output, stderr=subprocess.STDOUT, check=True, **kwargs)
58
59 log("install", ["feed", "install", args.keys, args.repo, args.arch, client, "--fakeroot",
60 "vinix-desktop-init", "vinix-accounts", "vinix-release", "netbase"])
61 log("audit", [args.auditor, args.arch, client])
62 root = work / "root"
63 shutil.copytree(client / "root", root, symlinks=True)
64 native_overlay(args.initramfs, args.arch, root)
65 shutil.copyfile(root / "desktop-programs.sha256", work / "desktop-programs.sha256")
66 log("compile", ["vinix-cc", "-Wall", "-Wextra", "-Werror", "-O2", tests / "userland/framebuffer.c",
67 "-o", root / "framebuffer-check"],
68 env={**os.environ, "VPAC_MAKEPKG_ROOT": str(args.sdk)})
69 helper = root / "usr/libexec/vinix-version-check"
70 helper.parent.mkdir(exist_ok=True)
71 with helper.open("x") as output:
72 output.write("#!/bin/sh\nexec /bin/sh /userland-check.sh\n")
73 helper.chmod(0o755)
74 mode = "--aarch64-fixture" if args.arch == "aarch64" else "--fixture"
75 log("boot", [args.boot, root, args.iso, work / "guest", mode, tests / "userland/desktop.sh"])
76 with (work / "receipts.sha256").open("x") as output:
77 for file in sorted([*work.glob("*.log"), work / "guest/serial.log", work / "desktop-programs.sha256"]):
78 output.write(f"{digest(file)} {file.relative_to(work)}\n")
79
80
81if __name__ == "__main__":
82 parser = argparse.ArgumentParser(description=__doc__)
83 parser.add_argument("arch", choices=INITRAMFS)
84 for name in ("keys", "repo", "auditor", "sdk", "initramfs", "boot", "iso", "work"):
85 parser.add_argument(name, type=lambda path: Path(path).resolve())
86 run(parser.parse_args())
87