Commit 39bc7884 authored by Hyang-Ah Hana Kim's avatar Hyang-Ah Hana Kim

runtime/pprof: fix TestCPUProfileWithFork for GOOS=android.

1) Large allocation in this test caused crash. This was not
detected by builder because builder runs tests with -test.short.

2) The command "go" for forking doesn't exist in some platforms
including android. This change uses the test binary itself which
is guaranteed to exist.

This change also adds logging of the total samples collected in
TestCPUProfileMultithreaded test that is flaky in android-arm
builder.

Change-Id: I225c6b7877d811edef8b25e7eb00559450640c42
Reviewed-on: https://go-review.googlesource.com/8131Reviewed-by: default avatarDavid Crawshaw <crawshaw@golang.org>
Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent dde5b56c
...@@ -143,7 +143,9 @@ func testCPUProfile(t *testing.T, need []string, f func()) { ...@@ -143,7 +143,9 @@ func testCPUProfile(t *testing.T, need []string, f func()) {
// Check that profile is well formed and contains need. // Check that profile is well formed and contains need.
have := make([]uintptr, len(need)) have := make([]uintptr, len(need))
var samples uintptr
parseProfile(t, prof.Bytes(), func(count uintptr, stk []uintptr) { parseProfile(t, prof.Bytes(), func(count uintptr, stk []uintptr) {
samples += count
for _, pc := range stk { for _, pc := range stk {
f := runtime.FuncForPC(pc) f := runtime.FuncForPC(pc)
if f == nil { if f == nil {
...@@ -156,6 +158,7 @@ func testCPUProfile(t *testing.T, need []string, f func()) { ...@@ -156,6 +158,7 @@ func testCPUProfile(t *testing.T, need []string, f func()) {
} }
} }
}) })
t.Logf("total %d CPU profile samples collected", samples)
if len(need) == 0 { if len(need) == 0 {
return return
...@@ -200,6 +203,8 @@ func testCPUProfile(t *testing.T, need []string, f func()) { ...@@ -200,6 +203,8 @@ func testCPUProfile(t *testing.T, need []string, f func()) {
} }
} }
// Fork can hang if preempted with signals frequently enough (see issue 5517).
// Ensure that we do not do this.
func TestCPUProfileWithFork(t *testing.T) { func TestCPUProfileWithFork(t *testing.T) {
if runtime.GOOS == "darwin" { if runtime.GOOS == "darwin" {
if runtime.GOARCH == "arm" { if runtime.GOARCH == "arm" {
...@@ -207,9 +212,11 @@ func TestCPUProfileWithFork(t *testing.T) { ...@@ -207,9 +212,11 @@ func TestCPUProfileWithFork(t *testing.T) {
} }
} }
// Fork can hang if preempted with signals frequently enough (see issue 5517).
// Ensure that we do not do this.
heap := 1 << 30 heap := 1 << 30
if runtime.GOOS == "android" {
// Use smaller size for Android to avoid crash.
heap = 100 << 20
}
if testing.Short() { if testing.Short() {
heap = 100 << 20 heap = 100 << 20
} }
...@@ -232,7 +239,7 @@ func TestCPUProfileWithFork(t *testing.T) { ...@@ -232,7 +239,7 @@ func TestCPUProfileWithFork(t *testing.T) {
defer StopCPUProfile() defer StopCPUProfile()
for i := 0; i < 10; i++ { for i := 0; i < 10; i++ {
exec.Command("go").CombinedOutput() exec.Command(os.Args[0], "-h").CombinedOutput()
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment