Commit 0f84afe2 authored by Brad Fitzpatrick's avatar Brad Fitzpatrick

cmd/dist: add flag to build tests only, but not run them

To speed up the ssacheck check builder and make it on by default as a
trybot.

Change-Id: I91a3347491507c84f4878dff744ca426ba3e2e9f
Reviewed-on: https://go-review.googlesource.com/22755
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: 's avatarAndrew Gerrand <adg@golang.org>
parent 43d2a10e
......@@ -28,6 +28,7 @@ func cmdtest() {
flag.BoolVar(&noRebuild, "no-rebuild", false, "overrides -rebuild (historical dreg)")
flag.BoolVar(&t.keepGoing, "k", false, "keep going even when error occurred")
flag.BoolVar(&t.race, "race", false, "run in race builder mode (different set of tests)")
flag.BoolVar(&t.compileOnly, "compile-only", false, "compile tests, but don't run them. This is for some builders. Not all dist tests respect this flag, but most do.")
flag.StringVar(&t.banner, "banner", "##### ", "banner prefix; blank means no section banners")
flag.StringVar(&t.runRxStr, "run", os.Getenv("GOTESTONLY"),
"run only those tests matching the regular expression; empty means to run all. "+
......@@ -46,6 +47,7 @@ type tester struct {
rebuild bool
failed bool
keepGoing bool
compileOnly bool // just try to compile all tests, but no need to run
runRxStr string
runRx *regexp.Regexp
runRxWant bool // want runRx to match (true) or not match (false)
......@@ -279,6 +281,9 @@ func (t *tester) registerStdTest(pkg string) {
if t.race {
args = append(args, "-race")
}
if t.compileOnly {
args = append(args, "-run=^$")
}
args = append(args, stdMatches...)
cmd := exec.Command("go", args...)
cmd.Stdout = os.Stdout
......@@ -307,10 +312,12 @@ func (t *tester) registerRaceBenchTest(pkg string) {
"-short",
"-race",
"-run=^$", // nothing. only benchmarks.
"-bench=.*",
"-benchtime=.1s",
"-cpu=4",
}
if !t.compileOnly {
args = append(args, "-bench=.*")
}
args = append(args, benchMatches...)
cmd := exec.Command("go", args...)
cmd.Stdout = os.Stdout
......@@ -364,18 +371,20 @@ func (t *tester) registerTests() {
}
// Runtime CPU tests.
testName := "runtime:cpu124"
t.tests = append(t.tests, distTest{
name: testName,
heading: "GOMAXPROCS=2 runtime -cpu=1,2,4",
fn: func(dt *distTest) error {
cmd := t.addCmd(dt, "src", "go", "test", "-short", t.timeout(300), t.tags(), "runtime", "-cpu=1,2,4")
// We set GOMAXPROCS=2 in addition to -cpu=1,2,4 in order to test runtime bootstrap code,
// creation of first goroutines and first garbage collections in the parallel setting.
cmd.Env = mergeEnvLists([]string{"GOMAXPROCS=2"}, os.Environ())
return nil
},
})
if !t.compileOnly {
testName := "runtime:cpu124"
t.tests = append(t.tests, distTest{
name: testName,
heading: "GOMAXPROCS=2 runtime -cpu=1,2,4",
fn: func(dt *distTest) error {
cmd := t.addCmd(dt, "src", "go", "test", "-short", t.timeout(300), t.tags(), "runtime", "-cpu=1,2,4")
// We set GOMAXPROCS=2 in addition to -cpu=1,2,4 in order to test runtime bootstrap code,
// creation of first goroutines and first garbage collections in the parallel setting.
cmd.Env = mergeEnvLists([]string{"GOMAXPROCS=2"}, os.Environ())
return nil
},
})
}
// Test that internal linking of standard packages does not
// require libgcc. This ensures that we can install a Go
......@@ -407,7 +416,7 @@ func (t *tester) registerTests() {
name: "nolibgcc:" + pkg,
heading: "Testing without libgcc.",
fn: func(dt *distTest) error {
t.addCmd(dt, "src", "go", "test", "-short", "-ldflags=-linkmode=internal -libgcc=none", t.tags(), pkg, "-run="+run)
t.addCmd(dt, "src", "go", "test", "-short", "-ldflags=-linkmode=internal -libgcc=none", t.tags(), pkg, t.runFlag(run))
return nil
},
})
......@@ -418,7 +427,7 @@ func (t *tester) registerTests() {
name: "sync_cpu",
heading: "sync -cpu=10",
fn: func(dt *distTest) error {
t.addCmd(dt, "src", "go", "test", "sync", "-short", t.timeout(120), t.tags(), "-cpu=10")
t.addCmd(dt, "src", "go", "test", "sync", "-short", t.timeout(120), t.tags(), "-cpu=10", t.runFlag(""))
return nil
},
})
......@@ -528,7 +537,7 @@ func (t *tester) registerTests() {
}
if t.goos != "android" && !t.iOS() {
t.registerTest("bench_go1", "../test/bench/go1", "go", "test", t.timeout(600))
t.registerTest("bench_go1", "../test/bench/go1", "go", "test", t.timeout(600), t.runFlag(""))
}
if t.goos != "android" && !t.iOS() {
const nShards = 5
......@@ -546,6 +555,10 @@ func (t *tester) registerTests() {
name: "api",
heading: "API check",
fn: func(dt *distTest) error {
if t.compileOnly {
t.addCmd(dt, "src", "go", "build", filepath.Join(t.goroot, "src/cmd/api/run.go"))
return nil
}
t.addCmd(dt, "src", "go", "run", filepath.Join(t.goroot, "src/cmd/api/run.go"))
return nil
},
......@@ -722,14 +735,14 @@ func (t *tester) cgoTest(dt *distTest) error {
return cmd.Run()
}
cmd := t.addCmd(dt, "misc/cgo/test", "go", "test", t.tags(), "-ldflags", "-linkmode=auto")
cmd := t.addCmd(dt, "misc/cgo/test", "go", "test", t.tags(), "-ldflags", "-linkmode=auto", t.runFlag(""))
cmd.Env = env
if t.gohostos != "dragonfly" && t.gohostarch != "ppc64le" {
// linkmode=internal fails on dragonfly since errno is a TLS relocation.
// linkmode=internal fails on ppc64le because cmd/link doesn't
// handle the TOC correctly (issue 15409).
cmd := t.addCmd(dt, "misc/cgo/test", "go", "test", "-ldflags", "-linkmode=internal")
cmd := t.addCmd(dt, "misc/cgo/test", "go", "test", "-ldflags", "-linkmode=internal", t.runFlag(""))
cmd.Env = env
}
......@@ -981,10 +994,17 @@ func (t *tester) raceDetectorSupported() bool {
return false
}
func (t *tester) runFlag(rx string) string {
if t.compileOnly {
return "-run=^$"
}
return "-run=" + rx
}
func (t *tester) raceTest(dt *distTest) error {
t.addCmd(dt, "src", "go", "test", "-race", "-i", "runtime/race", "flag", "os/exec")
t.addCmd(dt, "src", "go", "test", "-race", "-run=Output", "runtime/race")
t.addCmd(dt, "src", "go", "test", "-race", "-short", "-run=TestParse|TestEcho", "flag", "os/exec")
t.addCmd(dt, "src", "go", "test", "-race", t.runFlag("Output"), "runtime/race")
t.addCmd(dt, "src", "go", "test", "-race", "-short", t.runFlag("TestParse|TestEcho"), "flag", "os/exec")
// We don't want the following line, because it
// slows down all.bash (by 10 seconds on my laptop).
// The race builder should catch any error here, but doesn't.
......@@ -992,12 +1012,12 @@ func (t *tester) raceTest(dt *distTest) error {
// t.addCmd(dt, "src", "go", "test", "-race", "-run=TestParallelTest", "cmd/go")
if t.cgoEnabled {
env := mergeEnvLists([]string{"GOTRACEBACK=2"}, os.Environ())
cmd := t.addCmd(dt, "misc/cgo/test", "go", "test", "-race", "-short")
cmd := t.addCmd(dt, "misc/cgo/test", "go", "test", "-race", "-short", t.runFlag(""))
cmd.Env = env
}
if t.extLink() {
// Test with external linking; see issue 9133.
t.addCmd(dt, "src", "go", "test", "-race", "-short", "-ldflags=-linkmode=external", "-run=TestParse|TestEcho", "flag", "os/exec")
t.addCmd(dt, "src", "go", "test", "-race", "-short", "-ldflags=-linkmode=external", t.runFlag("TestParse|TestEcho"), "flag", "os/exec")
}
return nil
}
......@@ -1025,7 +1045,9 @@ func (t *tester) testDirTest(dt *distTest, shard, shards int) error {
if runtest.err != nil {
return runtest.err
}
if t.compileOnly {
return nil
}
t.addCmd(dt, "test", runtest.exe,
fmt.Sprintf("--shard=%d", shard),
fmt.Sprintf("--shards=%d", shards),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment