From f9f5d1e8442e3268489f3cfab2f9b65922bd4b5b Mon Sep 17 00:00:00 2001 From: Damien Neil Date: Tue, 18 Mar 2025 10:22:04 -0700 Subject: [PATCH] runtime/race: detect when TestRace fails to run all tests, skip failures TestRace runs a collection of tests, some of which are expected to fail with data races. Make TestRace more robust at detecting when the test run is cut short, such as when a test causes an unhandled panic. Skip TestRaceRangeFuncIterator, which contains an unhandled panic. This test was causing all subsequent tests to not run. Skip TestNoRaceRangeFuncIterator, which contains an unexpected data race. This test was not running due to the above failure. For #72925 Change-Id: Id662375cc498ea25ae308619709768588bf6a2f0 Reviewed-on: https://go-review.googlesource.com/c/go/+/658875 Reviewed-by: Ian Lance Taylor LUCI-TryBot-Result: Go LUCI Auto-Submit: Damien Neil --- src/runtime/race/race_test.go | 16 ++++++++++------ src/runtime/race/testdata/main_test.go | 15 +++++++++++++++ src/runtime/race/testdata/rangefunc_test.go | 2 ++ 3 files changed, 27 insertions(+), 6 deletions(-) create mode 100644 src/runtime/race/testdata/main_test.go diff --git a/src/runtime/race/race_test.go b/src/runtime/race/race_test.go index cbc90ea0bb..98936e3d3e 100644 --- a/src/runtime/race/race_test.go +++ b/src/runtime/race/race_test.go @@ -14,6 +14,7 @@ package race_test import ( "bufio" "bytes" + "errors" "fmt" "internal/testenv" "io" @@ -112,13 +113,13 @@ func processLog(testName string, tsanLog []string) string { gotRace = true break } + if strings.Contains(s, "--- SKIP:") { + return fmt.Sprintf("%-*s SKIPPED", visibleLen, testName) + } } failing := strings.Contains(testName, "Failing") expRace := !strings.HasPrefix(testName, "No") - for len(testName) < visibleLen { - testName += " " - } if expRace == gotRace { passedTests++ totalTests++ @@ -126,7 +127,7 @@ func processLog(testName string, tsanLog []string) string { failed = true failingNeg++ } - return fmt.Sprintf("%s .", testName) + return fmt.Sprintf("%-*s .", visibleLen, testName) } pos := "" if expRace { @@ -141,7 +142,7 @@ func processLog(testName string, tsanLog []string) string { failed = true } totalTests++ - return fmt.Sprintf("%s %s%s", testName, "FAILED", pos) + return fmt.Sprintf("%-*s %s%s", visibleLen, testName, "FAILED", pos) } // runTests assures that the package and its dependencies is @@ -187,7 +188,10 @@ func runTests(t *testing.T) ([]byte, error) { if fatals > mapFatals { // But don't expect runtime to crash (other than // in the map concurrent access detector). - return out, fmt.Errorf("runtime fatal error") + return out, errors.New("runtime fatal error") + } + if !bytes.Contains(out, []byte("ALL TESTS COMPLETE")) { + return out, errors.New("not all tests ran") } return out, nil } diff --git a/src/runtime/race/testdata/main_test.go b/src/runtime/race/testdata/main_test.go new file mode 100644 index 0000000000..286589672b --- /dev/null +++ b/src/runtime/race/testdata/main_test.go @@ -0,0 +1,15 @@ +// Copyright 2025 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package race_test + +import ( + "fmt" + "testing" +) + +func TestMain(m *testing.M) { + m.Run() + fmt.Println("ALL TESTS COMPLETE") +} diff --git a/src/runtime/race/testdata/rangefunc_test.go b/src/runtime/race/testdata/rangefunc_test.go index f2ff793df7..453c0733ed 100644 --- a/src/runtime/race/testdata/rangefunc_test.go +++ b/src/runtime/race/testdata/rangefunc_test.go @@ -65,6 +65,7 @@ func foo(v int) int64 { // TestRaceRangeFuncIterator races because x%5 can be equal to 4, // therefore foo can early exit. func TestRaceRangeFuncIterator(t *testing.T) { + t.Skip("#72925: uncaught panic ends tests") x := foo(4) t.Logf("foo(4)=%d", x) } @@ -72,6 +73,7 @@ func TestRaceRangeFuncIterator(t *testing.T) { // TestNoRaceRangeFuncIterator does not race because x%5 is never 5, // therefore foo's loop will not exit early, and this it will not race. func TestNoRaceRangeFuncIterator(t *testing.T) { + t.Skip("#72925: unexpected data race") x := foo(5) t.Logf("foo(5)=%d", x) } -- 2.51.0