aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/mpallocbits_test.go
diff options
context:
space:
mode:
authorCherry Mui <cherryyz@google.com>2025-10-03 10:11:20 -0400
committerCherry Mui <cherryyz@google.com>2025-10-03 10:11:21 -0400
commitfb1749a3fe6ac40c56127d8fcea2e8b13db820e8 (patch)
tree72dd38fc84286bf88311850a99e6becf2cbd99bf /src/runtime/mpallocbits_test.go
parent703a5fbaad81f1285776bf6f2900506d3c751ea1 (diff)
parentadce7f196e6ac6d22e9bc851efea5f3ab650947c (diff)
downloadgo-fb1749a3fe6ac40c56127d8fcea2e8b13db820e8.tar.xz
[dev.simd] all: merge master (adce7f1) into dev.simd
Conflicts: - src/internal/goexperiment/flags.go - src/runtime/export_test.go Merge List: + 2025-10-03 adce7f196e cmd/link: support .def file with MSVC clang toolchain + 2025-10-03 d5b950399d cmd/cgo: fix unaligned arguments typedmemmove crash on iOS + 2025-10-02 53845004d6 net/http/httputil: deprecate ReverseProxy.Director + 2025-10-02 bbdff9e8e1 net/http: update bundled x/net/http2 and delete obsolete http2inTests + 2025-10-02 4008e07080 io/fs: move path name documentation up to the package doc comment + 2025-10-02 0e4e2e6832 runtime: skip TestGoroutineLeakProfile under mayMoreStackPreempt + 2025-10-02 f03c392295 runtime: fix aix/ppc64 library initialization + 2025-10-02 707454b41f cmd/go: update `go help mod edit` with the tool and ignore sections + 2025-10-02 8c68a1c1ab runtime,net/http/pprof: goroutine leak detection by using the garbage collector + 2025-10-02 84db201ae1 cmd/compile: propagate len([]T{}) to make builtin to allow stack allocation + 2025-10-02 5799c139a7 crypto/tls: rm marshalEncryptedClientHelloConfigList dead code + 2025-10-01 633dd1d475 encoding/json: fix Decoder.InputOffset regression in goexperiment.jsonv2 + 2025-10-01 8ad27fb656 doc/go_spec.html: update date + 2025-10-01 3f451f2c54 testing/synctest: fix inverted test failure message in TestContextAfterFunc + 2025-10-01 be0fed8a5f cmd/go/testdata/script/test_fuzz_fuzztime.txt: disable + 2025-09-30 eb1c7f6e69 runtime: move loong64 library entry point to os-agnostic file + 2025-09-30 c9257151e5 runtime: unify ppc64/ppc64le library entry point + 2025-09-30 4ff8a457db test/codegen: codify handling of floating point constants on arm64 + 2025-09-30 fcb893fc4b cmd/compile/internal/ssa: remove redundant "type:" prefix check + 2025-09-30 19cc1022ba mime: reduce allocs incurred by ParseMediaType + 2025-09-30 08afc50bea mime: extend "builtinTypes" to include a more complete list of common types + 2025-09-30 97da068774 cmd/compile: eliminate nil checks on .dict arg + 2025-09-30 300d9d2714 runtime: initialise debug settings much earlier in startup process + 2025-09-30 a846bb0aa5 errors: add AsType + 2025-09-30 7c8166d02d cmd/link/internal/arm64: support Mach-O ARM64_RELOC_SUBTRACTOR in internal linking + 2025-09-30 6e95748335 cmd/link/internal/arm64: support Mach-O ARM64_RELOC_POINTER_TO_GOT in internal linking + 2025-09-30 742f92063e cmd/compile, runtime: always enable Wasm signext and satconv features + 2025-09-30 db10db6be3 internal/poll: remove operation fields from FD + 2025-09-29 75c87df58e internal/poll: pass the I/O mode instead of an overlapped object in execIO + 2025-09-29 fc88e18b4a crypto/internal/fips140/entropy: add CPU jitter-based entropy source + 2025-09-29 db4fade759 crypto/internal/fips140/mlkem: make CAST conditional + 2025-09-29 db3cb3fd9a runtime: correct reference to getStackMap in comment + 2025-09-29 690fc2fb05 internal/poll: remove buf field from operation + 2025-09-29 eaf2345256 cmd/link: use a .def file to mark exported symbols on Windows + 2025-09-29 4b77733565 internal/syscall/windows: regenerate GetFileSizeEx + 2025-09-29 4e9006a716 crypto/tls: quote protocols in ALPN error message + 2025-09-29 047c2ab841 cmd/link: don't pass -Wl,-S on Solaris + 2025-09-29 ae8eba071b cmd/link: use correct length for pcln.cutab + 2025-09-29 fe3ba74b9e cmd/link: skip TestFlagW on platforms without DWARF symbol table + 2025-09-29 d42d56b764 encoding/xml: make use of reflect.TypeAssert + 2025-09-29 6d51f93257 runtime: jump instead of branch in netbsd/arm64 entry point + 2025-09-28 5500cbf0e4 debug/elf: prevent offset overflow + 2025-09-27 34e67623a8 all: fix typos + 2025-09-27 af6999e60d cmd/compile: implement jump table on loong64 + 2025-09-26 63cd912083 os/user: simplify go:build + 2025-09-26 53009b26dd runtime: use a smaller arena size on Wasm + 2025-09-26 3a5df9d2b2 net/http: add HTTP2Config.StrictMaxConcurrentRequests + 2025-09-26 16be34df02 net/http: add more tests of transport connection pool + 2025-09-26 3e4540b49d os/user: use getgrouplist on illumos && cgo + 2025-09-26 15fbe3480b internal/poll: simplify WriteMsg and ReadMsg on Windows + 2025-09-26 16ae11a9e1 runtime: move TestReadMetricsSched to testprog + 2025-09-26 459f3a3adc cmd/link: don't pass -Wl,-S on AIX + 2025-09-26 4631a2d3c6 cmd/link: skip TestFlagW on AIX + 2025-09-26 0f31d742cd cmd/compile: fix ICE with new(<untyped expr>) + 2025-09-26 7d7cd6e07b internal/poll: don't call SetFilePointerEx in Seek for overlapped handles + 2025-09-26 41cba31e66 mime/multipart: percent-encode CR and LF in header values to avoid CRLF injection + 2025-09-26 dd1d597c3a Revert "cmd/internal/obj/loong64: use the MOVVP instruction to optimize prologue" + 2025-09-26 45d6bc76af runtime: unify arm64 entry point code + 2025-09-25 fdea7da3e6 runtime: use common library entry point on windows amd64/386 + 2025-09-25 e8a4f508d1 lib/fips140: re-seal v1.0.0 + 2025-09-25 9b7a328089 crypto/internal/fips140: remove key import PCTs, make keygen PCTs fatal + 2025-09-25 7f9ab7203f crypto/internal/fips140: update frozen module version to "v1.0.0" + 2025-09-25 fb5719cbda crypto/internal/fips140/ecdsa: make TestingOnlyNewDRBG generic + 2025-09-25 56067e31f2 std: remove unused declarations Change-Id: Iecb28fd62c69fbed59da557f46d31bae55889e2c
Diffstat (limited to 'src/runtime/mpallocbits_test.go')
-rw-r--r--src/runtime/mpallocbits_test.go189
1 files changed, 103 insertions, 86 deletions
diff --git a/src/runtime/mpallocbits_test.go b/src/runtime/mpallocbits_test.go
index 5095e24220..cf49f77507 100644
--- a/src/runtime/mpallocbits_test.go
+++ b/src/runtime/mpallocbits_test.go
@@ -54,35 +54,39 @@ func TestPallocBitsAllocRange(t *testing.T) {
want[PallocChunkPages/64-1] = 1 << 63
test(t, PallocChunkPages-1, 1, want)
})
- t.Run("Inner", func(t *testing.T) {
- want := new(PallocBits)
- want[2] = 0x3e
- test(t, 129, 5, want)
- })
- t.Run("Aligned", func(t *testing.T) {
- want := new(PallocBits)
- want[2] = ^uint64(0)
- want[3] = ^uint64(0)
- test(t, 128, 128, want)
- })
- t.Run("Begin", func(t *testing.T) {
- want := new(PallocBits)
- want[0] = ^uint64(0)
- want[1] = ^uint64(0)
- want[2] = ^uint64(0)
- want[3] = ^uint64(0)
- want[4] = ^uint64(0)
- want[5] = 0x1
- test(t, 0, 321, want)
- })
- t.Run("End", func(t *testing.T) {
- want := new(PallocBits)
- want[PallocChunkPages/64-1] = ^uint64(0)
- want[PallocChunkPages/64-2] = ^uint64(0)
- want[PallocChunkPages/64-3] = ^uint64(0)
- want[PallocChunkPages/64-4] = 1 << 63
- test(t, PallocChunkPages-(64*3+1), 64*3+1, want)
- })
+ if PallocChunkPages >= 512 {
+ t.Run("Inner", func(t *testing.T) {
+ want := new(PallocBits)
+ want[:][2] = 0x3e
+ test(t, 129, 5, want)
+ })
+ t.Run("Aligned", func(t *testing.T) {
+ want := new(PallocBits)
+ want[:][2] = ^uint64(0)
+ want[:][3] = ^uint64(0)
+ test(t, 128, 128, want)
+ })
+ t.Run("Begin", func(t *testing.T) {
+ want := new(PallocBits)
+ want[:][0] = ^uint64(0)
+ want[:][1] = ^uint64(0)
+ want[:][2] = ^uint64(0)
+ want[:][3] = ^uint64(0)
+ want[:][4] = ^uint64(0)
+ want[:][5] = 0x1
+ test(t, 0, 321, want)
+ })
+ t.Run("End", func(t *testing.T) {
+ // avoid constant overflow when PallocChunkPages is small
+ var PallocChunkPages uint = PallocChunkPages
+ want := new(PallocBits)
+ want[PallocChunkPages/64-1] = ^uint64(0)
+ want[PallocChunkPages/64-2] = ^uint64(0)
+ want[PallocChunkPages/64-3] = ^uint64(0)
+ want[PallocChunkPages/64-4] = 1 << 63
+ test(t, PallocChunkPages-(64*3+1), 64*3+1, want)
+ })
+ }
t.Run("All", func(t *testing.T) {
want := new(PallocBits)
for i := range want {
@@ -118,10 +122,11 @@ func TestMallocBitsPopcntRange(t *testing.T) {
i, n uint // bit range to popcnt over.
want uint // expected popcnt result on that range.
}
- tests := map[string]struct {
+ type testCase struct {
init []BitRange // bit ranges to set to 1 in the bitmap.
tests []test // a set of popcnt tests to run over the bitmap.
- }{
+ }
+ tests := map[string]testCase{
"None": {
tests: []test{
{0, 1, 0},
@@ -157,7 +162,9 @@ func TestMallocBitsPopcntRange(t *testing.T) {
{0, PallocChunkPages, PallocChunkPages / 2},
},
},
- "OddBound": {
+ }
+ if PallocChunkPages >= 512 {
+ tests["OddBound"] = testCase{
init: []BitRange{{0, 111}},
tests: []test{
{0, 1, 1},
@@ -172,8 +179,8 @@ func TestMallocBitsPopcntRange(t *testing.T) {
{PallocChunkPages / 2, PallocChunkPages / 2, 0},
{0, PallocChunkPages, 111},
},
- },
- "Scattered": {
+ }
+ tests["Scattered"] = testCase{
init: []BitRange{
{1, 3}, {5, 1}, {7, 1}, {10, 2}, {13, 1}, {15, 4},
{21, 1}, {23, 1}, {26, 2}, {30, 5}, {36, 2}, {40, 3},
@@ -190,7 +197,7 @@ func TestMallocBitsPopcntRange(t *testing.T) {
{1, 128, 74},
{0, PallocChunkPages, 75},
},
- },
+ }
}
for name, v := range tests {
v := v
@@ -251,23 +258,25 @@ func TestPallocBitsSummarize(t *testing.T) {
PackPallocSum(11, 23, 23),
},
}
- tests["StartMaxEnd"] = test{
- free: []BitRange{{0, 4}, {50, 100}, {PallocChunkPages - 4, 4}},
- hits: []PallocSum{
- PackPallocSum(4, 100, 4),
- },
- }
- tests["OnlyMax"] = test{
- free: []BitRange{{1, 20}, {35, 241}, {PallocChunkPages - 50, 30}},
- hits: []PallocSum{
- PackPallocSum(0, 241, 0),
- },
- }
- tests["MultiMax"] = test{
- free: []BitRange{{35, 2}, {40, 5}, {100, 5}},
- hits: []PallocSum{
- PackPallocSum(0, 5, 0),
- },
+ if PallocChunkPages >= 512 {
+ tests["StartMaxEnd"] = test{
+ free: []BitRange{{0, 4}, {50, 100}, {PallocChunkPages - 4, 4}},
+ hits: []PallocSum{
+ PackPallocSum(4, 100, 4),
+ },
+ }
+ tests["OnlyMax"] = test{
+ free: []BitRange{{1, 20}, {35, 241}, {PallocChunkPages - 50, 30}},
+ hits: []PallocSum{
+ PackPallocSum(0, 241, 0),
+ },
+ }
+ tests["MultiMax"] = test{
+ free: []BitRange{{35, 2}, {40, 5}, {100, 5}},
+ hits: []PallocSum{
+ PackPallocSum(0, 5, 0),
+ },
+ }
}
tests["One"] = test{
free: []BitRange{{2, 1}},
@@ -329,12 +338,13 @@ func BenchmarkPallocBitsSummarize(b *testing.B) {
// Ensures page allocation works.
func TestPallocBitsAlloc(t *testing.T) {
- tests := map[string]struct {
+ type test struct {
before []BitRange
after []BitRange
npages uintptr
hits []uint
- }{
+ }
+ tests := map[string]test{
"AllFree1": {
npages: 1,
hits: []uint{0, 1, 2, 3, 4, 5},
@@ -350,22 +360,6 @@ func TestPallocBitsAlloc(t *testing.T) {
hits: []uint{0, 5, 10, 15, 20},
after: []BitRange{{0, 25}},
},
- "AllFree64": {
- npages: 64,
- hits: []uint{0, 64, 128},
- after: []BitRange{{0, 192}},
- },
- "AllFree65": {
- npages: 65,
- hits: []uint{0, 65, 130},
- after: []BitRange{{0, 195}},
- },
- "SomeFree64": {
- before: []BitRange{{0, 32}, {64, 32}, {100, PallocChunkPages - 100}},
- npages: 64,
- hits: []uint{^uint(0)},
- after: []BitRange{{0, 32}, {64, 32}, {100, PallocChunkPages - 100}},
- },
"NoneFree1": {
before: []BitRange{{0, PallocChunkPages}},
npages: 1,
@@ -408,18 +402,38 @@ func TestPallocBitsAlloc(t *testing.T) {
hits: []uint{PallocChunkPages/2 - 3, ^uint(0)},
after: []BitRange{{0, PallocChunkPages}},
},
- "ExactFit65": {
+ }
+ if PallocChunkPages >= 512 {
+ // avoid constant overflow when PallocChunkPages is small
+ var PallocChunkPages uint = PallocChunkPages
+ tests["AllFree64"] = test{
+ npages: 64,
+ hits: []uint{0, 64, 128},
+ after: []BitRange{{0, 192}},
+ }
+ tests["AllFree65"] = test{
+ npages: 65,
+ hits: []uint{0, 65, 130},
+ after: []BitRange{{0, 195}},
+ }
+ tests["SomeFree64"] = test{
+ before: []BitRange{{0, 32}, {64, 32}, {100, PallocChunkPages - 100}},
+ npages: 64,
+ hits: []uint{^uint(0)},
+ after: []BitRange{{0, 32}, {64, 32}, {100, PallocChunkPages - 100}},
+ }
+ tests["ExactFit65"] = test{
before: []BitRange{{0, PallocChunkPages/2 - 31}, {PallocChunkPages/2 + 34, PallocChunkPages/2 - 34}},
npages: 65,
hits: []uint{PallocChunkPages/2 - 31, ^uint(0)},
after: []BitRange{{0, PallocChunkPages}},
- },
- "SomeFree161": {
+ }
+ tests["SomeFree161"] = test{
before: []BitRange{{0, 185}, {331, 1}},
npages: 161,
hits: []uint{332},
after: []BitRange{{0, 185}, {331, 162}},
- },
+ }
}
for name, v := range tests {
v := v
@@ -442,18 +456,13 @@ func TestPallocBitsAlloc(t *testing.T) {
// Ensures page freeing works.
func TestPallocBitsFree(t *testing.T) {
- tests := map[string]struct {
+ type test struct {
beforeInv []BitRange
afterInv []BitRange
frees []uint
npages uintptr
- }{
- "SomeFree": {
- npages: 1,
- beforeInv: []BitRange{{0, 32}, {64, 32}, {100, 1}},
- frees: []uint{32},
- afterInv: []BitRange{{0, 33}, {64, 32}, {100, 1}},
- },
+ }
+ tests := map[string]test{
"NoneFree1": {
npages: 1,
frees: []uint{0, 1, 2, 3, 4, 5},
@@ -469,16 +478,24 @@ func TestPallocBitsFree(t *testing.T) {
frees: []uint{0, 5, 10, 15, 20},
afterInv: []BitRange{{0, 25}},
},
- "NoneFree64": {
+ }
+ if PallocChunkPages >= 512 {
+ tests["SomeFree"] = test{
+ npages: 1,
+ beforeInv: []BitRange{{0, 32}, {64, 32}, {100, 1}},
+ frees: []uint{32},
+ afterInv: []BitRange{{0, 33}, {64, 32}, {100, 1}},
+ }
+ tests["NoneFree64"] = test{
npages: 64,
frees: []uint{0, 64, 128},
afterInv: []BitRange{{0, 192}},
- },
- "NoneFree65": {
+ }
+ tests["NoneFree65"] = test{
npages: 65,
frees: []uint{0, 65, 130},
afterInv: []BitRange{{0, 195}},
- },
+ }
}
for name, v := range tests {
v := v