diff options
| author | Austin Clements <austin@google.com> | 2022-04-25 17:21:58 -0400 |
|---|---|---|
| committer | Gopher Robot <gobot@golang.org> | 2022-04-28 18:28:44 +0000 |
| commit | 123e27170aac5b26c38e6bf9866e16a38aed1696 (patch) | |
| tree | bc6f5c6957d983f3151626c5ae1548558cf2d13d /src/runtime/map_test.go | |
| parent | c15d0a93c772c03fb028f0473016629a70a4427e (diff) | |
| download | go-123e27170aac5b26c38e6bf9866e16a38aed1696.tar.xz | |
runtime: clean up escaping in tests
There are several tests in the runtime that need to force various
things to escape to the heap. This CL centralizes this functionality
into runtime.Escape, defined in export_test.
Change-Id: I2de2519661603ad46c372877a9c93efef8e7a857
Reviewed-on: https://go-review.googlesource.com/c/go/+/402178
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Run-TryBot: Austin Clements <austin@google.com>
Auto-Submit: Austin Clements <austin@google.com>
Diffstat (limited to 'src/runtime/map_test.go')
| -rw-r--r-- | src/runtime/map_test.go | 14 |
1 files changed, 4 insertions, 10 deletions
diff --git a/src/runtime/map_test.go b/src/runtime/map_test.go index 5c458b4a49..4afbae6bc4 100644 --- a/src/runtime/map_test.go +++ b/src/runtime/map_test.go @@ -673,8 +673,6 @@ func TestIgnoreBogusMapHint(t *testing.T) { } } -var mapSink map[int]int - var mapBucketTests = [...]struct { n int // n is the number of map elements noescape int // number of expected buckets for non-escaping map @@ -710,7 +708,7 @@ func TestMapBuckets(t *testing.T) { if got := runtime.MapBucketsCount(localMap); got != tt.noescape { t.Errorf("no escape: n=%d want %d buckets, got %d", tt.n, tt.noescape, got) } - escapingMap := map[int]int{} + escapingMap := runtime.Escape(map[int]int{}) if count := runtime.MapBucketsCount(escapingMap); count > 1 && runtime.MapBucketsPointerIsNil(escapingMap) { t.Errorf("escape: buckets pointer is nil for n=%d buckets", count) } @@ -720,7 +718,6 @@ func TestMapBuckets(t *testing.T) { if got := runtime.MapBucketsCount(escapingMap); got != tt.escape { t.Errorf("escape n=%d want %d buckets, got %d", tt.n, tt.escape, got) } - mapSink = escapingMap } }) t.Run("nohint", func(t *testing.T) { @@ -735,7 +732,7 @@ func TestMapBuckets(t *testing.T) { if got := runtime.MapBucketsCount(localMap); got != tt.noescape { t.Errorf("no escape: n=%d want %d buckets, got %d", tt.n, tt.noescape, got) } - escapingMap := make(map[int]int) + escapingMap := runtime.Escape(make(map[int]int)) if count := runtime.MapBucketsCount(escapingMap); count > 1 && runtime.MapBucketsPointerIsNil(escapingMap) { t.Errorf("escape: buckets pointer is nil for n=%d buckets", count) } @@ -745,7 +742,6 @@ func TestMapBuckets(t *testing.T) { if got := runtime.MapBucketsCount(escapingMap); got != tt.escape { t.Errorf("escape: n=%d want %d buckets, got %d", tt.n, tt.escape, got) } - mapSink = escapingMap } }) t.Run("makemap", func(t *testing.T) { @@ -760,7 +756,7 @@ func TestMapBuckets(t *testing.T) { if got := runtime.MapBucketsCount(localMap); got != tt.noescape { t.Errorf("no escape: n=%d want %d buckets, got %d", tt.n, tt.noescape, got) } - escapingMap := make(map[int]int, tt.n) + escapingMap := runtime.Escape(make(map[int]int, tt.n)) if count := runtime.MapBucketsCount(escapingMap); count > 1 && runtime.MapBucketsPointerIsNil(escapingMap) { t.Errorf("escape: buckets pointer is nil for n=%d buckets", count) } @@ -770,7 +766,6 @@ func TestMapBuckets(t *testing.T) { if got := runtime.MapBucketsCount(escapingMap); got != tt.escape { t.Errorf("escape: n=%d want %d buckets, got %d", tt.n, tt.escape, got) } - mapSink = escapingMap } }) t.Run("makemap64", func(t *testing.T) { @@ -785,7 +780,7 @@ func TestMapBuckets(t *testing.T) { if got := runtime.MapBucketsCount(localMap); got != tt.noescape { t.Errorf("no escape: n=%d want %d buckets, got %d", tt.n, tt.noescape, got) } - escapingMap := make(map[int]int, tt.n) + escapingMap := runtime.Escape(make(map[int]int, tt.n)) if count := runtime.MapBucketsCount(escapingMap); count > 1 && runtime.MapBucketsPointerIsNil(escapingMap) { t.Errorf("escape: buckets pointer is nil for n=%d buckets", count) } @@ -795,7 +790,6 @@ func TestMapBuckets(t *testing.T) { if got := runtime.MapBucketsCount(escapingMap); got != tt.escape { t.Errorf("escape: n=%d want %d buckets, got %d", tt.n, tt.escape, got) } - mapSink = escapingMap } }) |
