Skip to content

Commit 4b236b4

Browse files
mknyszekgopherbot
authored andcommitted
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 <[email protected]> Reviewed-by: Bryan Mills <[email protected]> Reviewed-by: Michael Pratt <[email protected]> Run-TryBot: Michael Knyszek <[email protected]> Auto-Submit: Michael Knyszek <[email protected]>
1 parent 530511b commit 4b236b4

File tree

6 files changed

+58
-354
lines changed

6 files changed

+58
-354
lines changed

src/go/build/deps_test.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -543,10 +543,7 @@ var depsRules = `
543543
internal/fuzz, internal/testlog, runtime/pprof, regexp
544544
< testing/internal/testdeps;
545545
546-
MATH, errors, testing
547-
< internal/testmath;
548-
549-
OS, flag, testing, internal/cfg, internal/testmath
546+
OS, flag, testing, internal/cfg
550547
< internal/testenv;
551548
552549
OS, encoding/base64

src/internal/testenv/testenv.go

Lines changed: 0 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import (
1616
"flag"
1717
"fmt"
1818
"internal/cfg"
19-
"internal/testmath"
2019
"os"
2120
"os/exec"
2221
"path/filepath"
@@ -464,67 +463,3 @@ func RunWithTimeout(t testing.TB, cmd *exec.Cmd) ([]byte, error) {
464463

465464
return b.Bytes(), err
466465
}
467-
468-
// CheckLinear checks if the function produced by f scales linearly.
469-
//
470-
// f must accept a scale factor which causes the input to the function it
471-
// produces to scale by that factor.
472-
func CheckLinear(t *testing.T, f func(scale float64) func(*testing.B)) {
473-
MustHaveExec(t)
474-
475-
if os.Getenv("GO_PERF_UNIT_TEST") == "" {
476-
// Invoke the same test as a subprocess with the GO_PERF_UNIT_TEST environment variable set.
477-
// We create a subprocess for two reasons:
478-
//
479-
// 1. There's no other way to set the benchmarking parameters of testing.Benchmark.
480-
// 2. Since we're effectively running a performance test, running in a subprocess grants
481-
// us a little bit more isolation than using the same process.
482-
//
483-
// As an alternative, we could fairly easily reimplement the timing code in testing.Benchmark,
484-
// but a subprocess is just as easy to create.
485-
486-
selfCmd := CleanCmdEnv(exec.Command(os.Args[0], "-test.v", fmt.Sprintf("-test.run=^%s$", t.Name()), "-test.benchtime=1x"))
487-
selfCmd.Env = append(selfCmd.Env, "GO_PERF_UNIT_TEST=1")
488-
output, err := RunWithTimeout(t, selfCmd)
489-
if err != nil {
490-
t.Error(err)
491-
t.Logf("--- subprocess output ---\n%s", string(output))
492-
}
493-
if bytes.Contains(output, []byte("insignificant result")) {
494-
t.Skip("insignificant result")
495-
}
496-
return
497-
}
498-
499-
// Pick a reasonable sample count.
500-
const count = 10
501-
502-
// Collect samples for scale factor 1.
503-
x1 := make([]testing.BenchmarkResult, 0, count)
504-
for i := 0; i < count; i++ {
505-
x1 = append(x1, testing.Benchmark(f(1.0)))
506-
}
507-
508-
// Collect samples for scale factor 2.
509-
x2 := make([]testing.BenchmarkResult, 0, count)
510-
for i := 0; i < count; i++ {
511-
x2 = append(x2, testing.Benchmark(f(2.0)))
512-
}
513-
514-
// Run a t-test on the results.
515-
r1 := testmath.BenchmarkResults(x1)
516-
r2 := testmath.BenchmarkResults(x2)
517-
result, err := testmath.TwoSampleWelchTTest(r1, r2, testmath.LocationDiffers)
518-
if err != nil {
519-
t.Fatalf("failed to run t-test: %v", err)
520-
}
521-
if result.P > 0.005 {
522-
// Insignificant result.
523-
t.Skip("insignificant result")
524-
}
525-
526-
// Let ourselves be within 3x; 2x is too strict.
527-
if m1, m2 := r1.Mean(), r2.Mean(); 3.0*m1 < m2 {
528-
t.Fatalf("failure to scale linearly: µ_1=%s µ_2=%s p=%f", time.Duration(m1), time.Duration(m2), result.P)
529-
}
530-
}

src/internal/testmath/bench.go

Lines changed: 0 additions & 38 deletions
This file was deleted.

src/internal/testmath/ttest.go

Lines changed: 0 additions & 213 deletions
This file was deleted.

src/runtime/sema.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ import (
3535
// where n is the number of distinct addresses with goroutines blocked
3636
// on them that hash to the given semaRoot.
3737
// See golang.org/issue/17953 for a program that worked badly
38-
// before we introduced the second level of list, and TestSemTableOneAddrCollisionLinear
39-
// for a test that exercises this.
38+
// before we introduced the second level of list, and
39+
// BenchmarkSemTable/OneAddrCollision/* for a benchmark that exercises this.
4040
type semaRoot struct {
4141
lock mutex
4242
treap *sudog // root of balanced tree of unique waiters.

0 commit comments

Comments
 (0)