osbase/bringup: Add panichandler and pstore handling
This expands bringup to use cgroups,
adds our panichandler and
implements a redirect of stdout and stderr.
The last one for intercepting using it with the race detector or
third party code which uses said outputs.
By adding RunWith it is now possible to add metrics collection and
LogTree filtering.
Change-Id: I9795d7b1d7f66cc67003dbaee0aadf134ebdba65
Reviewed-on: https://review.monogon.dev/c/monogon/+/3705
Reviewed-by: Lorenz Brun <lorenz@monogon.tech>
Tested-by: Jenkins CI
Reviewed-by: Jan Schär <jan@monogon.tech>
diff --git a/osbase/bringup/test/BUILD.bazel b/osbase/bringup/test/BUILD.bazel
index a791a66..1e9312a 100644
--- a/osbase/bringup/test/BUILD.bazel
+++ b/osbase/bringup/test/BUILD.bazel
@@ -7,7 +7,8 @@
size = "medium",
srcs = ["run_test.go"],
data = [
- ":kernel_failed",
+ ":kernel_error",
+ ":kernel_panic",
":kernel_succeeded",
"//third_party/edk2:OVMF_CODE.fd",
"//third_party/edk2:OVMF_VARS.fd",
@@ -18,7 +19,8 @@
"xOvmfVarsPath": "$(rlocationpath //third_party/edk2:OVMF_VARS.fd )",
"xOvmfCodePath": "$(rlocationpath //third_party/edk2:OVMF_CODE.fd )",
"xSucceedKernelPath": "$(rlocationpath :kernel_succeeded )",
- "xFailedKernelPath": "$(rlocationpath :kernel_failed )",
+ "xPanicKernelPath": "$(rlocationpath :kernel_panic )",
+ "xErrorKernelPath": "$(rlocationpath :kernel_error )",
},
deps = [
"//osbase/cmd",
@@ -68,8 +70,8 @@
)
go_library(
- name = "failed_lib",
- srcs = ["main_failed.go"],
+ name = "panic_lib",
+ srcs = ["main_panic.go"],
importpath = "source.monogon.dev/osbase/bringup/test",
visibility = ["//visibility:private"],
deps = [
@@ -84,15 +86,15 @@
)
go_binary(
- name = "failed",
- embed = [":failed_lib"],
+ name = "panic",
+ embed = [":panic_lib"],
visibility = ["//visibility:private"],
)
node_initramfs(
- name = "initramfs_failed",
+ name = "initramfs_panic",
files = {
- ":failed": "/init",
+ ":panic": "/init",
},
fsspecs = [
"//osbase/build:earlydev.fsspec",
@@ -101,9 +103,50 @@
)
efi_unified_kernel_image(
- name = "kernel_failed",
+ name = "kernel_panic",
cmdline = "quiet console=ttyS0 init=/init",
- initrd = [":initramfs_failed"],
+ initrd = [":initramfs_panic"],
+ kernel = "//third_party/linux",
+ visibility = ["//visibility:private"],
+)
+
+go_library(
+ name = "error_lib",
+ srcs = ["main_error.go"],
+ importpath = "source.monogon.dev/osbase/bringup/test",
+ visibility = ["//visibility:private"],
+ deps = [
+ "//osbase/bootparam",
+ "//osbase/bringup",
+ "//osbase/efivarfs",
+ "//osbase/logtree",
+ "//osbase/supervisor",
+ "@org_golang_x_sys//unix",
+ "@org_uber_go_multierr//:multierr",
+ ],
+)
+
+go_binary(
+ name = "error",
+ embed = [":error_lib"],
+ visibility = ["//visibility:private"],
+)
+
+node_initramfs(
+ name = "initramfs_error",
+ files = {
+ ":error": "/init",
+ },
+ fsspecs = [
+ "//osbase/build:earlydev.fsspec",
+ ],
+ visibility = ["//visibility:private"],
+)
+
+efi_unified_kernel_image(
+ name = "kernel_error",
+ cmdline = "quiet console=ttyS0 init=/init",
+ initrd = [":initramfs_error"],
kernel = "//third_party/linux",
visibility = ["//visibility:private"],
)
diff --git a/osbase/bringup/test/main_error.go b/osbase/bringup/test/main_error.go
new file mode 100644
index 0000000..f632c1b
--- /dev/null
+++ b/osbase/bringup/test/main_error.go
@@ -0,0 +1,14 @@
+package main
+
+import (
+ "context"
+ "fmt"
+
+ "source.monogon.dev/osbase/bringup"
+)
+
+func main() {
+ bringup.Runnable(func(ctx context.Context) error {
+ return fmt.Errorf("this is an error")
+ }).Run()
+}
diff --git a/osbase/bringup/test/main_failed.go b/osbase/bringup/test/main_panic.go
similarity index 100%
rename from osbase/bringup/test/main_failed.go
rename to osbase/bringup/test/main_panic.go
diff --git a/osbase/bringup/test/run_test.go b/osbase/bringup/test/run_test.go
index 87d3309..b560c8c 100644
--- a/osbase/bringup/test/run_test.go
+++ b/osbase/bringup/test/run_test.go
@@ -17,14 +17,15 @@
xOvmfCodePath string
xOvmfVarsPath string
xSucceedKernelPath string
- xFailedKernelPath string
+ xPanicKernelPath string
+ xErrorKernelPath string
)
func init() {
var err error
for _, path := range []*string{
&xOvmfCodePath, &xOvmfVarsPath,
- &xSucceedKernelPath, &xFailedKernelPath,
+ &xSucceedKernelPath, &xPanicKernelPath, &xErrorKernelPath,
} {
*path, err = runfiles.Rlocation(*path)
if err != nil {
@@ -71,11 +72,11 @@
t.Errorf("QEMU didn't produce the expected output %q", expectedOutput)
}
}
-func TestBringupFailed(t *testing.T) {
+func TestBringupPanic(t *testing.T) {
ctx, ctxC := context.WithTimeout(context.Background(), time.Second*30)
defer ctxC()
- extraArgs := append([]string(nil), "-kernel", xFailedKernelPath)
+ extraArgs := append([]string(nil), "-kernel", xPanicKernelPath)
// Run QEMU. Expect the installer to fail with a predefined error string.
expectedOutput := "root runnable paniced"
@@ -87,3 +88,20 @@
t.Errorf("QEMU didn't produce the expected output %q", expectedOutput)
}
}
+
+func TestBringupError(t *testing.T) {
+ ctx, ctxC := context.WithTimeout(context.Background(), time.Second*30)
+ defer ctxC()
+
+ extraArgs := append([]string(nil), "-kernel", xErrorKernelPath)
+
+ // Run QEMU. Expect the installer to fail with a predefined error string.
+ expectedOutput := "this is an error"
+ result, err := runQemu(ctx, extraArgs, expectedOutput)
+ if err != nil {
+ t.Error(err.Error())
+ }
+ if !result {
+ t.Errorf("QEMU didn't produce the expected output %q", expectedOutput)
+ }
+}