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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
|
// Copyright 2017 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.
// +build aetest
package dash
import (
"testing"
"github.com/google/syzkaller/dashboard/dashapi"
)
func reportAllBugs(c *Ctx, expect int) []*dashapi.BugReport {
pr := &dashapi.PollBugsRequest{
Type: "test",
}
resp := new(dashapi.PollBugsResponse)
c.expectOK(c.API(client1, key1, "reporting_poll_bugs", pr, resp))
if len(resp.Reports) != expect {
c.t.Fatalf("\n%v: want %v reports, got %v", caller(0), expect, len(resp.Reports))
}
for _, rep := range resp.Reports {
reproLevel := dashapi.ReproLevelNone
if len(rep.ReproC) != 0 {
reproLevel = dashapi.ReproLevelC
} else if len(rep.ReproSyz) != 0 {
reproLevel = dashapi.ReproLevelSyz
}
cmd := &dashapi.BugUpdate{
ID: rep.ID,
Status: dashapi.BugStatusOpen,
ReproLevel: reproLevel,
}
reply := new(dashapi.BugUpdateReply)
c.expectOK(c.API(client1, key1, "reporting_update", cmd, reply))
c.expectEQ(reply.Error, false)
c.expectEQ(reply.OK, true)
}
return resp.Reports
}
// Basic scenario of marking a bug as fixed by a particular commit,
// discovering this commit on builder and marking the bug as ultimately fixed.
func TestFixBasic(t *testing.T) {
c := NewCtx(t)
defer c.Close()
build1 := testBuild(1)
c.expectOK(c.API(client1, key1, "upload_build", build1, nil))
crash1 := testCrash(build1, 1)
c.expectOK(c.API(client1, key1, "report_crash", crash1, nil))
builderPollReq := &dashapi.BuilderPollReq{build1.Manager}
builderPollResp := new(dashapi.BuilderPollResp)
c.expectOK(c.API(client1, key1, "builder_poll", builderPollReq, builderPollResp))
c.expectEQ(len(builderPollResp.PendingCommits), 0)
cid := testCrashID(crash1)
needReproResp := new(dashapi.NeedReproResp)
c.expectOK(c.API(client1, key1, "need_repro", cid, needReproResp))
c.expectEQ(needReproResp.NeedRepro, true)
reports := reportAllBugs(c, 1)
rep := reports[0]
// Specify fixing commit for the bug.
cmd := &dashapi.BugUpdate{
ID: rep.ID,
Status: dashapi.BugStatusOpen,
FixCommits: []string{"foo: fix the crash"},
}
reply := new(dashapi.BugUpdateReply)
c.expectOK(c.API(client1, key1, "reporting_update", cmd, reply))
c.expectEQ(reply.OK, true)
// Don't need repro once there are fixing commits.
c.expectOK(c.API(client1, key1, "need_repro", cid, needReproResp))
c.expectEQ(needReproResp.NeedRepro, false)
// Check that the commit is now passed to builders.
c.expectOK(c.API(client1, key1, "builder_poll", builderPollReq, builderPollResp))
c.expectEQ(len(builderPollResp.PendingCommits), 1)
c.expectEQ(builderPollResp.PendingCommits[0], "foo: fix the crash")
// Patches must not be reset on other actions.
cmd = &dashapi.BugUpdate{
ID: rep.ID,
Status: dashapi.BugStatusOpen,
}
c.expectOK(c.API(client1, key1, "reporting_update", cmd, reply))
c.expectEQ(reply.OK, true)
// Upstream commands must fail if patches are already present.
// Right course of action is unclear in this situation,
// so this test merely documents the current behavior.
cmd = &dashapi.BugUpdate{
ID: rep.ID,
Status: dashapi.BugStatusUpstream,
}
c.expectOK(c.API(client1, key1, "reporting_update", cmd, reply))
c.expectEQ(reply.OK, false)
c.expectOK(c.API(client1, key1, "report_crash", crash1, nil))
reportAllBugs(c, 0)
// Upload another build with the commit present.
build2 := testBuild(2)
build2.Manager = build1.Manager
build2.Commits = []string{"foo: fix the crash"}
c.expectOK(c.API(client1, key1, "upload_build", build2, nil))
// Check that the commit is now not passed to this builder.
c.expectOK(c.API(client1, key1, "builder_poll", builderPollReq, builderPollResp))
c.expectEQ(len(builderPollResp.PendingCommits), 0)
// Ensure that a new crash creates a new bug (the old one must be marked as fixed).
c.expectOK(c.API(client1, key1, "report_crash", crash1, nil))
reports = reportAllBugs(c, 1)
c.expectEQ(reports[0].Title, "title1 (2)")
// Regression test: previously upstreamming failed because the new bug had fixing commits.
c.expectOK(c.API(client1, key1, "report_crash", crash1, nil))
cmd = &dashapi.BugUpdate{
ID: reports[0].ID,
Status: dashapi.BugStatusUpstream,
}
c.expectOK(c.API(client1, key1, "reporting_update", cmd, reply))
c.expectEQ(reply.OK, true)
}
// Test bug that is fixed by 2 commits.
func TestFixedByTwoCommits(t *testing.T) {
c := NewCtx(t)
defer c.Close()
build1 := testBuild(1)
c.expectOK(c.API(client1, key1, "upload_build", build1, nil))
crash1 := testCrash(build1, 1)
c.expectOK(c.API(client1, key1, "report_crash", crash1, nil))
builderPollReq := &dashapi.BuilderPollReq{build1.Manager}
builderPollResp := new(dashapi.BuilderPollResp)
c.expectOK(c.API(client1, key1, "builder_poll", builderPollReq, builderPollResp))
c.expectEQ(len(builderPollResp.PendingCommits), 0)
reports := reportAllBugs(c, 1)
rep := reports[0]
// Specify fixing commit for the bug.
cmd := &dashapi.BugUpdate{
ID: rep.ID,
Status: dashapi.BugStatusOpen,
FixCommits: []string{"bar: prepare for fixing", "\"foo: fix the crash\""},
}
reply := new(dashapi.BugUpdateReply)
c.expectOK(c.API(client1, key1, "reporting_update", cmd, reply))
c.expectEQ(reply.OK, true)
// Check that the commit is now passed to builders.
c.expectOK(c.API(client1, key1, "builder_poll", builderPollReq, builderPollResp))
c.expectEQ(len(builderPollResp.PendingCommits), 2)
c.expectEQ(builderPollResp.PendingCommits[0], "bar: prepare for fixing")
c.expectEQ(builderPollResp.PendingCommits[1], "foo: fix the crash")
// Upload another build with only one of the commits.
build2 := testBuild(2)
build2.Manager = build1.Manager
build2.Commits = []string{"bar: prepare for fixing"}
c.expectOK(c.API(client1, key1, "upload_build", build2, nil))
// Check that it has not fixed the bug.
c.expectOK(c.API(client1, key1, "builder_poll", builderPollReq, builderPollResp))
c.expectEQ(len(builderPollResp.PendingCommits), 2)
c.expectEQ(builderPollResp.PendingCommits[0], "bar: prepare for fixing")
c.expectEQ(builderPollResp.PendingCommits[1], "foo: fix the crash")
c.expectOK(c.API(client1, key1, "report_crash", crash1, nil))
reportAllBugs(c, 0)
// Now upload build with both commits.
build3 := testBuild(3)
build3.Manager = build1.Manager
build3.Commits = []string{"foo: fix the crash", "bar: prepare for fixing"}
c.expectOK(c.API(client1, key1, "upload_build", build3, nil))
// Check that the commit is now not passed to this builder.
c.expectOK(c.API(client1, key1, "builder_poll", builderPollReq, builderPollResp))
c.expectEQ(len(builderPollResp.PendingCommits), 0)
// Ensure that a new crash creates a new bug (the old one must be marked as fixed).
c.expectOK(c.API(client1, key1, "report_crash", crash1, nil))
reports = reportAllBugs(c, 1)
c.expectEQ(reports[0].Title, "title1 (2)")
}
// A bug is marked as fixed by one commit and then remarked as fixed by another.
func TestReFixed(t *testing.T) {
c := NewCtx(t)
defer c.Close()
build1 := testBuild(1)
c.expectOK(c.API(client1, key1, "upload_build", build1, nil))
crash1 := testCrash(build1, 1)
c.expectOK(c.API(client1, key1, "report_crash", crash1, nil))
builderPollReq := &dashapi.BuilderPollReq{build1.Manager}
builderPollResp := new(dashapi.BuilderPollResp)
c.expectOK(c.API(client1, key1, "builder_poll", builderPollReq, builderPollResp))
c.expectEQ(len(builderPollResp.PendingCommits), 0)
reports := reportAllBugs(c, 1)
rep := reports[0]
// Specify fixing commit for the bug.
cmd := &dashapi.BugUpdate{
ID: rep.ID,
Status: dashapi.BugStatusOpen,
FixCommits: []string{"a wrong one"},
}
reply := new(dashapi.BugUpdateReply)
c.expectOK(c.API(client1, key1, "reporting_update", cmd, reply))
c.expectEQ(reply.OK, true)
cmd = &dashapi.BugUpdate{
ID: rep.ID,
Status: dashapi.BugStatusOpen,
FixCommits: []string{"the right one"},
}
c.expectOK(c.API(client1, key1, "reporting_update", cmd, reply))
c.expectEQ(reply.OK, true)
c.expectOK(c.API(client1, key1, "builder_poll", builderPollReq, builderPollResp))
c.expectEQ(len(builderPollResp.PendingCommits), 1)
c.expectEQ(builderPollResp.PendingCommits[0], "the right one")
// Upload another build with the wrong commit.
build2 := testBuild(2)
build2.Manager = build1.Manager
build2.Commits = []string{"a wrong one"}
c.expectOK(c.API(client1, key1, "upload_build", build2, nil))
// Check that it has not fixed the bug.
c.expectOK(c.API(client1, key1, "builder_poll", builderPollReq, builderPollResp))
c.expectEQ(len(builderPollResp.PendingCommits), 1)
c.expectEQ(builderPollResp.PendingCommits[0], "the right one")
c.expectOK(c.API(client1, key1, "report_crash", crash1, nil))
reportAllBugs(c, 0)
// Now upload build with the right commit.
build3 := testBuild(3)
build3.Manager = build1.Manager
build3.Commits = []string{"the right one"}
c.expectOK(c.API(client1, key1, "upload_build", build3, nil))
// Check that the commit is now not passed to this builder.
c.expectOK(c.API(client1, key1, "builder_poll", builderPollReq, builderPollResp))
c.expectEQ(len(builderPollResp.PendingCommits), 0)
}
// Fixing commit is present on one manager, but missing on another.
func TestFixTwoManagers(t *testing.T) {
c := NewCtx(t)
defer c.Close()
build1 := testBuild(1)
c.expectOK(c.API(client1, key1, "upload_build", build1, nil))
crash1 := testCrash(build1, 1)
c.expectOK(c.API(client1, key1, "report_crash", crash1, nil))
builderPollReq := &dashapi.BuilderPollReq{build1.Manager}
builderPollResp := new(dashapi.BuilderPollResp)
c.expectOK(c.API(client1, key1, "builder_poll", builderPollReq, builderPollResp))
c.expectEQ(len(builderPollResp.PendingCommits), 0)
reports := reportAllBugs(c, 1)
rep := reports[0]
// Specify fixing commit for the bug.
cmd := &dashapi.BugUpdate{
ID: rep.ID,
Status: dashapi.BugStatusOpen,
FixCommits: []string{"foo: fix the crash"},
}
reply := new(dashapi.BugUpdateReply)
c.expectOK(c.API(client1, key1, "reporting_update", cmd, reply))
c.expectEQ(reply.OK, true)
// Now the second manager appears.
build2 := testBuild(2)
c.expectOK(c.API(client1, key1, "upload_build", build2, nil))
// Check that the commit is now passed to builders.
builderPollReq = &dashapi.BuilderPollReq{build1.Manager}
c.expectOK(c.API(client1, key1, "builder_poll", builderPollReq, builderPollResp))
c.expectEQ(len(builderPollResp.PendingCommits), 1)
c.expectEQ(builderPollResp.PendingCommits[0], "foo: fix the crash")
builderPollReq = &dashapi.BuilderPollReq{build2.Manager}
c.expectOK(c.API(client1, key1, "builder_poll", builderPollReq, builderPollResp))
c.expectEQ(len(builderPollResp.PendingCommits), 1)
c.expectEQ(builderPollResp.PendingCommits[0], "foo: fix the crash")
// Now first manager picks up the commit.
build3 := testBuild(3)
build3.Manager = build1.Manager
build3.Commits = []string{"foo: fix the crash"}
c.expectOK(c.API(client1, key1, "upload_build", build3, nil))
// Check that the commit is now not passed to this builder.
builderPollReq = &dashapi.BuilderPollReq{build1.Manager}
c.expectOK(c.API(client1, key1, "builder_poll", builderPollReq, builderPollResp))
c.expectEQ(len(builderPollResp.PendingCommits), 0)
// But still passed to another.
builderPollReq = &dashapi.BuilderPollReq{build2.Manager}
c.expectOK(c.API(client1, key1, "builder_poll", builderPollReq, builderPollResp))
c.expectEQ(len(builderPollResp.PendingCommits), 1)
c.expectEQ(builderPollResp.PendingCommits[0], "foo: fix the crash")
// Check that the bug is still open.
c.expectOK(c.API(client1, key1, "report_crash", crash1, nil))
reportAllBugs(c, 0)
// Now the second manager picks up the commit.
build4 := testBuild(4)
build4.Manager = build2.Manager
build4.Commits = []string{"foo: fix the crash"}
c.expectOK(c.API(client1, key1, "upload_build", build4, nil))
// Now the bug must be fixed.
builderPollReq = &dashapi.BuilderPollReq{build2.Manager}
c.expectOK(c.API(client1, key1, "builder_poll", builderPollReq, builderPollResp))
c.expectEQ(len(builderPollResp.PendingCommits), 0)
c.expectOK(c.API(client1, key1, "report_crash", crash1, nil))
reports = reportAllBugs(c, 1)
c.expectEQ(reports[0].Title, "title1 (2)")
}
func TestReFixedTwoManagers(t *testing.T) {
c := NewCtx(t)
defer c.Close()
build1 := testBuild(1)
c.expectOK(c.API(client1, key1, "upload_build", build1, nil))
crash1 := testCrash(build1, 1)
c.expectOK(c.API(client1, key1, "report_crash", crash1, nil))
builderPollReq := &dashapi.BuilderPollReq{build1.Manager}
builderPollResp := new(dashapi.BuilderPollResp)
c.expectOK(c.API(client1, key1, "builder_poll", builderPollReq, builderPollResp))
c.expectEQ(len(builderPollResp.PendingCommits), 0)
reports := reportAllBugs(c, 1)
rep := reports[0]
// Specify fixing commit for the bug.
cmd := &dashapi.BugUpdate{
ID: rep.ID,
Status: dashapi.BugStatusOpen,
FixCommits: []string{"foo: fix the crash"},
}
reply := new(dashapi.BugUpdateReply)
c.expectOK(c.API(client1, key1, "reporting_update", cmd, reply))
c.expectEQ(reply.OK, true)
// Now the second manager appears.
build2 := testBuild(2)
c.expectOK(c.API(client1, key1, "upload_build", build2, nil))
// Now first manager picks up the commit.
build3 := testBuild(3)
build3.Manager = build1.Manager
build3.Commits = []string{"foo: fix the crash"}
c.expectOK(c.API(client1, key1, "upload_build", build3, nil))
builderPollReq = &dashapi.BuilderPollReq{build1.Manager}
c.expectOK(c.API(client1, key1, "builder_poll", builderPollReq, builderPollResp))
c.expectEQ(len(builderPollResp.PendingCommits), 0)
// Now we change the fixing commit.
cmd = &dashapi.BugUpdate{
ID: rep.ID,
Status: dashapi.BugStatusOpen,
FixCommits: []string{"the right one"},
}
c.expectOK(c.API(client1, key1, "reporting_update", cmd, reply))
c.expectEQ(reply.OK, true)
// Now it must again appear on both managers.
builderPollReq = &dashapi.BuilderPollReq{build1.Manager}
c.expectOK(c.API(client1, key1, "builder_poll", builderPollReq, builderPollResp))
c.expectEQ(len(builderPollResp.PendingCommits), 1)
c.expectEQ(builderPollResp.PendingCommits[0], "the right one")
builderPollReq = &dashapi.BuilderPollReq{build2.Manager}
c.expectOK(c.API(client1, key1, "builder_poll", builderPollReq, builderPollResp))
c.expectEQ(len(builderPollResp.PendingCommits), 1)
c.expectEQ(builderPollResp.PendingCommits[0], "the right one")
// Now the second manager picks up the second commit.
build4 := testBuild(4)
build4.Manager = build2.Manager
build4.Commits = []string{"the right one"}
c.expectOK(c.API(client1, key1, "upload_build", build4, nil))
// The bug must be still open.
c.expectOK(c.API(client1, key1, "report_crash", crash1, nil))
reportAllBugs(c, 0)
// Specify fixing commit again, but it's the same one as before, so nothing changed.
cmd = &dashapi.BugUpdate{
ID: rep.ID,
Status: dashapi.BugStatusOpen,
FixCommits: []string{"the right one"},
}
c.expectOK(c.API(client1, key1, "reporting_update", cmd, reply))
c.expectEQ(reply.OK, true)
// Now the first manager picks up the second commit.
build5 := testBuild(5)
build5.Manager = build1.Manager
build5.Commits = []string{"the right one"}
c.expectOK(c.API(client1, key1, "upload_build", build5, nil))
// Now the bug must be fixed.
builderPollReq = &dashapi.BuilderPollReq{build1.Manager}
c.expectOK(c.API(client1, key1, "builder_poll", builderPollReq, builderPollResp))
c.expectEQ(len(builderPollResp.PendingCommits), 0)
c.expectOK(c.API(client1, key1, "report_crash", crash1, nil))
reports = reportAllBugs(c, 1)
c.expectEQ(reports[0].Title, "title1 (2)")
}
|