runtime: Change gc_test to test only newly allocated memory.
authorIan Lance Taylor <ian@gcc.gnu.org>
Tue, 13 Dec 2011 23:15:36 +0000 (23:15 +0000)
committerIan Lance Taylor <ian@gcc.gnu.org>
Tue, 13 Dec 2011 23:15:36 +0000 (23:15 +0000)
From-SVN: r182315

libgo/go/runtime/gc_test.go

index fad60a368041c7b457791f68b7345a595326e928..156d3bc7d30264675103696ef2c388be6fd3e74e 100644 (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)
        }
 }