From 05f3bdd35b64d63f7293b9cc4a51efff7ef9d05e Mon Sep 17 00:00:00 2001 From: Adam Piasecki Date: Mon, 16 Sep 2024 16:37:28 +0100 Subject: [PATCH] test --- mantle/cmd/kola/testiso.go | 51 ++++++++++++++++++++++++++++++++++++- mantle/kola/harness.go | 52 ++++++++++++-------------------------- 2 files changed, 66 insertions(+), 37 deletions(-) diff --git a/mantle/cmd/kola/testiso.go b/mantle/cmd/kola/testiso.go index 48d90a4e7f..402a1a4ac2 100644 --- a/mantle/cmd/kola/testiso.go +++ b/mantle/cmd/kola/testiso.go @@ -679,7 +679,56 @@ func awaitCompletion(ctx context.Context, inst *platform.QemuInstance, outdir st errchan <- err } }() - // check for console badness + + go func() { + + // errBuf, err := inst.CheckConsoleForBadness(ctx) + // if err == nil { + // if errBuf != "" { + // plog.Info("Badness recognized") + // path := filepath.Join(outdir, "test.txt") + // if err := os.WriteFile(path, []byte(errBuf), 0644); err != nil { + // plog.Errorf("Failed to write to consolefile: %v", err) + // } + // err = platform.ErrInitramfsEmergency + // } + // } + // if err != nil { + // errchan <- err + // } + + // }() + // figure out how to get console file from instance + builder := platform.NewMetalQemuBuilderDefault() + if enableUefiSecure { + builder.Firmware = "uefi-secure" + } else if enableUefi { + builder.Firmware = "uefi" + } + + if err := os.MkdirAll(outdir, 0755); err != nil { + fmt.Println(err) + } + + builder.InheritConsole = console + if !console { + builder.ConsoleFile = filepath.Join(outdir, "console.txt") + } + + fmt.Println(builder) + // var inst = *builder.ConsoleFile + // fmt.Println(&inst) + // below something like + // inst.builder.ConsoleFile + + // zz, err := inst.CheckConsoleForBadness(ctx) + // fmt.Println(zz,err) + + //plus that + // ReadFile(path/tofile...) + // path := filepath.Base(outdir) // returns test name / dir + + }() errBuf, err := inst.CheckConsoleForBadness(ctx) if err == nil { if errBuf != "" { diff --git a/mantle/kola/harness.go b/mantle/kola/harness.go index b1b4ae84a4..dea364b808 100644 --- a/mantle/kola/harness.go +++ b/mantle/kola/harness.go @@ -1919,33 +1919,30 @@ func ScpKolet(machines []platform.Machine) error { // CheckConsoleText checks console output for badness -func CheckConsoleText(badlines []string) (bool, []string) { - badness := false - newBadlines := []string{} +// input : the console content +// output true if badlines were found and the bad lines. +func CheckConsoleText(input []byte) (bool, []string) { + warnOnly := true + badlines := []string{} - // Ensure there are enough badlines to check - if len(badlines) < 2 { - return badness, badlines // Return early if not enough lines - } for _, check := range consoleChecks { if check.skipFlag != nil { continue } - match := check.match.FindStringSubmatch(badlines[1]) + match := check.match.FindSubmatch(input) if match != nil { badline := check.desc if len(match) > 1 { // include first subexpression badline += fmt.Sprintf(" (%v)", match[1]) } - newBadlines = append(newBadlines, badline) + badlines = append(badlines, badline) if !check.warnOnly { - badness = false + warnOnly = false } } } - badlines = append(badlines, newBadlines...) - return badness, badlines + return warnOnly, badlines } // CheckConsole checks some console output for badness and returns short @@ -1956,33 +1953,16 @@ func CheckConsoleText(badlines []string) (bool, []string) { // rerun success. func CheckConsole(output []byte, t *register.Test) (bool, []string) { var badlines []string - warnOnly, allowRerunSuccess := true, true - for _, check := range consoleChecks { - if check.skipFlag != nil && t != nil && t.HasFlag(*check.skipFlag) { - continue - } - match := check.match.FindSubmatch(output) - if match != nil { - badline := check.desc - if len(match) > 1 { - // include first subexpression - badline += fmt.Sprintf(" (%s)", match[1]) - } - badlines = append(badlines, badline) - if !check.warnOnly { - warnOnly = false - } - if !check.allowRerunSuccess { - allowRerunSuccess = false - } - is_it_err,checkConsole := CheckConsoleText([]string(badlines)) - fmt.Printf("%v\n,%v", checkConsole, is_it_err) - } - } + var badness bool + allowRerunSuccess := true + + //here pass output to checkconsoleText + badness, badlines = CheckConsoleText(output) + if len(badlines) > 0 && allowRerunSuccess && t != nil { markTestForRerunSuccess(t, "CheckConsole:") } - return warnOnly, badlines + return badness, badlines } func SetupOutputDir(outputDir, platform string) (string, error) {