]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: accept NumGC==0 in TestMemStats
authorAustin Clements <austin@google.com>
Mon, 14 Dec 2015 23:04:40 +0000 (18:04 -0500)
committerAustin Clements <austin@google.com>
Wed, 16 Dec 2015 18:54:50 +0000 (18:54 +0000)
TestMemStats currently requires that NumGC != 0, but GC may
legitimately not have run (for example, if this test runs first, or
GOGC is set high, etc). Accept NumGC == 0 and instead sanity check
NumGC by making sure that all pause times after NumGC are 0.

Fixes #11989.

Change-Id: I4203859fbb83292d59a509f2eeb24d6033e7aabc
Reviewed-on: https://go-review.googlesource.com/17830
Run-TryBot: Austin Clements <austin@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Mikio Hara <mikioh.mikioh@gmail.com>
src/runtime/malloc_test.go

index b8278bb4bcaf6b8d43f6b4fd4d7cff2cb4d907db..767b51f453bb124eb12b7ed5e474c1c3cdf7bc9d 100644 (file)
@@ -17,13 +17,14 @@ func TestMemStats(t *testing.T) {
        st := new(MemStats)
        ReadMemStats(st)
 
-       // Everything except HeapReleased and HeapIdle, because they indeed can be 0.
+       // Everything except HeapReleased, HeapIdle, and NumGC,
+       // because they indeed can be 0.
        if st.Alloc == 0 || st.TotalAlloc == 0 || st.Sys == 0 || st.Lookups == 0 ||
                st.Mallocs == 0 || st.Frees == 0 || st.HeapAlloc == 0 || st.HeapSys == 0 ||
                st.HeapInuse == 0 || st.HeapObjects == 0 || st.StackInuse == 0 ||
                st.StackSys == 0 || st.MSpanInuse == 0 || st.MSpanSys == 0 || st.MCacheInuse == 0 ||
                st.MCacheSys == 0 || st.BuckHashSys == 0 || st.GCSys == 0 || st.OtherSys == 0 ||
-               st.NextGC == 0 || st.NumGC == 0 {
+               st.NextGC == 0 {
                t.Fatalf("Zero value: %+v", *st)
        }
 
@@ -58,6 +59,14 @@ func TestMemStats(t *testing.T) {
                if st.PauseTotalNs != pauseTotal {
                        t.Fatalf("PauseTotalNs(%d) != sum PauseNs(%d)", st.PauseTotalNs, pauseTotal)
                }
+               for i := int(st.NumGC); i < len(st.PauseNs); i++ {
+                       if st.PauseNs[i] != 0 {
+                               t.Fatalf("Non-zero PauseNs[%d]: %+v", i, st)
+                       }
+                       if st.PauseEnd[i] != 0 {
+                               t.Fatalf("Non-zero PauseEnd[%d]: %+v", i, st)
+                       }
+               }
        } else {
                if st.PauseTotalNs < pauseTotal {
                        t.Fatalf("PauseTotalNs(%d) < sum PauseNs(%d)", st.PauseTotalNs, pauseTotal)