Skip to content

Commit

Permalink
Optimised through gofmt
Browse files Browse the repository at this point in the history
  • Loading branch information
c4rt0 committed Sep 25, 2024
1 parent 73327a6 commit d143be0
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 65 deletions.
126 changes: 63 additions & 63 deletions mantle/cmd/kola/testiso.go
Original file line number Diff line number Diff line change
Expand Up @@ -682,78 +682,78 @@ func awaitCompletion(ctx context.Context, inst *platform.QemuInstance, outdir st
}()

go func() {
file, err := os.Open(consoleFilePath)
if err != nil {
fmt.Printf("Error opening %s file: \n", consoleFilePath)
return
}
defer file.Close()
errBuf, err := inst.CheckConsoleForBadness(ctx)
if err == nil && errBuf != "" {
plog.Info("Badness identified")
if err := os.WriteFile(consoleFilePath, []byte(errBuf), 0644); err != nil {
plog.Errorf("Failed to write journal: %v", err)
file, err := os.Open(consoleFilePath)
if err != nil {
fmt.Printf("Error opening %s file: \n", consoleFilePath)
return
}
defer file.Close()
errBuf, err := inst.CheckConsoleForBadness(ctx)
if err == nil && errBuf != "" {
plog.Info("Badness identified")
if err := os.WriteFile(consoleFilePath, []byte(errBuf), 0644); err != nil {
plog.Errorf("Failed to write journal: %v", err)
}
err = platform.ErrInitramfsEmergency
}
err = platform.ErrInitramfsEmergency
}

if err != nil {
errchan <- errors.Wrapf(err, "CheckConsoleForBadness detected an error")
}
}()

go func() {
err := inst.Wait()
// only one Wait() gets process data, so also manually check for signal
plog.Debugf("qemu exited err=%v", err)
if err == nil && inst.Signaled() {
err = errors.New("process killed")
}
if err != nil {
errchan <- errors.Wrapf(err, "QEMU unexpectedly exited while awaiting completion")
}
time.Sleep(1 * time.Minute)
errchan <- fmt.Errorf("QEMU exited; timed out waiting for completion")
}()
if err != nil {
errchan <- errors.Wrapf(err, "CheckConsoleForBadness detected an error")
}
}()

go func() {
r := bufio.NewReader(qchan)
for _, exp := range expected {
l, err := r.ReadString('\n')
go func() {
err := inst.Wait()
// only one Wait() gets process data, so also manually check for signal
plog.Debugf("qemu exited err=%v", err)
if err == nil && inst.Signaled() {
err = errors.New("process killed")
}
if err != nil {
if err == io.EOF {
// this may be from QEMU getting killed or exiting; wait a bit
// to give a chance for .Wait() above to feed the channel with a
// better error
time.Sleep(1 * time.Second)
errchan <- fmt.Errorf("Got EOF from completion channel, %s expected", exp)
} else {
errchan <- errors.Wrapf(err, "reading from completion channel")
}
return
errchan <- errors.Wrapf(err, "QEMU unexpectedly exited while awaiting completion")
}
line := strings.TrimSpace(l)
if line != exp {
errchan <- fmt.Errorf("Unexpected string from completion channel: %s expected: %s", line, exp)
return
time.Sleep(1 * time.Minute)
errchan <- fmt.Errorf("QEMU exited; timed out waiting for completion")
}()

go func() {
r := bufio.NewReader(qchan)
for _, exp := range expected {
l, err := r.ReadString('\n')
if err != nil {
if err == io.EOF {
// this may be from QEMU getting killed or exiting; wait a bit
// to give a chance for .Wait() above to feed the channel with a
// better error
time.Sleep(1 * time.Second)
errchan <- fmt.Errorf("Got EOF from completion channel, %s expected", exp)
} else {
errchan <- errors.Wrapf(err, "reading from completion channel")
}
return
}
line := strings.TrimSpace(l)
if line != exp {
errchan <- fmt.Errorf("Unexpected string from completion channel: %s expected: %s", line, exp)
return
}
plog.Debugf("Matched expected message %s", exp)
}
plog.Debugf("Matched expected message %s", exp)
}
plog.Debugf("Matched all expected messages")
// OK!
errchan <- nil
}()
plog.Debugf("Matched all expected messages")
// OK!
errchan <- nil
}()

go func() {
//check for error when switching boot order
if booterrchan != nil {
if err := <-booterrchan; err != nil {
errchan <- err
go func() {
//check for error when switching boot order
if booterrchan != nil {
if err := <-booterrchan; err != nil {
errchan <- err
}
}
}
}()
}()

}
}
err := <-errchan
return time.Since(start), err
}
Expand Down
3 changes: 1 addition & 2 deletions mantle/kola/harness.go
Original file line number Diff line number Diff line change
Expand Up @@ -1917,7 +1917,6 @@ func ScpKolet(machines []platform.Machine) error {
return fmt.Errorf("Unable to locate kolet binary for %s", mArch)
}


// CheckConsoleText checks console output for badness
// input : the console content
// output true if badlines were found and the bad lines.
Expand Down Expand Up @@ -1953,7 +1952,7 @@ func CheckConsoleText(input []byte) (bool, []string) {
// rerun success.
func CheckConsole(output []byte, t *register.Test) (bool, []string) {
var badlines []string
var badness bool
var badness bool
allowRerunSuccess := true

//here pass output to checkconsoleText
Expand Down

0 comments on commit d143be0

Please sign in to comment.