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/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)
+	}
+}