]> Cypherpunks repositories - gostls13.git/commitdiff
runtime/race: install alternate packages to temp dir
authorRuss Cox <rsc@golang.org>
Fri, 27 Oct 2017 17:45:50 +0000 (13:45 -0400)
committerRuss Cox <rsc@golang.org>
Tue, 31 Oct 2017 13:20:41 +0000 (13:20 +0000)
The content-based staleness code means that

go run -gcflags=-l helloworld.go

recompiles all of helloworld.go's dependencies with -gcflags=-l,
whereas before it would have assumed installed packages were
up-to-date. In this test, that means every race iteration rebuilds
the runtime and maybe a few other packages. Instead, install them
to a temporary location for reuse.

This speeds the test from 17s to 9s on my MacBook Pro.

Change-Id: Ied136ce72650261083bb19cc7dee38dac0ad05ca
Reviewed-on: https://go-review.googlesource.com/73992
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/runtime/race/output_test.go

index 13dfc33b477b0cee05cc9eab13cda38e0ac885d1..f5b6fea43e48ea392cfcaa4bddf61f5d01571fdf 100644 (file)
@@ -19,6 +19,16 @@ import (
 )
 
 func TestOutput(t *testing.T) {
+       pkgdir, err := ioutil.TempDir("", "go-build-race-output")
+       if err != nil {
+               t.Fatal(err)
+       }
+       defer os.RemoveAll(pkgdir)
+       out, err := exec.Command(testenv.GoToolPath(t), "install", "-race", "-pkgdir="+pkgdir, "-gcflags=-l", "testing").CombinedOutput()
+       if err != nil {
+               t.Fatalf("go install -race: %v\n%s", err, out)
+       }
+
        for _, test := range tests {
                if test.goos != "" && test.goos != runtime.GOOS {
                        t.Logf("test %v runs only on %v, skipping: ", test.name, test.goos)
@@ -47,7 +57,7 @@ func TestOutput(t *testing.T) {
                        t.Fatalf("failed to close file: %v", err)
                }
                // Pass -l to the compiler to test stack traces.
-               cmd := exec.Command(testenv.GoToolPath(t), test.run, "-race", "-gcflags=-l", src)
+               cmd := exec.Command(testenv.GoToolPath(t), test.run, "-race", "-pkgdir="+pkgdir, "-gcflags=-l", src)
                // GODEBUG spoils program output, GOMAXPROCS makes it flaky.
                for _, env := range os.Environ() {
                        if strings.HasPrefix(env, "GODEBUG=") ||