1
0
mirror of https://github.com/golang/go synced 2024-11-15 02:40:32 -07:00

hash/maphash: parallel run test

This is a reapplication of CL 564576.

This reduces the go test hash/maphash time
by more than half.

After investigation it was confirmed that
the original CL would cause OOM when 32-bit machine.

This CL add testenv.ParallelOn64Bit for tests
that can be parallel on 64-bit machines,
it is not parallel on 32-bit machines,
because CL 564995 require the same API.

Change-Id: I1b7feaa07716cb3f55db4671653348fabf2396b0
GitHub-Last-Rev: 2827725558
GitHub-Pull-Request: golang/go#66359
Cq-Include-Trybots: luci.golang.try:gotip-linux-386-longtest
Reviewed-on: https://go-review.googlesource.com/c/go/+/572195
Reviewed-by: Keith Randall <khr@google.com>
Auto-Submit: Keith Randall <khr@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: David Chase <drchase@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
This commit is contained in:
qiulaidongfeng 2024-05-01 13:42:46 +00:00 committed by Gopher Robot
parent 18dd682672
commit 44e48c7e6c
2 changed files with 24 additions and 0 deletions

View File

@ -8,6 +8,7 @@ package maphash
import (
"fmt"
"internal/testenv"
"math"
"math/rand"
"runtime"
@ -30,6 +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()
r := rand.New(rand.NewSource(1234))
const REP = 10
const KEYMAX = 128
@ -118,6 +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()
s := "hello" + strings.Repeat("\x00", 256)
h := newHashSet()
for i := 0; i <= len(s); i++ {
@ -128,6 +131,7 @@ func TestSmhasherAppendedZeros(t *testing.T) {
// All 0-3 byte strings have distinct hashes.
func TestSmhasherSmallKeys(t *testing.T) {
testenv.ParallelOn64Bit(t)
h := newHashSet()
var b [3]byte
for i := 0; i < 256; i++ {
@ -149,6 +153,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 +174,7 @@ func TestSmhasherTwoNonzero(t *testing.T) {
if testing.Short() {
t.Skip("Skipping in short mode")
}
testenv.ParallelOn64Bit(t)
h := newHashSet()
for n := 2; n <= 16; n++ {
twoNonZero(h, n)
@ -211,6 +217,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
@ -240,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)
@ -278,6 +286,7 @@ func TestSmhasherPermutation(t *testing.T) {
if testing.Short() {
t.Skip("Skipping in short mode")
}
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)
@ -344,6 +353,7 @@ func TestSmhasherAvalanche(t *testing.T) {
if testing.Short() {
t.Skip("Skipping in short mode")
}
t.Parallel()
avalancheTest1(t, &bytesKey{make([]byte, 2)})
avalancheTest1(t, &bytesKey{make([]byte, 4)})
avalancheTest1(t, &bytesKey{make([]byte, 8)})
@ -407,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) {
@ -438,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", "")
@ -472,6 +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)")
}
t.Parallel()
h := newHashSet()
const N = 100000
s := "hello"

View File

@ -16,6 +16,7 @@ import (
"flag"
"fmt"
"internal/cfg"
"internal/goarch"
"internal/platform"
"os"
"os/exec"
@ -511,3 +512,13 @@ func WriteImportcfg(t testing.TB, dstPath string, packageFiles map[string]string
func SyscallIsNotSupported(err error) bool {
return syscallIsNotSupported(err)
}
// 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
}
t.Parallel()
}