]> Cypherpunks repositories - gostls13.git/commitdiff
all: respect $GO_GCFLAGS during run.bash
authorRuss Cox <rsc@golang.org>
Mon, 30 Oct 2017 19:28:11 +0000 (15:28 -0400)
committerRuss Cox <rsc@golang.org>
Tue, 31 Oct 2017 13:19:15 +0000 (13:19 +0000)
If the go install doesn't use the same flags as the main build
it can overwrite the installed standard library, leading to
flakiness and slow future tests.

Force uses of 'go install' etc to propagate $GO_GCFLAGS
or disable them entirely, to avoid problems.

As I understand it, the main place this happens is the ssacheck builder.
If there are other uses that need to run some of the now-disabled
tests we can reenable fixed tests in followup CLs.

Change-Id: Ib860a253539f402f8a96a3c00ec34f0bbf137c9a
Reviewed-on: https://go-review.googlesource.com/74470
Reviewed-by: David Crawshaw <crawshaw@golang.org>
src/cmd/dist/test.go
src/cmd/go/go_test.go
src/cmd/internal/goobj/goobj_test.go
src/internal/testenv/testenv.go
src/runtime/crash_test.go
test/run.go

index 3bbeb76e4da1b02423c3fb0c0b0c5452186e066a..3cf88eb0c68b3bf189950a1114fd8d9612f3643b 100644 (file)
@@ -578,7 +578,12 @@ func (t *tester) registerTests() {
        if t.hasBash() && t.cgoEnabled && goos != "android" && goos != "darwin" {
                t.registerTest("testgodefs", "../misc/cgo/testgodefs", "./test.bash")
        }
-       if t.cgoEnabled {
+
+       // Don't run these tests with $GO_GCFLAGS because most of them
+       // assume that they can run "go install" with no -gcflags and not
+       // recompile the entire standard library. If make.bash ran with
+       // special -gcflags, that's not true.
+       if t.cgoEnabled && gogcflags == "" {
                if t.cgoTestSOSupported() {
                        t.tests = append(t.tests, distTest{
                                name:    "testso",
index a51d58a9683bb6eccf0ea72559ef33865fb206bf..14ee51c9061a8e5ce5acc024c51613b26de26ae9 100644 (file)
@@ -86,6 +86,13 @@ var testCC string
 // The TestMain function creates a go command for testing purposes and
 // deletes it after the tests have been run.
 func TestMain(m *testing.M) {
+       if os.Getenv("GO_GCFLAGS") != "" {
+               fmt.Fprintf(os.Stderr, "testing: warning: no tests to run\n") // magic string for cmd/go
+               fmt.Printf("cmd/go test is not compatible with $GO_GCFLAGS being set\n")
+               fmt.Printf("SKIP\n")
+               return
+       }
+
        if canRun {
                args := []string{"build", "-tags", "testgo", "-o", "testgo" + exeSuffix}
                if race.Enabled {
index e5f4dd938517683ab148fed7b4daad101c43cf58..92c2bf981927804359c108f48ef040211e4f7cbf 100644 (file)
@@ -133,7 +133,7 @@ func buildGoobj() error {
                if err != nil {
                        return err
                }
-               cmd := exec.Command(gotool, "install", "mycgo")
+               cmd := exec.Command(gotool, "install", "-gcflags="+os.Getenv("GO_GCFLAGS"), "mycgo")
                cmd.Env = append(os.Environ(), "GOPATH="+gopath)
                out, err = cmd.CombinedOutput()
                if err != nil {
index 88c93bfe70149a627782986b7ef13bcf2a714616..83f0e8347a1ce907074518c28ed3b2bbe97a6260 100644 (file)
@@ -33,6 +33,13 @@ func Builder() string {
 // HasGoBuild reports whether the current system can build programs with ``go build''
 // and then run them with os.StartProcess or exec.Command.
 func HasGoBuild() bool {
+       if os.Getenv("GO_GCFLAGS") != "" {
+               // It's too much work to require every caller of the go command
+               // to pass along "-gcflags="+os.Getenv("GO_GCFLAGS").
+               // For now, if $GO_GCFLAGS is set, report that we simply can't
+               // run go build.
+               return false
+       }
        switch runtime.GOOS {
        case "android", "nacl":
                return false
@@ -48,6 +55,9 @@ func HasGoBuild() bool {
 // and then run them with os.StartProcess or exec.Command.
 // If not, MustHaveGoBuild calls t.Skip with an explanation.
 func MustHaveGoBuild(t testing.TB) {
+       if os.Getenv("GO_GCFLAGS") != "" {
+               t.Skipf("skipping test: 'go build' not compatible with setting $GO_GCFLAGS")
+       }
        if !HasGoBuild() {
                t.Skipf("skipping test: 'go build' not available on %s/%s", runtime.GOOS, runtime.GOARCH)
        }
index 0f11150f181648b2915c574daafea3ecb99006a3..80ae4fa63e0e344ba6400fa557e129bf212f2064 100644 (file)
@@ -140,14 +140,14 @@ var (
 func checkStaleRuntime(t *testing.T) {
        staleRuntimeOnce.Do(func() {
                // 'go run' uses the installed copy of runtime.a, which may be out of date.
-               out, err := testenv.CleanCmdEnv(exec.Command(testenv.GoToolPath(t), "list", "-f", "{{.Stale}}", "runtime")).CombinedOutput()
+               out, err := testenv.CleanCmdEnv(exec.Command(testenv.GoToolPath(t), "list", "-gcflags="+os.Getenv("GO_GCFLAGS"), "-f", "{{.Stale}}", "runtime")).CombinedOutput()
                if err != nil {
                        staleRuntimeErr = fmt.Errorf("failed to execute 'go list': %v\n%v", err, string(out))
                        return
                }
                if string(out) != "false\n" {
                        t.Logf("go list -f {{.Stale}} runtime:\n%s", out)
-                       out, err := testenv.CleanCmdEnv(exec.Command(testenv.GoToolPath(t), "list", "-f", "{{.StaleReason}}", "runtime")).CombinedOutput()
+                       out, err := testenv.CleanCmdEnv(exec.Command(testenv.GoToolPath(t), "list", "-gcflags="+os.Getenv("GO_GCFLAGS"), "-f", "{{.StaleReason}}", "runtime")).CombinedOutput()
                        if err != nil {
                                t.Logf("go list -f {{.StaleReason}} failed: %v", err)
                        }
index 2fa206746bee56c0e102e43f30c0b1d4b08d8ddf..921a8ee33200f1720f7431ecf636c9f4f101b46e 100644 (file)
@@ -417,6 +417,14 @@ func (ctxt *context) match(name string) bool {
 
 func init() { checkShouldTest() }
 
+// goGcflags returns the -gcflags argument to use with go build / go run.
+// This must match the flags used for building the standard libary,
+// or else the commands will rebuild any needed packages (like runtime)
+// over and over.
+func goGcflags() string {
+       return "-gcflags=" + os.Getenv("GO_GCFLAGS")
+}
+
 // run runs a test.
 func (t *test) run() {
        start := time.Now()
@@ -701,7 +709,7 @@ func (t *test) run() {
                }
 
        case "build":
-               _, err := runcmd("go", "build", "-o", "a.exe", long)
+               _, err := runcmd("go", "build", goGcflags(), "-o", "a.exe", long)
                if err != nil {
                        t.err = err
                }
@@ -766,7 +774,7 @@ func (t *test) run() {
        case "buildrun": // build binary, then run binary, instead of go run. Useful for timeout tests where failure mode is infinite loop.
                // TODO: not supported on NaCl
                useTmp = true
-               cmd := []string{"go", "build", "-o", "a.exe"}
+               cmd := []string{"go", "build", goGcflags(), "-o", "a.exe"}
                if *linkshared {
                        cmd = append(cmd, "-linkshared")
                }
@@ -791,7 +799,7 @@ func (t *test) run() {
 
        case "run":
                useTmp = false
-               cmd := []string{"go", "run"}
+               cmd := []string{"go", "run", goGcflags()}
                if *linkshared {
                        cmd = append(cmd, "-linkshared")
                }
@@ -812,7 +820,7 @@ func (t *test) run() {
                        <-rungatec
                }()
                useTmp = false
-               cmd := []string{"go", "run"}
+               cmd := []string{"go", "run", goGcflags()}
                if *linkshared {
                        cmd = append(cmd, "-linkshared")
                }
@@ -827,7 +835,7 @@ func (t *test) run() {
                        t.err = fmt.Errorf("write tempfile:%s", err)
                        return
                }
-               cmd = []string{"go", "run"}
+               cmd = []string{"go", "run", goGcflags()}
                if *linkshared {
                        cmd = append(cmd, "-linkshared")
                }
@@ -843,7 +851,7 @@ func (t *test) run() {
 
        case "errorcheckoutput":
                useTmp = false
-               cmd := []string{"go", "run"}
+               cmd := []string{"go", "run", goGcflags()}
                if *linkshared {
                        cmd = append(cmd, "-linkshared")
                }