m/t/i/testos: introduce stub os for installer tests
TestOS is a tiny "operating system" which is packaged the exact same
way as an actual Metropolis node but only outputs a single flag before
exiting. It's used for decoupling the installer tests from the
Metropolis Node code.
Change-Id: I156ee05a6c54b831696aeadd207f2c20db65a25c
Reviewed-on: https://review.monogon.dev/c/monogon/+/432
Reviewed-by: Mateusz Zalega <mateusz@monogon.tech>
diff --git a/metropolis/test/installer/testos/BUILD b/metropolis/test/installer/testos/BUILD
new file mode 100644
index 0000000..c6ced2b
--- /dev/null
+++ b/metropolis/test/installer/testos/BUILD
@@ -0,0 +1,43 @@
+load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library")
+load("//metropolis/node/build:def.bzl", "erofs_image")
+load("//metropolis/node/build:efi.bzl", "efi_unified_kernel_image")
+load("@rules_pkg//:pkg.bzl", "pkg_zip")
+
+erofs_image(
+ name = "rootfs",
+ files = {
+ ":testos": "/init",
+ },
+)
+
+efi_unified_kernel_image(
+ name = "kernel_efi",
+ cmdline = "console=ttyS0 root=PARTLABEL=METROPOLIS-SYSTEM rootfstype=erofs init=/init",
+ kernel = "//third_party/linux",
+)
+
+# An intermediary "bundle" format until we finalize the actual bundle format. This is NOT stable until migrated
+# to the actual bundle format.
+# TODO(lorenz): Replace this
+pkg_zip(
+ name = "testos_bundle",
+ srcs = [
+ ":kernel_efi",
+ ":rootfs",
+ ],
+ visibility = ["//metropolis/test/installer:__subpackages__"],
+)
+
+go_library(
+ name = "go_default_library",
+ srcs = ["main.go"],
+ importpath = "source.monogon.dev/metropolis/test/installer/testos",
+ visibility = ["//visibility:private"],
+ deps = ["@org_golang_x_sys//unix:go_default_library"],
+)
+
+go_binary(
+ name = "testos",
+ embed = [":go_default_library"],
+ visibility = ["//visibility:public"],
+)
diff --git a/metropolis/test/installer/testos/main.go b/metropolis/test/installer/testos/main.go
new file mode 100644
index 0000000..f0a6e80
--- /dev/null
+++ b/metropolis/test/installer/testos/main.go
@@ -0,0 +1,15 @@
+// TestOS is a tiny "operating system" which is packaged the exact same way as
+// an actual Metropolis node but only outputs a single flag before exiting.
+// It's used for decoupling the installer tests from the Metropolis Node code.
+package main
+
+import (
+ "fmt"
+
+ "golang.org/x/sys/unix"
+)
+
+func main() {
+ fmt.Println("TestOS launched successfully! _TESTOS_LAUNCH_SUCCESS_")
+ unix.Reboot(unix.LINUX_REBOOT_CMD_POWER_OFF)
+}