Commit 46890f60 authored by Dmitriy Vyukov's avatar Dmitriy Vyukov

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
parent fd9049f4
...@@ -14,7 +14,24 @@ func TestGcSys(t *testing.T) { ...@@ -14,7 +14,24 @@ func TestGcSys(t *testing.T) {
if os.Getenv("GOGC") == "off" { if os.Getenv("GOGC") == "off" {
t.Fatalf("GOGC=off in environment; test cannot pass") 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) memstats := new(runtime.MemStats)
runtime.GC() runtime.GC()
runtime.ReadMemStats(memstats) runtime.ReadMemStats(memstats)
...@@ -23,9 +40,9 @@ func TestGcSys(t *testing.T) { ...@@ -23,9 +40,9 @@ func TestGcSys(t *testing.T) {
runtime.MemProfileRate = 0 // disable profiler runtime.MemProfileRate = 0 // disable profiler
itercount := 1000000 itercount := 1000000
if testing.Short() { {{if .Short}}
itercount = 100000 itercount = 100000
} {{end}}
for i := 0; i < itercount; i++ { for i := 0; i < itercount; i++ {
workthegc() workthegc()
} }
...@@ -38,15 +55,17 @@ func TestGcSys(t *testing.T) { ...@@ -38,15 +55,17 @@ func TestGcSys(t *testing.T) {
} else { } else {
sys = memstats.Sys - sys sys = memstats.Sys - sys
} }
t.Logf("used %d extra bytes", sys)
if sys > 16<<20 { 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 { func workthegc() []byte {
return make([]byte, 1029) return make([]byte, 1029)
} }
`
func TestGcDeepNesting(t *testing.T) { func TestGcDeepNesting(t *testing.T) {
type T [2][2][2][2][2][2][2][2][2][2]*int type T [2][2][2][2][2][2][2][2][2][2]*int
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment