2018-09-29 13:48:29 +00:00
|
|
|
// Run a test
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
2020-11-05 11:33:32 +00:00
|
|
|
"context"
|
2018-09-29 13:48:29 +00:00
|
|
|
"fmt"
|
|
|
|
"go/build"
|
|
|
|
"io"
|
|
|
|
"os"
|
|
|
|
"os/exec"
|
|
|
|
"path"
|
|
|
|
"regexp"
|
|
|
|
"runtime"
|
2018-11-23 14:25:51 +00:00
|
|
|
"sort"
|
2019-09-16 17:52:41 +00:00
|
|
|
"strconv"
|
2018-09-29 13:48:29 +00:00
|
|
|
"strings"
|
2018-10-23 10:44:56 +00:00
|
|
|
"sync"
|
2018-09-29 13:48:29 +00:00
|
|
|
"time"
|
|
|
|
|
2019-07-28 17:47:38 +00:00
|
|
|
"github.com/rclone/rclone/fs"
|
2019-10-04 15:51:07 +00:00
|
|
|
"github.com/rclone/rclone/fstest/testserver"
|
2018-09-29 13:48:29 +00:00
|
|
|
)
|
|
|
|
|
2018-10-23 10:44:56 +00:00
|
|
|
// Control concurrency per backend if required
|
|
|
|
var (
|
|
|
|
oneOnlyMu sync.Mutex
|
|
|
|
oneOnly = map[string]*sync.Mutex{}
|
|
|
|
)
|
|
|
|
|
2018-09-29 13:48:29 +00:00
|
|
|
// Run holds info about a running test
|
|
|
|
//
|
|
|
|
// A run just runs one command line, but it can be run multiple times
|
|
|
|
// if retries are needed.
|
|
|
|
type Run struct {
|
|
|
|
// Config
|
2020-10-25 16:15:41 +00:00
|
|
|
Remote string // name of the test remote
|
|
|
|
Backend string // name of the backend
|
|
|
|
Path string // path to the source directory
|
|
|
|
FastList bool // add -fast-list to tests
|
|
|
|
Short bool // add -short
|
|
|
|
NoRetries bool // don't retry if set
|
|
|
|
OneOnly bool // only run test for this backend at once
|
|
|
|
NoBinary bool // set to not build a binary
|
|
|
|
SizeLimit int64 // maximum test file size
|
|
|
|
Ignore map[string]struct{}
|
2021-10-20 16:34:56 +00:00
|
|
|
ListRetries int // -list-retries if > 0
|
|
|
|
ExtraTime float64 // multiply the timeout by this
|
2018-09-29 13:48:29 +00:00
|
|
|
// Internals
|
2020-08-20 11:23:33 +00:00
|
|
|
CmdLine []string
|
|
|
|
CmdString string
|
|
|
|
Try int
|
2018-09-29 13:48:29 +00:00
|
|
|
err error
|
|
|
|
output []byte
|
2020-08-20 11:23:33 +00:00
|
|
|
FailedTests []string
|
|
|
|
RunFlag string
|
|
|
|
LogDir string // directory to place the logs
|
|
|
|
TrialName string // name/log file name of current trial
|
|
|
|
TrialNames []string // list of all the trials
|
2018-09-29 13:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Runs records multiple Run objects
|
|
|
|
type Runs []*Run
|
|
|
|
|
|
|
|
// Sort interface
|
|
|
|
func (rs Runs) Len() int { return len(rs) }
|
|
|
|
func (rs Runs) Swap(i, j int) { rs[i], rs[j] = rs[j], rs[i] }
|
|
|
|
func (rs Runs) Less(i, j int) bool {
|
|
|
|
a, b := rs[i], rs[j]
|
|
|
|
if a.Backend < b.Backend {
|
|
|
|
return true
|
|
|
|
} else if a.Backend > b.Backend {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if a.Remote < b.Remote {
|
|
|
|
return true
|
|
|
|
} else if a.Remote > b.Remote {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if a.Path < b.Path {
|
|
|
|
return true
|
|
|
|
} else if a.Path > b.Path {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if !a.FastList && b.FastList {
|
|
|
|
return true
|
|
|
|
} else if a.FastList && !b.FastList {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
// dumpOutput prints the error output
|
|
|
|
func (r *Run) dumpOutput() {
|
2024-08-18 14:58:35 +00:00
|
|
|
fs.Log(nil, "------------------------------------------------------------")
|
|
|
|
fs.Logf(nil, "---- %q ----", r.CmdString)
|
|
|
|
fs.Log(nil, string(r.output))
|
|
|
|
fs.Log(nil, "------------------------------------------------------------")
|
2018-09-29 13:48:29 +00:00
|
|
|
}
|
|
|
|
|
2024-04-14 15:50:53 +00:00
|
|
|
// trie for storing runs
|
|
|
|
type trie map[string]trie
|
|
|
|
|
|
|
|
// turn a trie into multiple regexp matches
|
|
|
|
//
|
|
|
|
// We can't ever have a / in a regexp as it doesn't work.
|
|
|
|
func match(current trie) []string {
|
|
|
|
var names []string
|
|
|
|
var parts []string
|
|
|
|
for name, value := range current {
|
|
|
|
matchName := "^" + name + "$"
|
|
|
|
if len(value) == 0 {
|
|
|
|
names = append(names, name)
|
|
|
|
} else {
|
|
|
|
for _, part := range match(value) {
|
|
|
|
parts = append(parts, matchName+"/"+part)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
sort.Strings(names)
|
|
|
|
if len(names) > 1 {
|
|
|
|
parts = append(parts, "^("+strings.Join(names, "|")+")$")
|
|
|
|
} else if len(names) == 1 {
|
|
|
|
parts = append(parts, "^"+names[0]+"$")
|
|
|
|
}
|
|
|
|
sort.Strings(parts)
|
|
|
|
return parts
|
|
|
|
}
|
|
|
|
|
2018-11-23 14:25:51 +00:00
|
|
|
// This converts a slice of test names into a regexp which matches
|
|
|
|
// them.
|
|
|
|
func testsToRegexp(tests []string) string {
|
2024-04-14 15:50:53 +00:00
|
|
|
var split = trie{}
|
|
|
|
// Make a trie showing which parts are used at each level
|
2018-11-23 14:25:51 +00:00
|
|
|
for _, test := range tests {
|
2024-04-14 15:50:53 +00:00
|
|
|
var parent = split
|
|
|
|
for _, name := range strings.Split(test, "/") {
|
|
|
|
current := parent[name]
|
|
|
|
if current == nil {
|
|
|
|
current = trie{}
|
|
|
|
parent[name] = current
|
2018-11-23 14:25:51 +00:00
|
|
|
}
|
2024-04-14 15:50:53 +00:00
|
|
|
parent = current
|
2018-11-23 14:25:51 +00:00
|
|
|
}
|
|
|
|
}
|
2024-04-14 15:50:53 +00:00
|
|
|
parts := match(split)
|
|
|
|
return strings.Join(parts, "|")
|
2018-11-23 14:25:51 +00:00
|
|
|
}
|
|
|
|
|
2018-10-23 15:56:35 +00:00
|
|
|
var failRe = regexp.MustCompile(`(?m)^\s*--- FAIL: (Test.*?) \(`)
|
2018-09-29 13:48:29 +00:00
|
|
|
|
|
|
|
// findFailures looks for all the tests which failed
|
|
|
|
func (r *Run) findFailures() {
|
2020-08-20 11:23:33 +00:00
|
|
|
oldFailedTests := r.FailedTests
|
|
|
|
r.FailedTests = nil
|
2018-10-23 15:56:35 +00:00
|
|
|
excludeParents := map[string]struct{}{}
|
2019-01-12 20:18:05 +00:00
|
|
|
ignored := 0
|
2018-09-29 13:48:29 +00:00
|
|
|
for _, matches := range failRe.FindAllSubmatch(r.output, -1) {
|
2018-10-23 15:56:35 +00:00
|
|
|
failedTest := string(matches[1])
|
2019-01-12 20:18:05 +00:00
|
|
|
// Skip any ignored failures
|
|
|
|
if _, found := r.Ignore[failedTest]; found {
|
|
|
|
ignored++
|
|
|
|
} else {
|
2020-08-20 11:23:33 +00:00
|
|
|
r.FailedTests = append(r.FailedTests, failedTest)
|
2019-01-12 20:18:05 +00:00
|
|
|
}
|
2018-10-23 15:56:35 +00:00
|
|
|
// Find all the parents of this test
|
|
|
|
parts := strings.Split(failedTest, "/")
|
|
|
|
for i := len(parts) - 1; i >= 1; i-- {
|
|
|
|
excludeParents[strings.Join(parts[:i], "/")] = struct{}{}
|
|
|
|
}
|
2018-09-29 13:48:29 +00:00
|
|
|
}
|
2018-10-23 15:56:35 +00:00
|
|
|
// Exclude the parents
|
2020-08-20 11:23:33 +00:00
|
|
|
var newTests = r.FailedTests[:0]
|
|
|
|
for _, failedTest := range r.FailedTests {
|
2018-10-23 15:56:35 +00:00
|
|
|
if _, excluded := excludeParents[failedTest]; !excluded {
|
|
|
|
newTests = append(newTests, failedTest)
|
|
|
|
}
|
|
|
|
}
|
2020-08-20 11:23:33 +00:00
|
|
|
r.FailedTests = newTests
|
|
|
|
if len(r.FailedTests) == 0 && ignored > 0 {
|
2024-08-18 14:58:35 +00:00
|
|
|
fs.Logf(nil, "%q - Found %d ignored errors only - marking as good", r.CmdString, ignored)
|
2019-01-12 20:18:05 +00:00
|
|
|
r.err = nil
|
|
|
|
r.dumpOutput()
|
|
|
|
return
|
|
|
|
}
|
2020-08-20 11:23:33 +00:00
|
|
|
if len(r.FailedTests) != 0 {
|
|
|
|
r.RunFlag = testsToRegexp(r.FailedTests)
|
2018-09-29 13:48:29 +00:00
|
|
|
} else {
|
2020-08-20 11:23:33 +00:00
|
|
|
r.RunFlag = ""
|
2018-09-29 13:48:29 +00:00
|
|
|
}
|
2020-08-20 11:23:33 +00:00
|
|
|
if r.passed() && len(r.FailedTests) != 0 {
|
2024-08-18 14:58:35 +00:00
|
|
|
fs.Logf(nil, "%q - Expecting no errors but got: %v", r.CmdString, r.FailedTests)
|
2018-09-29 13:48:29 +00:00
|
|
|
r.dumpOutput()
|
2020-08-20 11:23:33 +00:00
|
|
|
} else if !r.passed() && len(r.FailedTests) == 0 {
|
2024-08-18 14:58:35 +00:00
|
|
|
fs.Logf(nil, "%q - Expecting errors but got none: %v", r.CmdString, r.FailedTests)
|
2018-09-29 13:48:29 +00:00
|
|
|
r.dumpOutput()
|
2020-08-20 11:23:33 +00:00
|
|
|
r.FailedTests = oldFailedTests
|
2018-09-29 13:48:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// nextCmdLine returns the next command line
|
|
|
|
func (r *Run) nextCmdLine() []string {
|
2020-08-20 11:23:33 +00:00
|
|
|
CmdLine := r.CmdLine
|
|
|
|
if r.RunFlag != "" {
|
|
|
|
CmdLine = append(CmdLine, "-test.run", r.RunFlag)
|
2018-09-29 13:48:29 +00:00
|
|
|
}
|
2020-08-20 11:23:33 +00:00
|
|
|
return CmdLine
|
2018-09-29 13:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// trial runs a single test
|
|
|
|
func (r *Run) trial() {
|
2020-08-20 11:23:33 +00:00
|
|
|
CmdLine := r.nextCmdLine()
|
|
|
|
CmdString := toShell(CmdLine)
|
|
|
|
msg := fmt.Sprintf("%q - Starting (try %d/%d)", CmdString, r.Try, *maxTries)
|
2024-08-18 14:58:35 +00:00
|
|
|
fs.Log(nil, msg)
|
2020-08-20 11:23:33 +00:00
|
|
|
logName := path.Join(r.LogDir, r.TrialName)
|
2018-09-29 13:48:29 +00:00
|
|
|
out, err := os.Create(logName)
|
|
|
|
if err != nil {
|
2024-08-18 14:58:35 +00:00
|
|
|
fs.Fatalf(nil, "Couldn't create log file: %v", err)
|
2018-09-29 13:48:29 +00:00
|
|
|
}
|
|
|
|
defer func() {
|
|
|
|
err := out.Close()
|
|
|
|
if err != nil {
|
2024-08-18 14:58:35 +00:00
|
|
|
fs.Fatalf(nil, "Failed to close log file: %v", err)
|
2018-09-29 13:48:29 +00:00
|
|
|
}
|
|
|
|
}()
|
|
|
|
_, _ = fmt.Fprintln(out, msg)
|
|
|
|
|
|
|
|
// Early exit if --try-run
|
|
|
|
if *dryRun {
|
2024-08-18 14:58:35 +00:00
|
|
|
fs.Logf(nil, "Not executing as --dry-run: %v", CmdLine)
|
2018-09-29 13:48:29 +00:00
|
|
|
_, _ = fmt.Fprintln(out, "--dry-run is set - not running")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-10-04 15:51:07 +00:00
|
|
|
// Start the test server if required
|
|
|
|
finish, err := testserver.Start(r.Remote)
|
|
|
|
if err != nil {
|
2024-08-18 14:58:35 +00:00
|
|
|
fs.Logf(nil, "%s: Failed to start test server: %v", r.Remote, err)
|
2019-10-04 15:51:07 +00:00
|
|
|
_, _ = fmt.Fprintf(out, "%s: Failed to start test server: %v\n", r.Remote, err)
|
|
|
|
r.err = err
|
|
|
|
return
|
|
|
|
}
|
|
|
|
defer finish()
|
|
|
|
|
2018-09-29 13:48:29 +00:00
|
|
|
// Internal buffer
|
|
|
|
var b bytes.Buffer
|
|
|
|
multiOut := io.MultiWriter(out, &b)
|
|
|
|
|
2020-08-20 11:23:33 +00:00
|
|
|
cmd := exec.Command(CmdLine[0], CmdLine[1:]...)
|
2018-09-29 13:48:29 +00:00
|
|
|
cmd.Stderr = multiOut
|
|
|
|
cmd.Stdout = multiOut
|
2018-10-23 16:31:11 +00:00
|
|
|
cmd.Dir = r.Path
|
2018-09-29 13:48:29 +00:00
|
|
|
start := time.Now()
|
|
|
|
r.err = cmd.Run()
|
|
|
|
r.output = b.Bytes()
|
|
|
|
duration := time.Since(start)
|
|
|
|
r.findFailures()
|
|
|
|
if r.passed() {
|
2020-08-20 11:23:33 +00:00
|
|
|
msg = fmt.Sprintf("%q - Finished OK in %v (try %d/%d)", CmdString, duration, r.Try, *maxTries)
|
2018-09-29 13:48:29 +00:00
|
|
|
} else {
|
2020-08-20 11:23:33 +00:00
|
|
|
msg = fmt.Sprintf("%q - Finished ERROR in %v (try %d/%d): %v: Failed %v", CmdString, duration, r.Try, *maxTries, r.err, r.FailedTests)
|
2018-09-29 13:48:29 +00:00
|
|
|
}
|
2024-08-18 14:58:35 +00:00
|
|
|
fs.Log(nil, msg)
|
2018-09-29 13:48:29 +00:00
|
|
|
_, _ = fmt.Fprintln(out, msg)
|
|
|
|
}
|
|
|
|
|
|
|
|
// passed returns true if the test passed
|
|
|
|
func (r *Run) passed() bool {
|
|
|
|
return r.err == nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// GOPATH returns the current GOPATH
|
|
|
|
func GOPATH() string {
|
|
|
|
gopath := os.Getenv("GOPATH")
|
|
|
|
if gopath == "" {
|
|
|
|
gopath = build.Default.GOPATH
|
|
|
|
}
|
|
|
|
return gopath
|
|
|
|
}
|
|
|
|
|
|
|
|
// BinaryName turns a package name into a binary name
|
|
|
|
func (r *Run) BinaryName() string {
|
|
|
|
binary := path.Base(r.Path) + ".test"
|
|
|
|
if runtime.GOOS == "windows" {
|
|
|
|
binary += ".exe"
|
|
|
|
}
|
|
|
|
return binary
|
|
|
|
}
|
|
|
|
|
|
|
|
// BinaryPath turns a package name into a binary path
|
|
|
|
func (r *Run) BinaryPath() string {
|
|
|
|
return path.Join(r.Path, r.BinaryName())
|
|
|
|
}
|
|
|
|
|
|
|
|
// PackagePath returns the path to the package
|
|
|
|
func (r *Run) PackagePath() string {
|
|
|
|
return path.Join(GOPATH(), "src", r.Path)
|
|
|
|
}
|
|
|
|
|
|
|
|
// MakeTestBinary makes the binary we will run
|
|
|
|
func (r *Run) MakeTestBinary() {
|
|
|
|
binary := r.BinaryPath()
|
|
|
|
binaryName := r.BinaryName()
|
2024-08-18 14:58:35 +00:00
|
|
|
fs.Logf(nil, "%s: Making test binary %q", r.Path, binaryName)
|
2020-08-20 11:23:33 +00:00
|
|
|
CmdLine := []string{"go", "test", "-c"}
|
2024-01-24 11:25:47 +00:00
|
|
|
if *race {
|
|
|
|
CmdLine = append(CmdLine, "-race")
|
|
|
|
}
|
2018-09-29 13:48:29 +00:00
|
|
|
if *dryRun {
|
2024-08-18 14:58:35 +00:00
|
|
|
fs.Logf(nil, "Not executing: %v", CmdLine)
|
2018-09-29 13:48:29 +00:00
|
|
|
return
|
|
|
|
}
|
2020-08-20 11:23:33 +00:00
|
|
|
cmd := exec.Command(CmdLine[0], CmdLine[1:]...)
|
2018-10-23 16:31:11 +00:00
|
|
|
cmd.Dir = r.Path
|
|
|
|
err := cmd.Run()
|
2018-09-29 13:48:29 +00:00
|
|
|
if err != nil {
|
2024-08-18 14:58:35 +00:00
|
|
|
fs.Fatalf(nil, "Failed to make test binary: %v", err)
|
2018-09-29 13:48:29 +00:00
|
|
|
}
|
|
|
|
if _, err := os.Stat(binary); err != nil {
|
2024-08-18 14:58:35 +00:00
|
|
|
fs.Fatalf(nil, "Couldn't find test binary %q", binary)
|
2018-09-29 13:48:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// RemoveTestBinary removes the binary made in makeTestBinary
|
|
|
|
func (r *Run) RemoveTestBinary() {
|
|
|
|
if *dryRun {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
binary := r.BinaryPath()
|
|
|
|
err := os.Remove(binary) // Delete the binary when finished
|
|
|
|
if err != nil {
|
2024-08-18 14:58:35 +00:00
|
|
|
fs.Logf(nil, "Error removing test binary %q: %v", binary, err)
|
2018-09-29 13:48:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Name returns the run name as a file name friendly string
|
|
|
|
func (r *Run) Name() string {
|
|
|
|
ns := []string{
|
|
|
|
r.Backend,
|
2022-05-16 16:11:45 +00:00
|
|
|
strings.ReplaceAll(r.Path, "/", "."),
|
2018-09-29 13:48:29 +00:00
|
|
|
r.Remote,
|
|
|
|
}
|
|
|
|
if r.FastList {
|
|
|
|
ns = append(ns, "fastlist")
|
|
|
|
}
|
2020-08-20 11:23:33 +00:00
|
|
|
ns = append(ns, fmt.Sprintf("%d", r.Try))
|
2018-09-29 13:48:29 +00:00
|
|
|
s := strings.Join(ns, "-")
|
2022-05-16 16:11:45 +00:00
|
|
|
s = strings.ReplaceAll(s, ":", "")
|
2018-09-29 13:48:29 +00:00
|
|
|
return s
|
|
|
|
}
|
|
|
|
|
|
|
|
// Init the Run
|
|
|
|
func (r *Run) Init() {
|
2018-10-23 16:31:11 +00:00
|
|
|
prefix := "-test."
|
|
|
|
if r.NoBinary {
|
|
|
|
prefix = "-"
|
2020-08-20 11:23:33 +00:00
|
|
|
r.CmdLine = []string{"go", "test"}
|
2018-10-23 16:31:11 +00:00
|
|
|
} else {
|
2020-08-20 11:23:33 +00:00
|
|
|
r.CmdLine = []string{"./" + r.BinaryName()}
|
2018-10-23 16:31:11 +00:00
|
|
|
}
|
2021-10-20 16:34:56 +00:00
|
|
|
testTimeout := *timeout
|
|
|
|
if r.ExtraTime > 0 {
|
|
|
|
testTimeout = time.Duration(float64(testTimeout) * r.ExtraTime)
|
|
|
|
}
|
|
|
|
r.CmdLine = append(r.CmdLine, prefix+"v", prefix+"timeout", testTimeout.String(), "-remote", r.Remote)
|
2020-10-25 16:15:41 +00:00
|
|
|
listRetries := *listRetries
|
|
|
|
if r.ListRetries > 0 {
|
|
|
|
listRetries = r.ListRetries
|
|
|
|
}
|
|
|
|
if listRetries > 0 {
|
|
|
|
r.CmdLine = append(r.CmdLine, "-list-retries", fmt.Sprint(listRetries))
|
2020-05-07 19:36:45 +00:00
|
|
|
}
|
2020-08-20 11:23:33 +00:00
|
|
|
r.Try = 1
|
2020-11-05 11:33:32 +00:00
|
|
|
ci := fs.GetConfig(context.Background())
|
2018-09-29 13:48:29 +00:00
|
|
|
if *verbose {
|
2020-08-20 11:23:33 +00:00
|
|
|
r.CmdLine = append(r.CmdLine, "-verbose")
|
2020-11-05 11:33:32 +00:00
|
|
|
ci.LogLevel = fs.LogLevelDebug
|
2018-09-29 13:48:29 +00:00
|
|
|
}
|
|
|
|
if *runOnly != "" {
|
2020-08-20 11:23:33 +00:00
|
|
|
r.CmdLine = append(r.CmdLine, prefix+"run", *runOnly)
|
2018-09-29 13:48:29 +00:00
|
|
|
}
|
|
|
|
if r.FastList {
|
2020-08-20 11:23:33 +00:00
|
|
|
r.CmdLine = append(r.CmdLine, "-fast-list")
|
2018-09-29 13:48:29 +00:00
|
|
|
}
|
2019-08-29 05:10:10 +00:00
|
|
|
if r.Short {
|
2020-08-20 11:23:33 +00:00
|
|
|
r.CmdLine = append(r.CmdLine, "-short")
|
2019-08-29 05:10:10 +00:00
|
|
|
}
|
2019-09-16 17:52:41 +00:00
|
|
|
if r.SizeLimit > 0 {
|
2020-08-20 11:23:33 +00:00
|
|
|
r.CmdLine = append(r.CmdLine, "-size-limit", strconv.FormatInt(r.SizeLimit, 10))
|
2019-09-16 17:52:41 +00:00
|
|
|
}
|
2020-08-20 11:23:33 +00:00
|
|
|
r.CmdString = toShell(r.CmdLine)
|
2018-09-29 13:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Logs returns all the log names
|
|
|
|
func (r *Run) Logs() []string {
|
2020-08-20 11:23:33 +00:00
|
|
|
return r.TrialNames
|
2018-09-29 13:48:29 +00:00
|
|
|
}
|
|
|
|
|
2020-08-20 11:23:33 +00:00
|
|
|
// FailedTestsCSV returns the failed tests as a comma separated string, limiting the number
|
|
|
|
func (r *Run) FailedTestsCSV() string {
|
2018-09-29 13:48:29 +00:00
|
|
|
const maxTests = 5
|
2020-08-20 11:23:33 +00:00
|
|
|
ts := r.FailedTests
|
2018-09-29 13:48:29 +00:00
|
|
|
if len(ts) > maxTests {
|
|
|
|
ts = ts[:maxTests:maxTests]
|
2020-08-20 11:23:33 +00:00
|
|
|
ts = append(ts, fmt.Sprintf("… (%d more)", len(r.FailedTests)-maxTests))
|
2018-09-29 13:48:29 +00:00
|
|
|
}
|
|
|
|
return strings.Join(ts, ", ")
|
|
|
|
}
|
|
|
|
|
|
|
|
// Run runs all the trials for this test
|
2020-08-20 11:23:33 +00:00
|
|
|
func (r *Run) Run(LogDir string, result chan<- *Run) {
|
2018-10-23 10:44:56 +00:00
|
|
|
if r.OneOnly {
|
|
|
|
oneOnlyMu.Lock()
|
|
|
|
mu := oneOnly[r.Backend]
|
|
|
|
if mu == nil {
|
|
|
|
mu = new(sync.Mutex)
|
|
|
|
oneOnly[r.Backend] = mu
|
|
|
|
}
|
|
|
|
oneOnlyMu.Unlock()
|
|
|
|
mu.Lock()
|
|
|
|
defer mu.Unlock()
|
|
|
|
}
|
2018-09-29 13:48:29 +00:00
|
|
|
r.Init()
|
2020-08-20 11:23:33 +00:00
|
|
|
r.LogDir = LogDir
|
|
|
|
for r.Try = 1; r.Try <= *maxTries; r.Try++ {
|
|
|
|
r.TrialName = r.Name() + ".txt"
|
|
|
|
r.TrialNames = append(r.TrialNames, r.TrialName)
|
2024-08-18 14:58:35 +00:00
|
|
|
fs.Logf(nil, "Starting run with log %q", r.TrialName)
|
2018-09-29 13:48:29 +00:00
|
|
|
r.trial()
|
|
|
|
if r.passed() || r.NoRetries {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if !r.passed() {
|
|
|
|
r.dumpOutput()
|
|
|
|
}
|
|
|
|
result <- r
|
|
|
|
}
|