metropolis/test/launch: convert :launch to a test
"bazel run" simply executes the binary outside the sandbox, so swtpm
and other dependencies from the sandbox sysroot won't be available.
If swtpm is installed on the host, running the _bin target still works,
but it's better to point contributors to something that works
out of the box.
This is a temporary workaround. Tests have timeouts and take the global
Bazel server lock. The correct solution is a static swtpm build
which can run outside the sandbox.
Change-Id: Icf7bf5cc44825df676d37a75ea9c1e135de14fef
Reviewed-on: https://review.monogon.dev/c/monogon/+/1078
Reviewed-by: Lorenz Brun <lorenz@monogon.tech>
Tested-by: Jenkins CI
diff --git a/metropolis/README.md b/metropolis/README.md
index 28fbb45..6c9ad57 100644
--- a/metropolis/README.md
+++ b/metropolis/README.md
@@ -1,11 +1 @@
# Metropolis Operating System
-
-## Launch VM
-
-Launch the VM:
-
-```
-scripts/bin/bazel run //core/scripts:launch
-```
-
-Ctrl-C will kill the VM.
diff --git a/metropolis/test/launch/cli/launch-multi2/BUILD.bazel b/metropolis/test/launch/cli/launch-multi2/BUILD.bazel
index c53b626..e56d131 100644
--- a/metropolis/test/launch/cli/launch-multi2/BUILD.bazel
+++ b/metropolis/test/launch/cli/launch-multi2/BUILD.bazel
@@ -1,4 +1,5 @@
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library")
+load("@bazel_skylib//rules:native_binary.bzl", "native_test")
go_library(
name = "launch-multi2_lib",
@@ -12,7 +13,7 @@
)
go_binary(
- name = "launch-multi2",
+ name = "launch-multi2_bin",
data = [
"//metropolis/node:image",
"//metropolis/node:swtpm_data",
@@ -24,3 +25,11 @@
embed = [":launch-multi2_lib"],
visibility = ["//:__pkg__"],
)
+
+native_test(
+ name = "launch-multi2",
+ src = ":launch-multi2_bin",
+ out = "launch-multi2",
+ tags = ["manual"],
+ visibility = ["//visibility:public"],
+)
diff --git a/metropolis/test/launch/cli/launch/BUILD.bazel b/metropolis/test/launch/cli/launch/BUILD.bazel
index 31d491a..2e58632 100644
--- a/metropolis/test/launch/cli/launch/BUILD.bazel
+++ b/metropolis/test/launch/cli/launch/BUILD.bazel
@@ -1,4 +1,5 @@
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library")
+load("@bazel_skylib//rules:native_binary.bzl", "native_test")
go_library(
name = "launch_lib",
@@ -14,7 +15,7 @@
)
go_binary(
- name = "launch",
+ name = "launch_bin",
data = [
"//metropolis/node:image",
"//metropolis/node:swtpm_data",
@@ -23,3 +24,13 @@
embed = [":launch_lib"],
visibility = ["//:__pkg__"],
)
+
+# Wrap the binary in a native_test so that we can run it with the
+# `bazel test` command inside the sandbox.
+native_test(
+ name = "launch",
+ src = ":launch_bin",
+ out = "launch",
+ tags = ["manual"],
+ visibility = ["//visibility:public"],
+)