Skip to content

Commit 40290bd

Browse files
committed
testiso.go: Add check for badness
After tests are complete this checks for badness in the console.txt and journal.txt files. Ref: #3788
1 parent 77118ab commit 40290bd

File tree

1 file changed

+92
-43
lines changed

1 file changed

+92
-43
lines changed

mantle/cmd/kola/testiso.go

Lines changed: 92 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -679,55 +679,104 @@ func awaitCompletion(ctx context.Context, inst *platform.QemuInstance, outdir st
679679
errchan <- err
680680
}
681681
}()
682-
}
683-
go func() {
684-
err := inst.Wait()
685-
// only one Wait() gets process data, so also manually check for signal
686-
plog.Debugf("qemu exited err=%v", err)
687-
if err == nil && inst.Signaled() {
688-
err = errors.New("process killed")
689-
}
690-
if err != nil {
691-
errchan <- errors.Wrapf(err, "QEMU unexpectedly exited while awaiting completion")
692-
}
693-
time.Sleep(1 * time.Minute)
694-
errchan <- fmt.Errorf("QEMU exited; timed out waiting for completion")
695-
}()
696-
go func() {
697-
r := bufio.NewReader(qchan)
698-
for _, exp := range expected {
699-
l, err := r.ReadString('\n')
682+
go func() {
683+
err := inst.Wait()
684+
// only one Wait() gets process data, so also manually check for signal
685+
plog.Debugf("qemu exited err=%v", err)
686+
if err == nil && inst.Signaled() {
687+
err = errors.New("process killed")
688+
}
700689
if err != nil {
701-
if err == io.EOF {
702-
// this may be from QEMU getting killed or exiting; wait a bit
703-
// to give a chance for .Wait() above to feed the channel with a
704-
// better error
705-
time.Sleep(1 * time.Second)
706-
errchan <- fmt.Errorf("Got EOF from completion channel, %s expected", exp)
707-
} else {
708-
errchan <- errors.Wrapf(err, "reading from completion channel")
690+
errchan <- errors.Wrapf(err, "QEMU unexpectedly exited while awaiting completion")
691+
}
692+
time.Sleep(1 * time.Minute)
693+
errchan <- fmt.Errorf("QEMU exited; timed out waiting for completion")
694+
}()
695+
go func() {
696+
r := bufio.NewReader(qchan)
697+
for _, exp := range expected {
698+
l, err := r.ReadString('\n')
699+
if err != nil {
700+
if err == io.EOF {
701+
// this may be from QEMU getting killed or exiting; wait a bit
702+
// to give a chance for .Wait() above to feed the channel with a
703+
// better error
704+
time.Sleep(1 * time.Second)
705+
errchan <- fmt.Errorf("Got EOF from completion channel, %s expected", exp)
706+
} else {
707+
errchan <- errors.Wrapf(err, "reading from completion channel")
708+
}
709+
return
709710
}
710-
return
711+
line := strings.TrimSpace(l)
712+
if line != exp {
713+
errchan <- fmt.Errorf("Unexpected string from completion channel: %s expected: %s", line, exp)
714+
return
715+
}
716+
plog.Debugf("Matched expected message %s", exp)
711717
}
712-
line := strings.TrimSpace(l)
713-
if line != exp {
714-
errchan <- fmt.Errorf("Unexpected string from completion channel: %s expected: %s", line, exp)
715-
return
718+
plog.Debugf("Matched all expected messages")
719+
// OK!
720+
errchan <- nil
721+
}()
722+
go func() {
723+
//check for error when switching boot order
724+
if booterrchan != nil {
725+
if err := <-booterrchan; err != nil {
726+
errchan <- err
727+
}
716728
}
717-
plog.Debugf("Matched expected message %s", exp)
718-
}
719-
plog.Debugf("Matched all expected messages")
720-
// OK!
721-
errchan <- nil
722-
}()
723-
go func() {
724-
//check for error when switching boot order
725-
if booterrchan != nil {
726-
if err := <-booterrchan; err != nil {
727-
errchan <- err
729+
}()
730+
err := <-errchan
731+
elapsed := time.Since(start)
732+
if err == nil {
733+
// No error so far, check the console and journal files
734+
consoleFile := filepath.Join(outdir, "console.txt")
735+
journalFile := filepath.Join(outdir, "journal.txt")
736+
files := []string{consoleFile, journalFile}
737+
for _, file := range files {
738+
fileName := filepath.Base(file)
739+
// Check if the file exists
740+
_, err := os.Stat(file)
741+
if os.IsNotExist(err) {
742+
fmt.Printf("The file: %v does not exist\n", fileName)
743+
continue
744+
} else if err != nil {
745+
fmt.Println(err)
746+
errchan <- err
747+
return elapsed, err
748+
}
749+
// Read the contents of the file
750+
fileContent, err := os.ReadFile(file)
751+
if err != nil {
752+
fmt.Println(err)
753+
errchan <- err
754+
return elapsed, err
755+
}
756+
// Check for badness with CheckConsole
757+
warnOnly, badlines := kola.CheckConsole([]byte(fileContent), nil)
758+
if len(badlines) == 0 {
759+
fmt.Printf("No badness detected in the file: %v\n", fileName)
760+
} else {
761+
for _, badline := range badlines {
762+
err = fmt.Errorf("badness detected: \n%v", badline)
763+
fmt.Printf("badness detected\n")
764+
if err != nil {
765+
errchan <- err
766+
return elapsed, err
767+
}
768+
}
769+
fmt.Printf("WarnOnly: %v\n", warnOnly)
770+
if warnOnly {
771+
err = fmt.Errorf("warnings found in console file")
772+
errchan <- err
773+
return elapsed, err
774+
}
775+
}
728776
}
729777
}
730-
}()
778+
return elapsed, err
779+
}
731780
err := <-errchan
732781
return time.Since(start), err
733782
}

0 commit comments

Comments
 (0)