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 <mknyszek@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
This commit is contained in:
Michael Anthony Knyszek 2025-12-03 22:29:19 +00:00 committed by Gopher Robot
parent 54e5540014
commit 435e61c801
2 changed files with 13 additions and 9 deletions

View file

@ -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)

View file

@ -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"