mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
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: Mikio Hara <mikioh.mikioh@gmail.com>
This commit is contained in:
parent
65cd1ba682
commit
5de3ff2648
1 changed files with 11 additions and 2 deletions
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue