Commit 349b7820 authored by Russ Cox's avatar Russ Cox

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: default avatarBrad Fitzpatrick <bradfitz@golang.org>
parent 67fcd9c5
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
package main package main
import ( import (
"bytes"
"fmt" "fmt"
"log" "log"
"os" "os"
...@@ -36,12 +37,14 @@ func checkLinear(typ string, tries int, f func(n int)) { ...@@ -36,12 +37,14 @@ func checkLinear(typ string, tries int, f func(n int)) {
n := tries n := tries
fails := 0 fails := 0
var buf bytes.Buffer
for { for {
t1 := timeF(n) t1 := timeF(n)
t2 := timeF(2 * n) t2 := timeF(2 * n)
if debug { if debug {
println(n, t1.String(), 2*n, t2.String()) 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 // should be 2x (linear); allow up to 2.5x
if t1*3/2 < t2 && t2 < t1*5/2 { if t1*3/2 < t2 && t2 < t1*5/2 {
return return
...@@ -56,23 +59,27 @@ func checkLinear(typ string, tries int, f func(n int)) { ...@@ -56,23 +59,27 @@ func checkLinear(typ string, tries int, f func(n int)) {
} }
// Once the test runs long enough for n ops, // Once the test runs long enough for n ops,
// try to get the right ratio at least once. // try to get the right ratio at least once.
// If five in a row all fail, give up. // If many in a row all fail, give up.
if fails++; fails >= 5 { if fails++; fails >= 10 {
panic(fmt.Sprintf("%s: too slow: %d ops: %v; %d ops: %v\n", panic(fmt.Sprintf("%s: too slow: %d ops: %v; %d ops: %v\n\n%s",
typ, n, t1, 2*n, t2)) typ, n, t1, 2*n, t2, buf.String()))
} }
} }
} }
const offset = 251 // known size of runtime hash table const offset = 251 // known size of runtime hash table
const profile = false
func main() { func main() {
f, err := os.Create("lock.prof") if profile {
if err != nil { f, err := os.Create("lock.prof")
log.Fatal(err) if err != nil {
log.Fatal(err)
}
pprof.StartCPUProfile(f)
defer pprof.StopCPUProfile()
} }
pprof.StartCPUProfile(f)
defer pprof.StopCPUProfile()
checkLinear("lockone", 1000, func(n int) { checkLinear("lockone", 1000, func(n int) {
ch := make(chan int) ch := make(chan int)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment