vinix-ports / tests / desktop-guest.py
90 lines · 78 sloc · 3.78 KB · b41bb3151b4f73b05fc31159672968d19efd81b5
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 watchdog = "usr/libexec/vinix-desktop-watchdog"
44 checksummed = ["sbin/init", *PROGRAMS]
45 if (root / watchdog).is_file():
46 checksummed.append(watchdog)
47 manifest = root / "desktop-programs.sha256"
48 with manifest.open("x") as output:
49 for name in checksummed:
50 output.write(f"{digest(root / name)} /{name}\n")
51
52
53def run(args):
54 work = args.work
55 work.mkdir()
56 client = work / "client"
57 tests = Path(__file__).resolve().parent
58
59 def log(name, argv, **kwargs):
60 with (work / (name + ".log")).open("x") as output:
61 subprocess.run(argv, stdout=output, stderr=subprocess.STDOUT, check=True, **kwargs)
62
63 log("install", ["feed", "install", args.keys, args.repo, args.arch, client, "--fakeroot",
64 "vinix-desktop-init", "vinix-accounts", "vinix-release", "netbase"])
65 log("audit", [args.auditor, args.arch, client])
66 root = work / "root"
67 shutil.copytree(client / "root", root, symlinks=True)
68 native_overlay(args.initramfs, args.arch, root)
69 shutil.copyfile(root / "desktop-programs.sha256", work / "desktop-programs.sha256")
70 log("compile", ["vinix-cc", "-Wall", "-Wextra", "-Werror", "-O2", tests / "userland/framebuffer.c",
71 "-o", root / "framebuffer-check"],
72 env={**os.environ, "VPAC_MAKEPKG_ROOT": str(args.sdk)})
73 helper = root / "usr/libexec/vinix-version-check"
74 helper.parent.mkdir(exist_ok=True)
75 with helper.open("x") as output:
76 output.write("#!/bin/sh\nexec /bin/sh /userland-check.sh\n")
77 helper.chmod(0o755)
78 mode = "--aarch64-fixture" if args.arch == "aarch64" else "--fixture"
79 log("boot", [args.boot, root, args.iso, work / "guest", mode, tests / "userland/desktop.sh"])
80 with (work / "receipts.sha256").open("x") as output:
81 for file in sorted([*work.glob("*.log"), work / "guest/serial.log", work / "desktop-programs.sha256"]):
82 output.write(f"{digest(file)} {file.relative_to(work)}\n")
83
84
85if __name__ == "__main__":
86 parser = argparse.ArgumentParser(description=__doc__)
87 parser.add_argument("arch", choices=INITRAMFS)
88 for name in ("keys", "repo", "auditor", "sdk", "initramfs", "boot", "iso", "work"):
89 parser.add_argument(name, type=lambda path: Path(path).resolve())
90 run(parser.parse_args())
91