]> Cypherpunks repositories - gostls13.git/commitdiff
runtime, runtime/debug, runtime/race: deflake tests
authorAlbert Strasheim <fullung@gmail.com>
Sun, 7 Apr 2013 18:37:37 +0000 (11:37 -0700)
committerBrad Fitzpatrick <bradfitz@golang.org>
Sun, 7 Apr 2013 18:37:37 +0000 (11:37 -0700)
R=golang-dev, dvyukov, bradfitz
CC=golang-dev
https://golang.org/cl/8366044

src/pkg/runtime/crash_test.go
src/pkg/runtime/debug/garbage_test.go
src/pkg/runtime/race/race_test.go

index 80549a50549d594d1904f22e34c15d9909f2fe61..929d4a9636ba1cc8165b8b395530115a87069d1b 100644 (file)
@@ -14,6 +14,22 @@ import (
        "text/template"
 )
 
+// testEnv excludes GOGCTRACE from the environment
+// to prevent its output from breaking tests that
+// are trying to parse other command output.
+func testEnv(cmd *exec.Cmd) *exec.Cmd {
+       if cmd.Env != nil {
+               panic("environment already set")
+       }
+       for _, env := range os.Environ() {
+               if strings.HasPrefix(env, "GOGCTRACE=") {
+                       continue
+               }
+               cmd.Env = append(cmd.Env, env)
+       }
+       return cmd
+}
+
 func executeTest(t *testing.T, templ string, data interface{}) string {
        checkStaleRuntime(t)
 
@@ -37,13 +53,13 @@ func executeTest(t *testing.T, templ string, data interface{}) string {
        }
        f.Close()
 
-       got, _ := exec.Command("go", "run", src).CombinedOutput()
+       got, _ := testEnv(exec.Command("go", "run", src)).CombinedOutput()
        return string(got)
 }
 
 func checkStaleRuntime(t *testing.T) {
        // 'go run' uses the installed copy of runtime.a, which may be out of date.
-       out, err := exec.Command("go", "list", "-f", "{{.Stale}}", "runtime").CombinedOutput()
+       out, err := testEnv(exec.Command("go", "list", "-f", "{{.Stale}}", "runtime")).CombinedOutput()
        if err != nil {
                t.Fatalf("failed to execute 'go list': %v\n%v", err, string(out))
        }
index b93cfee56852f91c5e4dcf5d41465a1ea98f1392..149bafc6f3c106e375d6af17121e31fc8ce97563 100644 (file)
@@ -11,6 +11,8 @@ import (
 )
 
 func TestReadGCStats(t *testing.T) {
+       defer SetGCPercent(SetGCPercent(-1))
+
        var stats GCStats
        var mstats runtime.MemStats
        var min, max time.Duration
index c77569c37f48a1e1390bdd45000feeba78b7e718..47d34d7ad9c9f462d63fb3bde059a5df3777bc99 100644 (file)
@@ -147,7 +147,7 @@ func runTests() ([]byte, error) {
        // It is required because the tests contain a lot of data races on the same addresses
        // (the tests are simple and the memory is constantly reused).
        for _, env := range os.Environ() {
-               if strings.HasPrefix(env, "GOMAXPROCS=") {
+               if strings.HasPrefix(env, "GOMAXPROCS=") || strings.HasPrefix(env, "GOGCTRACE=") {
                        continue
                }
                cmd.Env = append(cmd.Env, env)