package race_test
import (
+ "fmt"
"internal/testenv"
"os"
"os/exec"
"GORACE="+test.gorace,
)
got, _ := cmd.CombinedOutput()
- if !regexp.MustCompile(test.re).MatchString(string(got)) {
- t.Fatalf("failed test case %v, expect:\n%v\ngot:\n%s",
- test.name, test.re, got)
+ matched := false
+ for _, re := range test.re {
+ if regexp.MustCompile(re).MatchString(string(got)) {
+ matched = true
+ break
+ }
+ }
+ if !matched {
+ exp := fmt.Sprintf("expect:\n%v\n", test.re[0])
+ if len(test.re) > 1 {
+ exp = fmt.Sprintf("expected one of %d patterns:\n",
+ len(test.re))
+ for k, re := range test.re {
+ exp += fmt.Sprintf("pattern %d:\n%v\n", k, re)
+ }
+ }
+ t.Fatalf("failed test case %v, %sgot:\n%s",
+ test.name, exp, got)
}
}
}
goos string
gorace string
source string
- re string
+ re []string
}{
{"simple", "run", "", "atexit_sleep_ms=0", `
package main
store(x, 42)
done <- true
}
-`, `==================
+`, []string{`==================
WARNING: DATA RACE
Write at 0x[0-9,a-f]+ by goroutine [0-9]:
main\.store\(\)
==================
Found 1 data race\(s\)
exit status 66
-`},
+`}},
{"exitcode", "run", "", "atexit_sleep_ms=0 exitcode=13", `
package main
x = 43
<-done
}
-`, `exit status 13`},
+`, []string{`exit status 13`}},
{"strip_path_prefix", "run", "", "atexit_sleep_ms=0 strip_path_prefix=/main.", `
package main
x = 43
<-done
}
-`, `
+`, []string{`
go:7 \+0x[0-9,a-f]+
-`},
+`}},
{"halt_on_error", "run", "", "atexit_sleep_ms=0 halt_on_error=1", `
package main
x = 43
<-done
}
-`, `
+`, []string{`
==================
exit status 66
-`},
+`}},
{"test_fails_on_race", "test", "", "atexit_sleep_ms=0", `
package main_test
<-done
t.Log(t.Failed())
}
-`, `
+`, []string{`
==================
--- FAIL: TestFail \(0...s\)
.*main_test.go:14: true
.*testing.go:.*: race detected during execution of test
-FAIL`},
+FAIL`}},
{"slicebytetostring_pc", "run", "", "atexit_sleep_ms=0", `
package main
data[0] = 1
<-done
}
-`, `
+`, []string{`
runtime\.slicebytetostring\(\)
.*/runtime/string\.go:.*
main\.main\.func1\(\)
- .*/main.go:7`},
+ .*/main.go:7`}},
// Test for https://golang.org/issue/33309
{"midstack_inlining_traceback", "run", "linux", "atexit_sleep_ms=0", `
func h(c chan int) {
c <- x
}
-`, `==================
+`, []string{`==================
WARNING: DATA RACE
Read at 0x[0-9,a-f]+ by goroutine [0-9]:
main\.h\(\)
==================
Found 1 data race\(s\)
exit status 66
-`},
+`}},
// Test for https://golang.org/issue/17190
{"external_cgo_thread", "run", "linux", "atexit_sleep_ms=0", `
racy++
<- done
}
-`, `==================
+`, []string{`==================
+WARNING: DATA RACE
+Read at 0x[0-9,a-f]+ by main goroutine:
+ main\.main\(\)
+ .*/main\.go:34 \+0x[0-9,a-f]+
+
+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]+
+ _cgoexp_[0-9a-z]+_goCallback\(\)
+ <autogenerated>:1 \+0x[0-9,a-f]+
+
+Goroutine [0-9] \(running\) created at:
+ runtime\.newextram\(\)
+ .*/runtime/proc.go:[0-9]+ \+0x[0-9,a-f]+
+==================`,
+ `==================
WARNING: DATA RACE
Read at 0x[0-9,a-f]+ by .*:
main\..*
Goroutine [0-9] \(running\) created at:
runtime\.newextram\(\)
.*/runtime/proc.go:[0-9]+ \+0x[0-9,a-f]+
-==================`},
+==================`}},
{"second_test_passes", "test", "", "atexit_sleep_ms=0", `
package main_test
import "testing"
func TestPass(t *testing.T) {
}
-`, `
+`, []string{`
==================
--- FAIL: TestFail \(0...s\)
.*testing.go:.*: race detected during execution of test
-FAIL`},
+FAIL`}},
{"mutex", "run", "", "atexit_sleep_ms=0", `
package main
import (
}
wg.Wait()
if (data == iterations*(threads+1)) { fmt.Println("pass") }
-}`, `pass`},
+}`, []string{`pass`}},
// Test for https://github.com/golang/go/issues/37355
{"chanmm", "run", "", "atexit_sleep_ms=0", `
package main
wg.Wait()
_ = data
}
-`, `==================
+`, []string{`==================
WARNING: DATA RACE
Write at 0x[0-9,a-f]+ by goroutine [0-9]:
main\.main\.func2\(\)
Goroutine [0-9] \(running\) created at:
main\.main\(\)
.*/main.go:[0-9]+ \+0x[0-9,a-f]+
-==================`},
+==================`}},
}