Commit 5de3ff26 authored by Austin Clements's avatar Austin Clements

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 <austin@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: 's avatarMikio Hara <mikioh.mikioh@gmail.com>
parent 65cd1ba6
......@@ -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)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment