]> Cypherpunks repositories - gostls13.git/commitdiff
runtime/pprof: use testenv.Command in tests instead of exec.Command
authorBryan C. Mills <bcmills@google.com>
Fri, 30 Jun 2023 16:47:06 +0000 (12:47 -0400)
committerGopher Robot <gobot@golang.org>
Thu, 20 Jul 2023 19:30:53 +0000 (19:30 +0000)
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>

src/runtime/pprof/pprof_test.go

index 56ba6d98031117f4c98cdbca960e8b81a0c0056d..1ade860441ca6aee49f36e287acb50c7f29e85cd 100644 (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()
        }
 }