runtime: Change gc_test to test only newly allocated memory.
From-SVN: r182315
This commit is contained in:
parent
c915f63f73
commit
90a9ea010a
1 changed files with 12 additions and 4 deletions
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue