Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(320)

Side by Side Diff: fuzzer/go/deduplicator/deduplicator_test.go

Issue 1672033002: Deduplicate fuzz cases on the frontend before they are displayed. (Closed) Base URL: https://skia.googlesource.com/buildbot@remove-overview
Patch Set: merged upstream Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « fuzzer/go/deduplicator/deduplicator.go ('k') | fuzzer/go/frontend/data/report_mock.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 package deduplicator
2
3 import (
4 "testing"
5
6 "go.skia.org/infra/fuzzer/go/frontend/data"
7 )
8
9 func TestSimpleDeduplication(t *testing.T) {
10 d := New()
11 r1 := data.MockReport("skpicture", "aaaa")
12 r2 := data.MockReport("skpicture", "bbbb")
13 // mock report ffff and aaaa are the same, except for the name.
14 r3 := data.MockReport("skpicture", "ffff")
15 if !d.IsUnique(r1) {
16 t.Errorf("The deduplicator has not seen %#v, but said it has", r 1)
17 }
18 if !d.IsUnique(r2) {
19 t.Errorf("The deduplicator has not seen %#v, but said it has", r 2)
20 }
21 if d.IsUnique(r1) {
22 t.Errorf("Should not have said %#v was unique, it just saw it.", r1)
23 }
24 if d.IsUnique(r3) {
25 t.Errorf("Should not have said %#v was unique, it just saw somet hing like it.", r3)
26 }
27 }
28
29 func TestUnknownStacktraces(t *testing.T) {
30 d := New()
31 // mock report ee has no stacktrace for either. It should not be consid ered a duplicate, ever.
32 r1 := data.MockReport("skpicture", "eeee")
33 if !d.IsUnique(r1) {
34 t.Errorf("The deduplicator has not seen %#v, but said it has", r 1)
35 }
36 if !d.IsUnique(r1) {
37 t.Errorf("Should not have said %#v was not unique, unknown stack traces don't count.", r1)
38 }
39 }
40
41 func TestKey(t *testing.T) {
42 // r1 is a report with 6 and 7 stacktrace frames for Debug/Release
43 r1 := makeReport()
44 r1.DebugStackTrace.Frames = append(r1.DebugStackTrace.Frames, data.Stack TraceFrame{})
45 r1.ReleaseStackTrace.Frames = append(r1.DebugStackTrace.Frames, data.Sta ckTraceFrame{})
46
47 k1 := key(r1)
48 k2 := key(r1)
49 if k1 != k2 {
50 t.Errorf("Keys should be deterministic\n%s != %s", k1, k2)
51 }
52 if n := len(r1.DebugStackTrace.Frames); n != _MAX_STACKTRACE_LINES+1 {
53 t.Errorf("key() should not have changed the report - it now has %d frames instead of 6", n)
54 t.Errorf(r1.DebugStackTrace.String())
55 }
56 if n := len(r1.ReleaseStackTrace.Frames); n != _MAX_STACKTRACE_LINES+2 {
57 t.Errorf("key() should not have changed the report - it now has %d frames instead of 7", n)
58 t.Errorf(r1.DebugStackTrace.String())
59 }
60 if frame := r1.DebugStackTrace.Frames[0]; frame.LineNumber == 0 {
61 t.Errorf("key() should not have changed the report - it now has the wrong line number at index 0: %s", r1.DebugStackTrace.String())
62 }
63 if frame := r1.ReleaseStackTrace.Frames[0]; frame.LineNumber == 0 {
64 t.Errorf("key() should not have changed the report - it now has the wrong line number at index 0: %s", r1.ReleaseStackTrace.String())
65 }
66 }
67
68 func TestLinesOfStacktrace(t *testing.T) {
69 d := New()
70 r1 := makeReport()
71 r2 := makeReport()
72 r2.DebugStackTrace.Frames = append(r2.DebugStackTrace.Frames, data.Stack TraceFrame{})
73 r3 := makeReport()
74 r3.ReleaseStackTrace.Frames = append(r3.ReleaseStackTrace.Frames, data.S tackTraceFrame{})
75 if !d.IsUnique(r1) {
76 t.Errorf("The deduplicator has not seen %#v, but said it has", r 1)
77 }
78 if d.IsUnique(r2) {
79 t.Errorf("Should not have said %#v was unique, it just saw somet hing with the same top %d stacktraces.", r2, _MAX_STACKTRACE_LINES)
80 t.Errorf("Debug stacktraces: \n%s\n\n%s", r1.DebugStackTrace.Str ing(), r2.DebugStackTrace.String())
81 t.Errorf("Release stacktraces: \n%s\n\n%s", r1.ReleaseStackTrace .String(), r2.ReleaseStackTrace.String())
82 }
83 if d.IsUnique(r3) {
84 t.Errorf("Should not have said %#v was unique, it just saw somet hing with the same top %d stacktraces.", r3, _MAX_STACKTRACE_LINES)
85 t.Errorf("Debug stacktraces: \n%s\n\n%s", r1.DebugStackTrace.Str ing(), r3.DebugStackTrace.String())
86 t.Errorf("Release stacktraces: \n%s\n\n%s", r1.ReleaseStackTrace .String(), r3.ReleaseStackTrace.String())
87 }
88 }
89
90 func TestLineNumbers(t *testing.T) {
91 d := New()
92 r1 := makeReport()
93 r2 := makeReport()
94 r2.DebugStackTrace.Frames[0].LineNumber = 9999
95 r3 := makeReport()
96 r3.ReleaseStackTrace.Frames[0].LineNumber = 9999
97 if !d.IsUnique(r1) {
98 t.Errorf("The deduplicator has not seen %#v, but said it has", r 1)
99 }
100 if d.IsUnique(r2) {
101 t.Errorf("Should not have said %#v was unique, it just saw somet hing with the same top %d stacktraces, not counting line numbers.", r2, _MAX_STA CKTRACE_LINES)
102 t.Errorf("Debug stacktraces: \n%s\n\n%s", r1.DebugStackTrace.Str ing(), r2.DebugStackTrace.String())
103 t.Errorf("Release stacktraces: \n%s\n\n%s", r1.ReleaseStackTrace .String(), r2.ReleaseStackTrace.String())
104 }
105 if d.IsUnique(r3) {
106 t.Errorf("Should not have said %#v was unique, it just saw somet hing with the same top %d stacktraces, not counting line numbers.", r3, _MAX_STA CKTRACE_LINES)
107 t.Errorf("Debug stacktraces: \n%s\n\n%s", r1.DebugStackTrace.Str ing(), r3.DebugStackTrace.String())
108 t.Errorf("Release stacktraces: \n%s\n\n%s", r1.ReleaseStackTrace .String(), r3.ReleaseStackTrace.String())
109 }
110 }
111
112 func TestFlags(t *testing.T) {
113 d := New()
114 r1 := makeReport()
115 r2 := makeReport()
116 r2.ReleaseFlags = makeFlags(4, 2)
117 r3 := makeReport()
118 r3.DebugFlags = makeFlags(4, 2)
119 if !d.IsUnique(r1) {
120 t.Errorf("The deduplicator has not seen %#v, but said it has", r 1)
121 }
122 if !d.IsUnique(r2) {
123 t.Errorf("The deduplicator has not seen %#v, but said it has", r 2)
124 t.Errorf("Release flags: \n%s\n\n%s", r1.ReleaseFlags, r2.Releas eFlags)
125 }
126 if !d.IsUnique(r3) {
127 t.Errorf("The deduplicator has not seen %#v, but said it has", r 3)
128 t.Errorf("Release flags: \n%s\n\n%s", r1.ReleaseFlags, r3.Releas eFlags)
129 }
130 }
131
132 func TestCategory(t *testing.T) {
133 d := New()
134 r1 := makeReport()
135 r2 := makeReport()
136 r2.FuzzCategory = "something else"
137 if !d.IsUnique(r1) {
138 t.Errorf("The deduplicator has not seen %#v, but said it has", r 1)
139 }
140 if !d.IsUnique(r2) {
141 t.Errorf("The deduplicator has not seen %#v, but said it has", r 2)
142 }
143 }
144
145 func TestOther(t *testing.T) {
146 d := New()
147 r1 := makeReport()
148 r1.DebugFlags = append(r1.DebugFlags, "Other")
149 r2 := makeReport()
150 r2.ReleaseFlags = append(r2.ReleaseFlags, "Other")
151 if !d.IsUnique(r1) {
152 t.Errorf("The deduplicator has not seen %#v, but said it has", r 1)
153 }
154 if !d.IsUnique(r1) {
155 t.Errorf("The deduplicator should have said %#v was unique. The flag 'Other' should not be filtered.", r1)
156 }
157
158 if !d.IsUnique(r2) {
159 t.Errorf("The deduplicator has not seen %#v, but said it has", r 2)
160 }
161 if !d.IsUnique(r2) {
162 t.Errorf("The deduplicator should have said %#v was unique. The flag 'Other' should not be filtered.", r2)
163 }
164 }
165
166 // Makes a report with the smallest stacktraces distinguishable by the deduplica tor, 3 debug
167 // flags, 3 release flags and a standard name and category
168 func makeReport() data.FuzzReport {
169 ds := makeStacktrace(0)
170 rs := makeStacktrace(3)
171 df := makeFlags(0, 3)
172 rf := makeFlags(1, 2)
173
174 return data.FuzzReport{
175 DebugStackTrace: ds,
176 ReleaseStackTrace: rs,
177 DebugFlags: df,
178 ReleaseFlags: rf,
179 FuzzName: "doesn't matter",
180 FuzzCategory: "api",
181 }
182 }
183
184 var names = []string{"alpha", "beta", "gamma", "delta", "epsilon", "zeta", "thet a", "iota", "kappa", "lambda", "mu"}
185
186 func makeStacktrace(start int) data.StackTrace {
187 st := data.StackTrace{}
188 r := start
189 n := len(names)
190 for i := 0; i < _MAX_STACKTRACE_LINES; i++ {
191 a, b, c, d := r%n, (r+1)%n, (r+2)%n, (r+3)%n
192 st.Frames = append(st.Frames, data.FullStackFrame(names[a], name s[b], names[c], d))
193 r = (r + 4) % n
194 }
195 return st
196 }
197
198 func makeFlags(start, count int) []string {
199 return names[start:(start + count)]
200 }
OLDNEW
« no previous file with comments | « fuzzer/go/deduplicator/deduplicator.go ('k') | fuzzer/go/frontend/data/report_mock.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698