MCPcopy Create free account
hub / github.com/google/pprof / testSourceMapping

Function testSourceMapping

internal/report/source_test.go:66–121  ·  view source on GitHub ↗

testSourceMapping checks that source info is found even when no applicable Mapping/objectFile exists. The locations used in the test are either zero (if zeroAddress is true), or non-zero (otherwise).

(t *testing.T, zeroAddress bool)

Source from the content-addressed store, hash-verified

64// Mapping/objectFile exists. The locations used in the test are either zero
65// (if zeroAddress is true), or non-zero (otherwise).
66func testSourceMapping(t *testing.T, zeroAddress bool) {
67 nextAddr := uint64(0)
68
69 makeLoc := func(name, fname string, line int64) *profile.Location {
70 if !zeroAddress {
71 nextAddr++
72 }
73 return &profile.Location{
74 Address: nextAddr,
75 Line: []profile.Line{
76 {
77 Function: &profile.Function{Name: name, Filename: fname},
78 Line: line,
79 },
80 },
81 }
82 }
83
84 // Create profile that will need synthetic addresses since it has no mappings.
85 foo100 := makeLoc("foo", "foo.go", 100)
86 bar50 := makeLoc("bar", "bar.go", 50)
87 prof := &profile.Profile{
88 Sample: []*profile.Sample{
89 {
90 Value: []int64{9},
91 Location: []*profile.Location{foo100, bar50},
92 },
93 {
94 Value: []int64{17},
95 Location: []*profile.Location{bar50},
96 },
97 },
98 }
99 rpt := &Report{
100 prof: prof,
101 options: &Options{
102 Symbol: regexp.MustCompile("foo|bar"),
103 SampleValue: func(s []int64) int64 { return s[0] },
104 },
105 formatValue: func(v int64) string { return fmt.Sprint(v) },
106 }
107
108 result, err := MakeWebList(rpt, nil, -1)
109 if err != nil {
110 t.Fatalf("MakeWebList returned unexpected error: %v", err)
111 }
112 got := fmt.Sprint(result)
113
114 expect := regexp.MustCompile(
115 `(?s)` + // Allow "." to match newline
116 `bar\.go.* 50\b.* 17 +26 .*` +
117 `foo\.go.* 100\b.* 9 +9 `)
118 if !expect.MatchString(got) {
119 t.Errorf("expected regular expression %v does not match output:\n%s\n", expect, got)
120 }
121}
122
123func TestOpenSourceFile(t *testing.T) {

Callers 2

TestSourceMissingMappingFunction · 0.85

Calls 1

MakeWebListFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…