aboutsummaryrefslogtreecommitdiff
path: root/src/internal/trace/trace_test.go
diff options
context:
space:
mode:
authorMichael Anthony Knyszek <mknyszek@google.com>2025-06-11 21:20:05 +0000
committerMichael Knyszek <mknyszek@google.com>2025-06-12 13:23:34 -0700
commit934d5f2cf703c6aad9f0ce6a73a3922d1af83049 (patch)
tree261f22a8dff2601fc41b3abc257b1fd42ffaa685 /src/internal/trace/trace_test.go
parent5a08865de339b5eeb8ad1c52635ea8ba505aafec (diff)
downloadgo-934d5f2cf703c6aad9f0ce6a73a3922d1af83049.tar.xz
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>
Diffstat (limited to 'src/internal/trace/trace_test.go')
-rw-r--r--src/internal/trace/trace_test.go27
1 files changed, 22 insertions, 5 deletions
diff --git a/src/internal/trace/trace_test.go b/src/internal/trace/trace_test.go
index 7eb50d0f4e..eaf194cf07 100644
--- a/src/internal/trace/trace_test.go
+++ b/src/internal/trace/trace_test.go
@@ -582,13 +582,30 @@ func testTraceProg(t *testing.T, progName string, extra func(t *testing.T, trace
testPath := filepath.Join("./testdata/testprog", progName)
testName := progName
runTest := func(t *testing.T, stress bool, extraGODEBUG string) {
- // Run the program and capture the trace, which is always written to stdout.
- cmd := testenv.Command(t, testenv.GoToolPath(t), "run")
+ // Build the program.
+ binFile, err := os.CreateTemp("", progName)
+ if err != nil {
+ t.Fatalf("failed to create temporary output file: %v", err)
+ }
+ bin := binFile.Name()
+ binFile.Close()
+ t.Cleanup(func() {
+ os.Remove(bin)
+ })
+ buildCmd := testenv.CommandContext(t, t.Context(), testenv.GoToolPath(t), "build", "-o", bin)
if race.Enabled {
- cmd.Args = append(cmd.Args, "-race")
+ buildCmd.Args = append(buildCmd.Args, "-race")
+ }
+ buildCmd.Args = append(buildCmd.Args, testPath)
+ buildCmd.Env = append(os.Environ(), "GOEXPERIMENT=rangefunc")
+ buildOutput, err := buildCmd.CombinedOutput()
+ if err != nil {
+ t.Fatalf("failed to build %s: %v: output:\n%s", testPath, err, buildOutput)
}
- cmd.Args = append(cmd.Args, testPath)
- cmd.Env = append(os.Environ(), "GOEXPERIMENT=rangefunc")
+
+ // Run the program and capture the trace, which is always written to stdout.
+ cmd := testenv.CommandContext(t, t.Context(), bin)
+
// Add a stack ownership check. This is cheap enough for testing.
godebug := "tracecheckstackownership=1"
if stress {