mirror of https://github.com/golang/go.git
cmd/dist: make registerTest take a goTest
The overall goal is to make registerTest the primary entry point for adding dist tests and to convert nearly all dist tests to be represented by a goTest, registered via registerTest. This will centralize the logic for creating dist tests corresponding to go tool tests. I traced all exec calls from cmd/dist on linux/amd64 and this makes only no-op changes (such as re-arranging the order of flags). For #37486. Change-Id: I4749e6f3666134d3259b54ee6055d76a4235c60c Reviewed-on: https://go-review.googlesource.com/c/go/+/450016 Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Run-TryBot: Austin Clements <austin@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
This commit is contained in:
parent
2946c887ba
commit
135770abea
|
|
@ -909,8 +909,8 @@ func (t *tester) registerTests() {
|
||||||
if t.cgoEnabled && gogcflags == "" {
|
if t.cgoEnabled && gogcflags == "" {
|
||||||
t.registerHostTest("testgodefs", "../misc/cgo/testgodefs", "misc/cgo/testgodefs", ".")
|
t.registerHostTest("testgodefs", "../misc/cgo/testgodefs", "misc/cgo/testgodefs", ".")
|
||||||
|
|
||||||
t.registerTest("testso", "../misc/cgo/testso", t.goTest(), t.timeout(600), ".")
|
t.registerTest("testso", "", &goTest{dir: "../misc/cgo/testso", timeout: 600 * time.Second})
|
||||||
t.registerTest("testsovar", "../misc/cgo/testsovar", t.goTest(), t.timeout(600), ".")
|
t.registerTest("testsovar", "", &goTest{dir: "../misc/cgo/testsovar", timeout: 600 * time.Second})
|
||||||
if t.supportedBuildmode("c-archive") {
|
if t.supportedBuildmode("c-archive") {
|
||||||
t.registerHostTest("testcarchive", "../misc/cgo/testcarchive", "misc/cgo/testcarchive", ".")
|
t.registerHostTest("testcarchive", "../misc/cgo/testcarchive", "misc/cgo/testcarchive", ".")
|
||||||
}
|
}
|
||||||
|
|
@ -918,10 +918,10 @@ func (t *tester) registerTests() {
|
||||||
t.registerHostTest("testcshared", "../misc/cgo/testcshared", "misc/cgo/testcshared", ".")
|
t.registerHostTest("testcshared", "../misc/cgo/testcshared", "misc/cgo/testcshared", ".")
|
||||||
}
|
}
|
||||||
if t.supportedBuildmode("shared") {
|
if t.supportedBuildmode("shared") {
|
||||||
t.registerTest("testshared", "../misc/cgo/testshared", t.goTest(), t.timeout(600), ".")
|
t.registerTest("testshared", "", &goTest{dir: "../misc/cgo/testshared", timeout: 600 * time.Second})
|
||||||
}
|
}
|
||||||
if t.supportedBuildmode("plugin") {
|
if t.supportedBuildmode("plugin") {
|
||||||
t.registerTest("testplugin", "../misc/cgo/testplugin", t.goTest(), t.timeout(600), ".")
|
t.registerTest("testplugin", "", &goTest{dir: "../misc/cgo/testplugin", timeout: 600 * time.Second})
|
||||||
}
|
}
|
||||||
if goos == "linux" || (goos == "freebsd" && goarch == "amd64") {
|
if goos == "linux" || (goos == "freebsd" && goarch == "amd64") {
|
||||||
// because Pdeathsig of syscall.SysProcAttr struct used in misc/cgo/testsanitizers is only
|
// because Pdeathsig of syscall.SysProcAttr struct used in misc/cgo/testsanitizers is only
|
||||||
|
|
@ -936,7 +936,7 @@ func (t *tester) registerTests() {
|
||||||
if goos != "android" && !t.iOS() {
|
if goos != "android" && !t.iOS() {
|
||||||
// There are no tests in this directory, only benchmarks.
|
// There are no tests in this directory, only benchmarks.
|
||||||
// Check that the test binary builds.
|
// Check that the test binary builds.
|
||||||
t.registerTest("bench_go1", "../test/bench/go1", t.goTest(), ".")
|
t.registerTest("bench_go1", "", &goTest{dir: "../test/bench/go1"})
|
||||||
}
|
}
|
||||||
if goos != "android" && !t.iOS() {
|
if goos != "android" && !t.iOS() {
|
||||||
// Only start multiple test dir shards on builders,
|
// Only start multiple test dir shards on builders,
|
||||||
|
|
@ -996,16 +996,60 @@ func (t *tester) isRegisteredTestName(testName string) bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *tester) registerTest(name, dirBanner string, cmdline ...interface{}) {
|
type registerTestOpt interface {
|
||||||
bin, args := flattenCmdline(cmdline)
|
isRegisterTestOpt()
|
||||||
|
}
|
||||||
|
|
||||||
|
// rtSequential is a registerTest option that causes the registered test to run
|
||||||
|
// sequentially.
|
||||||
|
type rtSequential struct{}
|
||||||
|
|
||||||
|
func (rtSequential) isRegisterTestOpt() {}
|
||||||
|
|
||||||
|
// rtPreFunc is a registerTest option that runs a pre function before running
|
||||||
|
// the test.
|
||||||
|
type rtPreFunc struct {
|
||||||
|
pre func(*distTest) bool // Return false to skip the test
|
||||||
|
}
|
||||||
|
|
||||||
|
func (rtPreFunc) isRegisterTestOpt() {}
|
||||||
|
|
||||||
|
// registerTest registers a test that runs the given goTest.
|
||||||
|
//
|
||||||
|
// If heading is "", it uses test.dir as the heading.
|
||||||
|
func (t *tester) registerTest(name, heading string, test *goTest, opts ...registerTestOpt) {
|
||||||
|
seq := false
|
||||||
|
var preFunc func(*distTest) bool
|
||||||
|
for _, opt := range opts {
|
||||||
|
switch opt := opt.(type) {
|
||||||
|
case rtSequential:
|
||||||
|
seq = true
|
||||||
|
case rtPreFunc:
|
||||||
|
preFunc = opt.pre
|
||||||
|
}
|
||||||
|
}
|
||||||
if t.isRegisteredTestName(name) {
|
if t.isRegisteredTestName(name) {
|
||||||
panic("duplicate registered test name " + name)
|
panic("duplicate registered test name " + name)
|
||||||
}
|
}
|
||||||
|
if heading == "" {
|
||||||
|
heading = test.dir
|
||||||
|
}
|
||||||
t.tests = append(t.tests, distTest{
|
t.tests = append(t.tests, distTest{
|
||||||
name: name,
|
name: name,
|
||||||
heading: dirBanner,
|
heading: heading,
|
||||||
fn: func(dt *distTest) error {
|
fn: func(dt *distTest) error {
|
||||||
t.addCmd(dt, filepath.Join(goroot, "src", dirBanner), bin, args)
|
if preFunc != nil && !preFunc(dt) {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
if seq {
|
||||||
|
t.runPending(dt)
|
||||||
|
return test.run(t)
|
||||||
|
}
|
||||||
|
w := &work{
|
||||||
|
dt: dt,
|
||||||
|
cmd: test.bgCommand(t),
|
||||||
|
}
|
||||||
|
t.worklist = append(t.worklist, w)
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue