...
1
2
3
4
5 package profile
6
7 import (
8 "testing"
9 )
10
11 func TestParseContention(t *testing.T) {
12 tests := []struct {
13 name string
14 in string
15 wantErr bool
16 }{
17 {
18 name: "valid",
19 in: `--- mutex:
20 cycles/second=3491920901
21 sampling period=1
22 43227965305 1659640 @ 0x45e851 0x45f764 0x4a2be1 0x44ea31
23 34035731690 15760 @ 0x45e851 0x45f764 0x4a2b17 0x44ea31
24 `,
25 },
26 {
27 name: "valid with comment",
28 in: `--- mutex:
29 cycles/second=3491920901
30 sampling period=1
31 43227965305 1659640 @ 0x45e851 0x45f764 0x4a2be1 0x44ea31
32 # 0x45e850 sync.(*Mutex).Unlock+0x80 /go/src/sync/mutex.go:126
33 # 0x45f763 sync.(*RWMutex).Unlock+0x83 /go/src/sync/rwmutex.go:125
34 # 0x4a2be0 main.main.func3+0x70 /go/src/internal/pprof/profile/a_binary.go:58
35
36 34035731690 15760 @ 0x45e851 0x45f764 0x4a2b17 0x44ea31
37 # 0x45e850 sync.(*Mutex).Unlock+0x80 /go/src/sync/mutex.go:126
38 # 0x45f763 sync.(*RWMutex).Unlock+0x83 /go/src/sync/rwmutex.go:125
39 # 0x4a2b16 main.main.func2+0xd6 /go/src/internal/pprof/profile/a_binary.go:48
40 `,
41 },
42 {
43 name: "empty",
44 in: `--- mutex:`,
45 wantErr: true,
46 },
47 {
48 name: "invalid header",
49 in: `--- channel:
50 43227965305 1659640 @ 0x45e851 0x45f764 0x4a2be1 0x44ea31`,
51 wantErr: true,
52 },
53 }
54 for _, tc := range tests {
55 _, err := parseContention([]byte(tc.in))
56 if tc.wantErr && err == nil {
57 t.Errorf("parseContention(%q) succeeded unexpectedly", tc.name)
58 }
59 if !tc.wantErr && err != nil {
60 t.Errorf("parseContention(%q) failed unexpectedly: %v", tc.name, err)
61 }
62 }
63
64 }
65
View as plain text