diff options
| author | Paschalis Tsilias <paschalis.tsilias@gmail.com> | 2021-04-14 23:55:38 +0300 |
|---|---|---|
| committer | Ian Lance Taylor <iant@golang.org> | 2021-04-28 16:06:21 +0000 |
| commit | cbb3f090477de92a7e158050803ef71a5ea825ee (patch) | |
| tree | f8cb18236c1fb9ca9d19db1c2586086516b8a9b8 /src/math | |
| parent | e51246c8819f16cd78d3da01162ca14b432d30bc (diff) | |
| download | go-cbb3f090477de92a7e158050803ef71a5ea825ee.tar.xz | |
testing: add -shuffle=off|on|N to alter the execution order of tests and benchmarks
This CL adds a new flag to the testing package and the go test command
which randomizes the execution order for tests and benchmarks.
This can be useful for identifying unwanted dependencies
between test or benchmark functions.
The flag is off by default. If `-shuffle` is set to `on` then the system
clock will be used as the seed value. If `-shuffle` is set to an integer
N, then N will be used as the seed value. In both cases, the seed will
be reported for failed runs so that they can reproduced later on.
Fixes #28592
Change-Id: I62e7dfae5f63f97a0cbd7830ea844d9f7beac335
Reviewed-on: https://go-review.googlesource.com/c/go/+/310033
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com>
Trust: Bryan C. Mills <bcmills@google.com>
Diffstat (limited to 'src/math')
| -rw-r--r-- | src/math/rand/export_test.go | 17 | ||||
| -rw-r--r-- | src/math/rand/race_test.go | 3 | ||||
| -rw-r--r-- | src/math/rand/rand_test.go | 8 |
3 files changed, 25 insertions, 3 deletions
diff --git a/src/math/rand/export_test.go b/src/math/rand/export_test.go new file mode 100644 index 0000000000..560010be6b --- /dev/null +++ b/src/math/rand/export_test.go @@ -0,0 +1,17 @@ +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package rand + +func Int31nForTest(r *Rand, n int32) int32 { + return r.int31n(n) +} + +func GetNormalDistributionParameters() (float64, [128]uint32, [128]float32, [128]float32) { + return rn, kn, wn, fn +} + +func GetExponentialDistributionParameters() (float64, [256]uint32, [256]float32, [256]float32) { + return re, ke, we, fe +} diff --git a/src/math/rand/race_test.go b/src/math/rand/race_test.go index 186c7169d8..e7d103664b 100644 --- a/src/math/rand/race_test.go +++ b/src/math/rand/race_test.go @@ -2,9 +2,10 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -package rand +package rand_test import ( + . "math/rand" "sync" "testing" ) diff --git a/src/math/rand/rand_test.go b/src/math/rand/rand_test.go index e037aaed0e..462de8b73b 100644 --- a/src/math/rand/rand_test.go +++ b/src/math/rand/rand_test.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -package rand +package rand_test import ( "bytes" @@ -11,6 +11,7 @@ import ( "internal/testenv" "io" "math" + . "math/rand" "os" "runtime" "testing" @@ -21,6 +22,9 @@ const ( numTestSamples = 10000 ) +var rn, kn, wn, fn = GetNormalDistributionParameters() +var re, ke, we, fe = GetExponentialDistributionParameters() + type statsResults struct { mean float64 stddev float64 @@ -503,7 +507,7 @@ func TestUniformFactorial(t *testing.T) { fn func() int }{ {name: "Int31n", fn: func() int { return int(r.Int31n(int32(nfact))) }}, - {name: "int31n", fn: func() int { return int(r.int31n(int32(nfact))) }}, + {name: "int31n", fn: func() int { return int(Int31nForTest(r, int32(nfact))) }}, {name: "Perm", fn: func() int { return encodePerm(r.Perm(n)) }}, {name: "Shuffle", fn: func() int { // Generate permutation using Shuffle. |
