forked from google/syzkaller
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrepro_test.go
239 lines (199 loc) · 7.08 KB
/
repro_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
// Copyright 2018 syzkaller project authors. All rights reserved.
// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.
package main
import (
"testing"
"time"
"github.com/google/syzkaller/dashboard/dashapi"
)
// Normal workflow:
// - upload crash -> need repro
// - upload syz repro -> still need repro
// - upload C repro -> don't need repro
func testNeedRepro1(t *testing.T, crashCtor func(c *Ctx) *dashapi.Crash, newBug bool) {
c := NewCtx(t)
defer c.Close()
crash1 := crashCtor(c)
resp, _ := c.client.ReportCrash(crash1)
c.expectEQ(resp.NeedRepro, true)
cid := testCrashID(crash1)
needRepro, _ := c.client.NeedRepro(cid)
c.expectEQ(needRepro, true)
// Still need repro for this crash.
resp, _ = c.client.ReportCrash(crash1)
c.expectEQ(resp.NeedRepro, true)
needRepro, _ = c.client.NeedRepro(cid)
c.expectEQ(needRepro, true)
crash2 := new(dashapi.Crash)
*crash2 = *crash1
crash2.ReproOpts = []byte("opts")
crash2.ReproSyz = []byte("repro syz")
resp, _ = c.client.ReportCrash(crash2)
c.expectEQ(resp.NeedRepro, true)
needRepro, _ = c.client.NeedRepro(cid)
c.expectEQ(needRepro, true)
// MayBeMissing flag must not affect bugs that actually exist.
cidMissing := testCrashID(crash1)
cidMissing.MayBeMissing = true
needRepro, _ = c.client.NeedRepro(cidMissing)
c.expectEQ(needRepro, true)
crash2.ReproC = []byte("repro C")
resp, _ = c.client.ReportCrash(crash2)
c.expectEQ(resp.NeedRepro, false)
needRepro, _ = c.client.NeedRepro(cid)
c.expectEQ(needRepro, false)
needRepro, _ = c.client.NeedRepro(cidMissing)
c.expectEQ(needRepro, false)
resp, _ = c.client.ReportCrash(crash2)
c.expectEQ(resp.NeedRepro, false)
if newBug {
c.client.pollBug()
}
}
func TestNeedRepro1_normal(t *testing.T) { testNeedRepro1(t, normalCrash, true) }
func TestNeedRepro1_dup(t *testing.T) { testNeedRepro1(t, dupCrash, false) }
func TestNeedRepro1_closed(t *testing.T) { testNeedRepro1(t, closedCrash, true) }
func TestNeedRepro1_closedRepro(t *testing.T) { testNeedRepro1(t, closedWithReproCrash, true) }
// Upload C repro with first crash -> don't need repro.
func testNeedRepro2(t *testing.T, crashCtor func(c *Ctx) *dashapi.Crash, newBug bool) {
c := NewCtx(t)
defer c.Close()
crash1 := crashCtor(c)
crash1.ReproOpts = []byte("opts")
crash1.ReproSyz = []byte("repro syz")
crash1.ReproC = []byte("repro C")
resp, _ := c.client.ReportCrash(crash1)
c.expectEQ(resp.NeedRepro, false)
needRepro, _ := c.client.NeedRepro(testCrashID(crash1))
c.expectEQ(needRepro, false)
if newBug {
c.client.pollBug()
}
}
func TestNeedRepro2_normal(t *testing.T) { testNeedRepro2(t, normalCrash, true) }
func TestNeedRepro2_dup(t *testing.T) { testNeedRepro2(t, dupCrash, false) }
func TestNeedRepro2_closed(t *testing.T) { testNeedRepro2(t, closedCrash, true) }
func TestNeedRepro2_closedRepro(t *testing.T) { testNeedRepro2(t, closedWithReproCrash, true) }
// Test that after uploading 5 failed repros, app stops requesting repros.
func testNeedRepro3(t *testing.T, crashCtor func(c *Ctx) *dashapi.Crash) {
c := NewCtx(t)
defer c.Close()
crash1 := crashCtor(c)
for i := 0; i < maxReproPerBug; i++ {
resp, _ := c.client.ReportCrash(crash1)
c.expectEQ(resp.NeedRepro, true)
needRepro, _ := c.client.NeedRepro(testCrashID(crash1))
c.expectEQ(needRepro, true)
c.client.ReportFailedRepro(testCrashID(crash1))
}
for i := 0; i < 3; i++ {
// No more repros today.
c.advanceTime(time.Hour)
resp, _ := c.client.ReportCrash(crash1)
c.expectEQ(resp.NeedRepro, false)
needRepro, _ := c.client.NeedRepro(testCrashID(crash1))
c.expectEQ(needRepro, false)
// Then another repro after a day.
c.advanceTime(25 * time.Hour)
for j := 0; j < 2; j++ {
resp, _ := c.client.ReportCrash(crash1)
c.expectEQ(resp.NeedRepro, true)
needRepro, _ := c.client.NeedRepro(testCrashID(crash1))
c.expectEQ(needRepro, true)
}
c.client.ReportFailedRepro(testCrashID(crash1))
}
}
func TestNeedRepro3_normal(t *testing.T) { testNeedRepro3(t, normalCrash) }
func TestNeedRepro3_dup(t *testing.T) { testNeedRepro3(t, dupCrash) }
func TestNeedRepro3_closed(t *testing.T) { testNeedRepro3(t, closedCrash) }
func TestNeedRepro3_closedRepro(t *testing.T) { testNeedRepro3(t, closedWithReproCrash) }
// Test that after uploading 5 syz repros, app stops requesting repros.
func testNeedRepro4(t *testing.T, crashCtor func(c *Ctx) *dashapi.Crash, newBug bool) {
c := NewCtx(t)
defer c.Close()
crash1 := crashCtor(c)
crash1.ReproOpts = []byte("opts")
crash1.ReproSyz = []byte("repro syz")
for i := 0; i < maxReproPerBug-1; i++ {
resp, _ := c.client.ReportCrash(crash1)
c.expectEQ(resp.NeedRepro, true)
needRepro, _ := c.client.NeedRepro(testCrashID(crash1))
c.expectEQ(needRepro, true)
}
resp, _ := c.client.ReportCrash(crash1)
c.expectEQ(resp.NeedRepro, false)
needRepro, _ := c.client.NeedRepro(testCrashID(crash1))
c.expectEQ(needRepro, false)
// No more repros even after a day.
c.advanceTime(25 * time.Hour)
crash1.ReproOpts = nil
crash1.ReproSyz = nil
resp, _ = c.client.ReportCrash(crash1)
c.expectEQ(resp.NeedRepro, false)
needRepro, _ = c.client.NeedRepro(testCrashID(crash1))
c.expectEQ(needRepro, false)
if newBug {
c.client.pollBug()
}
}
func TestNeedRepro4_normal(t *testing.T) { testNeedRepro4(t, normalCrash, true) }
func TestNeedRepro4_dup(t *testing.T) { testNeedRepro4(t, dupCrash, false) }
func TestNeedRepro4_closed(t *testing.T) { testNeedRepro4(t, closedCrash, true) }
func TestNeedRepro4_closedRepro(t *testing.T) { testNeedRepro4(t, closedWithReproCrash, true) }
func normalCrash(c *Ctx) *dashapi.Crash {
build := testBuild(1)
c.client.UploadBuild(build)
crash := testCrash(build, 1)
c.client.ReportCrash(crash)
c.client.pollBug()
return crash
}
func dupCrash(c *Ctx) *dashapi.Crash {
build := testBuild(1)
c.client.UploadBuild(build)
c.client.ReportCrash(testCrash(build, 1))
crash2 := testCrash(build, 2)
c.client.ReportCrash(crash2)
reports := c.client.pollBugs(2)
c.client.updateBug(reports[1].ID, dashapi.BugStatusDup, reports[0].ID)
return crash2
}
func closedCrash(c *Ctx) *dashapi.Crash {
return closedCrashImpl(c, false)
}
func closedWithReproCrash(c *Ctx) *dashapi.Crash {
return closedCrashImpl(c, true)
}
func closedCrashImpl(c *Ctx, withRepro bool) *dashapi.Crash {
build := testBuild(1)
c.client.UploadBuild(build)
crash := testCrash(build, 1)
if withRepro {
crash.ReproC = []byte("repro C")
}
resp, _ := c.client.ReportCrash(crash)
c.expectEQ(resp.NeedRepro, !withRepro)
rep := c.client.pollBug()
c.client.updateBug(rep.ID, dashapi.BugStatusInvalid, "")
crash.ReproC = nil
c.client.ReportCrash(crash)
c.client.pollBug()
return crash
}
func TestNeedReproMissing(t *testing.T) {
c := NewCtx(t)
defer c.Close()
client := c.makeClient(client1, password1, false)
cid := &dashapi.CrashID{
BuildID: "some missing build",
Title: "some missing title",
}
needRepro, err := client.NeedRepro(cid)
c.expectNE(err, nil)
c.expectEQ(needRepro, false)
cid.MayBeMissing = true
needRepro, err = client.NeedRepro(cid)
c.expectEQ(err, nil)
c.expectEQ(needRepro, true)
}