Skip to content

Commit d4ff25a

Browse files
committed
misc/cgo/testsanitizers: determine compiler version for tsan tests on ppc64le
Some tests in misc/cgo/testsanitizers had been disabled on ppc64le until recently, due to an intermittent error in the tsan tests, with the goal of trying to understand the failure. After further investigation, I found that the code for tsan within gcc does not work consistently when ASLR is enabled on ppc64le. A fix for that problem was integrated in gcc 9. This adds a check to testsanitizers to determine the gcc compiler version on ppc64le and skip the test if the version is too old. A similar check is needed for asan too. Updates #54645 Change-Id: I70717d1aa9e967cf1e871566e72b3862b91fea3f Reviewed-on: https://go-review.googlesource.com/c/go/+/425355 TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]> Reviewed-by: Archana Ravindar <[email protected]> Reviewed-by: Cherry Mui <[email protected]> Run-TryBot: Lynn Boger <[email protected]>
1 parent 8c8429f commit d4ff25a

File tree

4 files changed

+37
-3
lines changed

4 files changed

+37
-3
lines changed

misc/cgo/testsanitizers/asan_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ func TestASAN(t *testing.T) {
2727
// -asan option must use a compatible version of ASan library, which requires that
2828
// the gcc version is not less than 7 and the clang version is not less than 9,
2929
// otherwise a segmentation fault will occur.
30-
if !compilerRequiredAsanVersion() {
31-
t.Skipf("skipping: too old version of compiler")
30+
if !compilerRequiredAsanVersion(goos, goarch) {
31+
t.Skipf("skipping on %s/%s: too old version of compiler", goos, goarch)
3232
}
3333

3434
t.Parallel()

misc/cgo/testsanitizers/cc_test.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,14 +252,30 @@ func compilerSupportsLocation() bool {
252252
}
253253
}
254254

255+
// compilerRequiredTsanVersion reports whether the compiler is the version required by Tsan.
256+
// Only restrictions for ppc64le are known; otherwise return true.
257+
func compilerRequiredTsanVersion(goos, goarch string) bool {
258+
compiler, err := compilerVersion()
259+
if err != nil {
260+
return false
261+
}
262+
if compiler.name == "gcc" && goarch == "ppc64le" {
263+
return compiler.major >= 9
264+
}
265+
return true
266+
}
267+
255268
// compilerRequiredAsanVersion reports whether the compiler is the version required by Asan.
256-
func compilerRequiredAsanVersion() bool {
269+
func compilerRequiredAsanVersion(goos, goarch string) bool {
257270
compiler, err := compilerVersion()
258271
if err != nil {
259272
return false
260273
}
261274
switch compiler.name {
262275
case "gcc":
276+
if goarch == "ppc64le" {
277+
return compiler.major >= 9
278+
}
263279
return compiler.major >= 7
264280
case "clang":
265281
return compiler.major >= 9

misc/cgo/testsanitizers/cshared_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ func TestShared(t *testing.T) {
5252
t.Logf("skipping %s test on %s/%s; -msan option is not supported.", name, GOOS, GOARCH)
5353
continue
5454
}
55+
if tc.sanitizer == "thread" && !compilerRequiredTsanVersion(GOOS, GOARCH) {
56+
t.Logf("skipping %s test on %s/%s; compiler version too old for -tsan.", name, GOOS, GOARCH)
57+
continue
58+
}
59+
5560
t.Run(name, func(t *testing.T) {
5661
t.Parallel()
5762
config := configure(tc.sanitizer)

misc/cgo/testsanitizers/tsan_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,19 @@ import (
1010
)
1111

1212
func TestTSAN(t *testing.T) {
13+
goos, err := goEnv("GOOS")
14+
if err != nil {
15+
t.Fatal(err)
16+
}
17+
goarch, err := goEnv("GOARCH")
18+
if err != nil {
19+
t.Fatal(err)
20+
}
21+
// The msan tests require support for the -msan option.
22+
if !compilerRequiredTsanVersion(goos, goarch) {
23+
t.Skipf("skipping on %s/%s; compiler version for -tsan option is too old.", goos, goarch)
24+
}
25+
1326
t.Parallel()
1427
requireOvercommit(t)
1528
config := configure("thread")

0 commit comments

Comments
 (0)