forked from google/syzkaller
-
Notifications
You must be signed in to change notification settings - Fork 0
/
notifications_test.go
353 lines (306 loc) · 9.65 KB
/
notifications_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
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
// Copyright 2019 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 (
"strings"
"testing"
"time"
"github.com/google/syzkaller/dashboard/dashapi"
)
func TestEmailNotifUpstreamEmbargo(t *testing.T) {
c := NewCtx(t)
defer c.Close()
build := testBuild(1)
c.client2.UploadBuild(build)
crash := testCrash(build, 1)
c.client2.ReportCrash(crash)
report := c.pollEmailBug()
c.expectEQ(report.To, []string{"[email protected]"})
// Upstreaming happens after 14 days, so no emails yet.
c.advanceTime(13 * 24 * time.Hour)
c.expectNoEmail()
// Now we should get notification about upstreaming and upstream report:
c.advanceTime(2 * 24 * time.Hour)
notifUpstream := c.pollEmailBug()
upstreamReport := c.pollEmailBug()
c.expectEQ(notifUpstream.Subject, crash.Title)
c.expectEQ(notifUpstream.Sender, report.Sender)
c.expectEQ(notifUpstream.Body, "Sending this report upstream.")
c.expectEQ(upstreamReport.Subject, "[syzbot] "+crash.Title)
c.expectNE(upstreamReport.Sender, report.Sender)
c.expectEQ(upstreamReport.To, []string{"[email protected]", "[email protected]"})
}
func TestEmailNotifUpstreamSkip(t *testing.T) {
c := NewCtx(t)
defer c.Close()
build := testBuild(1)
c.client2.UploadBuild(build)
crash := testCrash(build, 1)
crash.Title = "skip with repro 1"
c.client2.ReportCrash(crash)
report := c.pollEmailBug()
c.expectEQ(report.To, []string{"[email protected]"})
// No emails yet.
c.expectNoEmail()
// Now upload repro and it should be auto-upstreamed.
crash.ReproOpts = []byte("repro opts")
crash.ReproSyz = []byte("getpid()")
c.client2.ReportCrash(crash)
notifUpstream := c.pollEmailBug()
upstreamReport := c.pollEmailBug()
c.expectEQ(notifUpstream.Sender, report.Sender)
c.expectEQ(notifUpstream.Body, "Sending this report upstream.")
c.expectNE(upstreamReport.Sender, report.Sender)
c.expectEQ(upstreamReport.To, []string{"[email protected]", "[email protected]"})
}
func TestEmailNotifBadFix(t *testing.T) {
c := NewCtx(t)
defer c.Close()
build := testBuild(1)
c.client2.UploadBuild(build)
crash := testCrash(build, 1)
c.client2.ReportCrash(crash)
report := c.pollEmailBug()
c.expectEQ(report.To, []string{"[email protected]"})
c.incomingEmail(report.Sender, "#syz fix some: commit title")
c.expectNoEmail()
// Notification about bad fixing commit should be send after 90 days.
c.advanceTime(50 * 24 * time.Hour)
c.expectNoEmail()
c.advanceTime(35 * 24 * time.Hour)
c.expectNoEmail()
c.advanceTime(10 * 24 * time.Hour)
notif := c.pollEmailBug()
if !strings.Contains(notif.Body, "This bug is marked as fixed by commit:\nsome: commit title\n") {
t.Fatalf("bad notification text: %q", notif.Body)
}
// No notifications for another 14 days, then another one.
c.advanceTime(13 * 24 * time.Hour)
c.expectNoEmail()
c.advanceTime(2 * 24 * time.Hour)
notif = c.pollEmailBug()
if !strings.Contains(notif.Body, "This bug is marked as fixed by commit:\nsome: commit title\n") {
t.Fatalf("bad notification text: %q", notif.Body)
}
}
func TestBugObsoleting(t *testing.T) {
// To simplify test we specify all dates in days from a fixed point in time.
const day = 24 * time.Hour
days := func(n int) time.Time {
t := time.Date(2000, 0, 0, 0, 0, 0, 0, time.UTC)
t.Add(time.Duration(n+1) * day)
return t
}
tests := []struct {
bug *Bug
period time.Duration
}{
// Final bug with just 1 crash: max final period.
{
bug: &Bug{
FirstTime: days(0),
LastTime: days(0),
NumCrashes: 1,
Reporting: []BugReporting{{Reported: days(0)}},
},
period: 100 * day,
},
// Non-final bug with just 1 crash: max non-final period.
{
bug: &Bug{
FirstTime: days(0),
LastTime: days(0),
NumCrashes: 1,
Reporting: []BugReporting{{Reported: days(0)}, {}},
},
period: 60 * day,
},
// Special manger: max period that that manager.
{
bug: &Bug{
FirstTime: days(0),
LastTime: days(0),
NumCrashes: 1,
HappenedOn: []string{"special-obsoleting"},
Reporting: []BugReporting{{Reported: days(0)}, {}},
},
period: 20 * day,
},
// Special manger and a non-special: normal rules.
{
bug: &Bug{
FirstTime: days(0),
LastTime: days(0),
NumCrashes: 1,
HappenedOn: []string{"special-obsoleting", "non-special-manager"},
Reporting: []BugReporting{{Reported: days(0)}},
},
period: 100 * day,
},
// Happened a lot: min period.
{
bug: &Bug{
FirstTime: days(0),
LastTime: days(1),
NumCrashes: 1000,
Reporting: []BugReporting{{Reported: days(0)}},
},
period: 80 * day,
},
}
for i, test := range tests {
test.bug.Namespace = "test1"
got := test.bug.obsoletePeriod()
if got != test.period {
t.Errorf("test #%v: got: %.2f, want %.2f",
i, float64(got/time.Hour)/24, float64(test.period/time.Hour)/24)
}
}
}
func TestEmailNotifObsoleted(t *testing.T) {
c := NewCtx(t)
defer c.Close()
build := testBuild(1)
c.client2.UploadBuild(build)
crash := testCrash(build, 1)
crash.Maintainers = []string{"[email protected]"}
c.client2.ReportCrash(crash)
report := c.pollEmailBug()
// Need to upstream so that it's not auto-upstreamed before obsoleted.
c.incomingEmail(report.Sender, "#syz upstream")
report = c.pollEmailBug()
// Add more people to bug CC.
c.incomingEmail(report.Sender, "wow", EmailOptCC([]string{"[email protected]"}))
// Bug is open, new crashes don't create new bug.
c.client2.ReportCrash(crash)
c.expectNoEmail()
// Not yet.
c.advanceTime(59 * 24 * time.Hour)
c.expectNoEmail()
// Now!
c.advanceTime(2 * 24 * time.Hour)
notif := c.pollEmailBug()
if !strings.Contains(notif.Body, "Auto-closing this bug as obsolete") {
t.Fatalf("bad notification text: %q", notif.Body)
}
// New crash must create new bug.
c.client2.ReportCrash(crash)
report = c.pollEmailBug()
c.expectEQ(report.Subject, "title1 (2)")
// Now the same, but for the last reporting (must have smaller CC list).
c.incomingEmail(report.Sender, "#syz upstream")
report = c.pollEmailBug()
c.incomingEmail(report.Sender, "#syz upstream")
report = c.pollEmailBug()
_ = report
c.advanceTime(101 * 24 * time.Hour)
notif = c.pollEmailBug()
if !strings.Contains(notif.Body, "Auto-closing this bug as obsolete") {
t.Fatalf("bad notification text: %q", notif.Body)
}
c.expectEQ(notif.Subject, crash.Title+" (2)")
c.expectEQ(notif.To, []string{"[email protected]"})
}
func TestEmailNotifNotObsoleted(t *testing.T) {
c := NewCtx(t)
defer c.Close()
build := testBuild(1)
c.client2.UploadBuild(build)
// Crashes with repro are not auto-obsoleted.
crash1 := testCrash(build, 1)
crash1.ReproSyz = []byte("repro")
c.client2.ReportCrash(crash1)
report1 := c.pollEmailBug()
c.incomingEmail(report1.Sender, "#syz upstream")
report1 = c.pollEmailBug()
_ = report1
// This crash will get another crash later.
crash2 := testCrash(build, 2)
c.client2.ReportCrash(crash2)
report2 := c.pollEmailBug()
c.incomingEmail(report2.Sender, "#syz upstream")
report2 = c.pollEmailBug()
_ = report2
// This crash will get some activity later.
crash3 := testCrash(build, 3)
c.client2.ReportCrash(crash3)
report3 := c.pollEmailBug()
c.incomingEmail(report3.Sender, "#syz upstream")
report3 = c.pollEmailBug()
// This will be obsoleted (just to check that we have timings right).
c.advanceTime(24 * time.Hour)
crash4 := testCrash(build, 4)
c.client2.ReportCrash(crash4)
report4 := c.pollEmailBug()
c.incomingEmail(report4.Sender, "#syz upstream")
report4 = c.pollEmailBug()
c.advanceTime(59 * 24 * time.Hour)
c.expectNoEmail()
c.client2.ReportCrash(crash2)
c.incomingEmail(report3.Sender, "I am looking at it")
c.advanceTime(5 * 24 * time.Hour)
// Only crash 4 is obsoleted.
notif := c.pollEmailBug()
c.expectEQ(notif.Sender, report4.Sender)
c.expectNoEmail()
// Crash 3 also obsoleted after some time.
c.advanceTime(20 * 24 * time.Hour)
notif = c.pollEmailBug()
c.expectEQ(notif.Sender, report3.Sender)
}
func TestEmailNotifObsoletedManager(t *testing.T) {
// Crashes with repro are auto-obsoleted if happen on a particular manager only.
c := NewCtx(t)
defer c.Close()
build := testBuild(1)
build.Manager = noFixBisectionManager
c.client2.UploadBuild(build)
crash := testCrashWithRepro(build, 1)
c.client2.ReportCrash(crash)
report := c.pollEmailBug()
c.incomingEmail(report.Sender, "#syz upstream")
report = c.pollEmailBug()
_ = report
c.advanceTime(200 * 24 * time.Hour)
notif := c.pollEmailBug()
c.expectTrue(strings.Contains(notif.Body, "Auto-closing this bug as obsolete"))
}
func TestExtNotifUpstreamEmbargo(t *testing.T) {
c := NewCtx(t)
defer c.Close()
build1 := testBuild(1)
c.client.UploadBuild(build1)
crash1 := testCrash(build1, 1)
c.client.ReportCrash(crash1)
rep := c.client.pollBug()
// Specify fixing commit for the bug.
reply, _ := c.client.ReportingUpdate(&dashapi.BugUpdate{
ID: rep.ID,
Status: dashapi.BugStatusOpen,
})
c.expectEQ(reply.OK, true)
c.client.pollNotifs(0)
c.advanceTime(20 * 24 * time.Hour)
notif := c.client.pollNotifs(1)[0]
c.expectEQ(notif.ID, rep.ID)
c.expectEQ(notif.Type, dashapi.BugNotifUpstream)
}
func TestExtNotifUpstreamOnHold(t *testing.T) {
c := NewCtx(t)
defer c.Close()
build1 := testBuild(1)
c.client.UploadBuild(build1)
crash1 := testCrash(build1, 1)
c.client.ReportCrash(crash1)
rep := c.client.pollBug()
// Specify fixing commit for the bug.
reply, _ := c.client.ReportingUpdate(&dashapi.BugUpdate{
ID: rep.ID,
Status: dashapi.BugStatusOpen,
OnHold: true,
})
c.expectEQ(reply.OK, true)
c.advanceTime(20 * 24 * time.Hour)
c.client.pollNotifs(0)
}