aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/map_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/runtime/map_test.go')
-rw-r--r--src/runtime/map_test.go34
1 files changed, 28 insertions, 6 deletions
diff --git a/src/runtime/map_test.go b/src/runtime/map_test.go
index 4afbae6bc4..3675106d9c 100644
--- a/src/runtime/map_test.go
+++ b/src/runtime/map_test.go
@@ -6,6 +6,7 @@ package runtime_test
import (
"fmt"
+ "internal/abi"
"internal/goarch"
"math"
"reflect"
@@ -506,7 +507,12 @@ func TestMapNanGrowIterator(t *testing.T) {
}
func TestMapIterOrder(t *testing.T) {
- for _, n := range [...]int{3, 7, 9, 15} {
+ sizes := []int{3, 7, 9, 15}
+ if abi.MapBucketCountBits >= 5 {
+ // it gets flaky (often only one iteration order) at size 3 when abi.MapBucketCountBits >=5.
+ t.Fatalf("This test becomes flaky if abi.MapBucketCountBits(=%d) is 5 or larger", abi.MapBucketCountBits)
+ }
+ for _, n := range sizes {
for i := 0; i < 1000; i++ {
// Make m be {0: true, 1: true, ..., n-1: true}.
m := make(map[int]bool)
@@ -673,6 +679,17 @@ func TestIgnoreBogusMapHint(t *testing.T) {
}
}
+const bs = abi.MapBucketCount
+
+// belowOverflow should be a pretty-full pair of buckets;
+// atOverflow is 1/8 bs larger = 13/8 buckets or two buckets
+// that are 13/16 full each, which is the overflow boundary.
+// Adding one to that should ensure overflow to the next higher size.
+const (
+ belowOverflow = bs * 3 / 2 // 1.5 bs = 2 buckets @ 75%
+ atOverflow = belowOverflow + bs/8 // 2 buckets at 13/16 fill.
+)
+
var mapBucketTests = [...]struct {
n int // n is the number of map elements
noescape int // number of expected buckets for non-escaping map
@@ -682,11 +699,16 @@ var mapBucketTests = [...]struct {
{-1, 1, 1},
{0, 1, 1},
{1, 1, 1},
- {8, 1, 1},
- {9, 2, 2},
- {13, 2, 2},
- {14, 4, 4},
- {26, 4, 4},
+ {bs, 1, 1},
+ {bs + 1, 2, 2},
+ {belowOverflow, 2, 2}, // 1.5 bs = 2 buckets @ 75%
+ {atOverflow + 1, 4, 4}, // 13/8 bs + 1 == overflow to 4
+
+ {2 * belowOverflow, 4, 4}, // 3 bs = 4 buckets @75%
+ {2*atOverflow + 1, 8, 8}, // 13/4 bs + 1 = overflow to 8
+
+ {4 * belowOverflow, 8, 8}, // 6 bs = 8 buckets @ 75%
+ {4*atOverflow + 1, 16, 16}, // 13/2 bs + 1 = overflow to 16
}
func TestMapBuckets(t *testing.T) {