runtime: Change gc_test to test only newly allocated memory.

From-SVN: r182315
This commit is contained in:
Ian Lance Taylor 2011-12-13 23:15:36 +00:00
parent c915f63f73
commit 90a9ea010a

View file

@ -6,16 +6,24 @@ import (
)
func TestGcSys(t *testing.T) {
runtime.GC()
runtime.UpdateMemStats()
sys := runtime.MemStats.Sys
for i := 0; i < 1000000; i++ {
workthegc()
}
// Should only be using a few MB.
runtime.UpdateMemStats()
sys := runtime.MemStats.Sys
t.Logf("using %d MB", sys>>20)
if sys > 10e6 {
t.Fatalf("using too much memory: %d MB", sys>>20)
if sys > runtime.MemStats.Sys {
sys = 0
} else {
sys = runtime.MemStats.Sys - sys
}
t.Logf("used %d extra bytes", sys)
if sys > 2<<20 {
t.Fatalf("using too much memory: %d bytes", sys)
}
}