Skip to content

Commit 934d5f2

Browse files
committed
internal/trace: end test programs with SIGQUIT
This change switches from using testenv.Command to testenv.CommandContext which is a little bit friendlier. It also switches away from using 'go run' to 'go build' and running the resulting binary explicitly. This helps eliminate any questions about signal handling and propagation. For #72740. Change-Id: Ife8010da89a7bc439e061fe0c9c6b1f5620d90f1 Reviewed-on: https://go-review.googlesource.com/c/go/+/680977 Reviewed-by: Carlos Amedee <carlos@golang.org> TryBot-Bypass: Michael Knyszek <mknyszek@google.com>
1 parent 5a08865 commit 934d5f2

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

src/internal/trace/trace_test.go

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -582,13 +582,30 @@ func testTraceProg(t *testing.T, progName string, extra func(t *testing.T, trace
582582
testPath := filepath.Join("./testdata/testprog", progName)
583583
testName := progName
584584
runTest := func(t *testing.T, stress bool, extraGODEBUG string) {
585-
// Run the program and capture the trace, which is always written to stdout.
586-
cmd := testenv.Command(t, testenv.GoToolPath(t), "run")
585+
// Build the program.
586+
binFile, err := os.CreateTemp("", progName)
587+
if err != nil {
588+
t.Fatalf("failed to create temporary output file: %v", err)
589+
}
590+
bin := binFile.Name()
591+
binFile.Close()
592+
t.Cleanup(func() {
593+
os.Remove(bin)
594+
})
595+
buildCmd := testenv.CommandContext(t, t.Context(), testenv.GoToolPath(t), "build", "-o", bin)
587596
if race.Enabled {
588-
cmd.Args = append(cmd.Args, "-race")
597+
buildCmd.Args = append(buildCmd.Args, "-race")
598+
}
599+
buildCmd.Args = append(buildCmd.Args, testPath)
600+
buildCmd.Env = append(os.Environ(), "GOEXPERIMENT=rangefunc")
601+
buildOutput, err := buildCmd.CombinedOutput()
602+
if err != nil {
603+
t.Fatalf("failed to build %s: %v: output:\n%s", testPath, err, buildOutput)
589604
}
590-
cmd.Args = append(cmd.Args, testPath)
591-
cmd.Env = append(os.Environ(), "GOEXPERIMENT=rangefunc")
605+
606+
// Run the program and capture the trace, which is always written to stdout.
607+
cmd := testenv.CommandContext(t, t.Context(), bin)
608+
592609
// Add a stack ownership check. This is cheap enough for testing.
593610
godebug := "tracecheckstackownership=1"
594611
if stress {

0 commit comments

Comments
 (0)