aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/pprof/pprof_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/runtime/pprof/pprof_test.go')
-rw-r--r--src/runtime/pprof/pprof_test.go55
1 files changed, 34 insertions, 21 deletions
diff --git a/src/runtime/pprof/pprof_test.go b/src/runtime/pprof/pprof_test.go
index b6ee160e84..1b86dbff5b 100644
--- a/src/runtime/pprof/pprof_test.go
+++ b/src/runtime/pprof/pprof_test.go
@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
+//go:build !js
// +build !js
package pprof
@@ -11,6 +12,7 @@ import (
"context"
"fmt"
"internal/profile"
+ "internal/race"
"internal/testenv"
"io"
"math/big"
@@ -261,34 +263,25 @@ func parseProfile(t *testing.T, valBytes []byte, f func(uintptr, []*profile.Loca
// as interpreted by matches, and returns the parsed profile.
func testCPUProfile(t *testing.T, matches matchFunc, need []string, avoid []string, f func(dur time.Duration)) *profile.Profile {
switch runtime.GOOS {
- case "darwin", "ios":
- switch runtime.GOARCH {
- case "arm64":
- // nothing
- default:
- out, err := exec.Command("uname", "-a").CombinedOutput()
- if err != nil {
- t.Fatal(err)
- }
- vers := string(out)
- t.Logf("uname -a: %v", vers)
+ case "darwin":
+ out, err := exec.Command("uname", "-a").CombinedOutput()
+ if err != nil {
+ t.Fatal(err)
}
+ vers := string(out)
+ t.Logf("uname -a: %v", vers)
case "plan9":
t.Skip("skipping on plan9")
}
broken := false
switch runtime.GOOS {
- case "darwin", "ios", "dragonfly", "netbsd", "illumos", "solaris":
+ case "ios", "dragonfly", "netbsd", "illumos", "solaris":
broken = true
case "openbsd":
if runtime.GOARCH == "arm" || runtime.GOARCH == "arm64" {
broken = true
}
- case "windows":
- if runtime.GOARCH == "arm" {
- broken = true // See https://golang.org/issues/42862
- }
}
maxDuration := 5 * time.Second
@@ -514,8 +507,10 @@ func TestGoroutineSwitch(t *testing.T) {
}
StopCPUProfile()
- // Read profile to look for entries for runtime.gogo with an attempt at a traceback.
- // The special entry
+ // Read profile to look for entries for gogo with an attempt at a traceback.
+ // "runtime.gogo" is OK, because that's the part of the context switch
+ // before the actual switch begins. But we should not see "gogo",
+ // aka "gogo<>(SB)", which does the actual switch and is marked SPWRITE.
parseProfile(t, prof.Bytes(), func(count uintptr, stk []*profile.Location, _ map[string][]string) {
// An entry with two frames with 'System' in its top frame
// exists to record a PC without a traceback. Those are okay.
@@ -526,13 +521,19 @@ func TestGoroutineSwitch(t *testing.T) {
}
}
- // Otherwise, should not see runtime.gogo.
+ // An entry with just one frame is OK too:
+ // it knew to stop at gogo.
+ if len(stk) == 1 {
+ return
+ }
+
+ // Otherwise, should not see gogo.
// The place we'd see it would be the inner most frame.
name := stk[0].Line[0].Function.Name
- if name == "runtime.gogo" {
+ if name == "gogo" {
var buf bytes.Buffer
fprintStack(&buf, stk)
- t.Fatalf("found profile entry for runtime.gogo:\n%s", buf.String())
+ t.Fatalf("found profile entry for gogo:\n%s", buf.String())
}
})
}
@@ -584,6 +585,18 @@ func stackContainsAll(spec string, count uintptr, stk []*profile.Location, label
}
func TestMorestack(t *testing.T) {
+ if runtime.GOOS == "darwin" && race.Enabled {
+ // For whatever reason, using the race detector on macOS keeps us
+ // from finding the newstack/growstack calls in the profile.
+ // Not worth worrying about.
+ // https://build.golang.org/log/280d387327806e17c8aabeb38b9503dbbd942ed1
+ t.Skip("skipping on darwin race detector")
+ }
+ if runtime.GOOS == "darwin" && runtime.GOARCH == "arm64" {
+ // For whatever reason, darwin/arm64 also doesn't work.
+ // https://build.golang.org/log/c45e82cc25f152642e6fb90d882ef5a8cd130ce5
+ t.Skip("skipping on darwin/arm64")
+ }
testCPUProfile(t, stackContainsAll, []string{"runtime.newstack,runtime/pprof.growstack"}, avoidFunctions(), func(duration time.Duration) {
t := time.After(duration)
c := make(chan bool)