aboutsummaryrefslogtreecommitdiff
path: root/test/locklinear.go
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2017-02-24 16:01:50 -0500
committerRuss Cox <rsc@golang.org>2017-02-24 21:18:21 +0000
commit349b7820eb8bd30d42afad945b22e4e9fe74eff1 (patch)
treef9215ce1e4ab01182a6b0ef641085efa062a576e /test/locklinear.go
parent67fcd9c5d9f84e4f66df1e357ca9f76523ecff4e (diff)
downloadgo-349b7820eb8bd30d42afad945b22e4e9fe74eff1.tar.gz
go-349b7820eb8bd30d42afad945b22e4e9fe74eff1.zip
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 <rsc@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Diffstat (limited to 'test/locklinear.go')
-rw-r--r--test/locklinear.go25
1 files changed, 16 insertions, 9 deletions
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)