OLD | NEW |
1 package data | 1 package data |
2 | 2 |
3 import ( | 3 import ( |
4 "reflect" | 4 "reflect" |
5 "testing" | 5 "testing" |
6 | 6 |
7 "go.skia.org/infra/fuzzer/go/common" | 7 "go.skia.org/infra/fuzzer/go/common" |
8 ) | 8 ) |
9 | 9 |
10 func TestSortedFuzzReports(t *testing.T) { | 10 func TestSortedFuzzReports(t *testing.T) { |
11 a := make(SortedFuzzReports, 0, 5) | 11 a := make(SortedFuzzReports, 0, 5) |
12 addingOrder := []string{"gggg", "aaaa", "cccc", "eeee", "dddd", "bbbb", | 12 addingOrder := []string{"gggg", "aaaa", "cccc", "eeee", "dddd", "bbbb", |
13 "ffff"} | 13 "ffff"} |
14 | 14 |
15 for _, key := range addingOrder { | 15 for _, key := range addingOrder { |
16 » » a = a.append(mockPictureDetails[key]) | 16 » » a = a.append(MockReport("skpicture", key)) |
17 } | 17 } |
18 | 18 |
19 b := make(SortedFuzzReports, 0, 5) | 19 b := make(SortedFuzzReports, 0, 5) |
20 sortedOrder := []string{"aaaa", "bbbb", "cccc", "dddd", "eeee", | 20 sortedOrder := []string{"aaaa", "bbbb", "cccc", "dddd", "eeee", |
21 "ffff", "gggg"} | 21 "ffff", "gggg"} |
22 | 22 |
23 for _, key := range sortedOrder { | 23 for _, key := range sortedOrder { |
24 // just add them in already sorted order | 24 // just add them in already sorted order |
25 » » b = append(b, mockPictureDetails[key]) | 25 » » b = append(b, MockReport("skpicture", key)) |
26 } | 26 } |
27 if !reflect.DeepEqual(a, b) { | 27 if !reflect.DeepEqual(a, b) { |
28 t.Errorf("Expected: %#v\n, but was: %#v", a, b) | 28 t.Errorf("Expected: %#v\n, but was: %#v", a, b) |
29 } | 29 } |
30 } | 30 } |
31 | 31 |
32 func TestAddFuzz(t *testing.T) { | 32 func TestAddFuzz(t *testing.T) { |
33 builder := loadReports() | 33 builder := loadReports() |
34 | 34 |
35 report := builder.getTreeSortedByTotal("skpicture") | 35 report := builder.getTreeSortedByTotal("skpicture") |
36 if !reflect.DeepEqual(expectedPictureTree, report) { | 36 if !reflect.DeepEqual(expectedPictureTree, report) { |
37 t.Errorf("Expected: %#v\n, but was: %#v", expectedPictureTree, r
eport) | 37 t.Errorf("Expected: %#v\n, but was: %#v", expectedPictureTree, r
eport) |
38 } | 38 } |
39 | 39 |
40 report = builder.getTreeSortedByTotal("api") | 40 report = builder.getTreeSortedByTotal("api") |
41 if !reflect.DeepEqual(expectedAPITree, report) { | 41 if !reflect.DeepEqual(expectedAPITree, report) { |
42 t.Errorf("Expected: %#v\n, but was: %#v", expectedAPITree, repor
t) | 42 t.Errorf("Expected: %#v\n, but was: %#v", expectedAPITree, repor
t) |
43 } | 43 } |
44 } | 44 } |
45 | 45 |
46 func loadReports() *treeReportBuilder { | 46 func loadReports() *treeReportBuilder { |
47 addingOrder := []string{"aaaa", "bbbb", "eeee", "dddd", | 47 addingOrder := []string{"aaaa", "bbbb", "eeee", "dddd", |
48 "cccc", "ffff", "gggg"} | 48 "cccc", "ffff", "gggg"} |
49 | 49 |
50 builder := newBuilder() | 50 builder := newBuilder() |
51 for _, key := range addingOrder { | 51 for _, key := range addingOrder { |
52 » » builder.addFuzzReport("skpicture", mockPictureDetails[key]) | 52 » » builder.addFuzzReport("skpicture", MockReport("skpicture", key)) |
53 } | 53 } |
54 addingOrder = []string{"iiii", "hhhh"} | 54 addingOrder = []string{"iiii", "hhhh"} |
55 for _, key := range addingOrder { | 55 for _, key := range addingOrder { |
56 » » builder.addFuzzReport("api", mockAPIDetails[key]) | 56 » » builder.addFuzzReport("api", MockReport("api", key)) |
57 } | 57 } |
58 return builder | 58 return builder |
59 } | 59 } |
60 | 60 |
61 func makeStacktrace(file, function string, line int) StackTrace { | |
62 return StackTrace{ | |
63 Frames: []StackTraceFrame{ | |
64 { | |
65 PackageName: "mock/package/", | |
66 FileName: file, | |
67 LineNumber: line, | |
68 FunctionName: function, | |
69 }, | |
70 }, | |
71 } | |
72 } | |
73 | |
74 var mockFlags = []string{"foo", "bar"} | |
75 | |
76 var mockPictureDetails = map[string]FuzzReport{ | |
77 "aaaa": FuzzReport{ | |
78 DebugStackTrace: makeStacktrace("alpha", "beta", 16), | |
79 ReleaseStackTrace: makeStacktrace("alpha", "beta", 16), | |
80 DebugFlags: mockFlags, | |
81 FuzzName: "aaaa", | |
82 FuzzCategory: "skpicture", | |
83 }, | |
84 "bbbb": FuzzReport{ | |
85 DebugStackTrace: makeStacktrace("alpha", "beta", 16), | |
86 ReleaseStackTrace: StackTrace{}, | |
87 DebugFlags: mockFlags, | |
88 FuzzName: "bbbb", | |
89 FuzzCategory: "skpicture", | |
90 }, | |
91 "cccc": FuzzReport{ | |
92 DebugStackTrace: makeStacktrace("alpha", "beta", 16), | |
93 ReleaseStackTrace: makeStacktrace("alpha", "gamma", 26), | |
94 DebugFlags: mockFlags, | |
95 FuzzName: "cccc", | |
96 FuzzCategory: "skpicture", | |
97 }, | |
98 "dddd": FuzzReport{ | |
99 DebugStackTrace: makeStacktrace("alpha", "gamma", 43), | |
100 ReleaseStackTrace: makeStacktrace("delta", "epsilon", 125), | |
101 DebugFlags: mockFlags, | |
102 FuzzName: "dddd", | |
103 FuzzCategory: "skpicture", | |
104 }, | |
105 "eeee": FuzzReport{ | |
106 DebugStackTrace: StackTrace{}, | |
107 ReleaseStackTrace: StackTrace{}, | |
108 DebugFlags: mockFlags, | |
109 FuzzName: "eeee", | |
110 FuzzCategory: "skpicture", | |
111 }, | |
112 "ffff": FuzzReport{ | |
113 DebugStackTrace: makeStacktrace("alpha", "beta", 16), | |
114 ReleaseStackTrace: makeStacktrace("alpha", "beta", 16), | |
115 DebugFlags: mockFlags, | |
116 FuzzName: "ffff", | |
117 FuzzCategory: "skpicture", | |
118 }, | |
119 "gggg": FuzzReport{ | |
120 DebugStackTrace: makeStacktrace("delta", "epsilon", 122), | |
121 ReleaseStackTrace: StackTrace{}, | |
122 DebugFlags: mockFlags, | |
123 FuzzName: "gggg", | |
124 FuzzCategory: "skpicture", | |
125 }, | |
126 } | |
127 | |
128 var mockAPIDetails = map[string]FuzzReport{ | |
129 "hhhh": FuzzReport{ | |
130 DebugStackTrace: makeStacktrace("alpha", "beta", 16), | |
131 ReleaseStackTrace: makeStacktrace("alpha", "beta", 16), | |
132 DebugFlags: mockFlags, | |
133 FuzzName: "hhhh", | |
134 FuzzCategory: "api", | |
135 }, | |
136 "iiii": FuzzReport{ | |
137 DebugStackTrace: makeStacktrace("alpha", "beta", 16), | |
138 ReleaseStackTrace: StackTrace{}, | |
139 DebugFlags: mockFlags, | |
140 FuzzName: "iiii", | |
141 FuzzCategory: "api", | |
142 }, | |
143 } | |
144 | |
145 var expectedPictureTree = FuzzReportTree{ | 61 var expectedPictureTree = FuzzReportTree{ |
146 FileFuzzReport{ | 62 FileFuzzReport{ |
147 FileName: "mock/package/alpha", Count: 4, Functions: []FunctionF
uzzReport{ | 63 FileName: "mock/package/alpha", Count: 4, Functions: []FunctionF
uzzReport{ |
148 FunctionFuzzReport{ | 64 FunctionFuzzReport{ |
149 FunctionName: "beta", Count: 3, LineNumbers: []L
ineFuzzReport{ | 65 FunctionName: "beta", Count: 3, LineNumbers: []L
ineFuzzReport{ |
150 LineFuzzReport{ | 66 LineFuzzReport{ |
151 » » » » » » LineNumber: 16, Count: 3, Detail
s: []FuzzReport{mockPictureDetails["aaaa"], mockPictureDetails["bbbb"], mockPict
ureDetails["ffff"]}, | 67 » » » » » » LineNumber: 16, Count: 3, Detail
s: []FuzzReport{MockReport("skpicture", "aaaa"), MockReport("skpicture", "bbbb")
, MockReport("skpicture", "ffff")}, |
152 }, | 68 }, |
153 }, | 69 }, |
154 }, FunctionFuzzReport{ | 70 }, FunctionFuzzReport{ |
155 FunctionName: "gamma", Count: 1, LineNumbers: []
LineFuzzReport{ | 71 FunctionName: "gamma", Count: 1, LineNumbers: []
LineFuzzReport{ |
156 LineFuzzReport{ | 72 LineFuzzReport{ |
157 » » » » » » LineNumber: 26, Count: 1, Detail
s: []FuzzReport{mockPictureDetails["cccc"]}, | 73 » » » » » » LineNumber: 26, Count: 1, Detail
s: []FuzzReport{MockReport("skpicture", "cccc")}, |
158 }, | 74 }, |
159 }, | 75 }, |
160 }, | 76 }, |
161 }, | 77 }, |
162 }, | 78 }, |
163 FileFuzzReport{ | 79 FileFuzzReport{ |
164 FileName: "mock/package/delta", Count: 2, Functions: []FunctionF
uzzReport{ | 80 FileName: "mock/package/delta", Count: 2, Functions: []FunctionF
uzzReport{ |
165 FunctionFuzzReport{ | 81 FunctionFuzzReport{ |
166 FunctionName: "epsilon", Count: 2, LineNumbers:
[]LineFuzzReport{ | 82 FunctionName: "epsilon", Count: 2, LineNumbers:
[]LineFuzzReport{ |
167 LineFuzzReport{ | 83 LineFuzzReport{ |
168 » » » » » » LineNumber: 122, Count: 1, Detai
ls: []FuzzReport{mockPictureDetails["gggg"]}, | 84 » » » » » » LineNumber: 122, Count: 1, Detai
ls: []FuzzReport{MockReport("skpicture", "gggg")}, |
169 }, | 85 }, |
170 LineFuzzReport{ | 86 LineFuzzReport{ |
171 » » » » » » LineNumber: 125, Count: 1, Detai
ls: []FuzzReport{mockPictureDetails["dddd"]}, | 87 » » » » » » LineNumber: 125, Count: 1, Detai
ls: []FuzzReport{MockReport("skpicture", "dddd")}, |
172 }, | 88 }, |
173 }, | 89 }, |
174 }, | 90 }, |
175 }, | 91 }, |
176 }, | 92 }, |
177 FileFuzzReport{ | 93 FileFuzzReport{ |
178 FileName: common.UNKNOWN_FILE, Count: 1, Functions: []FunctionFu
zzReport{ | 94 FileName: common.UNKNOWN_FILE, Count: 1, Functions: []FunctionFu
zzReport{ |
179 FunctionFuzzReport{ | 95 FunctionFuzzReport{ |
180 FunctionName: common.UNKNOWN_FUNCTION, Count: 1,
LineNumbers: []LineFuzzReport{ | 96 FunctionName: common.UNKNOWN_FUNCTION, Count: 1,
LineNumbers: []LineFuzzReport{ |
181 LineFuzzReport{ | 97 LineFuzzReport{ |
182 » » » » » » LineNumber: -1, Count: 1, Detail
s: []FuzzReport{mockPictureDetails["eeee"]}, | 98 » » » » » » LineNumber: -1, Count: 1, Detail
s: []FuzzReport{MockReport("skpicture", "eeee")}, |
183 }, | 99 }, |
184 }, | 100 }, |
185 }, | 101 }, |
186 }, | 102 }, |
187 }, | 103 }, |
188 } | 104 } |
189 | 105 |
190 var expectedPictureSummary = FuzzReportTree{ | 106 var expectedPictureSummary = FuzzReportTree{ |
191 FileFuzzReport{ | 107 FileFuzzReport{ |
192 FileName: "mock/package/alpha", Count: 4, Functions: []FunctionF
uzzReport{ | 108 FileName: "mock/package/alpha", Count: 4, Functions: []FunctionF
uzzReport{ |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 }, | 147 }, |
232 }, | 148 }, |
233 } | 149 } |
234 | 150 |
235 var expectedAPITree = FuzzReportTree{ | 151 var expectedAPITree = FuzzReportTree{ |
236 FileFuzzReport{ | 152 FileFuzzReport{ |
237 FileName: "mock/package/alpha", Count: 2, Functions: []FunctionF
uzzReport{ | 153 FileName: "mock/package/alpha", Count: 2, Functions: []FunctionF
uzzReport{ |
238 FunctionFuzzReport{ | 154 FunctionFuzzReport{ |
239 FunctionName: "beta", Count: 2, LineNumbers: []L
ineFuzzReport{ | 155 FunctionName: "beta", Count: 2, LineNumbers: []L
ineFuzzReport{ |
240 LineFuzzReport{ | 156 LineFuzzReport{ |
241 » » » » » » LineNumber: 16, Count: 2, Detail
s: []FuzzReport{mockAPIDetails["hhhh"], mockAPIDetails["iiii"]}, | 157 » » » » » » LineNumber: 16, Count: 2, Detail
s: []FuzzReport{MockReport("api", "hhhh"), MockReport("api", "iiii")}, |
242 }, | 158 }, |
243 }, | 159 }, |
244 }, | 160 }, |
245 }, | 161 }, |
246 }, | 162 }, |
247 } | 163 } |
248 | 164 |
249 var expectedAPISummary = FuzzReportTree{ | 165 var expectedAPISummary = FuzzReportTree{ |
250 FileFuzzReport{ | 166 FileFuzzReport{ |
251 FileName: "mock/package/alpha", Count: 2, Functions: []FunctionF
uzzReport{ | 167 FileName: "mock/package/alpha", Count: 2, Functions: []FunctionF
uzzReport{ |
252 FunctionFuzzReport{ | 168 FunctionFuzzReport{ |
253 FunctionName: "beta", Count: 2, LineNumbers: []L
ineFuzzReport{ | 169 FunctionName: "beta", Count: 2, LineNumbers: []L
ineFuzzReport{ |
254 LineFuzzReport{ | 170 LineFuzzReport{ |
255 LineNumber: 16, Count: 2, Detail
s: nil, | 171 LineNumber: 16, Count: 2, Detail
s: nil, |
256 }, | 172 }, |
257 }, | 173 }, |
258 }, | 174 }, |
259 }, | 175 }, |
260 }, | 176 }, |
261 } | 177 } |
OLD | NEW |