runtime/pprof: use testenv.Command in tests instead of exec.Command

If the test is about to time out, testenv.Command sends SIGQUIT to the
child process. The runtime's SIGQUIT goroutine dump should help us to
determine whether the hangs observed in TestCPUProfileWithFork are a
symptom of #60108 or a separate bug.

For #59995.
Updates #60108.

Change-Id: I26342ca262b2b0772795c8be142cfcad8d90db30
Reviewed-on: https://go-review.googlesource.com/c/go/+/507356
Run-TryBot: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Auto-Submit: Bryan Mills <bcmills@google.com>
This commit is contained in:
Bryan C. Mills 2023-06-30 12:47:06 -04:00 committed by Gopher Robot
parent 7c1157f954
commit 3ffc8a2556
1 changed files with 7 additions and 3 deletions

View File

@ -18,7 +18,6 @@ import (
"math"
"math/big"
"os"
"os/exec"
"regexp"
"runtime"
"runtime/debug"
@ -440,7 +439,7 @@ func cpuProfilingBroken() bool {
func testCPUProfile(t *testing.T, matches profileMatchFunc, f func(dur time.Duration)) *profile.Profile {
switch runtime.GOOS {
case "darwin":
out, err := exec.Command("uname", "-a").CombinedOutput()
out, err := testenv.Command(t, "uname", "-a").CombinedOutput()
if err != nil {
t.Fatal(err)
}
@ -653,6 +652,11 @@ func matchAndAvoidStacks(matches sampleMatchFunc, need []string, avoid []string)
func TestCPUProfileWithFork(t *testing.T) {
testenv.MustHaveExec(t)
exe, err := os.Executable()
if err != nil {
t.Fatal(err)
}
heap := 1 << 30
if runtime.GOOS == "android" {
// Use smaller size for Android to avoid crash.
@ -684,7 +688,7 @@ func TestCPUProfileWithFork(t *testing.T) {
defer StopCPUProfile()
for i := 0; i < 10; i++ {
exec.Command(os.Args[0], "-h").CombinedOutput()
testenv.Command(t, exe, "-h").CombinedOutput()
}
}