diff options
| author | Dmitri Shuralyov <dmitshur@golang.org> | 2023-02-08 11:40:06 -0500 |
|---|---|---|
| committer | Gopher Robot <gobot@golang.org> | 2023-02-28 01:11:37 +0000 |
| commit | 7a0799b2c0bdfaf745dbd8c74a3db2f3d238fd1b (patch) | |
| tree | 873ad764e00d3aee2212539cb04411401b9bf208 /src/cmd/dist | |
| parent | 01f5a17aa3b99af34ad7c914657fc7345fe562fe (diff) | |
| download | go-7a0799b2c0bdfaf745dbd8c74a3db2f3d238fd1b.tar.xz | |
cmd/dist, test: convert test/run.go runner to a cmd/go test
As motivated on the issue, we want to move the functionality of the
run.go program to happen via a normal go test. Each .go test case in
the GOROOT/test directory gets a subtest, and cmd/go's support for
parallel test execution replaces run.go's own implementation thereof.
The goal of this change is to have fairly minimal and readable diff
while making an atomic changeover. The working directory is modified
during the test execution to be GOROOT/test as it was with run.go,
and most of the test struct and its run method are kept unchanged.
The next CL in the stack applies further simplifications and cleanups
that become viable.
There's no noticeable difference in test execution time: it takes around
60-80 seconds both before and after on my machine. Test caching, which
the previous runner lacked, can shorten the time significantly.
For #37486.
Fixes #56844.
Change-Id: I209619dc9d90e7529624e49c01efeadfbeb5c9ae
Reviewed-on: https://go-review.googlesource.com/c/go/+/463276
Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Austin Clements <austin@google.com>
Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Diffstat (limited to 'src/cmd/dist')
| -rw-r--r-- | src/cmd/dist/test.go | 66 |
1 files changed, 21 insertions, 45 deletions
diff --git a/src/cmd/dist/test.go b/src/cmd/dist/test.go index bc58f0936b..a906c0dbdb 100644 --- a/src/cmd/dist/test.go +++ b/src/cmd/dist/test.go @@ -18,7 +18,6 @@ import ( "runtime" "strconv" "strings" - "sync" "time" ) @@ -594,6 +593,12 @@ func (t *tester) registerRaceBenchTest(pkg string) { } func (t *tester) registerTests() { + // registerStdTestSpecially tracks import paths in the standard library + // whose test registration happens in a special way. + registerStdTestSpecially := map[string]bool{ + "internal/testdir": true, // Registered at the bottom with sharding. + } + // Fast path to avoid the ~1 second of `go list std cmd` when // the caller lists specific tests to run. (as the continuous // build coordinator does). @@ -621,10 +626,16 @@ func (t *tester) registerTests() { } pkgs := strings.Fields(string(all)) for _, pkg := range pkgs { + if registerStdTestSpecially[pkg] { + continue + } t.registerStdTest(pkg) } if t.race { for _, pkg := range pkgs { + if registerStdTestSpecially[pkg] { + continue + } if t.packageHasBenchmarks(pkg) { t.registerRaceBenchTest(pkg) } @@ -907,12 +918,15 @@ func (t *tester) registerTests() { nShards = n } for shard := 0; shard < nShards; shard++ { - shard := shard - t.tests = append(t.tests, distTest{ - name: fmt.Sprintf("test:%d_%d", shard, nShards), - heading: "../test", - fn: func(dt *distTest) error { return t.testDirTest(dt, shard, nShards) }, - }) + t.registerTest( + fmt.Sprintf("test:%d_%d", shard, nShards), + "../test", + &goTest{ + dir: "internal/testdir", + testFlags: []string{fmt.Sprintf("-shard=%d", shard), fmt.Sprintf("-shards=%d", nShards)}, + }, + rtHostTest{}, + ) } } // Only run the API check on fast development platforms. @@ -1514,44 +1528,6 @@ func (t *tester) registerRaceTests() { } } -var runtest struct { - sync.Once - exe string - err error -} - -func (t *tester) testDirTest(dt *distTest, shard, shards int) error { - runtest.Do(func() { - f, err := os.CreateTemp("", "runtest-*.exe") // named exe for Windows, but harmless elsewhere - if err != nil { - runtest.err = err - return - } - f.Close() - - runtest.exe = f.Name() - xatexit(func() { - os.Remove(runtest.exe) - }) - - cmd := t.dirCmd("test", gorootBinGo, "build", "-o", runtest.exe, "run.go") - setEnv(cmd, "GOOS", gohostos) - setEnv(cmd, "GOARCH", gohostarch) - runtest.err = cmd.Run() - }) - 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), - ) - return nil -} - // cgoPackages is the standard packages that use cgo. var cgoPackages = []string{ "net", |
