OLD | NEW |
| (Empty) |
1 package data | |
2 | |
3 import ( | |
4 "reflect" | |
5 "testing" | |
6 | |
7 "go.skia.org/infra/fuzzer/go/common" | |
8 ) | |
9 | |
10 func TestSortedFuzzReports(t *testing.T) { | |
11 a := make(SortedFuzzReports, 0, 5) | |
12 addingOrder := []string{"gggg", "aaaa", "cccc", "eeee", "dddd", "bbbb", | |
13 "ffff"} | |
14 | |
15 for _, key := range addingOrder { | |
16 a = a.append(MockReport("skpicture", key)) | |
17 } | |
18 | |
19 b := make(SortedFuzzReports, 0, 5) | |
20 sortedOrder := []string{"aaaa", "bbbb", "cccc", "dddd", "eeee", | |
21 "ffff", "gggg"} | |
22 | |
23 for _, key := range sortedOrder { | |
24 // just add them in already sorted order | |
25 b = append(b, MockReport("skpicture", key)) | |
26 } | |
27 if !reflect.DeepEqual(a, b) { | |
28 t.Errorf("Expected: %#v\n, but was: %#v", a, b) | |
29 } | |
30 } | |
31 | |
32 func TestAddFuzz(t *testing.T) { | |
33 builder := loadReports() | |
34 | |
35 report := builder.getTreeSortedByTotal("skpicture") | |
36 if !reflect.DeepEqual(expectedPictureTree, report) { | |
37 t.Errorf("Expected: %#v\n, but was: %#v", expectedPictureTree, r
eport) | |
38 } | |
39 | |
40 report = builder.getTreeSortedByTotal("api") | |
41 if !reflect.DeepEqual(expectedAPITree, report) { | |
42 t.Errorf("Expected: %#v\n, but was: %#v", expectedAPITree, repor
t) | |
43 } | |
44 } | |
45 | |
46 func loadReports() *treeReportBuilder { | |
47 addingOrder := []string{"aaaa", "bbbb", "eeee", "dddd", | |
48 "cccc", "ffff", "gggg"} | |
49 | |
50 builder := newBuilder() | |
51 for _, key := range addingOrder { | |
52 builder.addFuzzReport("skpicture", MockReport("skpicture", key)) | |
53 } | |
54 addingOrder = []string{"iiii", "hhhh"} | |
55 for _, key := range addingOrder { | |
56 builder.addFuzzReport("api", MockReport("api", key)) | |
57 } | |
58 return builder | |
59 } | |
60 | |
61 var expectedPictureTree = FuzzReportTree{ | |
62 FileFuzzReport{ | |
63 FileName: "mock/package/alpha", Count: 4, Functions: []FunctionF
uzzReport{ | |
64 FunctionFuzzReport{ | |
65 FunctionName: "beta", Count: 3, LineNumbers: []L
ineFuzzReport{ | |
66 LineFuzzReport{ | |
67 LineNumber: 16, Count: 3, Detail
s: []FuzzReport{MockReport("skpicture", "aaaa"), MockReport("skpicture", "bbbb")
, MockReport("skpicture", "ffff")}, | |
68 }, | |
69 }, | |
70 }, FunctionFuzzReport{ | |
71 FunctionName: "gamma", Count: 1, LineNumbers: []
LineFuzzReport{ | |
72 LineFuzzReport{ | |
73 LineNumber: 26, Count: 1, Detail
s: []FuzzReport{MockReport("skpicture", "cccc")}, | |
74 }, | |
75 }, | |
76 }, | |
77 }, | |
78 }, | |
79 FileFuzzReport{ | |
80 FileName: "mock/package/delta", Count: 2, Functions: []FunctionF
uzzReport{ | |
81 FunctionFuzzReport{ | |
82 FunctionName: "epsilon", Count: 2, LineNumbers:
[]LineFuzzReport{ | |
83 LineFuzzReport{ | |
84 LineNumber: 122, Count: 1, Detai
ls: []FuzzReport{MockReport("skpicture", "gggg")}, | |
85 }, | |
86 LineFuzzReport{ | |
87 LineNumber: 125, Count: 1, Detai
ls: []FuzzReport{MockReport("skpicture", "dddd")}, | |
88 }, | |
89 }, | |
90 }, | |
91 }, | |
92 }, | |
93 FileFuzzReport{ | |
94 FileName: common.UNKNOWN_FILE, Count: 1, Functions: []FunctionFu
zzReport{ | |
95 FunctionFuzzReport{ | |
96 FunctionName: common.UNKNOWN_FUNCTION, Count: 1,
LineNumbers: []LineFuzzReport{ | |
97 LineFuzzReport{ | |
98 LineNumber: -1, Count: 1, Detail
s: []FuzzReport{MockReport("skpicture", "eeee")}, | |
99 }, | |
100 }, | |
101 }, | |
102 }, | |
103 }, | |
104 } | |
105 | |
106 var expectedPictureSummary = FuzzReportTree{ | |
107 FileFuzzReport{ | |
108 FileName: "mock/package/alpha", Count: 4, Functions: []FunctionF
uzzReport{ | |
109 FunctionFuzzReport{ | |
110 FunctionName: "beta", Count: 3, LineNumbers: []L
ineFuzzReport{ | |
111 LineFuzzReport{ | |
112 LineNumber: 16, Count: 3, Detail
s: nil, | |
113 }, | |
114 }, | |
115 }, FunctionFuzzReport{ | |
116 FunctionName: "gamma", Count: 1, LineNumbers: []
LineFuzzReport{ | |
117 LineFuzzReport{ | |
118 LineNumber: 26, Count: 1, Detail
s: nil, | |
119 }, | |
120 }, | |
121 }, | |
122 }, | |
123 }, | |
124 FileFuzzReport{ | |
125 FileName: "mock/package/delta", Count: 2, Functions: []FunctionF
uzzReport{ | |
126 FunctionFuzzReport{ | |
127 FunctionName: "epsilon", Count: 2, LineNumbers:
[]LineFuzzReport{ | |
128 LineFuzzReport{ | |
129 LineNumber: 122, Count: 1, Detai
ls: nil, | |
130 }, | |
131 LineFuzzReport{ | |
132 LineNumber: 125, Count: 1, Detai
ls: nil, | |
133 }, | |
134 }, | |
135 }, | |
136 }, | |
137 }, | |
138 FileFuzzReport{ | |
139 FileName: common.UNKNOWN_FILE, Count: 1, Functions: []FunctionFu
zzReport{ | |
140 FunctionFuzzReport{ | |
141 FunctionName: common.UNKNOWN_FUNCTION, Count: 1,
LineNumbers: []LineFuzzReport{ | |
142 LineFuzzReport{ | |
143 LineNumber: -1, Count: 1, Detail
s: nil, | |
144 }, | |
145 }, | |
146 }, | |
147 }, | |
148 }, | |
149 } | |
150 | |
151 var expectedAPITree = FuzzReportTree{ | |
152 FileFuzzReport{ | |
153 FileName: "mock/package/alpha", Count: 2, Functions: []FunctionF
uzzReport{ | |
154 FunctionFuzzReport{ | |
155 FunctionName: "beta", Count: 2, LineNumbers: []L
ineFuzzReport{ | |
156 LineFuzzReport{ | |
157 LineNumber: 16, Count: 2, Detail
s: []FuzzReport{MockReport("api", "hhhh"), MockReport("api", "iiii")}, | |
158 }, | |
159 }, | |
160 }, | |
161 }, | |
162 }, | |
163 } | |
164 | |
165 var expectedAPISummary = FuzzReportTree{ | |
166 FileFuzzReport{ | |
167 FileName: "mock/package/alpha", Count: 2, Functions: []FunctionF
uzzReport{ | |
168 FunctionFuzzReport{ | |
169 FunctionName: "beta", Count: 2, LineNumbers: []L
ineFuzzReport{ | |
170 LineFuzzReport{ | |
171 LineNumber: 16, Count: 2, Detail
s: nil, | |
172 }, | |
173 }, | |
174 }, | |
175 }, | |
176 }, | |
177 } | |
OLD | NEW |