test_all: export more internal variables to index.json for analysis

This commit is contained in:
Nick Craig-Wood 2020-08-20 12:23:33 +01:00
parent 85f9bd1abf
commit fb9edbe34e
2 changed files with 65 additions and 65 deletions

View File

@ -140,7 +140,7 @@ func (r *Report) LogSummary() {
if !r.AllPassed() { if !r.AllPassed() {
for _, t := range r.Failed { for _, t := range r.Failed {
log.Printf(" * %s", toShell(t.nextCmdLine())) log.Printf(" * %s", toShell(t.nextCmdLine()))
log.Printf(" * Failed tests: %v", t.failedTests) log.Printf(" * Failed tests: %v", t.FailedTests)
} }
} }
} }
@ -264,7 +264,7 @@ a:focus {
<td>{{ if ne $prevRemote .Remote }}{{ .Remote }}{{ end }}{{ $prevRemote = .Remote }}</td> <td>{{ if ne $prevRemote .Remote }}{{ .Remote }}{{ end }}{{ $prevRemote = .Remote }}</td>
<td>{{ .Path }}</td> <td>{{ .Path }}</td>
<td><span class="{{ .FastList }}">{{ .FastList }}</span></td> <td><span class="{{ .FastList }}">{{ .FastList }}</span></td>
<td>{{ .FailedTests }}</td> <td>{{ .FailedTestsCSV }}</td>
<td>{{ range $i, $v := .Logs }}<a href="{{ $v }}">#{{ $i }}</a> {{ end }}</td> <td>{{ range $i, $v := .Logs }}<a href="{{ $v }}">#{{ $i }}</a> {{ end }}</td>
</tr> </tr>
{{ end }} {{ end }}

View File

@ -46,16 +46,16 @@ type Run struct {
SizeLimit int64 // maximum test file size SizeLimit int64 // maximum test file size
Ignore map[string]struct{} Ignore map[string]struct{}
// Internals // Internals
cmdLine []string CmdLine []string
cmdString string CmdString string
try int Try int
err error err error
output []byte output []byte
failedTests []string FailedTests []string
runFlag string RunFlag string
logDir string // directory to place the logs LogDir string // directory to place the logs
trialName string // name/log file name of current trial TrialName string // name/log file name of current trial
trialNames []string // list of all the trials TrialNames []string // list of all the trials
} }
// Runs records multiple Run objects // Runs records multiple Run objects
@ -92,7 +92,7 @@ func (rs Runs) Less(i, j int) bool {
// dumpOutput prints the error output // dumpOutput prints the error output
func (r *Run) dumpOutput() { func (r *Run) dumpOutput() {
log.Println("------------------------------------------------------------") log.Println("------------------------------------------------------------")
log.Printf("---- %q ----", r.cmdString) log.Printf("---- %q ----", r.CmdString)
log.Println(string(r.output)) log.Println(string(r.output))
log.Println("------------------------------------------------------------") log.Println("------------------------------------------------------------")
} }
@ -130,8 +130,8 @@ var failRe = regexp.MustCompile(`(?m)^\s*--- FAIL: (Test.*?) \(`)
// findFailures looks for all the tests which failed // findFailures looks for all the tests which failed
func (r *Run) findFailures() { func (r *Run) findFailures() {
oldFailedTests := r.failedTests oldFailedTests := r.FailedTests
r.failedTests = nil r.FailedTests = nil
excludeParents := map[string]struct{}{} excludeParents := map[string]struct{}{}
ignored := 0 ignored := 0
for _, matches := range failRe.FindAllSubmatch(r.output, -1) { for _, matches := range failRe.FindAllSubmatch(r.output, -1) {
@ -140,7 +140,7 @@ func (r *Run) findFailures() {
if _, found := r.Ignore[failedTest]; found { if _, found := r.Ignore[failedTest]; found {
ignored++ ignored++
} else { } else {
r.failedTests = append(r.failedTests, failedTest) r.FailedTests = append(r.FailedTests, failedTest)
} }
// Find all the parents of this test // Find all the parents of this test
parts := strings.Split(failedTest, "/") parts := strings.Split(failedTest, "/")
@ -149,50 +149,50 @@ func (r *Run) findFailures() {
} }
} }
// Exclude the parents // Exclude the parents
var newTests = r.failedTests[:0] var newTests = r.FailedTests[:0]
for _, failedTest := range r.failedTests { for _, failedTest := range r.FailedTests {
if _, excluded := excludeParents[failedTest]; !excluded { if _, excluded := excludeParents[failedTest]; !excluded {
newTests = append(newTests, failedTest) newTests = append(newTests, failedTest)
} }
} }
r.failedTests = newTests r.FailedTests = newTests
if len(r.failedTests) == 0 && ignored > 0 { if len(r.FailedTests) == 0 && ignored > 0 {
log.Printf("%q - Found %d ignored errors only - marking as good", r.cmdString, ignored) log.Printf("%q - Found %d ignored errors only - marking as good", r.CmdString, ignored)
r.err = nil r.err = nil
r.dumpOutput() r.dumpOutput()
return return
} }
if len(r.failedTests) != 0 { if len(r.FailedTests) != 0 {
r.runFlag = testsToRegexp(r.failedTests) r.RunFlag = testsToRegexp(r.FailedTests)
} else { } else {
r.runFlag = "" r.RunFlag = ""
} }
if r.passed() && len(r.failedTests) != 0 { if r.passed() && len(r.FailedTests) != 0 {
log.Printf("%q - Expecting no errors but got: %v", r.cmdString, r.failedTests) log.Printf("%q - Expecting no errors but got: %v", r.CmdString, r.FailedTests)
r.dumpOutput() r.dumpOutput()
} else if !r.passed() && len(r.failedTests) == 0 { } else if !r.passed() && len(r.FailedTests) == 0 {
log.Printf("%q - Expecting errors but got none: %v", r.cmdString, r.failedTests) log.Printf("%q - Expecting errors but got none: %v", r.CmdString, r.FailedTests)
r.dumpOutput() r.dumpOutput()
r.failedTests = oldFailedTests r.FailedTests = oldFailedTests
} }
} }
// nextCmdLine returns the next command line // nextCmdLine returns the next command line
func (r *Run) nextCmdLine() []string { func (r *Run) nextCmdLine() []string {
cmdLine := r.cmdLine CmdLine := r.CmdLine
if r.runFlag != "" { if r.RunFlag != "" {
cmdLine = append(cmdLine, "-test.run", r.runFlag) CmdLine = append(CmdLine, "-test.run", r.RunFlag)
} }
return cmdLine return CmdLine
} }
// trial runs a single test // trial runs a single test
func (r *Run) trial() { func (r *Run) trial() {
cmdLine := r.nextCmdLine() CmdLine := r.nextCmdLine()
cmdString := toShell(cmdLine) CmdString := toShell(CmdLine)
msg := fmt.Sprintf("%q - Starting (try %d/%d)", cmdString, r.try, *maxTries) msg := fmt.Sprintf("%q - Starting (try %d/%d)", CmdString, r.Try, *maxTries)
log.Println(msg) log.Println(msg)
logName := path.Join(r.logDir, r.trialName) logName := path.Join(r.LogDir, r.TrialName)
out, err := os.Create(logName) out, err := os.Create(logName)
if err != nil { if err != nil {
log.Fatalf("Couldn't create log file: %v", err) log.Fatalf("Couldn't create log file: %v", err)
@ -207,7 +207,7 @@ func (r *Run) trial() {
// Early exit if --try-run // Early exit if --try-run
if *dryRun { if *dryRun {
log.Printf("Not executing as --dry-run: %v", cmdLine) log.Printf("Not executing as --dry-run: %v", CmdLine)
_, _ = fmt.Fprintln(out, "--dry-run is set - not running") _, _ = fmt.Fprintln(out, "--dry-run is set - not running")
return return
} }
@ -226,7 +226,7 @@ func (r *Run) trial() {
var b bytes.Buffer var b bytes.Buffer
multiOut := io.MultiWriter(out, &b) multiOut := io.MultiWriter(out, &b)
cmd := exec.Command(cmdLine[0], cmdLine[1:]...) cmd := exec.Command(CmdLine[0], CmdLine[1:]...)
cmd.Stderr = multiOut cmd.Stderr = multiOut
cmd.Stdout = multiOut cmd.Stdout = multiOut
cmd.Dir = r.Path cmd.Dir = r.Path
@ -236,9 +236,9 @@ func (r *Run) trial() {
duration := time.Since(start) duration := time.Since(start)
r.findFailures() r.findFailures()
if r.passed() { if r.passed() {
msg = fmt.Sprintf("%q - Finished OK in %v (try %d/%d)", cmdString, duration, r.try, *maxTries) msg = fmt.Sprintf("%q - Finished OK in %v (try %d/%d)", CmdString, duration, r.Try, *maxTries)
} else { } else {
msg = fmt.Sprintf("%q - Finished ERROR in %v (try %d/%d): %v: Failed %v", cmdString, duration, r.try, *maxTries, r.err, r.failedTests) msg = fmt.Sprintf("%q - Finished ERROR in %v (try %d/%d): %v: Failed %v", CmdString, duration, r.Try, *maxTries, r.err, r.FailedTests)
} }
log.Println(msg) log.Println(msg)
_, _ = fmt.Fprintln(out, msg) _, _ = fmt.Fprintln(out, msg)
@ -282,12 +282,12 @@ func (r *Run) MakeTestBinary() {
binary := r.BinaryPath() binary := r.BinaryPath()
binaryName := r.BinaryName() binaryName := r.BinaryName()
log.Printf("%s: Making test binary %q", r.Path, binaryName) log.Printf("%s: Making test binary %q", r.Path, binaryName)
cmdLine := []string{"go", "test", "-c"} CmdLine := []string{"go", "test", "-c"}
if *dryRun { if *dryRun {
log.Printf("Not executing: %v", cmdLine) log.Printf("Not executing: %v", CmdLine)
return return
} }
cmd := exec.Command(cmdLine[0], cmdLine[1:]...) cmd := exec.Command(CmdLine[0], CmdLine[1:]...)
cmd.Dir = r.Path cmd.Dir = r.Path
err := cmd.Run() err := cmd.Run()
if err != nil { if err != nil {
@ -320,7 +320,7 @@ func (r *Run) Name() string {
if r.FastList { if r.FastList {
ns = append(ns, "fastlist") ns = append(ns, "fastlist")
} }
ns = append(ns, fmt.Sprintf("%d", r.try)) ns = append(ns, fmt.Sprintf("%d", r.Try))
s := strings.Join(ns, "-") s := strings.Join(ns, "-")
s = strings.Replace(s, ":", "", -1) s = strings.Replace(s, ":", "", -1)
return s return s
@ -331,52 +331,52 @@ func (r *Run) Init() {
prefix := "-test." prefix := "-test."
if r.NoBinary { if r.NoBinary {
prefix = "-" prefix = "-"
r.cmdLine = []string{"go", "test"} r.CmdLine = []string{"go", "test"}
} else { } else {
r.cmdLine = []string{"./" + r.BinaryName()} r.CmdLine = []string{"./" + r.BinaryName()}
} }
r.cmdLine = append(r.cmdLine, prefix+"v", prefix+"timeout", timeout.String(), "-remote", r.Remote) r.CmdLine = append(r.CmdLine, prefix+"v", prefix+"timeout", timeout.String(), "-remote", r.Remote)
if *listRetries > 0 { if *listRetries > 0 {
r.cmdLine = append(r.cmdLine, "-list-retries", fmt.Sprint(*listRetries)) r.CmdLine = append(r.CmdLine, "-list-retries", fmt.Sprint(*listRetries))
} }
r.try = 1 r.Try = 1
if *verbose { if *verbose {
r.cmdLine = append(r.cmdLine, "-verbose") r.CmdLine = append(r.CmdLine, "-verbose")
fs.Config.LogLevel = fs.LogLevelDebug fs.Config.LogLevel = fs.LogLevelDebug
} }
if *runOnly != "" { if *runOnly != "" {
r.cmdLine = append(r.cmdLine, prefix+"run", *runOnly) r.CmdLine = append(r.CmdLine, prefix+"run", *runOnly)
} }
if r.FastList { if r.FastList {
r.cmdLine = append(r.cmdLine, "-fast-list") r.CmdLine = append(r.CmdLine, "-fast-list")
} }
if r.Short { if r.Short {
r.cmdLine = append(r.cmdLine, "-short") r.CmdLine = append(r.CmdLine, "-short")
} }
if r.SizeLimit > 0 { if r.SizeLimit > 0 {
r.cmdLine = append(r.cmdLine, "-size-limit", strconv.FormatInt(r.SizeLimit, 10)) r.CmdLine = append(r.CmdLine, "-size-limit", strconv.FormatInt(r.SizeLimit, 10))
} }
r.cmdString = toShell(r.cmdLine) r.CmdString = toShell(r.CmdLine)
} }
// Logs returns all the log names // Logs returns all the log names
func (r *Run) Logs() []string { func (r *Run) Logs() []string {
return r.trialNames return r.TrialNames
} }
// FailedTests returns the failed tests as a comma separated string, limiting the number // FailedTestsCSV returns the failed tests as a comma separated string, limiting the number
func (r *Run) FailedTests() string { func (r *Run) FailedTestsCSV() string {
const maxTests = 5 const maxTests = 5
ts := r.failedTests ts := r.FailedTests
if len(ts) > maxTests { if len(ts) > maxTests {
ts = ts[:maxTests:maxTests] ts = ts[:maxTests:maxTests]
ts = append(ts, fmt.Sprintf("… (%d more)", len(r.failedTests)-maxTests)) ts = append(ts, fmt.Sprintf("… (%d more)", len(r.FailedTests)-maxTests))
} }
return strings.Join(ts, ", ") return strings.Join(ts, ", ")
} }
// Run runs all the trials for this test // Run runs all the trials for this test
func (r *Run) Run(logDir string, result chan<- *Run) { func (r *Run) Run(LogDir string, result chan<- *Run) {
if r.OneOnly { if r.OneOnly {
oneOnlyMu.Lock() oneOnlyMu.Lock()
mu := oneOnly[r.Backend] mu := oneOnly[r.Backend]
@ -389,11 +389,11 @@ func (r *Run) Run(logDir string, result chan<- *Run) {
defer mu.Unlock() defer mu.Unlock()
} }
r.Init() r.Init()
r.logDir = logDir r.LogDir = LogDir
for r.try = 1; r.try <= *maxTries; r.try++ { for r.Try = 1; r.Try <= *maxTries; r.Try++ {
r.trialName = r.Name() + ".txt" r.TrialName = r.Name() + ".txt"
r.trialNames = append(r.trialNames, r.trialName) r.TrialNames = append(r.TrialNames, r.TrialName)
log.Printf("Starting run with log %q", r.trialName) log.Printf("Starting run with log %q", r.TrialName)
r.trial() r.trial()
if r.passed() || r.NoRetries { if r.passed() || r.NoRetries {
break break