Skip to content

Commit

Permalink
runtime/pprof: TestVMInfo reworked to avoid test flakiness.
Browse files Browse the repository at this point in the history
Fixes #62352.

Change-Id: Ib137a5f39d4630c4737badfabe8e6740593ecbcf
Reviewed-on: https://go-review.googlesource.com/c/go/+/527276
Reviewed-by: Cherry Mui <cherryyz@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Bryan Mills <bcmills@google.com>
Run-TryBot: Bryan Mills <bcmills@google.com>
  • Loading branch information
cosnicolaou authored and gopherbot committed Sep 14, 2023
1 parent 743121c commit 7d0b611
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions src/runtime/pprof/vminfo_darwin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ package pprof
import (
"bufio"
"bytes"
"fmt"
"internal/abi"
"internal/testenv"
"os"
Expand Down Expand Up @@ -56,19 +57,30 @@ func useVMMap(t *testing.T) (hi, lo uint64) {
pid := strconv.Itoa(os.Getpid())
testenv.MustHaveExecPath(t, "vmmap")
cmd := testenv.Command(t, "vmmap", pid)
out, err := cmd.Output()
out, cmdErr := cmd.Output()
if cmdErr != nil {
t.Logf("vmmap output: %s", out)
if ee, ok := cmdErr.(*exec.ExitError); ok && len(ee.Stderr) > 0 {
t.Logf("%v: %v\n%s", cmd, cmdErr, ee.Stderr)
}
t.Logf("%v: %v", cmd, cmdErr)
}
// Always parse the output of vmmap since it may return an error
// code even if it successfully reports the text segment information
// required for this test.
hi, lo, err := parseVmmap(out)
if err != nil {
t.Logf("vmmap failed: %s", out)
if ee, ok := err.(*exec.ExitError); ok && len(ee.Stderr) > 0 {
t.Fatalf("%v: %v\n%s", cmd, err, ee.Stderr)
if cmdErr != nil {
t.Fatalf("failed to parse vmmap output, vmmap reported an error: %v", err)
}
t.Fatalf("%v: %v", cmd, err)
t.Logf("vmmap output: %s", out)
t.Fatalf("failed to parse vmmap output, vmmap did not report an error: %v", err)
}
return parseVmmap(t, out)
return hi, lo
}

// parseVmmap parses the output of vmmap and calls addMapping for the first r-x TEXT segment in the output.
func parseVmmap(t *testing.T, data []byte) (hi, lo uint64) {
func parseVmmap(data []byte) (hi, lo uint64, err error) {
// vmmap 53799
// Process: gopls [53799]
// Path: /Users/USER/*/gopls
Expand Down Expand Up @@ -119,13 +131,12 @@ func parseVmmap(t *testing.T, data []byte) (hi, lo uint64) {
locs := strings.Split(p[1], "-")
start, _ := strconv.ParseUint(locs[0], 16, 64)
end, _ := strconv.ParseUint(locs[1], 16, 64)
return start, end
return start, end, nil
}
}
if strings.HasPrefix(l, banner) {
grabbing = true
}
}
t.Fatal("vmmap no text segment found")
return 0, 0
return 0, 0, fmt.Errorf("vmmap no text segment found")
}

0 comments on commit 7d0b611

Please sign in to comment.