Skip to content

Commit 349b782

Browse files
committed
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 <[email protected]> Reviewed-by: Brad Fitzpatrick <[email protected]>
1 parent 67fcd9c commit 349b782

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

test/locklinear.go

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
package main
1010

1111
import (
12+
"bytes"
1213
"fmt"
1314
"log"
1415
"os"
@@ -36,12 +37,14 @@ func checkLinear(typ string, tries int, f func(n int)) {
3637

3738
n := tries
3839
fails := 0
40+
var buf bytes.Buffer
3941
for {
4042
t1 := timeF(n)
4143
t2 := timeF(2 * n)
4244
if debug {
4345
println(n, t1.String(), 2*n, t2.String())
4446
}
47+
fmt.Fprintf(&buf, "%d %v %d %v\n", n, t1, 2*n, t2)
4548
// should be 2x (linear); allow up to 2.5x
4649
if t1*3/2 < t2 && t2 < t1*5/2 {
4750
return
@@ -56,23 +59,27 @@ func checkLinear(typ string, tries int, f func(n int)) {
5659
}
5760
// Once the test runs long enough for n ops,
5861
// try to get the right ratio at least once.
59-
// If five in a row all fail, give up.
60-
if fails++; fails >= 5 {
61-
panic(fmt.Sprintf("%s: too slow: %d ops: %v; %d ops: %v\n",
62-
typ, n, t1, 2*n, t2))
62+
// If many in a row all fail, give up.
63+
if fails++; fails >= 10 {
64+
panic(fmt.Sprintf("%s: too slow: %d ops: %v; %d ops: %v\n\n%s",
65+
typ, n, t1, 2*n, t2, buf.String()))
6366
}
6467
}
6568
}
6669

6770
const offset = 251 // known size of runtime hash table
6871

72+
const profile = false
73+
6974
func main() {
70-
f, err := os.Create("lock.prof")
71-
if err != nil {
72-
log.Fatal(err)
75+
if profile {
76+
f, err := os.Create("lock.prof")
77+
if err != nil {
78+
log.Fatal(err)
79+
}
80+
pprof.StartCPUProfile(f)
81+
defer pprof.StopCPUProfile()
7382
}
74-
pprof.StartCPUProfile(f)
75-
defer pprof.StopCPUProfile()
7683

7784
checkLinear("lockone", 1000, func(n int) {
7885
ch := make(chan int)

0 commit comments

Comments
 (0)