|
@@ -21,6 +21,7 @@ import (
|
21
|
21
|
"net/url"
|
22
|
22
|
"os"
|
23
|
23
|
"path/filepath"
|
|
24
|
+ "reflect"
|
24
|
25
|
"regexp"
|
25
|
26
|
"testing"
|
26
|
27
|
"time"
|
|
@@ -76,6 +77,55 @@ func TestSymbolizationPath(t *testing.T) {
|
76
|
77
|
os.Setenv("PPROF_BINARY_PATH", savePath)
|
77
|
78
|
}
|
78
|
79
|
|
|
80
|
+func TestCollectMappingSources(t *testing.T) {
|
|
81
|
+ const startAddress uint64 = 0x40000
|
|
82
|
+ const url = "http://example.com"
|
|
83
|
+ for _, tc := range []struct {
|
|
84
|
+ file, buildID string
|
|
85
|
+ want plugin.MappingSources
|
|
86
|
+ }{
|
|
87
|
+ {"/usr/bin/binary", "buildId", mappingSources("buildId", url, startAddress)},
|
|
88
|
+ {"/usr/bin/binary", "", mappingSources("/usr/bin/binary", url, startAddress)},
|
|
89
|
+ {"", "", mappingSources(url, url, startAddress)},
|
|
90
|
+ } {
|
|
91
|
+ p := &profile.Profile{
|
|
92
|
+ Mapping: []*profile.Mapping{
|
|
93
|
+ {
|
|
94
|
+ File: tc.file,
|
|
95
|
+ BuildID: tc.buildID,
|
|
96
|
+ Start: startAddress,
|
|
97
|
+ },
|
|
98
|
+ },
|
|
99
|
+ }
|
|
100
|
+ got := collectMappingSources(p, url)
|
|
101
|
+ if !reflect.DeepEqual(got, tc.want) {
|
|
102
|
+ t.Errorf("%s:%s, want %s, got %s", tc.file, tc.buildID, tc.want, got)
|
|
103
|
+ }
|
|
104
|
+ }
|
|
105
|
+}
|
|
106
|
+
|
|
107
|
+func TestUnsourceMappings(t *testing.T) {
|
|
108
|
+ for _, tc := range []struct {
|
|
109
|
+ file, buildID, want string
|
|
110
|
+ }{
|
|
111
|
+ {"/usr/bin/binary", "buildId", "/usr/bin/binary"},
|
|
112
|
+ {"http://example.com", "", ""},
|
|
113
|
+ } {
|
|
114
|
+ p := &profile.Profile{
|
|
115
|
+ Mapping: []*profile.Mapping{
|
|
116
|
+ {
|
|
117
|
+ File: tc.file,
|
|
118
|
+ BuildID: tc.buildID,
|
|
119
|
+ },
|
|
120
|
+ },
|
|
121
|
+ }
|
|
122
|
+ unsourceMappings(p)
|
|
123
|
+ if got := p.Mapping[0].File; got != tc.want {
|
|
124
|
+ t.Errorf("%s:%s, want %s, got %s", tc.file, tc.buildID, tc.want, got)
|
|
125
|
+ }
|
|
126
|
+ }
|
|
127
|
+}
|
|
128
|
+
|
79
|
129
|
type testObj struct {
|
80
|
130
|
home string
|
81
|
131
|
}
|
|
@@ -125,6 +175,18 @@ func TestFetch(t *testing.T) {
|
125
|
175
|
}
|
126
|
176
|
}
|
127
|
177
|
|
|
178
|
+// mappingSources creates MappingSources map with a single item.
|
|
179
|
+func mappingSources(key, source string, start uint64) plugin.MappingSources {
|
|
180
|
+ return plugin.MappingSources{
|
|
181
|
+ key: []struct {
|
|
182
|
+ Source string
|
|
183
|
+ Start uint64
|
|
184
|
+ }{
|
|
185
|
+ {Source: source, Start: start},
|
|
186
|
+ },
|
|
187
|
+ }
|
|
188
|
+}
|
|
189
|
+
|
128
|
190
|
// stubHTTPGet intercepts a call to http.Get and rewrites it to use
|
129
|
191
|
// "file://" to get the profile directly from a file.
|
130
|
192
|
func stubHTTPGet(source string, _ time.Duration) (*http.Response, error) {
|