From 46890f60cee89ffef7a9b5f2b8d5e263650f61f7 Mon Sep 17 00:00:00 2001 From: Dmitriy Vyukov Date: Sat, 2 Mar 2013 08:36:06 +0200 Subject: [PATCH] runtime: move TestGcSys into a separate process 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 | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/src/pkg/runtime/gc_test.go b/src/pkg/runtime/gc_test.go index 0215ff2cf4..e1e1b1d015 100644 --- a/src/pkg/runtime/gc_test.go +++ b/src/pkg/runtime/gc_test.go @@ -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 -- 2.50.0