From 5de3ff2648d614a58c94549873593d98f275fdcb Mon Sep 17 00:00:00 2001 From: Austin Clements Date: Mon, 14 Dec 2015 18:04:40 -0500 Subject: [PATCH] runtime: accept NumGC==0 in TestMemStats 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 TryBot-Result: Gobot Gobot Reviewed-by: Mikio Hara --- src/runtime/malloc_test.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/runtime/malloc_test.go b/src/runtime/malloc_test.go index b8278bb4bc..767b51f453 100644 --- a/src/runtime/malloc_test.go +++ b/src/runtime/malloc_test.go @@ -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) -- 2.48.1