Skip to content

Commit 4d50394

Browse files
c4rt0dustymabe
andcommitted
testiso.go: Add check for badness
After tests are complete this checks for badness in the console.txt and journal.txt files. Ref: #3788 Co-authored-by: Dusty Mabe <[email protected]>
1 parent 77118ab commit 4d50394

File tree

1 file changed

+89
-44
lines changed

1 file changed

+89
-44
lines changed

mantle/cmd/kola/testiso.go

Lines changed: 89 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -657,6 +657,8 @@ func runTestIso(cmd *cobra.Command, args []string) (err error) {
657657
func awaitCompletion(ctx context.Context, inst *platform.QemuInstance, outdir string, qchan *os.File, booterrchan chan error, expected []string) (time.Duration, error) {
658658
start := time.Now()
659659
errchan := make(chan error)
660+
// Retrurns the amount of time it took for the test to run
661+
elapsed := time.Since(start)
660662
go func() {
661663
timeout := (time.Duration(installTimeoutMins*(100+kola.Options.ExtendTimeoutPercent)) * time.Minute) / 100
662664
time.Sleep(timeout)
@@ -679,57 +681,100 @@ func awaitCompletion(ctx context.Context, inst *platform.QemuInstance, outdir st
679681
errchan <- err
680682
}
681683
}()
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')
684+
go func() {
685+
err := inst.Wait()
686+
// only one Wait() gets process data, so also manually check for signal
687+
plog.Debugf("qemu exited err=%v", err)
688+
if err == nil && inst.Signaled() {
689+
err = errors.New("process killed")
690+
}
700691
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")
692+
errchan <- errors.Wrapf(err, "QEMU unexpectedly exited while awaiting completion")
693+
}
694+
time.Sleep(1 * time.Minute)
695+
errchan <- fmt.Errorf("QEMU exited; timed out waiting for completion")
696+
}()
697+
go func() {
698+
r := bufio.NewReader(qchan)
699+
for _, exp := range expected {
700+
l, err := r.ReadString('\n')
701+
if err != nil {
702+
if err == io.EOF {
703+
// this may be from QEMU getting killed or exiting; wait a bit
704+
// to give a chance for .Wait() above to feed the channel with a
705+
// better error
706+
time.Sleep(1 * time.Second)
707+
errchan <- fmt.Errorf("Got EOF from completion channel, %s expected", exp)
708+
} else {
709+
errchan <- errors.Wrapf(err, "reading from completion channel")
710+
}
711+
return
712+
}
713+
line := strings.TrimSpace(l)
714+
if line != exp {
715+
errchan <- fmt.Errorf("Unexpected string from completion channel: %s expected: %s", line, exp)
716+
return
709717
}
710-
return
718+
plog.Debugf("Matched expected message %s", exp)
711719
}
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
720+
plog.Debugf("Matched all expected messages")
721+
// OK!
722+
errchan <- nil
723+
}()
724+
go func() {
725+
//check for error when switching boot order
726+
if booterrchan != nil {
727+
if err := <-booterrchan; err != nil {
728+
errchan <- err
729+
}
716730
}
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
731+
}()
732+
err := <-errchan
733+
if err == nil {
734+
// No error so far, check the console and journal files
735+
consoleFile := filepath.Join(outdir, "console.txt")
736+
journalFile := filepath.Join(outdir, "journal.txt")
737+
files := []string{consoleFile, journalFile}
738+
for _, file := range files {
739+
fileName := filepath.Base(file)
740+
// Check if the file exists
741+
_, err := os.Stat(file)
742+
if os.IsNotExist(err) {
743+
fmt.Printf("The file: %v does not exist\n", fileName)
744+
continue
745+
} else if err != nil {
746+
fmt.Println(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+
return elapsed, err
754+
}
755+
// Check for badness with CheckConsole
756+
warnOnly, badlines := kola.CheckConsole([]byte(fileContent), nil)
757+
if len(badlines) > 0 {
758+
for _, badline := range badlines {
759+
err = fmt.Errorf("badness detected: \n%v", badline)
760+
fmt.Printf("badness detected\n")
761+
if err != nil {
762+
return elapsed, err
763+
}
764+
if !warnOnly {
765+
plog.Errorf("checkConsole found bad lines in %v\n", fileName)
766+
return elapsed, err
767+
} else {
768+
plog.Warningf("WarnOnly: %v\n", warnOnly)
769+
}
770+
}
771+
}
728772
}
729773
}
730-
}()
774+
return elapsed, err
775+
}
731776
err := <-errchan
732-
return time.Since(start), err
777+
return elapsed, err
733778
}
734779

735780
func printResult(test string, duration time.Duration, err error) bool {

0 commit comments

Comments
 (0)