diff options
Diffstat (limited to 'src/runtime/malloc_test.go')
| -rw-r--r-- | src/runtime/malloc_test.go | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/src/runtime/malloc_test.go b/src/runtime/malloc_test.go index e028554b23..8ff88687bd 100644 --- a/src/runtime/malloc_test.go +++ b/src/runtime/malloc_test.go @@ -33,14 +33,14 @@ func TestMemStats(t *testing.T) { st := new(MemStats) ReadMemStats(st) - nz := func(x interface{}) error { + nz := func(x any) error { if x != reflect.Zero(reflect.TypeOf(x)).Interface() { return nil } return fmt.Errorf("zero value") } - le := func(thresh float64) func(interface{}) error { - return func(x interface{}) error { + le := func(thresh float64) func(any) error { + return func(x any) error { // These sanity tests aren't necessarily valid // with high -test.count values, so only run // them once. @@ -54,8 +54,8 @@ func TestMemStats(t *testing.T) { return fmt.Errorf("insanely high value (overflow?); want <= %v", thresh) } } - eq := func(x interface{}) func(interface{}) error { - return func(y interface{}) error { + eq := func(x any) func(any) error { + return func(y any) error { if x == y { return nil } @@ -64,7 +64,7 @@ func TestMemStats(t *testing.T) { } // Of the uint fields, HeapReleased, HeapIdle can be 0. // PauseTotalNs can be 0 if timer resolution is poor. - fields := map[string][]func(interface{}) error{ + fields := map[string][]func(any) error{ "Alloc": {nz, le(1e10)}, "TotalAlloc": {nz, le(1e11)}, "Sys": {nz, le(1e10)}, "Lookups": {eq(uint64(0))}, "Mallocs": {nz, le(1e10)}, "Frees": {nz, le(1e10)}, "HeapAlloc": {nz, le(1e10)}, "HeapSys": {nz, le(1e10)}, "HeapIdle": {le(1e10)}, @@ -198,6 +198,10 @@ func TestTinyAllocIssue37262(t *testing.T) { runtime.GC() runtime.GC() + // Disable preemption so we stay on one P's tiny allocator and + // nothing else allocates from it. + runtime.Acquirem() + // Make 1-byte allocations until we get a fresh tiny slot. aligned := false for i := 0; i < 16; i++ { @@ -208,6 +212,7 @@ func TestTinyAllocIssue37262(t *testing.T) { } } if !aligned { + runtime.Releasem() t.Fatal("unable to get a fresh tiny slot") } @@ -229,6 +234,8 @@ func TestTinyAllocIssue37262(t *testing.T) { tinyByteSink = nil tinyUint32Sink = nil tinyObj12Sink = nil + + runtime.Releasem() } func TestPageCacheLeak(t *testing.T) { |
