mirror of https://github.com/golang/go.git
runtime/pprof: TestVMInfo reworked to avoid test flakiness.
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>
This commit is contained in:
parent
743121c45c
commit
7d0b611dbe
|
|
@ -9,6 +9,7 @@ package pprof
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"fmt"
|
||||||
"internal/abi"
|
"internal/abi"
|
||||||
"internal/testenv"
|
"internal/testenv"
|
||||||
"os"
|
"os"
|
||||||
|
|
@ -56,19 +57,30 @@ func useVMMap(t *testing.T) (hi, lo uint64) {
|
||||||
pid := strconv.Itoa(os.Getpid())
|
pid := strconv.Itoa(os.Getpid())
|
||||||
testenv.MustHaveExecPath(t, "vmmap")
|
testenv.MustHaveExecPath(t, "vmmap")
|
||||||
cmd := testenv.Command(t, "vmmap", pid)
|
cmd := testenv.Command(t, "vmmap", pid)
|
||||||
out, err := cmd.Output()
|
out, cmdErr := cmd.Output()
|
||||||
if err != nil {
|
if cmdErr != nil {
|
||||||
t.Logf("vmmap failed: %s", out)
|
t.Logf("vmmap output: %s", out)
|
||||||
if ee, ok := err.(*exec.ExitError); ok && len(ee.Stderr) > 0 {
|
if ee, ok := cmdErr.(*exec.ExitError); ok && len(ee.Stderr) > 0 {
|
||||||
t.Fatalf("%v: %v\n%s", cmd, err, ee.Stderr)
|
t.Logf("%v: %v\n%s", cmd, cmdErr, ee.Stderr)
|
||||||
}
|
}
|
||||||
t.Fatalf("%v: %v", cmd, err)
|
t.Logf("%v: %v", cmd, cmdErr)
|
||||||
}
|
}
|
||||||
return parseVmmap(t, out)
|
// 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 {
|
||||||
|
if cmdErr != nil {
|
||||||
|
t.Fatalf("failed to parse vmmap output, vmmap reported an error: %v", err)
|
||||||
|
}
|
||||||
|
t.Logf("vmmap output: %s", out)
|
||||||
|
t.Fatalf("failed to parse vmmap output, vmmap did not report an error: %v", err)
|
||||||
|
}
|
||||||
|
return hi, lo
|
||||||
}
|
}
|
||||||
|
|
||||||
// parseVmmap parses the output of vmmap and calls addMapping for the first r-x TEXT segment in the output.
|
// 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
|
// vmmap 53799
|
||||||
// Process: gopls [53799]
|
// Process: gopls [53799]
|
||||||
// Path: /Users/USER/*/gopls
|
// Path: /Users/USER/*/gopls
|
||||||
|
|
@ -119,13 +131,12 @@ func parseVmmap(t *testing.T, data []byte) (hi, lo uint64) {
|
||||||
locs := strings.Split(p[1], "-")
|
locs := strings.Split(p[1], "-")
|
||||||
start, _ := strconv.ParseUint(locs[0], 16, 64)
|
start, _ := strconv.ParseUint(locs[0], 16, 64)
|
||||||
end, _ := strconv.ParseUint(locs[1], 16, 64)
|
end, _ := strconv.ParseUint(locs[1], 16, 64)
|
||||||
return start, end
|
return start, end, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if strings.HasPrefix(l, banner) {
|
if strings.HasPrefix(l, banner) {
|
||||||
grabbing = true
|
grabbing = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
t.Fatal("vmmap no text segment found")
|
return 0, 0, fmt.Errorf("vmmap no text segment found")
|
||||||
return 0, 0
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue