From b1718bf8991e47a352273f85b27a9ee9171e3f26 Mon Sep 17 00:00:00 2001 From: qiulaidongfeng <2645477756@qq.com> Date: Fri, 16 Feb 2024 09:45:41 +0800 Subject: [PATCH 1/8] hash/maphash: parallel run test This reduces the go test hash/maphash time by more than half. Change-Id: I4ea5f6af5263060f2f24d273f29a56d57df0d961 --- src/hash/maphash/smhasher_test.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/hash/maphash/smhasher_test.go b/src/hash/maphash/smhasher_test.go index 7fa30aa12fa404..2f9de513af40f7 100644 --- a/src/hash/maphash/smhasher_test.go +++ b/src/hash/maphash/smhasher_test.go @@ -30,6 +30,7 @@ var fixedSeed = MakeSeed() // hash should not depend on values outside key. // hash should not depend on alignment. func TestSmhasherSanity(t *testing.T) { + t.Parallel() r := rand.New(rand.NewSource(1234)) const REP = 10 const KEYMAX = 128 @@ -118,6 +119,7 @@ func (s *hashSet) check(t *testing.T) { // a string plus adding zeros must make distinct hashes func TestSmhasherAppendedZeros(t *testing.T) { + t.Parallel() s := "hello" + strings.Repeat("\x00", 256) h := newHashSet() for i := 0; i <= len(s); i++ { @@ -128,6 +130,7 @@ func TestSmhasherAppendedZeros(t *testing.T) { // All 0-3 byte strings have distinct hashes. func TestSmhasherSmallKeys(t *testing.T) { + t.Parallel() h := newHashSet() var b [3]byte for i := 0; i < 256; i++ { @@ -149,6 +152,7 @@ func TestSmhasherSmallKeys(t *testing.T) { // Different length strings of all zeros have distinct hashes. func TestSmhasherZeros(t *testing.T) { + t.Parallel() N := 256 * 1024 if testing.Short() { N = 1024 @@ -169,6 +173,7 @@ func TestSmhasherTwoNonzero(t *testing.T) { if testing.Short() { t.Skip("Skipping in short mode") } + t.Parallel() h := newHashSet() for n := 2; n <= 16; n++ { twoNonZero(h, n) @@ -211,6 +216,7 @@ func TestSmhasherCyclic(t *testing.T) { if testing.Short() { t.Skip("Skipping in short mode") } + t.Parallel() r := rand.New(rand.NewSource(1234)) const REPEAT = 8 const N = 1000000 @@ -416,6 +422,7 @@ func windowed(t *testing.T, k key) { if testing.Short() { t.Skip("Skipping in short mode") } + t.Parallel() const BITS = 16 h := newHashSet() @@ -472,6 +479,7 @@ func TestSmhasherSeed(t *testing.T) { if unsafe.Sizeof(uintptr(0)) == 4 { t.Skip("32-bit platforms don't have ideal seed-input distributions (see issue 33988)") } + t.Parallel() h := newHashSet() const N = 100000 s := "hello" From 73b9c96120890ad4cb240bc3f82e76749428bb30 Mon Sep 17 00:00:00 2001 From: qiulaidongfeng <2645477756@qq.com> Date: Sun, 17 Mar 2024 09:35:22 +0800 Subject: [PATCH 2/8] n Change-Id: I69373d3a8214a6df21d9bfdd54ada58a5b1d22e8 --- src/hash/maphash/smhasher_test.go | 18 ++++++++++-------- src/internal/testenv/testenv.go | 13 +++++++++++++ 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/src/hash/maphash/smhasher_test.go b/src/hash/maphash/smhasher_test.go index 2f9de513af40f7..523556f08bb403 100644 --- a/src/hash/maphash/smhasher_test.go +++ b/src/hash/maphash/smhasher_test.go @@ -8,6 +8,7 @@ package maphash import ( "fmt" + "internal/testenv" "math" "math/rand" "runtime" @@ -30,7 +31,7 @@ var fixedSeed = MakeSeed() // hash should not depend on values outside key. // hash should not depend on alignment. func TestSmhasherSanity(t *testing.T) { - t.Parallel() + testenv.Parallel(t) r := rand.New(rand.NewSource(1234)) const REP = 10 const KEYMAX = 128 @@ -119,7 +120,7 @@ func (s *hashSet) check(t *testing.T) { // a string plus adding zeros must make distinct hashes func TestSmhasherAppendedZeros(t *testing.T) { - t.Parallel() + testenv.Parallel(t) s := "hello" + strings.Repeat("\x00", 256) h := newHashSet() for i := 0; i <= len(s); i++ { @@ -130,7 +131,7 @@ func TestSmhasherAppendedZeros(t *testing.T) { // All 0-3 byte strings have distinct hashes. func TestSmhasherSmallKeys(t *testing.T) { - t.Parallel() + testenv.Parallel(t) h := newHashSet() var b [3]byte for i := 0; i < 256; i++ { @@ -152,7 +153,7 @@ func TestSmhasherSmallKeys(t *testing.T) { // Different length strings of all zeros have distinct hashes. func TestSmhasherZeros(t *testing.T) { - t.Parallel() + testenv.Parallel(t) N := 256 * 1024 if testing.Short() { N = 1024 @@ -173,7 +174,7 @@ func TestSmhasherTwoNonzero(t *testing.T) { if testing.Short() { t.Skip("Skipping in short mode") } - t.Parallel() + testenv.Parallel(t) h := newHashSet() for n := 2; n <= 16; n++ { twoNonZero(h, n) @@ -216,7 +217,7 @@ func TestSmhasherCyclic(t *testing.T) { if testing.Short() { t.Skip("Skipping in short mode") } - t.Parallel() + testenv.Parallel(t) r := rand.New(rand.NewSource(1234)) const REPEAT = 8 const N = 1000000 @@ -350,6 +351,7 @@ func TestSmhasherAvalanche(t *testing.T) { if testing.Short() { t.Skip("Skipping in short mode") } + testenv.Parallel(t) avalancheTest1(t, &bytesKey{make([]byte, 2)}) avalancheTest1(t, &bytesKey{make([]byte, 4)}) avalancheTest1(t, &bytesKey{make([]byte, 8)}) @@ -422,7 +424,7 @@ func windowed(t *testing.T, k key) { if testing.Short() { t.Skip("Skipping in short mode") } - t.Parallel() + testenv.Parallel(t) const BITS = 16 h := newHashSet() @@ -479,7 +481,7 @@ func TestSmhasherSeed(t *testing.T) { if unsafe.Sizeof(uintptr(0)) == 4 { t.Skip("32-bit platforms don't have ideal seed-input distributions (see issue 33988)") } - t.Parallel() + testenv.Parallel(t) h := newHashSet() const N = 100000 s := "hello" diff --git a/src/internal/testenv/testenv.go b/src/internal/testenv/testenv.go index 3b9d2fd1e9194a..8544e03db544c0 100644 --- a/src/internal/testenv/testenv.go +++ b/src/internal/testenv/testenv.go @@ -511,3 +511,16 @@ func WriteImportcfg(t testing.TB, dstPath string, packageFiles map[string]string func SyscallIsNotSupported(err error) bool { return syscallIsNotSupported(err) } + +// Parallel call t.Parallel() +// unless there is a case that cannot be parallel. +// +// know that there are no parallel cases: +// +// - in GOARCH=386 may raise OOM (see go.dev/issue/65823) +func Parallel(t *testing.T) { + if runtime.GOARCH == "386" { + return + } + t.Parallel() +} From a27f573c720e1392d66151dadcea263d3445c89f Mon Sep 17 00:00:00 2001 From: qiulaidongfeng <2645477756@qq.com> Date: Sun, 17 Mar 2024 09:43:09 +0800 Subject: [PATCH 3/8] n Change-Id: Ib320cc7ed44c763c32c519be6f52328cbd944582 --- src/internal/testenv/testenv.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/internal/testenv/testenv.go b/src/internal/testenv/testenv.go index 8544e03db544c0..4a0284476bd49e 100644 --- a/src/internal/testenv/testenv.go +++ b/src/internal/testenv/testenv.go @@ -21,6 +21,7 @@ import ( "os/exec" "path/filepath" "runtime" + "std/internal/goarch" "strconv" "strings" "sync" @@ -517,9 +518,9 @@ func SyscallIsNotSupported(err error) bool { // // know that there are no parallel cases: // -// - in GOARCH=386 may raise OOM (see go.dev/issue/65823) +// - in 32-bit machine may raise OOM (see go.dev/issue/65823) func Parallel(t *testing.T) { - if runtime.GOARCH == "386" { + if goarch.PtrSize == 4 { return } t.Parallel() From e0984a1ba082a37df813fd4af1cb7c4d68384a9b Mon Sep 17 00:00:00 2001 From: qiulaidongfeng <2645477756@qq.com> Date: Sun, 17 Mar 2024 09:56:39 +0800 Subject: [PATCH 4/8] n Change-Id: Ia7bfa6eaaf619ecfaf6709810c90a6e5891a2ed1 --- src/internal/testenv/testenv.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/internal/testenv/testenv.go b/src/internal/testenv/testenv.go index 4a0284476bd49e..7d9ca34429e37a 100644 --- a/src/internal/testenv/testenv.go +++ b/src/internal/testenv/testenv.go @@ -16,12 +16,12 @@ import ( "flag" "fmt" "internal/cfg" + "internal/goarch" "internal/platform" "os" "os/exec" "path/filepath" "runtime" - "std/internal/goarch" "strconv" "strings" "sync" From ee8912bb85b02b170d81945910ab649f36e73290 Mon Sep 17 00:00:00 2001 From: qiulaidongfeng <2645477756@qq.com> Date: Sun, 24 Mar 2024 09:25:51 +0800 Subject: [PATCH 5/8] n Change-Id: Ia70bf18fb75d4aa8e57d5d689351f41e1436513d --- src/internal/testenv/testenv.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/internal/testenv/testenv.go b/src/internal/testenv/testenv.go index 7d9ca34429e37a..21e719d07cc0f6 100644 --- a/src/internal/testenv/testenv.go +++ b/src/internal/testenv/testenv.go @@ -516,7 +516,7 @@ func SyscallIsNotSupported(err error) bool { // Parallel call t.Parallel() // unless there is a case that cannot be parallel. // -// know that there are no parallel cases: +// know that there are cannot parallel cases: // // - in 32-bit machine may raise OOM (see go.dev/issue/65823) func Parallel(t *testing.T) { From 9ea166ae38d49f542e0e75517ccbc0ddb9a9974b Mon Sep 17 00:00:00 2001 From: qiulaidongfeng <2645477756@qq.com> Date: Wed, 27 Mar 2024 22:26:35 +0800 Subject: [PATCH 6/8] n Change-Id: I5e5882bbe9af3a1d17fe0c11b72fbdda9842ae50 --- src/hash/maphash/smhasher_test.go | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/hash/maphash/smhasher_test.go b/src/hash/maphash/smhasher_test.go index 523556f08bb403..78e461a330f8aa 100644 --- a/src/hash/maphash/smhasher_test.go +++ b/src/hash/maphash/smhasher_test.go @@ -31,7 +31,7 @@ var fixedSeed = MakeSeed() // hash should not depend on values outside key. // hash should not depend on alignment. func TestSmhasherSanity(t *testing.T) { - testenv.Parallel(t) + t.Parallel() r := rand.New(rand.NewSource(1234)) const REP = 10 const KEYMAX = 128 @@ -120,7 +120,7 @@ func (s *hashSet) check(t *testing.T) { // a string plus adding zeros must make distinct hashes func TestSmhasherAppendedZeros(t *testing.T) { - testenv.Parallel(t) + t.Parallel() s := "hello" + strings.Repeat("\x00", 256) h := newHashSet() for i := 0; i <= len(s); i++ { @@ -153,7 +153,7 @@ func TestSmhasherSmallKeys(t *testing.T) { // Different length strings of all zeros have distinct hashes. func TestSmhasherZeros(t *testing.T) { - testenv.Parallel(t) + t.Parallel() N := 256 * 1024 if testing.Short() { N = 1024 @@ -217,7 +217,7 @@ func TestSmhasherCyclic(t *testing.T) { if testing.Short() { t.Skip("Skipping in short mode") } - testenv.Parallel(t) + t.Parallel() r := rand.New(rand.NewSource(1234)) const REPEAT = 8 const N = 1000000 @@ -247,6 +247,7 @@ func TestSmhasherSparse(t *testing.T) { if testing.Short() { t.Skip("Skipping in short mode") } + t.Parallel() h := newHashSet() sparse(t, h, 32, 6) sparse(t, h, 40, 6) @@ -285,6 +286,7 @@ func TestSmhasherPermutation(t *testing.T) { if testing.Short() { t.Skip("Skipping in short mode") } + t.Parallel() h := newHashSet() permutation(t, h, []uint32{0, 1, 2, 3, 4, 5, 6, 7}, 8) permutation(t, h, []uint32{0, 1 << 29, 2 << 29, 3 << 29, 4 << 29, 5 << 29, 6 << 29, 7 << 29}, 8) @@ -351,7 +353,7 @@ func TestSmhasherAvalanche(t *testing.T) { if testing.Short() { t.Skip("Skipping in short mode") } - testenv.Parallel(t) + t.Parallel() avalancheTest1(t, &bytesKey{make([]byte, 2)}) avalancheTest1(t, &bytesKey{make([]byte, 4)}) avalancheTest1(t, &bytesKey{make([]byte, 8)}) @@ -415,6 +417,7 @@ func avalancheTest1(t *testing.T, k key) { // All bit rotations of a set of distinct keys func TestSmhasherWindowed(t *testing.T) { + t.Parallel() windowed(t, &bytesKey{make([]byte, 128)}) } func windowed(t *testing.T, k key) { @@ -424,7 +427,6 @@ func windowed(t *testing.T, k key) { if testing.Short() { t.Skip("Skipping in short mode") } - testenv.Parallel(t) const BITS = 16 h := newHashSet() @@ -447,6 +449,7 @@ func TestSmhasherText(t *testing.T) { if testing.Short() { t.Skip("Skipping in short mode") } + t.Parallel() h := newHashSet() text(t, h, "Foo", "Bar") text(t, h, "FooBar", "") @@ -481,7 +484,7 @@ func TestSmhasherSeed(t *testing.T) { if unsafe.Sizeof(uintptr(0)) == 4 { t.Skip("32-bit platforms don't have ideal seed-input distributions (see issue 33988)") } - testenv.Parallel(t) + t.Parallel() h := newHashSet() const N = 100000 s := "hello" From bbeb53ea09d7b6860e6d64fb7817e71182af5f0e Mon Sep 17 00:00:00 2001 From: qiulaidongfeng <2645477756@qq.com> Date: Wed, 27 Mar 2024 22:44:46 +0800 Subject: [PATCH 7/8] n Change-Id: I2cd192688f134998741864a14be7d44ac8a0ea94 --- src/hash/maphash/smhasher_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hash/maphash/smhasher_test.go b/src/hash/maphash/smhasher_test.go index 78e461a330f8aa..9fbe950646321a 100644 --- a/src/hash/maphash/smhasher_test.go +++ b/src/hash/maphash/smhasher_test.go @@ -286,7 +286,7 @@ func TestSmhasherPermutation(t *testing.T) { if testing.Short() { t.Skip("Skipping in short mode") } - t.Parallel() + testenv.Parallel(t) h := newHashSet() permutation(t, h, []uint32{0, 1, 2, 3, 4, 5, 6, 7}, 8) permutation(t, h, []uint32{0, 1 << 29, 2 << 29, 3 << 29, 4 << 29, 5 << 29, 6 << 29, 7 << 29}, 8) From 28277255587f6a1b92b9bf1848e1f53adaca64dc Mon Sep 17 00:00:00 2001 From: qiulaidongfeng <2645477756@qq.com> Date: Wed, 1 May 2024 21:25:34 +0800 Subject: [PATCH 8/8] n Change-Id: If9746c5e5e9fa101c6071ae373cfb80b1fcec872 --- src/hash/maphash/smhasher_test.go | 6 +++--- src/internal/testenv/testenv.go | 11 ++++------- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/src/hash/maphash/smhasher_test.go b/src/hash/maphash/smhasher_test.go index 9fbe950646321a..b17ef794f7a7bd 100644 --- a/src/hash/maphash/smhasher_test.go +++ b/src/hash/maphash/smhasher_test.go @@ -131,7 +131,7 @@ func TestSmhasherAppendedZeros(t *testing.T) { // All 0-3 byte strings have distinct hashes. func TestSmhasherSmallKeys(t *testing.T) { - testenv.Parallel(t) + testenv.ParallelOn64Bit(t) h := newHashSet() var b [3]byte for i := 0; i < 256; i++ { @@ -174,7 +174,7 @@ func TestSmhasherTwoNonzero(t *testing.T) { if testing.Short() { t.Skip("Skipping in short mode") } - testenv.Parallel(t) + testenv.ParallelOn64Bit(t) h := newHashSet() for n := 2; n <= 16; n++ { twoNonZero(h, n) @@ -286,7 +286,7 @@ func TestSmhasherPermutation(t *testing.T) { if testing.Short() { t.Skip("Skipping in short mode") } - testenv.Parallel(t) + testenv.ParallelOn64Bit(t) h := newHashSet() permutation(t, h, []uint32{0, 1, 2, 3, 4, 5, 6, 7}, 8) permutation(t, h, []uint32{0, 1 << 29, 2 << 29, 3 << 29, 4 << 29, 5 << 29, 6 << 29, 7 << 29}, 8) diff --git a/src/internal/testenv/testenv.go b/src/internal/testenv/testenv.go index 21e719d07cc0f6..9fb92406e8d85e 100644 --- a/src/internal/testenv/testenv.go +++ b/src/internal/testenv/testenv.go @@ -513,13 +513,10 @@ func SyscallIsNotSupported(err error) bool { return syscallIsNotSupported(err) } -// Parallel call t.Parallel() -// unless there is a case that cannot be parallel. -// -// know that there are cannot parallel cases: -// -// - in 32-bit machine may raise OOM (see go.dev/issue/65823) -func Parallel(t *testing.T) { +// ParallelOn64Bit calls t.Parallel() unless there is a case that cannot be parallel. +// This function should be used when it is necessary to avoid t.Parallel on +// 32-bit machines, typically because the test uses lots of memory. +func ParallelOn64Bit(t *testing.T) { if goarch.PtrSize == 4 { return }