]> Cypherpunks repositories - gostls13.git/commitdiff
runtime/race: detect when TestRace fails to run all tests, skip failures
authorDamien Neil <dneil@google.com>
Tue, 18 Mar 2025 17:22:04 +0000 (10:22 -0700)
committerGopher Robot <gobot@golang.org>
Wed, 19 Mar 2025 17:21:06 +0000 (10:21 -0700)
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 <iant@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Damien Neil <dneil@google.com>

src/runtime/race/race_test.go
src/runtime/race/testdata/main_test.go [new file with mode: 0644]
src/runtime/race/testdata/rangefunc_test.go

index cbc90ea0bb6aafd9d7151b94fc986c72a8aade58..98936e3d3e2b32d6d7a190799064350e47d4c807 100644 (file)
@@ -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 (file)
index 0000000..2865896
--- /dev/null
@@ -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")
+}
index f2ff793df723e06a58e6affc8bdd20f108609293..453c0733edeee3d0f666f61b7e212a8c6eaf84de 100644 (file)
@@ -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)
 }