From: Russ Cox Date: Fri, 24 Feb 2017 21:01:50 +0000 (-0500) Subject: test: deflake locklinear a little X-Git-Tag: go1.9beta1~1435 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=349b7820eb8bd30d42afad945b22e4e9fe74eff1;p=gostls13.git test: deflake locklinear a little This should help on the openbsd systems where the test mostly passes. I don't expect it to help on s390x where the test reliably fails. But it should give more information when it does fail. For #19276. Change-Id: I496c291f2b4b0c747b8dd4315477d87d03010059 Reviewed-on: https://go-review.googlesource.com/37348 Run-TryBot: Russ Cox Reviewed-by: Brad Fitzpatrick --- diff --git a/test/locklinear.go b/test/locklinear.go index cddfff24f9..3585b40d67 100644 --- a/test/locklinear.go +++ b/test/locklinear.go @@ -9,6 +9,7 @@ package main import ( + "bytes" "fmt" "log" "os" @@ -36,12 +37,14 @@ func checkLinear(typ string, tries int, f func(n int)) { n := tries fails := 0 + var buf bytes.Buffer for { t1 := timeF(n) t2 := timeF(2 * n) if debug { println(n, t1.String(), 2*n, t2.String()) } + fmt.Fprintf(&buf, "%d %v %d %v\n", n, t1, 2*n, t2) // should be 2x (linear); allow up to 2.5x if t1*3/2 < t2 && t2 < t1*5/2 { return @@ -56,23 +59,27 @@ func checkLinear(typ string, tries int, f func(n int)) { } // Once the test runs long enough for n ops, // try to get the right ratio at least once. - // If five in a row all fail, give up. - if fails++; fails >= 5 { - panic(fmt.Sprintf("%s: too slow: %d ops: %v; %d ops: %v\n", - typ, n, t1, 2*n, t2)) + // If many in a row all fail, give up. + if fails++; fails >= 10 { + panic(fmt.Sprintf("%s: too slow: %d ops: %v; %d ops: %v\n\n%s", + typ, n, t1, 2*n, t2, buf.String())) } } } const offset = 251 // known size of runtime hash table +const profile = false + func main() { - f, err := os.Create("lock.prof") - if err != nil { - log.Fatal(err) + if profile { + f, err := os.Create("lock.prof") + if err != nil { + log.Fatal(err) + } + pprof.StartCPUProfile(f) + defer pprof.StopCPUProfile() } - pprof.StartCPUProfile(f) - defer pprof.StopCPUProfile() checkLinear("lockone", 1000, func(n int) { ch := make(chan int)