aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/race/output_test.go
diff options
context:
space:
mode:
authorDaniel S Fava <danielsfava@gmail.com>2020-12-09 23:56:50 +0100
committerIan Lance Taylor <iant@golang.org>2020-12-14 20:30:16 +0000
commit2f5b1a397454b76ad71e7eda5d574c304a416372 (patch)
tree0feecd05a55f79c6c7c4afcd9ab7f4538ec1d726 /src/runtime/race/output_test.go
parentc81343ce3aa1b8f1b2539a3d391f628f69a0a490 (diff)
downloadgo-2f5b1a397454b76ad71e7eda5d574c304a416372.tar.gz
go-2f5b1a397454b76ad71e7eda5d574c304a416372.zip
test: make a race detector test robust to timing variations
The `external_cgo_thread` test in `runtime/race/output_test.go` was producing intermittent failures. The test was performing a sleep, which may not be enough depending on how long it takes to setup the callBack goroutine. Added a synchronization to make sure callBack finishes before main ends. Whether the increment to racy++ happens first in the callBack or in main doesn't matter: the race detector should flag the race regardless. The output check was changed so that the test passes regardless of which increment occurs first. Fixes #43008 Change-Id: I325ec3dea52b3725e739fbf2bd7ae92875d2de10 Reviewed-on: https://go-review.googlesource.com/c/go/+/276752 Reviewed-by: Dmitry Vyukov <dvyukov@google.com> Run-TryBot: Dmitry Vyukov <dvyukov@google.com> TryBot-Result: Go Bot <gobot@golang.org> Trust: Ian Lance Taylor <iant@golang.org>
Diffstat (limited to 'src/runtime/race/output_test.go')
-rw-r--r--src/runtime/race/output_test.go21
1 files changed, 10 insertions, 11 deletions
diff --git a/src/runtime/race/output_test.go b/src/runtime/race/output_test.go
index 986667332f..69496874c6 100644
--- a/src/runtime/race/output_test.go
+++ b/src/runtime/race/output_test.go
@@ -284,32 +284,31 @@ static inline void startThread(cb* c) {
*/
import "C"
-import "time"
-
+var done chan bool
var racy int
//export goCallback
func goCallback() {
racy++
+ done <- true
}
func main() {
+ done = make(chan bool)
var c C.cb
C.startThread(&c)
- time.Sleep(time.Second)
racy++
+ <- done
}
`, `==================
WARNING: DATA RACE
-Read at 0x[0-9,a-f]+ by main goroutine:
- main\.main\(\)
- .*/main\.go:34 \+0x[0-9,a-f]+
+Read at 0x[0-9,a-f]+ by .*:
+ main\..*
+ .*/main\.go:[0-9]+ \+0x[0-9,a-f]+(?s).*
-Previous write at 0x[0-9,a-f]+ by goroutine [0-9]:
- main\.goCallback\(\)
- .*/main\.go:27 \+0x[0-9,a-f]+
- _cgoexp_[0-9a-z]+_goCallback\(\)
- .*_cgo_gotypes\.go:[0-9]+ \+0x[0-9,a-f]+
+Previous write at 0x[0-9,a-f]+ by .*:
+ main\..*
+ .*/main\.go:[0-9]+ \+0x[0-9,a-f]+(?s).*
Goroutine [0-9] \(running\) created at:
runtime\.newextram\(\)