From: Russ Cox Date: Fri, 17 Feb 2017 20:27:12 +0000 (-0500) Subject: runtime: check that pprof accepts but doesn't need executable X-Git-Tag: go1.9beta1~1437 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=8c24e52247365725c97b1ed5bea63a84642fd0f7;p=gostls13.git runtime: check that pprof accepts but doesn't need executable The profiles are self-contained now. Check that they work by themselves in the tests that invoke pprof, but also keep checking that the old command lines work. Change-Id: I24c74b5456f0b50473883c3640625c6612f72309 Reviewed-on: https://go-review.googlesource.com/37166 Run-TryBot: Russ Cox TryBot-Result: Gobot Gobot Reviewed-by: Michael Matloob --- diff --git a/src/runtime/crash_cgo_test.go b/src/runtime/crash_cgo_test.go index 347b820eb5..2c3fe39f2c 100644 --- a/src/runtime/crash_cgo_test.go +++ b/src/runtime/crash_cgo_test.go @@ -287,28 +287,34 @@ func testCgoPprof(t *testing.T, buildArg, runArg string) { fn := strings.TrimSpace(string(got)) defer os.Remove(fn) - cmd := testEnv(exec.Command(testenv.GoToolPath(t), "tool", "pprof", "-top", "-nodecount=1", exe, fn)) - - found := false - for i, e := range cmd.Env { - if strings.HasPrefix(e, "PPROF_TMPDIR=") { - cmd.Env[i] = "PPROF_TMPDIR=" + os.TempDir() - found = true - break + for try := 0; try < 2; try++ { + cmd := testEnv(exec.Command(testenv.GoToolPath(t), "tool", "pprof", "-top", "-nodecount=1")) + // Check that pprof works both with and without explicit executable on command line. + if try == 0 { + cmd.Args = append(cmd.Args, exe, fn) + } else { + cmd.Args = append(cmd.Args, fn) } - } - if !found { - cmd.Env = append(cmd.Env, "PPROF_TMPDIR="+os.TempDir()) - } - top, err := cmd.CombinedOutput() - t.Logf("%s", top) - if err != nil { - t.Fatal(err) - } + found := false + for i, e := range cmd.Env { + if strings.HasPrefix(e, "PPROF_TMPDIR=") { + cmd.Env[i] = "PPROF_TMPDIR=" + os.TempDir() + found = true + break + } + } + if !found { + cmd.Env = append(cmd.Env, "PPROF_TMPDIR="+os.TempDir()) + } - if !bytes.Contains(top, []byte("cpuHog")) { - t.Error("missing cpuHog in pprof output") + top, err := cmd.CombinedOutput() + t.Logf("%s:\n%s", cmd.Args, top) + if err != nil { + t.Error(err) + } else if !bytes.Contains(top, []byte("cpuHog")) { + t.Error("missing cpuHog in pprof output") + } } } diff --git a/src/runtime/crash_test.go b/src/runtime/crash_test.go index fae2981610..26161fda8d 100644 --- a/src/runtime/crash_test.go +++ b/src/runtime/crash_test.go @@ -476,28 +476,33 @@ func TestMemPprof(t *testing.T) { fn := strings.TrimSpace(string(got)) defer os.Remove(fn) - cmd := testEnv(exec.Command(testenv.GoToolPath(t), "tool", "pprof", "-alloc_space", "-top", exe, fn)) - - found := false - for i, e := range cmd.Env { - if strings.HasPrefix(e, "PPROF_TMPDIR=") { - cmd.Env[i] = "PPROF_TMPDIR=" + os.TempDir() - found = true - break + for try := 0; try < 2; try++ { + cmd := testEnv(exec.Command(testenv.GoToolPath(t), "tool", "pprof", "-alloc_space", "-top")) + // Check that pprof works both with and without explicit executable on command line. + if try == 0 { + cmd.Args = append(cmd.Args, exe, fn) + } else { + cmd.Args = append(cmd.Args, fn) + } + found := false + for i, e := range cmd.Env { + if strings.HasPrefix(e, "PPROF_TMPDIR=") { + cmd.Env[i] = "PPROF_TMPDIR=" + os.TempDir() + found = true + break + } + } + if !found { + cmd.Env = append(cmd.Env, "PPROF_TMPDIR="+os.TempDir()) } - } - if !found { - cmd.Env = append(cmd.Env, "PPROF_TMPDIR="+os.TempDir()) - } - - top, err := cmd.CombinedOutput() - t.Logf("%s", top) - if err != nil { - t.Fatal(err) - } - if !bytes.Contains(top, []byte("MemProf")) { - t.Error("missing MemProf in pprof output") + top, err := cmd.CombinedOutput() + t.Logf("%s:\n%s", cmd.Args, top) + if err != nil { + t.Error(err) + } else if !bytes.Contains(top, []byte("MemProf")) { + t.Error("missing MemProf in pprof output") + } } }