From 435e61c80141653c22e29d81447e4c6e4033f768 Mon Sep 17 00:00:00 2001 From: Michael Anthony Knyszek Date: Wed, 3 Dec 2025 22:29:19 +0000 Subject: [PATCH] runtime: reject any goroutine leak test failure that failed to execute This is far more general than the regexp, which was necessary only because runTestProg doesn't return the error. This change makes runTestProg a wrapper function around a function that *does* return the error. For #76526. Change-Id: Ib3daa75eb0fe314a28a7a368474943ba470d0d4d Reviewed-on: https://go-review.googlesource.com/c/go/+/726525 Auto-Submit: Michael Knyszek LUCI-TryBot-Result: Go LUCI Reviewed-by: Michael Pratt --- src/runtime/crash_test.go | 9 ++++++++- src/runtime/goroutineleakprofile_test.go | 13 +++++-------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/runtime/crash_test.go b/src/runtime/crash_test.go index 00e67aeca0..91f9740616 100644 --- a/src/runtime/crash_test.go +++ b/src/runtime/crash_test.go @@ -97,6 +97,13 @@ func runTestProg(t *testing.T, binary, name string, env ...string) string { func runBuiltTestProg(t *testing.T, exe, name string, env ...string) string { t.Helper() + out, _ := runBuiltTestProgErr(t, exe, name, env...) + return out +} + +func runBuiltTestProgErr(t *testing.T, exe, name string, env ...string) (string, error) { + t.Helper() + if *flagQuick { t.Skip("-quick") } @@ -120,7 +127,7 @@ func runBuiltTestProg(t *testing.T, exe, name string, env ...string) string { t.Fatalf("%v failed to start: %v", cmd, err) } } - return string(out) + return string(out), err } var serializeBuild = make(chan bool, 2) diff --git a/src/runtime/goroutineleakprofile_test.go b/src/runtime/goroutineleakprofile_test.go index 35f7dc6879..a0446b36f0 100644 --- a/src/runtime/goroutineleakprofile_test.go +++ b/src/runtime/goroutineleakprofile_test.go @@ -486,9 +486,6 @@ func TestGoroutineLeakProfile(t *testing.T) { testCases := append(microTests, stressTestCases...) testCases = append(testCases, patternTestCases...) - // Test cases must not panic or cause fatal exceptions. - failStates := regexp.MustCompile(`segmentation fault|fatal|panic|DATA RACE`) - runTests := func(exepath string, testCases []testCase) { // Build the test program once. @@ -515,14 +512,14 @@ func TestGoroutineLeakProfile(t *testing.T) { var output string for i := 0; i < tcase.repetitions; i++ { // Run program for one repetition and get runOutput trace. - runOutput := runBuiltTestProg(t, exe, tcase.name, cmdEnv...) + runOutput, err := runBuiltTestProgErr(t, exe, tcase.name, cmdEnv...) if len(runOutput) == 0 { t.Errorf("Test %s produced no output. Is the goroutine leak profile collected?", tcase.name) } - - // Zero tolerance policy for fatal exceptions, panics, or data races. - if failStates.MatchString(runOutput) { - t.Errorf("unexpected fatal exception or panic\noutput:\n%s\n\n", runOutput) + // Test cases must not end in a non-zero exit code, or otherwise experience a failure to + // actually execute. + if err != nil { + t.Errorf("unexpected failure\noutput:\n%s\n\n", runOutput) } output += runOutput + "\n\n" -- 2.52.0