From ae60636ab14e1bd49a8e5d818a5da8a526e59969 Mon Sep 17 00:00:00 2001 From: Austin Clements Date: Wed, 9 Feb 2022 09:38:01 -0500 Subject: [PATCH] cmd/dist: drop support for pre-compiled test binaries We haven't used this in a while and it's going to complicate later changes to dist, so drop support. This was primarily for supporting slow QEMU-based builders, but an alternative and simpler way to do that if we need to in the future is to supply a go_exec wrapper to run tests in QEMU, like we do for other emulated platforms. Simplification for #37486. Change-Id: Idc0383f59c61d8546ea3b4d2eede4acdaf30d9b6 Reviewed-on: https://go-review.googlesource.com/c/go/+/431256 TryBot-Result: Gopher Robot Auto-Submit: Austin Clements Reviewed-by: Bryan Mills Run-TryBot: Austin Clements --- src/cmd/dist/test.go | 60 -------------------------------------------- 1 file changed, 60 deletions(-) diff --git a/src/cmd/dist/test.go b/src/cmd/dist/test.go index 54eb41c8a4..5b8676c4c7 100644 --- a/src/cmd/dist/test.go +++ b/src/cmd/dist/test.go @@ -11,7 +11,6 @@ import ( "log" "os" "os/exec" - "path" "path/filepath" "reflect" "regexp" @@ -390,11 +389,6 @@ func (t *tester) registerStdTest(pkg string) { break } } - // Special case for our slow cross-compiled - // qemu builders: - if t.shouldUsePrecompiledStdTest() { - return t.runPrecompiledStdTest(t.timeoutDuration(timeoutSec)) - } args := []string{ "test", "-short=" + short(), @@ -1657,60 +1651,6 @@ func (t *tester) makeGOROOTUnwritable() (undo func()) { return undo } -// shouldUsePrecompiledStdTest reports whether "dist test" should use -// a pre-compiled go test binary on disk rather than running "go test" -// and compiling it again. This is used by our slow qemu-based builder -// that do full processor emulation where we cross-compile the -// make.bash step as well as pre-compile each std test binary. -// -// This only reports true if dist is run with an single go_test:foo -// argument (as the build coordinator does with our slow qemu-based -// builders), we're in a builder environment ("GO_BUILDER_NAME" is set), -// and the pre-built test binary exists. -func (t *tester) shouldUsePrecompiledStdTest() bool { - bin := t.prebuiltGoPackageTestBinary() - if bin == "" { - return false - } - _, err := os.Stat(bin) - return err == nil -} - -// prebuiltGoPackageTestBinary returns the path where we'd expect -// the pre-built go test binary to be on disk when dist test is run with -// a single argument. -// It returns an empty string if a pre-built binary should not be used. -func (t *tester) prebuiltGoPackageTestBinary() string { - if len(stdMatches) != 1 || t.race || t.compileOnly || os.Getenv("GO_BUILDER_NAME") == "" { - return "" - } - pkg := stdMatches[0] - return filepath.Join(os.Getenv("GOROOT"), "src", pkg, path.Base(pkg)+".test") -} - -// runPrecompiledStdTest runs the pre-compiled standard library package test binary. -// See shouldUsePrecompiledStdTest above; it must return true for this to be called. -func (t *tester) runPrecompiledStdTest(timeout time.Duration) error { - bin := t.prebuiltGoPackageTestBinary() - fmt.Fprintf(os.Stderr, "# %s: using pre-built %s...\n", stdMatches[0], bin) - cmd := exec.Command(bin, "-test.short="+short(), "-test.timeout="+timeout.String()) - setDir(cmd, filepath.Dir(bin)) - cmd.Stdout = os.Stdout - cmd.Stderr = os.Stderr - if err := cmd.Start(); err != nil { - return err - } - // And start a timer to kill the process if it doesn't kill - // itself in the prescribed timeout. - const backupKillFactor = 1.05 // add 5% - timer := time.AfterFunc(time.Duration(float64(timeout)*backupKillFactor), func() { - fmt.Fprintf(os.Stderr, "# %s: timeout running %s; killing...\n", stdMatches[0], bin) - cmd.Process.Kill() - }) - defer timer.Stop() - return cmd.Wait() -} - // raceDetectorSupported is a copy of the function // internal/platform.RaceDetectorSupported, which can't be used here // because cmd/dist has to be buildable by Go 1.4. -- 2.50.0