aboutsummaryrefslogtreecommitdiff
path: root/src/internal/testenv
diff options
context:
space:
mode:
authorMichael Anthony Knyszek <mknyszek@google.com>2022-06-17 19:56:27 +0000
committerGopher Robot <gobot@golang.org>2022-06-21 19:37:22 +0000
commit4b236b45d0bb659a447dcfc02ebd431587b52e2b (patch)
treeb65509093e8324d051252a22c265950c624ed847 /src/internal/testenv
parent530511bacccdea0bb8a0fec644887c2613535c50 (diff)
downloadgo-4b236b45d0bb659a447dcfc02ebd431587b52e2b.tar.xz
runtime: convert flaky semaphore linearity test into benchmark
Also, add a benchmark for another case that was originally tested. Also also, remove all the dead code this now creates. Fixes #53428. Change-Id: Idbba88d3d31d38a8854fd5ed99001e394da27300 Reviewed-on: https://go-review.googlesource.com/c/go/+/412878 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Bryan Mills <bcmills@google.com> Reviewed-by: Michael Pratt <mpratt@google.com> Run-TryBot: Michael Knyszek <mknyszek@google.com> Auto-Submit: Michael Knyszek <mknyszek@google.com>
Diffstat (limited to 'src/internal/testenv')
-rw-r--r--src/internal/testenv/testenv.go65
1 files changed, 0 insertions, 65 deletions
diff --git a/src/internal/testenv/testenv.go b/src/internal/testenv/testenv.go
index b7cb95063b..1feb630cf5 100644
--- a/src/internal/testenv/testenv.go
+++ b/src/internal/testenv/testenv.go
@@ -16,7 +16,6 @@ import (
"flag"
"fmt"
"internal/cfg"
- "internal/testmath"
"os"
"os/exec"
"path/filepath"
@@ -464,67 +463,3 @@ func RunWithTimeout(t testing.TB, cmd *exec.Cmd) ([]byte, error) {
return b.Bytes(), err
}
-
-// CheckLinear checks if the function produced by f scales linearly.
-//
-// f must accept a scale factor which causes the input to the function it
-// produces to scale by that factor.
-func CheckLinear(t *testing.T, f func(scale float64) func(*testing.B)) {
- MustHaveExec(t)
-
- if os.Getenv("GO_PERF_UNIT_TEST") == "" {
- // Invoke the same test as a subprocess with the GO_PERF_UNIT_TEST environment variable set.
- // We create a subprocess for two reasons:
- //
- // 1. There's no other way to set the benchmarking parameters of testing.Benchmark.
- // 2. Since we're effectively running a performance test, running in a subprocess grants
- // us a little bit more isolation than using the same process.
- //
- // As an alternative, we could fairly easily reimplement the timing code in testing.Benchmark,
- // but a subprocess is just as easy to create.
-
- selfCmd := CleanCmdEnv(exec.Command(os.Args[0], "-test.v", fmt.Sprintf("-test.run=^%s$", t.Name()), "-test.benchtime=1x"))
- selfCmd.Env = append(selfCmd.Env, "GO_PERF_UNIT_TEST=1")
- output, err := RunWithTimeout(t, selfCmd)
- if err != nil {
- t.Error(err)
- t.Logf("--- subprocess output ---\n%s", string(output))
- }
- if bytes.Contains(output, []byte("insignificant result")) {
- t.Skip("insignificant result")
- }
- return
- }
-
- // Pick a reasonable sample count.
- const count = 10
-
- // Collect samples for scale factor 1.
- x1 := make([]testing.BenchmarkResult, 0, count)
- for i := 0; i < count; i++ {
- x1 = append(x1, testing.Benchmark(f(1.0)))
- }
-
- // Collect samples for scale factor 2.
- x2 := make([]testing.BenchmarkResult, 0, count)
- for i := 0; i < count; i++ {
- x2 = append(x2, testing.Benchmark(f(2.0)))
- }
-
- // Run a t-test on the results.
- r1 := testmath.BenchmarkResults(x1)
- r2 := testmath.BenchmarkResults(x2)
- result, err := testmath.TwoSampleWelchTTest(r1, r2, testmath.LocationDiffers)
- if err != nil {
- t.Fatalf("failed to run t-test: %v", err)
- }
- if result.P > 0.005 {
- // Insignificant result.
- t.Skip("insignificant result")
- }
-
- // Let ourselves be within 3x; 2x is too strict.
- if m1, m2 := r1.Mean(), r2.Mean(); 3.0*m1 < m2 {
- t.Fatalf("failure to scale linearly: µ_1=%s µ_2=%s p=%f", time.Duration(m1), time.Duration(m2), result.P)
- }
-}