]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: move TestGcSys into a separate process
authorDmitriy Vyukov <dvyukov@google.com>
Sat, 2 Mar 2013 06:36:06 +0000 (08:36 +0200)
committerDmitriy Vyukov <dvyukov@google.com>
Sat, 2 Mar 2013 06:36:06 +0000 (08:36 +0200)
Fixes #4904.
The problem was that when the test runs the heap had grown to ~100MB,
so GC allows it to grow to 200MB, and so the test fails.
Moving the test to a separate process makes it much more isolated and stable.

R=golang-dev, minux.ma
CC=golang-dev
https://golang.org/cl/7441046

src/pkg/runtime/gc_test.go

index 0215ff2cf435059eb3a8da7dcc042a5c6decad83..e1e1b1d0154635286a8e0d2303a5a413245e6625 100644 (file)
@@ -14,7 +14,24 @@ func TestGcSys(t *testing.T) {
        if os.Getenv("GOGC") == "off" {
                t.Fatalf("GOGC=off in environment; test cannot pass")
        }
-       defer runtime.GOMAXPROCS(runtime.GOMAXPROCS(1))
+       data := struct{ Short bool }{testing.Short()}
+       got := executeTest(t, testGCSysSource, &data)
+       want := "OK\n"
+       if got != want {
+               t.Fatalf("expected %q, but got %q", want, got)
+       }
+}
+
+const testGCSysSource = `
+package main
+
+import (
+       "fmt"
+       "runtime"
+)
+
+func main() {
+       runtime.GOMAXPROCS(1)
        memstats := new(runtime.MemStats)
        runtime.GC()
        runtime.ReadMemStats(memstats)
@@ -23,9 +40,9 @@ func TestGcSys(t *testing.T) {
        runtime.MemProfileRate = 0 // disable profiler
 
        itercount := 1000000
-       if testing.Short() {
-               itercount = 100000
-       }
+{{if .Short}}
+       itercount = 100000
+{{end}}
        for i := 0; i < itercount; i++ {
                workthegc()
        }
@@ -38,15 +55,17 @@ func TestGcSys(t *testing.T) {
        } else {
                sys = memstats.Sys - sys
        }
-       t.Logf("used %d extra bytes", sys)
        if sys > 16<<20 {
-               t.Fatalf("using too much memory: %d bytes", sys)
+               fmt.Printf("using too much memory: %d bytes\n", sys)
+               return
        }
+       fmt.Printf("OK\n")
 }
 
 func workthegc() []byte {
        return make([]byte, 1029)
 }
+`
 
 func TestGcDeepNesting(t *testing.T) {
        type T [2][2][2][2][2][2][2][2][2][2]*int