]> Cypherpunks repositories - gostls13.git/commitdiff
test: deflake locklinear a little
authorRuss Cox <rsc@golang.org>
Fri, 24 Feb 2017 21:01:50 +0000 (16:01 -0500)
committerRuss Cox <rsc@golang.org>
Fri, 24 Feb 2017 21:18:21 +0000 (21:18 +0000)
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>
test/locklinear.go

index cddfff24f92300fc4074f8e7e1a36f55692b6a19..3585b40d677ff2e7131e9f56d0b6c058fcff8f9d 100644 (file)
@@ -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)