aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/crash_test.go
diff options
context:
space:
mode:
authorMichael Pratt <mpratt@google.com>2025-01-22 17:18:19 -0500
committerGopher Robot <gobot@golang.org>2025-05-19 11:00:01 -0700
commit2c929d6f4c8fcd1021dc3cd57b2eedff5ae9a592 (patch)
treebd5dc12ab00823fa1f4450eb838cf0eb4d2abfb8 /src/runtime/crash_test.go
parent5afada035ced1f89267d3177a9fb75fab4df81ff (diff)
downloadgo-2c929d6f4c8fcd1021dc3cd57b2eedff5ae9a592.tar.xz
runtime: pass through -asan/-msan/-race to testprog tests
The tests using testprog / testprogcgo are currently not covered on the asan/msan/race builders because they don't build testprog with the sanitizer flag. Explicitly pass the flag if the test itself is built with the sanitizer. There were a few tests that explicitly passed -race (even on non-race builders). These tests will now only run on race builders. For #71395. Cq-Include-Trybots: luci.golang.try:gotip-linux-amd64-asan-clang15,gotip-linux-amd64-msan-clang15,gotip-linux-amd64-race Change-Id: I6a6a636ce8271246316a80d426c0e4e2f6ab99c5 Reviewed-on: https://go-review.googlesource.com/c/go/+/643897 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Michael Knyszek <mknyszek@google.com> Auto-Submit: Michael Pratt <mpratt@google.com>
Diffstat (limited to 'src/runtime/crash_test.go')
-rw-r--r--src/runtime/crash_test.go54
1 files changed, 46 insertions, 8 deletions
diff --git a/src/runtime/crash_test.go b/src/runtime/crash_test.go
index e29a78c2e4..e691746598 100644
--- a/src/runtime/crash_test.go
+++ b/src/runtime/crash_test.go
@@ -10,7 +10,10 @@ import (
"errors"
"flag"
"fmt"
+ "internal/asan"
+ "internal/msan"
"internal/profile"
+ "internal/race"
"internal/testenv"
traceparse "internal/trace"
"io"
@@ -166,6 +169,16 @@ func buildTestProg(t *testing.T, binary string, flags ...string) (string, error)
// Don't get confused if testenv.GoToolPath calls t.Skip.
target.err = errors.New("building test called t.Skip")
+ if asan.Enabled {
+ flags = append(flags, "-asan")
+ }
+ if msan.Enabled {
+ flags = append(flags, "-msan")
+ }
+ if race.Enabled {
+ flags = append(flags, "-race")
+ }
+
exe := filepath.Join(dir, name+".exe")
start := time.Now()
@@ -230,9 +243,17 @@ func TestCrashHandler(t *testing.T) {
testCrashHandler(t, false)
}
+var deadlockBuildTypes = testenv.SpecialBuildTypes{
+ // External linking brings in cgo, causing deadlock detection not working.
+ Cgo: false,
+ Asan: asan.Enabled,
+ Msan: msan.Enabled,
+ Race: race.Enabled,
+}
+
func testDeadlock(t *testing.T, name string) {
// External linking brings in cgo, causing deadlock detection not working.
- testenv.MustInternalLink(t, false)
+ testenv.MustInternalLink(t, deadlockBuildTypes)
output := runTestProg(t, "testprog", name)
want := "fatal error: all goroutines are asleep - deadlock!\n"
@@ -259,7 +280,7 @@ func TestLockedDeadlock2(t *testing.T) {
func TestGoexitDeadlock(t *testing.T) {
// External linking brings in cgo, causing deadlock detection not working.
- testenv.MustInternalLink(t, false)
+ testenv.MustInternalLink(t, deadlockBuildTypes)
output := runTestProg(t, "testprog", "GoexitDeadlock")
want := "no goroutines (main called runtime.Goexit) - deadlock!"
@@ -390,7 +411,7 @@ func TestRepanickedPanicSandwich(t *testing.T) {
func TestGoexitCrash(t *testing.T) {
// External linking brings in cgo, causing deadlock detection not working.
- testenv.MustInternalLink(t, false)
+ testenv.MustInternalLink(t, deadlockBuildTypes)
output := runTestProg(t, "testprog", "GoexitExit")
want := "no goroutines (main called runtime.Goexit) - deadlock!"
@@ -451,7 +472,7 @@ func TestBreakpoint(t *testing.T) {
func TestGoexitInPanic(t *testing.T) {
// External linking brings in cgo, causing deadlock detection not working.
- testenv.MustInternalLink(t, false)
+ testenv.MustInternalLink(t, deadlockBuildTypes)
// see issue 8774: this code used to trigger an infinite recursion
output := runTestProg(t, "testprog", "GoexitInPanic")
@@ -518,7 +539,7 @@ func TestPanicAfterGoexit(t *testing.T) {
func TestRecoveredPanicAfterGoexit(t *testing.T) {
// External linking brings in cgo, causing deadlock detection not working.
- testenv.MustInternalLink(t, false)
+ testenv.MustInternalLink(t, deadlockBuildTypes)
output := runTestProg(t, "testprog", "RecoveredPanicAfterGoexit")
want := "fatal error: no goroutines (main called runtime.Goexit) - deadlock!"
@@ -529,7 +550,7 @@ func TestRecoveredPanicAfterGoexit(t *testing.T) {
func TestRecoverBeforePanicAfterGoexit(t *testing.T) {
// External linking brings in cgo, causing deadlock detection not working.
- testenv.MustInternalLink(t, false)
+ testenv.MustInternalLink(t, deadlockBuildTypes)
t.Parallel()
output := runTestProg(t, "testprog", "RecoverBeforePanicAfterGoexit")
@@ -541,7 +562,7 @@ func TestRecoverBeforePanicAfterGoexit(t *testing.T) {
func TestRecoverBeforePanicAfterGoexit2(t *testing.T) {
// External linking brings in cgo, causing deadlock detection not working.
- testenv.MustInternalLink(t, false)
+ testenv.MustInternalLink(t, deadlockBuildTypes)
t.Parallel()
output := runTestProg(t, "testprog", "RecoverBeforePanicAfterGoexit2")
@@ -654,6 +675,9 @@ func TestConcurrentMapWrites(t *testing.T) {
if !*concurrentMapTest {
t.Skip("skipping without -run_concurrent_map_tests")
}
+ if race.Enabled {
+ t.Skip("skipping test: -race will catch the race, this test is for the built-in race detection")
+ }
testenv.MustHaveGoRun(t)
output := runTestProg(t, "testprog", "concurrentMapWrites")
want := "fatal error: concurrent map writes\n"
@@ -668,6 +692,9 @@ func TestConcurrentMapReadWrite(t *testing.T) {
if !*concurrentMapTest {
t.Skip("skipping without -run_concurrent_map_tests")
}
+ if race.Enabled {
+ t.Skip("skipping test: -race will catch the race, this test is for the built-in race detection")
+ }
testenv.MustHaveGoRun(t)
output := runTestProg(t, "testprog", "concurrentMapReadWrite")
want := "fatal error: concurrent map read and map write\n"
@@ -682,6 +709,9 @@ func TestConcurrentMapIterateWrite(t *testing.T) {
if !*concurrentMapTest {
t.Skip("skipping without -run_concurrent_map_tests")
}
+ if race.Enabled {
+ t.Skip("skipping test: -race will catch the race, this test is for the built-in race detection")
+ }
testenv.MustHaveGoRun(t)
output := runTestProg(t, "testprog", "concurrentMapIterateWrite")
want := "fatal error: concurrent map iteration and map write\n"
@@ -695,6 +725,9 @@ func TestConcurrentMapIterateWrite(t *testing.T) {
func TestConcurrentMapWritesIssue69447(t *testing.T) {
testenv.MustHaveGoRun(t)
+ if race.Enabled {
+ t.Skip("skipping test: -race will catch the race, this test is for the built-in race detection")
+ }
exe, err := buildTestProg(t, "testprog")
if err != nil {
t.Fatal(err)
@@ -795,6 +828,9 @@ retry:
}
func TestBadTraceback(t *testing.T) {
+ if asan.Enabled || msan.Enabled || race.Enabled {
+ t.Skip("skipped test: checkptr mode catches the corruption")
+ }
output := runTestProg(t, "testprog", "BadTraceback")
for _, want := range []string{
"unexpected return pc",
@@ -1087,7 +1123,9 @@ func TestPanicWhilePanicking(t *testing.T) {
func TestPanicOnUnsafeSlice(t *testing.T) {
output := runTestProg(t, "testprog", "panicOnNilAndEleSizeIsZero")
- want := "panic: runtime error: unsafe.Slice: ptr is nil and len is not zero"
+ // Note: This is normally a panic, but is a throw when checkptr is
+ // enabled.
+ want := "unsafe.Slice: ptr is nil and len is not zero"
if !strings.Contains(output, want) {
t.Errorf("output does not contain %q:\n%s", want, output)
}