aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/crash_cgo_test.go
diff options
context:
space:
mode:
authorIan Lance Taylor <iant@golang.org>2016-06-07 21:46:25 -0700
committerIan Lance Taylor <iant@golang.org>2016-06-13 21:43:19 +0000
commit84d8aff94cf48439047c7edc68ae2ea0aac6ddf5 (patch)
tree0d7fd4e7b480ce2f9972646e9abe9463c3bc7a4d /src/runtime/crash_cgo_test.go
parent5701174c52a2d42621ec3c5c59dca3bde9a14bc6 (diff)
downloadgo-84d8aff94cf48439047c7edc68ae2ea0aac6ddf5.tar.gz
go-84d8aff94cf48439047c7edc68ae2ea0aac6ddf5.zip
runtime: collect stack trace if SIGPROF arrives on non-Go thread
Fixes #15994. Change-Id: I5aca91ab53985ac7dcb07ce094ec15eb8ec341f8 Reviewed-on: https://go-review.googlesource.com/23891 Run-TryBot: Ian Lance Taylor <iant@golang.org> Reviewed-by: Austin Clements <austin@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'src/runtime/crash_cgo_test.go')
-rw-r--r--src/runtime/crash_cgo_test.go43
1 files changed, 12 insertions, 31 deletions
diff --git a/src/runtime/crash_cgo_test.go b/src/runtime/crash_cgo_test.go
index 4f7c10b923..9e1811aa16 100644
--- a/src/runtime/crash_cgo_test.go
+++ b/src/runtime/crash_cgo_test.go
@@ -234,18 +234,18 @@ func TestCgoTracebackContext(t *testing.T) {
}
}
-func TestCgoPprof(t *testing.T) {
+func testCgoPprof(t *testing.T, buildArg, runArg string) {
if runtime.GOOS != "linux" || runtime.GOARCH != "amd64" {
t.Skipf("not yet supported on %s/%s", runtime.GOOS, runtime.GOARCH)
}
testenv.MustHaveGoRun(t)
- exe, err := buildTestProg(t, "testprogcgo")
+ exe, err := buildTestProg(t, "testprogcgo", buildArg)
if err != nil {
t.Fatal(err)
}
- got, err := testEnv(exec.Command(exe, "CgoPprof")).CombinedOutput()
+ got, err := testEnv(exec.Command(exe, runArg)).CombinedOutput()
if err != nil {
t.Fatal(err)
}
@@ -253,43 +253,24 @@ func TestCgoPprof(t *testing.T) {
defer os.Remove(fn)
top, err := exec.Command("go", "tool", "pprof", "-top", "-nodecount=1", exe, fn).CombinedOutput()
+ t.Logf("%s", top)
if err != nil {
t.Fatal(err)
}
- t.Logf("%s", top)
-
if !bytes.Contains(top, []byte("cpuHog")) {
t.Error("missing cpuHog in pprof output")
}
}
-func TestCgoPprofPIE(t *testing.T) {
- if runtime.GOOS != "linux" || runtime.GOARCH != "amd64" {
- t.Skipf("not yet supported on %s/%s", runtime.GOOS, runtime.GOARCH)
- }
- testenv.MustHaveGoRun(t)
-
- exe, err := buildTestProg(t, "testprogcgo", "-ldflags=-extldflags=-pie")
- if err != nil {
- t.Fatal(err)
- }
-
- got, err := testEnv(exec.Command(exe, "CgoPprof")).CombinedOutput()
- if err != nil {
- t.Fatal(err)
- }
- fn := strings.TrimSpace(string(got))
- defer os.Remove(fn)
-
- top, err := exec.Command("go", "tool", "pprof", "-top", "-nodecount=1", exe, fn).CombinedOutput()
- if err != nil {
- t.Fatal(err)
- }
+func TestCgoPprof(t *testing.T) {
+ testCgoPprof(t, "", "CgoPprof")
+}
- t.Logf("%s", top)
+func TestCgoPprofPIE(t *testing.T) {
+ testCgoPprof(t, "-ldflags=-extldflags=-pie", "CgoPprof")
+}
- if !bytes.Contains(top, []byte("cpuHog")) {
- t.Error("missing cpuHog in pprof output")
- }
+func TestCgoPprofThread(t *testing.T) {
+ testCgoPprof(t, "", "CgoPprofThread")
}