aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/malloc_test.go
diff options
context:
space:
mode:
authorAustin Clements <austin@google.com>2017-02-23 21:48:34 -0500
committerAustin Clements <austin@google.com>2017-03-31 00:46:16 +0000
commitef1829d1debc0bcd32052d9686adb75704e75984 (patch)
tree24304e153f946236ad308c9cfba35a41217e93ce /src/runtime/malloc_test.go
parentbda74b0e4a8eb1acae8c202efd62d298ec3268f0 (diff)
downloadgo-ef1829d1debc0bcd32052d9686adb75704e75984.tar.gz
go-ef1829d1debc0bcd32052d9686adb75704e75984.zip
runtime: improve TestMemStats checks
Now that we have a nice predicate system, improve the tests performed by TestMemStats. We add some more non-zero checks (now that we force a GC, things like NumGC must be non-zero), checks for trivial boolean fields, and a few more range checks. Change-Id: I6da46d33fa0ce5738407ee57d587825479413171 Reviewed-on: https://go-review.googlesource.com/37513 Run-TryBot: Austin Clements <austin@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Rick Hudson <rlh@golang.org>
Diffstat (limited to 'src/runtime/malloc_test.go')
-rw-r--r--src/runtime/malloc_test.go28
1 files changed, 20 insertions, 8 deletions
diff --git a/src/runtime/malloc_test.go b/src/runtime/malloc_test.go
index 596501f7d5..d9487eed3a 100644
--- a/src/runtime/malloc_test.go
+++ b/src/runtime/malloc_test.go
@@ -28,28 +28,40 @@ func TestMemStats(t *testing.T) {
}
return fmt.Errorf("zero value")
}
- le := func(thresh uint64) func(interface{}) error {
+ le := func(thresh float64) func(interface{}) error {
return func(x interface{}) error {
- if reflect.ValueOf(x).Uint() < thresh {
+ if reflect.ValueOf(x).Convert(reflect.TypeOf(thresh)).Float() < thresh {
return nil
}
- return fmt.Errorf("insanely high value (overflow?); want <= %d", thresh)
+ return fmt.Errorf("insanely high value (overflow?); want <= %v", thresh)
}
}
- // Of the uint fields, HeapReleased, HeapIdle, PauseTotalNs, and NumGC can be 0.
+ eq := func(x interface{}) func(interface{}) error {
+ return func(y interface{}) error {
+ if x == y {
+ return nil
+ }
+ return fmt.Errorf("want %v", x)
+ }
+ }
+ // Of the uint fields, HeapReleased, HeapIdle can be 0.
+ // PauseTotalNs can be 0 if timer resolution is poor.
+ //
+ // TODO: Test that GCCPUFraction is <= 0.99. This currently
+ // fails on windows/386. (Issue #19319)
fields := map[string][]func(interface{}) error{
"Alloc": {nz, le(1e10)}, "TotalAlloc": {nz, le(1e11)}, "Sys": {nz, le(1e10)},
"Lookups": {nz, le(1e10)}, "Mallocs": {nz, le(1e10)}, "Frees": {nz, le(1e10)},
"HeapAlloc": {nz, le(1e10)}, "HeapSys": {nz, le(1e10)}, "HeapIdle": {le(1e10)},
- "HeapInuse": {nz, le(1e10)}, "HeapReleased": nil, "HeapObjects": {nz, le(1e10)},
+ "HeapInuse": {nz, le(1e10)}, "HeapReleased": {le(1e10)}, "HeapObjects": {nz, le(1e10)},
"StackInuse": {nz, le(1e10)}, "StackSys": {nz, le(1e10)},
"MSpanInuse": {nz, le(1e10)}, "MSpanSys": {nz, le(1e10)},
"MCacheInuse": {nz, le(1e10)}, "MCacheSys": {nz, le(1e10)},
"BuckHashSys": {nz, le(1e10)}, "GCSys": {nz, le(1e10)}, "OtherSys": {nz, le(1e10)},
- "NextGC": {nz, le(1e10)}, "LastGC": nil,
+ "NextGC": {nz, le(1e10)}, "LastGC": {nz},
"PauseTotalNs": {le(1e11)}, "PauseNs": nil, "PauseEnd": nil,
- "NumGC": {le(1e9)}, "NumForcedGC": {nz, le(1e9)},
- "GCCPUFraction": nil, "EnableGC": nil, "DebugGC": nil,
+ "NumGC": {nz, le(1e9)}, "NumForcedGC": {nz, le(1e9)},
+ "GCCPUFraction": nil, "EnableGC": {eq(true)}, "DebugGC": {eq(false)},
"BySize": nil,
}