How to use log method of bisect Package

Best Syzkaller code snippet using bisect.log

bisect_test.go

Source:bisect_test.go Github

copy

Full Screen

...70 c.expectEQ(pollResp, pollResp2)71 // Bisection failed with an error.72 done := &dashapi.JobDoneReq{73 ID: pollResp.ID,74 Log: []byte("bisect log 3"),75 Error: []byte("bisect error 3"),76 }77 c.expectOK(c.client2.JobDone(done))78 c.expectNoEmail()79 // BisectCause #280 pollResp = c.client2.pollJobs(build.Manager)81 c.expectNE(pollResp.ID, pollResp2.ID)82 c.expectEQ(pollResp.ReproOpts, []byte("repro opts 2"))83 // Bisection succeeded.84 jobID := pollResp.ID85 done = &dashapi.JobDoneReq{86 ID: jobID,87 Build: *build,88 Log: []byte("bisect log 2"),89 CrashTitle: "bisect crash title",90 CrashLog: []byte("bisect crash log"),91 CrashReport: []byte("bisect crash report"),92 Commits: []dashapi.Commit{93 {94 Hash: "36e65cb4a0448942ec316b24d60446bbd5cc7827",95 Title: "kernel: add a bug",96 Author: "author@kernel.org",97 AuthorName: "Author Kernelov",98 CC: []string{99 "reviewer1@kernel.org", "\"Reviewer2\" <reviewer2@kernel.org>",100 // These must be filtered out:101 "syzbot@testapp.appspotmail.com",102 "syzbot+1234@testapp.appspotmail.com",103 "\"syzbot\" <syzbot+1234@testapp.appspotmail.com>",104 },105 Date: time.Date(2000, 2, 9, 4, 5, 6, 7, time.UTC),106 },107 },108 }109 done.Build.ID = jobID110 c.expectOK(c.client2.JobDone(done))111 _, extBugID, err := email.RemoveAddrContext(msg2.Sender)112 c.expectOK(err)113 dbBug, dbCrash, _ := c.loadBug(extBugID)114 reproSyzLink := externalLink(c.ctx, textReproSyz, dbCrash.ReproSyz)115 reproCLink := externalLink(c.ctx, textReproC, dbCrash.ReproC)116 dbJob, dbBuild, dbJobCrash := c.loadJob(jobID)117 kernelConfigLink := externalLink(c.ctx, textKernelConfig, dbBuild.KernelConfig)118 bisectCrashReportLink := externalLink(c.ctx, textCrashReport, dbJob.CrashReport)119 bisectCrashLogLink := externalLink(c.ctx, textCrashLog, dbJob.CrashLog)120 bisectLogLink := externalLink(c.ctx, textLog, dbJob.Log)121 crashLogLink := externalLink(c.ctx, textCrashLog, dbJobCrash.Log)122 {123 msg := c.pollEmailBug()124 // Not mailed to commit author/cc because !MailMaintainers.125 c.expectEQ(msg.To, []string{"test@syzkaller.com"})126 c.expectEQ(msg.Subject, crash2.Title)127 c.expectEQ(len(msg.Attachments), 0)128 c.expectEQ(msg.Body, fmt.Sprintf(`syzbot has bisected this bug to:129commit 36e65cb4a0448942ec316b24d60446bbd5cc7827130Author: Author Kernelov <author@kernel.org>131Date: Wed Feb 9 04:05:06 2000 +0000132 kernel: add a bug133bisection log: %[2]v134start commit: 11111111 kernel_commit_title1135git tree: repo1 branch1136final crash: %[3]v137console output: %[4]v138kernel config: %[5]v139dashboard link: https://testapp.appspot.com/bug?extid=%[1]v140syz repro: %[6]v141C reproducer: %[7]v142Reported-by: syzbot+%[1]v@testapp.appspotmail.com143Fixes: 36e65cb4a044 ("kernel: add a bug")144For information about bisection process see: https://goo.gl/tpsmEJ#bisection145`, extBugID, bisectLogLink, bisectCrashReportLink, bisectCrashLogLink, kernelConfigLink, reproSyzLink, reproCLink))146 syzRepro := []byte(fmt.Sprintf("# https://testapp.appspot.com/bug?id=%v\n%s#%s\n%s",147 dbBug.keyHash(), syzReproPrefix, crash2.ReproOpts, crash2.ReproSyz))148 cRepro := []byte(fmt.Sprintf("// https://testapp.appspot.com/bug?id=%v\n%s",149 dbBug.keyHash(), crash2.ReproC))150 c.checkURLContents(bisectLogLink, []byte("bisect log 2"))151 c.checkURLContents(bisectCrashReportLink, []byte("bisect crash report"))152 c.checkURLContents(bisectCrashLogLink, []byte("bisect crash log"))153 c.checkURLContents(kernelConfigLink, []byte("config1"))154 c.checkURLContents(reproSyzLink, syzRepro)155 c.checkURLContents(reproCLink, cRepro)156 }157 // The next reporting must get bug report with bisection results.158 c.incomingEmail(msg2.Sender, "#syz upstream")159 {160 msg := c.pollEmailBug()161 _, extBugID2, err := email.RemoveAddrContext(msg.Sender)162 c.expectOK(err)163 c.expectEQ(msg.To, []string{164 "author@kernel.org",165 "bugs@syzkaller.com",166 "default@maintainers.com",167 "reviewer1@kernel.org",168 "reviewer2@kernel.org",169 })170 c.expectEQ(msg.Subject, crash2.Title)171 c.expectEQ(msg.Body, fmt.Sprintf(`Hello,172syzbot found the following crash on:173HEAD commit: 11111111 kernel_commit_title1174git tree: repo1 branch1175console output: %[2]v176kernel config: %[3]v177dashboard link: https://testapp.appspot.com/bug?extid=%[1]v178compiler: compiler1179syz repro: %[4]v180C reproducer: %[5]v181CC: [author@kernel.org reviewer1@kernel.org reviewer2@kernel.org]182The bug was bisected to:183commit 36e65cb4a0448942ec316b24d60446bbd5cc7827184Author: Author Kernelov <author@kernel.org>185Date: Wed Feb 9 04:05:06 2000 +0000186 kernel: add a bug187bisection log: %[6]v188final crash: %[7]v189console output: %[8]v190IMPORTANT: if you fix the bug, please add the following tag to the commit:191Reported-by: syzbot+%[1]v@testapp.appspotmail.com192Fixes: 36e65cb4a044 ("kernel: add a bug")193report2194---195This bug is generated by a bot. It may contain errors.196See https://goo.gl/tpsmEJ for more information about syzbot.197syzbot engineers can be reached at syzkaller@googlegroups.com.198syzbot will keep track of this bug report. See:199https://goo.gl/tpsmEJ#status for how to communicate with syzbot.200For information about bisection process see: https://goo.gl/tpsmEJ#bisection201syzbot can test patches for this bug, for details see:202https://goo.gl/tpsmEJ#testing-patches`,203 extBugID2, crashLogLink, kernelConfigLink, reproSyzLink, reproCLink,204 bisectLogLink, bisectCrashReportLink, bisectCrashLogLink))205 }206 // BisectCause #4207 // Crash 4 is bisected in reporting with MailMaintainers.208 // It also skipped second reporting because of the title.209 c.incomingEmail(msg4.Sender, "#syz upstream")210 msg4 = c.pollEmailBug()211 c.expectEQ(msg4.To, []string{212 "bugs2@syzkaller.com",213 "default2@maintainers.com",214 })215 pollResp = c.client2.pollJobs(build.Manager)216 // Bisection succeeded.217 jobID = pollResp.ID218 done = &dashapi.JobDoneReq{219 ID: jobID,220 Build: *build,221 Log: []byte("bisectcause log 4"),222 CrashTitle: "bisectcause crash title 4",223 CrashLog: []byte("bisectcause crash log 4"),224 CrashReport: []byte("bisectcause crash report 4"),225 Commits: []dashapi.Commit{226 {227 Hash: "36e65cb4a0448942ec316b24d60446bbd5cc7827",228 Title: "kernel: add a bug",229 Author: "author@kernel.org",230 AuthorName: "Author Kernelov",231 CC: []string{232 "reviewer1@kernel.org", "\"Reviewer2\" <reviewer2@kernel.org>",233 // These must be filtered out:234 "syzbot@testapp.appspotmail.com",235 "syzbot+1234@testapp.appspotmail.com",236 "\"syzbot\" <syzbot+1234@testapp.appspotmail.com>",237 },238 Date: time.Date(2000, 2, 9, 4, 5, 6, 7, time.UTC),239 },240 },241 }242 done.Build.ID = jobID243 c.expectOK(c.client2.JobDone(done))244 {245 msg := c.pollEmailBug()246 c.expectEQ(msg.Subject, crash4.Title)247 c.expectEQ(msg.To, []string{248 "author@kernel.org",249 "bugs2@syzkaller.com",250 "default2@maintainers.com",251 "reviewer1@kernel.org",252 "reviewer2@kernel.org",253 })254 }255 {256 c.advanceTime(30 * 24 * time.Hour)257 subjects := []string{"title3", "title1", "title5", "title3", "title5", "title1"}258 for i := 0; i < 6; i++ {259 msg := c.pollEmailBug()260 c.expectEQ(msg.Subject, subjects[i])261 if i < 3 {262 c.expectTrue(strings.Contains(msg.Body, "Sending this report upstream."))263 } else {264 c.expectTrue(strings.Contains(msg.Body, "syzbot found the following crash on"))265 }266 }267 }268 // BisectFix #2269 pollResp = c.client2.pollJobs(build.Manager)270 c.expectNE(pollResp.ID, "")271 c.expectEQ(pollResp.Type, dashapi.JobBisectFix)272 c.expectEQ(pollResp.ReproOpts, []byte("repro opts 2"))273 c.advanceTime(5 * 24 * time.Hour)274 pollResp2 = c.client2.pollJobs(build.Manager)275 c.expectEQ(pollResp, pollResp2)276 done = &dashapi.JobDoneReq{277 ID: pollResp.ID,278 Log: []byte("bisect log 2"),279 Error: []byte("bisect error 2"),280 }281 c.expectOK(c.client2.JobDone(done))282 // BisectFix #3283 pollResp = c.client2.pollJobs(build.Manager)284 c.expectNE(pollResp.ID, "")285 c.expectEQ(pollResp.Type, dashapi.JobBisectFix)286 c.expectEQ(pollResp.ReproOpts, []byte("repro opts 3"))287 done = &dashapi.JobDoneReq{288 ID: pollResp.ID,289 Log: []byte("bisect log 3"),290 Error: []byte("bisect error 3"),291 }292 c.expectOK(c.client2.JobDone(done))293 // BisectFix #4294 pollResp = c.client2.pollJobs(build.Manager)295 c.expectNE(pollResp.ID, "")296 c.expectEQ(pollResp.Type, dashapi.JobBisectFix)297 c.expectEQ(pollResp.ReproOpts, []byte("repro opts 4"))298 jobID = pollResp.ID299 done = &dashapi.JobDoneReq{300 ID: jobID,301 Build: *build,302 Log: []byte("bisectfix log 4"),303 CrashTitle: "bisectfix crash title 4",304 CrashLog: []byte("bisectfix crash log 4"),305 CrashReport: []byte("bisectfix crash report 4"),306 Commits: []dashapi.Commit{307 {308 Hash: "46e65cb4a0448942ec316b24d60446bbd5cc7827",309 Title: "kernel: add a fix",310 Author: "author@kernel.org",311 AuthorName: "Author Kernelov",312 CC: []string{313 "reviewer1@kernel.org", "\"Reviewer2\" <reviewer2@kernel.org>",314 // These must be filtered out:315 "syzbot@testapp.appspotmail.com",316 "syzbot+1234@testapp.appspotmail.com",317 "\"syzbot\" <syzbot+1234@testapp.appspotmail.com>",318 },319 Date: time.Date(2000, 2, 9, 4, 5, 6, 7, time.UTC),320 },321 },322 }323 done.Build.ID = jobID324 c.expectOK(c.client2.JobDone(done))325 _, extBugID, err = email.RemoveAddrContext(msg4.Sender)326 c.expectOK(err)327 dbBug, dbCrash, _ = c.loadBug(extBugID)328 reproSyzLink = externalLink(c.ctx, textReproSyz, dbCrash.ReproSyz)329 reproCLink = externalLink(c.ctx, textReproC, dbCrash.ReproC)330 dbJob, dbBuild, _ = c.loadJob(jobID)331 kernelConfigLink = externalLink(c.ctx, textKernelConfig, dbBuild.KernelConfig)332 bisectCrashReportLink = externalLink(c.ctx, textCrashReport, dbJob.CrashReport)333 bisectCrashLogLink = externalLink(c.ctx, textCrashLog, dbJob.CrashLog)334 bisectLogLink = externalLink(c.ctx, textLog, dbJob.Log)335 {336 msg := c.pollEmailBug()337 // Not mailed to commit author/cc because !MailMaintainers.338 // c.expectEQ(msg.To, []string{"test@syzkaller.com"})339 c.expectEQ(msg.Subject, crash4.Title)340 c.expectEQ(len(msg.Attachments), 0)341 c.expectEQ(msg.Body, fmt.Sprintf(`syzbot suspects this bug was fixed by commit:342commit 46e65cb4a0448942ec316b24d60446bbd5cc7827343Author: Author Kernelov <author@kernel.org>344Date: Wed Feb 9 04:05:06 2000 +0000345 kernel: add a fix346bisection log: %[2]v347start commit: 11111111 kernel_commit_title1348git tree: repo1 branch1349final crash: %[3]v350console output: %[4]v351kernel config: %[5]v352dashboard link: https://testapp.appspot.com/bug?extid=%[1]v353syz repro: %[6]v354If the result looks correct, please mark the bug fixed by replying with:355#syz fix: kernel: add a fix356For information about bisection process see: https://goo.gl/tpsmEJ#bisection357`, extBugID, bisectLogLink, bisectCrashReportLink, bisectCrashLogLink, kernelConfigLink, reproSyzLink, reproCLink))358 syzRepro := []byte(fmt.Sprintf("# https://testapp.appspot.com/bug?id=%v\n%s#%s\n%s",359 dbBug.keyHash(), syzReproPrefix, crash4.ReproOpts, crash4.ReproSyz))360 c.checkURLContents(bisectLogLink, []byte("bisectfix log 4"))361 c.checkURLContents(bisectCrashReportLink, []byte("bisectfix crash report 4"))362 c.checkURLContents(bisectCrashLogLink, []byte("bisectfix crash log 4"))363 c.checkURLContents(kernelConfigLink, []byte("config1"))364 c.checkURLContents(reproSyzLink, syzRepro)365 }366 // No more bisection jobs.367 pollResp = c.client2.pollJobs(build.Manager)368 c.expectEQ(pollResp.ID, "")369}370func TestBisectCauseInconclusive(t *testing.T) {371 c := NewCtx(t)372 defer c.Close()373 build := testBuild(1)374 c.client2.UploadBuild(build)375 crash := testCrashWithRepro(build, 1)376 c.client2.ReportCrash(crash)377 msg := c.client2.pollEmailBug()378 pollResp := c.client2.pollJobs(build.Manager)379 jobID := pollResp.ID380 done := &dashapi.JobDoneReq{381 ID: jobID,382 Build: *build,383 Log: []byte("bisect log"),384 Commits: []dashapi.Commit{385 {386 Hash: "111111111111111111111111",387 Title: "kernel: break build",388 Author: "hacker@kernel.org",389 AuthorName: "Hacker Kernelov",390 CC: []string{"reviewer1@kernel.org", "reviewer2@kernel.org"},391 Date: time.Date(2000, 2, 9, 4, 5, 6, 7, time.UTC),392 },393 {394 Hash: "222222222222222222222222",395 Title: "kernel: now add a bug to the broken build",396 Author: "author@kernel.org",397 AuthorName: "Author Kernelov",398 CC: []string{"reviewer3@kernel.org", "reviewer4@kernel.org"},399 Date: time.Date(2001, 2, 9, 4, 5, 6, 7, time.UTC),400 },401 },402 }403 done.Build.ID = jobID404 c.expectOK(c.client2.JobDone(done))405 _, extBugID, err := email.RemoveAddrContext(msg.Sender)406 c.expectOK(err)407 _, dbCrash, _ := c.loadBug(extBugID)408 reproSyzLink := externalLink(c.ctx, textReproSyz, dbCrash.ReproSyz)409 reproCLink := externalLink(c.ctx, textReproC, dbCrash.ReproC)410 dbJob, dbBuild, dbJobCrash := c.loadJob(jobID)411 kernelConfigLink := externalLink(c.ctx, textKernelConfig, dbBuild.KernelConfig)412 bisectLogLink := externalLink(c.ctx, textLog, dbJob.Log)413 crashLogLink := externalLink(c.ctx, textCrashLog, dbJobCrash.Log)414 {415 msg := c.pollEmailBug()416 // Not mailed to commit author/cc because !MailMaintainers.417 c.expectEQ(msg.To, []string{"test@syzkaller.com"})418 c.expectEQ(msg.Subject, crash.Title)419 c.expectEQ(len(msg.Attachments), 0)420 c.expectEQ(msg.Body, fmt.Sprintf(`Bisection is inconclusive: the first bad commit could be any of:42111111111 kernel: break build42222222222 kernel: now add a bug to the broken build423bisection log: %[2]v424start commit: 11111111 kernel_commit_title1425git tree: repo1 branch1426kernel config: %[3]v427dashboard link: https://testapp.appspot.com/bug?extid=%[1]v428syz repro: %[4]v429C reproducer: %[5]v430For information about bisection process see: https://goo.gl/tpsmEJ#bisection431`, extBugID, bisectLogLink, kernelConfigLink, reproSyzLink, reproCLink))432 }433 // The next reporting must get bug report with bisection results.434 c.incomingEmail(msg.Sender, "#syz upstream")435 {436 msg := c.pollEmailBug()437 _, extBugID2, err := email.RemoveAddrContext(msg.Sender)438 c.expectOK(err)439 c.expectEQ(msg.To, []string{440 "bugs@syzkaller.com",441 "default@maintainers.com",442 })443 c.expectEQ(msg.Body, fmt.Sprintf(`Hello,444syzbot found the following crash on:445HEAD commit: 11111111 kernel_commit_title1446git tree: repo1 branch1447console output: %[2]v448kernel config: %[3]v449dashboard link: https://testapp.appspot.com/bug?extid=%[1]v450compiler: compiler1451syz repro: %[4]v452C reproducer: %[5]v453Bisection is inconclusive: the first bad commit could be any of:45411111111 kernel: break build45522222222 kernel: now add a bug to the broken build456bisection log: %[6]v457IMPORTANT: if you fix the bug, please add the following tag to the commit:458Reported-by: syzbot+%[1]v@testapp.appspotmail.com459report1460---461This bug is generated by a bot. It may contain errors.462See https://goo.gl/tpsmEJ for more information about syzbot.463syzbot engineers can be reached at syzkaller@googlegroups.com.464syzbot will keep track of this bug report. See:465https://goo.gl/tpsmEJ#status for how to communicate with syzbot.466For information about bisection process see: https://goo.gl/tpsmEJ#bisection467syzbot can test patches for this bug, for details see:468https://goo.gl/tpsmEJ#testing-patches`,469 extBugID2, crashLogLink, kernelConfigLink, reproSyzLink, reproCLink, bisectLogLink))470 }471}472func TestBisectWrong(t *testing.T) {473 // Test bisection results with BisectResultMerge/BisectResultNoop flags set.474 // If any of these set, the result must not be reported separately,475 // as part of bug report during upstreamming, nor should affect CC list.476 c := NewCtx(t)477 defer c.Close()478 build := testBuild(1)479 c.client2.UploadBuild(build)480 for i := 0; i < 6; i++ {481 var flags dashapi.JobDoneFlags482 switch i {483 case 0:484 case 1:485 flags = dashapi.BisectResultMerge486 case 2:487 flags = dashapi.BisectResultNoop488 case 3:489 flags = dashapi.BisectResultMerge | dashapi.BisectResultNoop490 case 4:491 flags = dashapi.BisectResultRelease492 case 5:493 flags = dashapi.BisectResultIgnore494 default:495 t.Fatalf("assign flags")496 }497 t.Logf("iteration %v: flags=%v", i, flags)498 crash := testCrashWithRepro(build, i)499 c.client2.ReportCrash(crash)500 c.client2.pollEmailBug()501 {502 pollResp := c.client2.pollJobs(build.Manager)503 done := &dashapi.JobDoneReq{504 ID: pollResp.ID,505 Flags: flags,506 Build: *build,507 Log: []byte("bisect log"),508 Commits: []dashapi.Commit{509 {510 Hash: "111111111111111111111111",511 Title: "kernel: break build",512 Author: "hacker@kernel.org",513 AuthorName: "Hacker Kernelov",514 Date: time.Date(2000, 2, 9, 4, 5, 6, 7, time.UTC),515 },516 },517 }518 done.Build.ID = pollResp.ID519 c.expectOK(c.client2.JobDone(done))520 if i == 0 {521 msg := c.pollEmailBug()522 c.expectTrue(strings.Contains(msg.Body, "syzbot has bisected this bug to:"))523 } else {524 c.expectNoEmail()525 }526 }527 {528 c.advanceTime(31 * 24 * time.Hour)529 pollResp := c.client2.pollJobs(build.Manager)530 done := &dashapi.JobDoneReq{531 ID: pollResp.ID,532 Flags: flags,533 Build: *build,534 Log: []byte("bisectfix log 4"),535 CrashTitle: "bisectfix crash title 4",536 CrashLog: []byte("bisectfix crash log 4"),537 CrashReport: []byte("bisectfix crash report 4"),538 Commits: []dashapi.Commit{539 {540 Hash: "46e65cb4a0448942ec316b24d60446bbd5cc7827",541 Title: "kernel: add a fix",542 Author: "fixer@kernel.org",543 AuthorName: "Author Kernelov",544 Date: time.Date(2000, 2, 9, 4, 5, 6, 7, time.UTC),545 },546 },547 }548 done.Build.ID = pollResp.ID549 c.expectOK(c.client2.JobDone(done))550 if i == 0 {551 msg := c.pollEmailBug()552 c.expectTrue(strings.Contains(msg.Body, "syzbot suspects this bug was fixed by commit:"))553 }554 }555 {556 // Auto-upstreamming.557 c.advanceTime(31 * 24 * time.Hour)558 msg := c.pollEmailBug()559 c.expectTrue(strings.Contains(msg.Body, "Sending this report upstream"))560 msg = c.pollEmailBug()561 c.expectTrue(strings.Contains(msg.Body, "syzbot found the following crash on:"))562 if i == 0 {563 c.expectTrue(strings.Contains(msg.Body, "The bug was bisected to:"))564 c.expectEQ(msg.To, []string{565 "bugs@syzkaller.com",566 "default@maintainers.com",567 "hacker@kernel.org",568 })569 } else {570 c.expectTrue(!strings.Contains(msg.Body, "The bug was bisected to:"))571 c.expectEQ(msg.To, []string{572 "bugs@syzkaller.com",573 "default@maintainers.com",574 })575 }576 }577 c.expectNoEmail()578 }579}580func TestBisectCauseAncient(t *testing.T) {581 c := NewCtx(t)582 defer c.Close()583 build := testBuild(1)584 c.client2.UploadBuild(build)585 crash := testCrashWithRepro(build, 1)586 c.client2.ReportCrash(crash)587 msg := c.client2.pollEmailBug()588 pollResp := c.client2.pollJobs(build.Manager)589 jobID := pollResp.ID590 done := &dashapi.JobDoneReq{591 ID: jobID,592 Build: *build,593 Log: []byte("bisect log"),594 CrashTitle: "bisect crash title",595 CrashLog: []byte("bisect crash log"),596 CrashReport: []byte("bisect crash report"),597 }598 done.Build.ID = jobID599 c.expectOK(c.client2.JobDone(done))600 _, extBugID, err := email.RemoveAddrContext(msg.Sender)601 c.expectOK(err)602 _, dbCrash, _ := c.loadBug(extBugID)603 reproSyzLink := externalLink(c.ctx, textReproSyz, dbCrash.ReproSyz)604 reproCLink := externalLink(c.ctx, textReproC, dbCrash.ReproC)605 dbJob, dbBuild, dbJobCrash := c.loadJob(jobID)606 bisectCrashReportLink := externalLink(c.ctx, textCrashReport, dbJob.CrashReport)607 bisectCrashLogLink := externalLink(c.ctx, textCrashLog, dbJob.CrashLog)608 kernelConfigLink := externalLink(c.ctx, textKernelConfig, dbBuild.KernelConfig)609 bisectLogLink := externalLink(c.ctx, textLog, dbJob.Log)610 crashLogLink := externalLink(c.ctx, textCrashLog, dbJobCrash.Log)611 {612 msg := c.pollEmailBug()613 // Not mailed to commit author/cc because !MailMaintainers.614 c.expectEQ(msg.To, []string{"test@syzkaller.com"})615 c.expectEQ(msg.Subject, crash.Title)616 c.expectEQ(len(msg.Attachments), 0)617 c.expectEQ(msg.Body, fmt.Sprintf(`Bisection is inconclusive: the bug happens on the oldest tested release.618bisection log: %[2]v619oldest commit: 11111111 kernel_commit_title1620git tree: repo1 branch1621final crash: %[3]v622console output: %[4]v623kernel config: %[5]v624dashboard link: https://testapp.appspot.com/bug?extid=%[1]v625syz repro: %[6]v626C reproducer: %[7]v627For information about bisection process see: https://goo.gl/tpsmEJ#bisection628`, extBugID, bisectLogLink, bisectCrashReportLink, bisectCrashLogLink,629 kernelConfigLink, reproSyzLink, reproCLink))630 }631 // The next reporting must get bug report with bisection results.632 c.incomingEmail(msg.Sender, "#syz upstream")633 {634 msg := c.pollEmailBug()635 _, extBugID2, err := email.RemoveAddrContext(msg.Sender)636 c.expectOK(err)637 c.expectEQ(msg.To, []string{638 "bugs@syzkaller.com",639 "default@maintainers.com",640 })641 c.expectEQ(msg.Body, fmt.Sprintf(`Hello,642syzbot found the following crash on:643HEAD commit: 11111111 kernel_commit_title1644git tree: repo1 branch1645console output: %[2]v646kernel config: %[3]v647dashboard link: https://testapp.appspot.com/bug?extid=%[1]v648compiler: compiler1649syz repro: %[4]v650C reproducer: %[5]v651Bisection is inconclusive: the bug happens on the oldest tested release.652bisection log: %[6]v653final crash: %[7]v654console output: %[8]v655IMPORTANT: if you fix the bug, please add the following tag to the commit:656Reported-by: syzbot+%[1]v@testapp.appspotmail.com657report1658---659This bug is generated by a bot. It may contain errors.660See https://goo.gl/tpsmEJ for more information about syzbot.661syzbot engineers can be reached at syzkaller@googlegroups.com.662syzbot will keep track of this bug report. See:663https://goo.gl/tpsmEJ#status for how to communicate with syzbot.664For information about bisection process see: https://goo.gl/tpsmEJ#bisection665syzbot can test patches for this bug, for details see:666https://goo.gl/tpsmEJ#testing-patches`,667 extBugID2, crashLogLink, kernelConfigLink, reproSyzLink, reproCLink,668 bisectLogLink, bisectCrashReportLink, bisectCrashLogLink))669 }670}671func TestBisectCauseExternal(t *testing.T) {672 c := NewCtx(t)673 defer c.Close()674 build := testBuild(1)675 c.client.UploadBuild(build)676 crash := testCrashWithRepro(build, 1)677 c.client.ReportCrash(crash)678 rep := c.client.pollBug()679 pollResp := c.client.pollJobs(build.Manager)680 c.expectNE(pollResp.ID, "")681 jobID := pollResp.ID682 done := &dashapi.JobDoneReq{683 ID: jobID,684 Build: *build,685 Log: []byte("bisect log"),686 Commits: []dashapi.Commit{687 {688 Hash: "111111111111111111111111",689 Title: "kernel: break build",690 Author: "hacker@kernel.org",691 AuthorName: "Hacker Kernelov",692 CC: []string{"reviewer1@kernel.org", "reviewer2@kernel.org"},693 Date: time.Date(2000, 2, 9, 4, 5, 6, 7, time.UTC),694 },695 },696 }697 done.Build.ID = jobID698 c.expectOK(c.client.JobDone(done))699 resp, _ := c.client.ReportingPollBugs("test")700 c.expectEQ(len(resp.Reports), 1)701 // Still reported because we did not ack.702 bisect := c.client.pollBug()703 // pollBug acks, must not be reported after that.704 c.client.pollBugs(0)705 c.expectEQ(bisect.Type, dashapi.ReportBisectCause)706 c.expectEQ(bisect.Title, rep.Title)707}708func TestBisectFixExternal(t *testing.T) {709 c := NewCtx(t)710 defer c.Close()711 build := testBuild(1)712 c.client.UploadBuild(build)713 crash := testCrashWithRepro(build, 1)714 c.client.ReportCrash(crash)715 rep := c.client.pollBug()716 {717 // Cause bisection fails.718 pollResp := c.client.pollJobs(build.Manager)719 done := &dashapi.JobDoneReq{720 ID: pollResp.ID,721 Log: []byte("bisect log"),722 Error: []byte("bisect error"),723 }724 c.expectOK(c.client.JobDone(done))725 }726 c.advanceTime(31 * 24 * time.Hour)727 {728 // Fix bisection succeeds.729 pollResp := c.client.pollJobs(build.Manager)730 done := &dashapi.JobDoneReq{731 ID: pollResp.ID,732 Build: *build,733 Log: []byte("bisectfix log"),734 CrashTitle: "bisectfix crash title",735 CrashLog: []byte("bisectfix crash log"),736 CrashReport: []byte("bisectfix crash report"),737 Commits: []dashapi.Commit{738 {739 Hash: "46e65cb4a0448942ec316b24d60446bbd5cc7827",740 Title: "kernel: add a fix",741 Author: "fixer@kernel.org",742 AuthorName: "Author Kernelov",743 Date: time.Date(2000, 2, 9, 4, 5, 6, 7, time.UTC),744 },745 },746 }747 done.Build.ID = pollResp.ID748 c.expectOK(c.client.JobDone(done))749 rep := c.client.pollBug()750 c.expectEQ(rep.Type, dashapi.ReportBisectFix)751 }752 {753 // At this point the bug should be marked as fixed by the commit754 // because the namespace has FixBisectionAutoClose set.755 dbBug, _, _ := c.loadBug(rep.ID)756 c.expectEQ(dbBug.Commits, []string{"kernel: add a fix"})757 }758}759func TestBisectCauseReproSyz(t *testing.T) {760 c := NewCtx(t)761 defer c.Close()762 build := testBuild(1)763 c.client2.UploadBuild(build)764 crash := testCrashWithRepro(build, 1)765 crash.ReproC = nil766 c.client2.ReportCrash(crash)767 pollResp := c.client2.pollJobs(build.Manager)768 jobID := pollResp.ID769 done := &dashapi.JobDoneReq{770 ID: jobID,771 Build: *build,772 Log: []byte("bisect log"),773 CrashTitle: "bisect crash title",774 CrashLog: []byte("bisect crash log"),775 }776 done.Build.ID = jobID777 c.expectOK(c.client2.JobDone(done))778 crash.ReproC = []byte("int main")779 c.client2.ReportCrash(crash)780 msg := c.client2.pollEmailBug()781 if !strings.Contains(msg.Body, "syzbot found the following crash") {782 t.Fatalf("wrong email header:\n%v", msg.Body)783 }784 if !strings.Contains(msg.Body, "Bisection is inconclusive") {785 t.Fatalf("report does not contain bisection results:\n%v", msg.Body)786 }787}788func TestBisectCauseReproSyz2(t *testing.T) {789 c := NewCtx(t)790 defer c.Close()791 build := testBuild(1)792 c.client2.UploadBuild(build)793 crash := testCrashWithRepro(build, 1)794 crash.ReproC = nil795 c.client2.ReportCrash(crash)796 pollResp := c.client2.pollJobs(build.Manager)797 jobID := pollResp.ID798 done := &dashapi.JobDoneReq{799 ID: jobID,800 Build: *build,801 Log: []byte("bisect log"),802 CrashTitle: "bisect crash title",803 CrashLog: []byte("bisect crash log"),804 }805 done.Build.ID = jobID806 c.expectOK(c.client2.JobDone(done))807 msg := c.client2.pollEmailBug()808 if !strings.Contains(msg.Body, "syzbot found the following crash") {809 t.Fatalf("wrong email header:\n%v", msg.Body)810 }811 if !strings.Contains(msg.Body, "Bisection is inconclusive") {812 t.Fatalf("report does not contain bisection results:\n%v", msg.Body)813 }814 crash.ReproC = []byte("int main")815 c.client2.ReportCrash(crash)816 msg = c.client2.pollEmailBug()817 if !strings.Contains(msg.Body, "syzbot has found a reproducer for the following crash") {818 t.Fatalf("wrong email header:\n%v", msg.Body)819 }820 // Do we need bisection results in this email as well?821 // We already mailed them, so we could not mail them here.822 // But if we don't include bisection results, need to check that CC is correct823 // (includes bisection CC).824 if !strings.Contains(msg.Body, "Bisection is inconclusive") {825 t.Fatalf("report still contains bisection results:\n%v", msg.Body)826 }827}828// Test that bisection results show up on UI.829func TestBugBisectionResults(t *testing.T) {830 c := NewCtx(t)831 defer c.Close()832 // Upload a crash report833 build := testBuild(1)834 c.client2.UploadBuild(build)835 crash := testCrashWithRepro(build, 1)836 c.client2.ReportCrash(crash)837 c.client2.pollEmailBug()838 // Receive the JobBisectCause and send cause information839 resp := c.client2.pollJobs(build.Manager)840 c.client2.expectNE(resp.ID, "")841 c.client2.expectEQ(resp.Type, dashapi.JobBisectCause)842 jobID := resp.ID843 done := &dashapi.JobDoneReq{844 ID: jobID,845 Build: *build,846 Log: []byte("bisectfix log 4"),847 CrashTitle: "bisectfix crash title 4",848 CrashLog: []byte("bisectfix crash log 4"),849 CrashReport: []byte("bisectfix crash report 4"),850 Commits: []dashapi.Commit{851 {852 Hash: "36e65cb4a0448942ec316b24d60446bbd5cc7827",853 Title: "kernel: add a bug",854 Author: "author@kernel.org",855 AuthorName: "Author Kernelov",856 CC: []string{857 "reviewer1@kernel.org", "\"Reviewer2\" <reviewer2@kernel.org>",858 // These must be filtered out:859 "syzbot@testapp.appspotmail.com",860 "syzbot+1234@testapp.appspotmail.com",861 "\"syzbot\" <syzbot+1234@testapp.appspotmail.com>",862 },863 Date: time.Date(2000, 2, 9, 4, 5, 6, 7, time.UTC),864 },865 },866 }867 c.expectOK(c.client2.JobDone(done))868 // Advance time by 30 days and read out any notification emails869 {870 c.advanceTime(30 * 24 * time.Hour)871 msg := c.client2.pollEmailBug()872 c.expectTrue(strings.Contains(msg.Body, "syzbot has bisected this bug to:"))873 msg = c.client2.pollEmailBug()874 c.expectTrue(strings.Contains(msg.Body, "Sending this report upstream."))875 msg = c.client2.pollEmailBug()876 c.expectTrue(strings.Contains(msg.Body, "syzbot found the following crash"))877 }878 // Receive a JobBisectfix and send fix information.879 resp = c.client2.pollJobs(build.Manager)880 c.client2.expectNE(resp.ID, "")881 c.client2.expectEQ(resp.Type, dashapi.JobBisectFix)882 jobID = resp.ID883 done = &dashapi.JobDoneReq{884 ID: jobID,885 Build: *build,886 Log: []byte("bisectfix log 4"),887 CrashTitle: "bisectfix crash title 4",888 CrashLog: []byte("bisectfix crash log 4"),889 CrashReport: []byte("bisectfix crash report 4"),890 Commits: []dashapi.Commit{891 {892 Hash: "46e65cb4a0448942ec316b24d60446bbd5cc7827",893 Title: "kernel: add a fix",894 Author: "author@kernel.org",895 AuthorName: "Author Kernelov",896 CC: []string{897 "reviewer1@kernel.org", "\"Reviewer2\" <reviewer2@kernel.org>",898 // These must be filtered out:899 "syzbot@testapp.appspotmail.com",900 "syzbot+1234@testapp.appspotmail.com",901 "\"syzbot\" <syzbot+1234@testapp.appspotmail.com>",902 },903 Date: time.Date(2000, 2, 9, 4, 5, 6, 7, time.UTC),904 },905 },906 }907 c.expectOK(c.client2.JobDone(done))908 msg := c.client2.pollEmailBug()909 c.expectTrue(strings.Contains(msg.Body, "syzbot suspects this bug was fixed by commit:"))910 // Fetch bug details911 var bugs []*Bug912 keys, err := db.NewQuery("Bug").GetAll(c.ctx, &bugs)913 c.expectEQ(err, nil)914 c.expectEQ(len(bugs), 1)915 // Ensure expected results show up on web UI916 url := fmt.Sprintf("/bug?id=%v", keys[0].StringID())917 content, err := c.httpRequest("GET", url, "", AccessAdmin)918 c.expectEQ(err, nil)919 c.expectTrue(bytes.Contains(content, []byte("Cause bisection: introduced by")))920 c.expectTrue(bytes.Contains(content, []byte("kernel: add a bug")))921 c.expectTrue(bytes.Contains(content, []byte("Fix bisection: fixed by")))922 c.expectTrue(bytes.Contains(content, []byte("kernel: add a fix")))923}924// Test that bisection status shows up on main page.925func TestBugBisectionStatus(t *testing.T) {926 c := NewCtx(t)927 defer c.Close()928 // Upload a crash report929 build := testBuild(1)930 c.client2.UploadBuild(build)931 crash := testCrashWithRepro(build, 1)932 c.client2.ReportCrash(crash)933 c.client2.pollEmailBug()934 // Receive the JobBisectCause and send cause information935 resp := c.client2.pollJobs(build.Manager)936 c.client2.expectNE(resp.ID, "")937 c.client2.expectEQ(resp.Type, dashapi.JobBisectCause)938 jobID := resp.ID939 done := &dashapi.JobDoneReq{940 ID: jobID,941 Build: *build,942 Log: []byte("bisectfix log 4"),943 CrashTitle: "bisectfix crash title 4",944 CrashLog: []byte("bisectfix crash log 4"),945 CrashReport: []byte("bisectfix crash report 4"),946 Commits: []dashapi.Commit{947 {948 Hash: "36e65cb4a0448942ec316b24d60446bbd5cc7827",949 Title: "kernel: add a bug",950 Author: "author@kernel.org",951 AuthorName: "Author Kernelov",952 CC: []string{953 "reviewer1@kernel.org", "\"Reviewer2\" <reviewer2@kernel.org>",954 // These must be filtered out:955 "syzbot@testapp.appspotmail.com",956 "syzbot+1234@testapp.appspotmail.com",957 "\"syzbot\" <syzbot+1234@testapp.appspotmail.com>",958 },959 Date: time.Date(2000, 2, 9, 4, 5, 6, 7, time.UTC),960 },961 },962 }963 c.expectOK(c.client2.JobDone(done))964 // Fetch bug, namespace details965 var bugs []*Bug966 _, err := db.NewQuery("Bug").GetAll(c.ctx, &bugs)967 c.expectEQ(err, nil)968 c.expectEQ(len(bugs), 1)969 url := fmt.Sprintf("/%v", bugs[0].Namespace)970 content, err := c.httpRequest("GET", url, "", AccessAdmin)971 c.expectEQ(err, nil)972 c.expectTrue(bytes.Contains(content, []byte("cause")))973 // Advance time by 30 days and read out any notification emails974 {975 c.advanceTime(30 * 24 * time.Hour)976 msg := c.client2.pollEmailBug()977 c.expectTrue(strings.Contains(msg.Body, "syzbot has bisected this bug to:"))978 msg = c.client2.pollEmailBug()979 c.expectTrue(strings.Contains(msg.Body, "Sending this report upstream."))980 msg = c.client2.pollEmailBug()981 c.expectTrue(strings.Contains(msg.Body, "syzbot found the following crash"))982 }983 // Receive a JobBisectfix and send fix information.984 resp = c.client2.pollJobs(build.Manager)985 c.client2.expectNE(resp.ID, "")986 c.client2.expectEQ(resp.Type, dashapi.JobBisectFix)987 jobID = resp.ID988 done = &dashapi.JobDoneReq{989 ID: jobID,990 Build: *build,991 Log: []byte("bisectfix log 4"),992 CrashTitle: "bisectfix crash title 4",993 CrashLog: []byte("bisectfix crash log 4"),994 CrashReport: []byte("bisectfix crash report 4"),995 Commits: []dashapi.Commit{996 {997 Hash: "46e65cb4a0448942ec316b24d60446bbd5cc7827",998 Title: "kernel: add a fix",999 Author: "author@kernel.org",1000 AuthorName: "Author Kernelov",1001 CC: []string{1002 "reviewer1@kernel.org", "\"Reviewer2\" <reviewer2@kernel.org>",1003 // These must be filtered out:1004 "syzbot@testapp.appspotmail.com",1005 "syzbot+1234@testapp.appspotmail.com",1006 "\"syzbot\" <syzbot+1234@testapp.appspotmail.com>",1007 },...

Full Screen

Full Screen

jobs.go

Source:jobs.go Github

copy

Full Screen

...11 "github.com/google/syzkaller/pkg/email"12 "github.com/google/syzkaller/pkg/vcs"13 "golang.org/x/net/context"14 db "google.golang.org/appengine/datastore"15 "google.golang.org/appengine/log"16)17// handleTestRequest added new job to db.18// Returns empty string if job added successfully, or reason why it wasn't added.19func handleTestRequest(c context.Context, bugID, user, extID, link, patch, repo, branch string,20 jobCC []string) string {21 log.Infof(c, "test request: bug=%q user=%q extID=%q patch=%v, repo=%q branch=%q",22 bugID, user, extID, len(patch), repo, branch)23 for _, blocked := range config.EmailBlocklist {24 if user == blocked {25 log.Errorf(c, "test request from blocked user: %v", user)26 return ""27 }28 }29 bug, bugKey, err := findBugByReportingID(c, bugID)30 if err != nil {31 log.Errorf(c, "can't find bug: %v", err)32 if link != "" {33 return "" // don't send duplicate error reply34 }35 myEmail, _ := email.AddAddrContext(ownEmail(c), "hash")36 return fmt.Sprintf("can't find the associated bug (do you have %v in To/CC?)", myEmail)37 }38 bugReporting, _ := bugReportingByID(bug, bugID)39 now := timeNow(c)40 reply, err := addTestJob(c, bug, bugKey, bugReporting, user, extID, link, patch, repo, branch, jobCC, now)41 if err != nil {42 log.Errorf(c, "test request failed: %v", err)43 if reply == "" {44 reply = internalError45 }46 }47 // Update bug CC and last activity time.48 tx := func(c context.Context) error {49 bug := new(Bug)50 if err := db.Get(c, bugKey, bug); err != nil {51 return err52 }53 bug.LastActivity = now54 bugReporting = bugReportingByName(bug, bugReporting.Name)55 bugCC := strings.Split(bugReporting.CC, "|")56 merged := email.MergeEmailLists(bugCC, jobCC)57 bugReporting.CC = strings.Join(merged, "|")58 if _, err := db.Put(c, bugKey, bug); err != nil {59 return fmt.Errorf("failed to put bug: %v", err)60 }61 return nil62 }63 if err := db.RunInTransaction(c, tx, nil); err != nil {64 // We've already stored the job, so just log the error.65 log.Errorf(c, "failed to update bug: %v", err)66 }67 if link != "" {68 reply = "" // don't send duplicate error reply69 }70 return reply71}72func addTestJob(c context.Context, bug *Bug, bugKey *db.Key, bugReporting *BugReporting,73 user, extID, link, patch, repo, branch string, jobCC []string, now time.Time) (string, error) {74 crash, crashKey, err := findCrashForBug(c, bug)75 if err != nil {76 return "", err77 }78 if reason := checkTestJob(c, bug, bugReporting, crash, repo, branch); reason != "" {79 return reason, nil80 }81 manager := crash.Manager82 for _, ns := range config.Namespaces {83 if mgr, ok := ns.Managers[manager]; ok {84 if mgr.RestrictedTestingRepo != "" && repo != mgr.RestrictedTestingRepo {85 return mgr.RestrictedTestingReason, nil86 }87 if mgr.Decommissioned {88 manager = mgr.DelegatedTo89 }90 break91 }92 }93 patchID, err := putText(c, bug.Namespace, textPatch, []byte(patch), false)94 if err != nil {95 return "", err96 }97 job := &Job{98 Type: JobTestPatch,99 Created: now,100 User: user,101 CC: jobCC,102 Reporting: bugReporting.Name,103 ExtID: extID,104 Link: link,105 Namespace: bug.Namespace,106 Manager: manager,107 BugTitle: bug.displayTitle(),108 CrashID: crashKey.IntID(),109 KernelRepo: repo,110 KernelBranch: branch,111 Patch: patchID,112 }113 deletePatch := false114 tx := func(c context.Context) error {115 deletePatch = false116 // We can get 2 emails for the same request: one direct and one from a mailing list.117 // Filter out such duplicates (for dup we only need link update).118 var jobs []*Job119 keys, err := db.NewQuery("Job").120 Ancestor(bugKey).121 Filter("ExtID=", extID).122 GetAll(c, &jobs)123 if len(jobs) > 1 || err != nil {124 return fmt.Errorf("failed to query jobs: jobs=%v err=%v", len(jobs), err)125 }126 if len(jobs) != 0 {127 // The job is already present, update link.128 deletePatch = true129 existingJob, jobKey := jobs[0], keys[0]130 if existingJob.Link != "" || link == "" {131 return nil132 }133 existingJob.Link = link134 if _, err := db.Put(c, jobKey, existingJob); err != nil {135 return fmt.Errorf("failed to put job: %v", err)136 }137 return nil138 }139 // Create a new job.140 jobKey := db.NewIncompleteKey(c, "Job", bugKey)141 if _, err := db.Put(c, jobKey, job); err != nil {142 return fmt.Errorf("failed to put job: %v", err)143 }144 return markCrashReported(c, job.CrashID, bugKey, now)145 }146 err = db.RunInTransaction(c, tx, &db.TransactionOptions{XG: true, Attempts: 30})147 if patchID != 0 && deletePatch || err != nil {148 if err := db.Delete(c, db.NewKey(c, textPatch, "", patchID, nil)); err != nil {149 log.Errorf(c, "failed to delete patch for dup job: %v", err)150 }151 }152 if err != nil {153 return "", fmt.Errorf("job tx failed: %v", err)154 }155 return "", nil156}157func checkTestJob(c context.Context, bug *Bug, bugReporting *BugReporting, crash *Crash,158 repo, branch string) string {159 switch {160 case crash.ReproC == 0 && crash.ReproSyz == 0:161 return "This crash does not have a reproducer. I cannot test it."162 case !vcs.CheckRepoAddress(repo):163 return fmt.Sprintf("%q does not look like a valid git repo address.", repo)164 case !vcs.CheckBranch(branch) && !vcs.CheckCommitHash(branch):165 return fmt.Sprintf("%q does not look like a valid git branch or commit.", branch)166 case bug.Status == BugStatusFixed:167 return "This bug is already marked as fixed. No point in testing."168 case bug.Status == BugStatusInvalid:169 return "This bug is already marked as invalid. No point in testing."170 // TODO(dvyukov): for BugStatusDup check status of the canonical bug.171 case !bugReporting.Closed.IsZero():172 return "This bug is already upstreamed. Please test upstream."173 }174 return ""175}176// pollPendingJobs returns the next job to execute for the provided list of managers.177func pollPendingJobs(c context.Context, managers map[string]dashapi.ManagerJobs) (178 *dashapi.JobPollResp, error) {179retry:180 job, jobKey, err := getNextJob(c, managers)181 if job == nil || err != nil {182 return nil, err183 }184 resp, stale, err := createJobResp(c, job, jobKey)185 if err != nil {186 return nil, err187 }188 if stale {189 goto retry190 }191 return resp, nil192}193func getNextJob(c context.Context, managers map[string]dashapi.ManagerJobs) (*Job, *db.Key, error) {194 job, jobKey, err := loadPendingJob(c, managers)195 if job != nil || err != nil {196 return job, jobKey, err197 }198 // We need both C and syz repros, but the crazy datastore query restrictions199 // do not allow to use ReproLevel>ReproLevelNone in the query. So we do 2 separate queries.200 // C repros tend to be of higher reliability so maybe it's not bad.201 job, jobKey, err = createBisectJob(c, managers, ReproLevelC)202 if job != nil || err != nil {203 return job, jobKey, err204 }205 return createBisectJob(c, managers, ReproLevelSyz)206}207func createBisectJob(c context.Context, managers map[string]dashapi.ManagerJobs,208 reproLevel dashapi.ReproLevel) (*Job, *db.Key, error) {209 causeManagers := make(map[string]bool)210 fixManagers := make(map[string]bool)211 for mgr, jobs := range managers {212 if jobs.BisectCause {213 causeManagers[mgr] = true214 }215 if jobs.BisectFix {216 fixManagers[mgr] = true217 }218 }219 job, jobKey, err := findBugsForBisection(c, causeManagers, reproLevel, JobBisectCause)220 if job != nil || err != nil {221 return job, jobKey, err222 }223 return findBugsForBisection(c, fixManagers, reproLevel, JobBisectFix)224}225func findBugsForBisection(c context.Context, managers map[string]bool,226 reproLevel dashapi.ReproLevel, jobType JobType) (*Job, *db.Key, error) {227 if len(managers) == 0 {228 return nil, nil, nil229 }230 // Note: we could also include len(Commits)==0 but datastore does not work this way.231 // So we would need an additional HasCommits field or something.232 // Note: For JobBisectCause, order the bugs from newest to oldest. For JobBisectFix,233 // order the bugs from oldest to newest.234 // Sort property should be the same as property used in the inequality filter.235 // We only need 1 job, but we skip some because the query is not precise.236 bugs, keys, err := loadAllBugs(c, func(query *db.Query) *db.Query {237 query = query.Filter("Status=", BugStatusOpen)238 if jobType == JobBisectCause {239 query = query.Filter("FirstTime>", time.Time{}).240 Filter("ReproLevel=", reproLevel).241 Filter("BisectCause=", BisectNot).242 Order("-FirstTime")243 } else {244 query = query.Filter("LastTime>", time.Time{}).245 Filter("ReproLevel=", reproLevel).246 Filter("BisectFix=", BisectNot).247 Order("LastTime")248 }249 return query250 })251 if err != nil {252 return nil, nil, fmt.Errorf("failed to query bugs: %v", err)253 }254 for bi, bug := range bugs {255 if !shouldBisectBug(bug, managers) {256 continue257 }258 crash, crashKey, err := bisectCrashForBug(c, bug, keys[bi], managers, jobType)259 if err != nil {260 return nil, nil, err261 }262 if crash == nil {263 continue264 }265 if jobType == JobBisectFix && timeSince(c, bug.LastTime) < 24*30*time.Hour {266 continue267 }268 return createBisectJobForBug(c, bug, crash, keys[bi], crashKey, jobType)269 }270 return nil, nil, nil271}272func shouldBisectBug(bug *Bug, managers map[string]bool) bool {273 if len(bug.Commits) != 0 {274 return false275 }276 for _, mgr := range bug.HappenedOn {277 if managers[mgr] {278 return true279 }280 }281 return false282}283func bisectCrashForBug(c context.Context, bug *Bug, bugKey *db.Key, managers map[string]bool, jobType JobType) (284 *Crash, *db.Key, error) {285 crashes, crashKeys, err := queryCrashesForBug(c, bugKey, maxCrashes)286 if err != nil {287 return nil, nil, err288 }289 for ci, crash := range crashes {290 if crash.ReproSyz == 0 || !managers[crash.Manager] {291 continue292 }293 if jobType == JobBisectFix &&294 config.Namespaces[bug.Namespace].Managers[crash.Manager].FixBisectionDisabled {295 continue296 }297 return crash, crashKeys[ci], nil298 }299 return nil, nil, nil300}301func createBisectJobForBug(c context.Context, bug0 *Bug, crash *Crash, bugKey, crashKey *db.Key, jobType JobType) (302 *Job, *db.Key, error) {303 build, err := loadBuild(c, bug0.Namespace, crash.BuildID)304 if err != nil {305 return nil, nil, err306 }307 now := timeNow(c)308 job := &Job{309 Type: jobType,310 Created: now,311 Namespace: bug0.Namespace,312 Manager: crash.Manager,313 KernelRepo: build.KernelRepo,314 KernelBranch: build.KernelBranch,315 BugTitle: bug0.displayTitle(),316 CrashID: crashKey.IntID(),317 }318 var jobKey *db.Key319 tx := func(c context.Context) error {320 jobKey = nil321 bug := new(Bug)322 if err := db.Get(c, bugKey, bug); err != nil {323 return fmt.Errorf("failed to get bug %v: %v", bugKey.StringID(), err)324 }325 if jobType == JobBisectFix && bug.BisectFix != BisectNot ||326 jobType == JobBisectCause && bug.BisectCause != BisectNot {327 // Race, we could do a more complex retry, but we just rely on the next poll.328 job = nil329 return nil330 }331 if jobType == JobBisectCause {332 bug.BisectCause = BisectPending333 } else {334 bug.BisectFix = BisectPending335 }336 // Create a new job.337 var err error338 jobKey = db.NewIncompleteKey(c, "Job", bugKey)339 if jobKey, err = db.Put(c, jobKey, job); err != nil {340 return fmt.Errorf("failed to put job: %v", err)341 }342 if _, err := db.Put(c, bugKey, bug); err != nil {343 return fmt.Errorf("failed to put bug: %v", err)344 }345 return markCrashReported(c, job.CrashID, bugKey, now)346 }347 if err := db.RunInTransaction(c, tx, nil); err != nil {348 return nil, nil, fmt.Errorf("create bisect job tx failed: %v", err)349 }350 return job, jobKey, nil351}352func createJobResp(c context.Context, job *Job, jobKey *db.Key) (*dashapi.JobPollResp, bool, error) {353 jobID := extJobID(jobKey)354 patch, _, err := getText(c, textPatch, job.Patch)355 if err != nil {356 return nil, false, err357 }358 bugKey := jobKey.Parent()359 crashKey := db.NewKey(c, "Crash", "", job.CrashID, bugKey)360 crash := new(Crash)361 if err := db.Get(c, crashKey, crash); err != nil {362 return nil, false, fmt.Errorf("job %v: failed to get crash: %v", jobID, err)363 }364 build, err := loadBuild(c, job.Namespace, crash.BuildID)365 if err != nil {366 return nil, false, err367 }368 kernelConfig, _, err := getText(c, textKernelConfig, build.KernelConfig)369 if err != nil {370 return nil, false, err371 }372 reproC, _, err := getText(c, textReproC, crash.ReproC)373 if err != nil {374 return nil, false, err375 }376 reproSyz, _, err := getText(c, textReproSyz, crash.ReproSyz)377 if err != nil {378 return nil, false, err379 }380 now := timeNow(c)381 stale := false382 tx := func(c context.Context) error {383 stale = false384 job = new(Job)385 if err := db.Get(c, jobKey, job); err != nil {386 return fmt.Errorf("job %v: failed to get in tx: %v", jobID, err)387 }388 if !job.Finished.IsZero() {389 // This happens sometimes due to inconsistent db.390 stale = true391 return nil392 }393 job.Attempts++394 job.Started = now395 if _, err := db.Put(c, jobKey, job); err != nil {396 return fmt.Errorf("job %v: failed to put: %v", jobID, err)397 }398 return nil399 }400 if err := db.RunInTransaction(c, tx, nil); err != nil {401 return nil, false, err402 }403 if stale {404 return nil, true, nil405 }406 resp := &dashapi.JobPollResp{407 ID: jobID,408 Manager: job.Manager,409 KernelRepo: job.KernelRepo,410 KernelBranch: job.KernelBranch,411 KernelCommit: build.KernelCommit,412 KernelCommitTitle: build.KernelCommitTitle,413 KernelCommitDate: build.KernelCommitDate,414 KernelConfig: kernelConfig,415 SyzkallerCommit: build.SyzkallerCommit,416 Patch: patch,417 ReproOpts: crash.ReproOpts,418 ReproSyz: reproSyz,419 ReproC: reproC,420 }421 switch job.Type {422 case JobTestPatch:423 resp.Type = dashapi.JobTestPatch424 case JobBisectCause:425 resp.Type = dashapi.JobBisectCause426 case JobBisectFix:427 resp.Type = dashapi.JobBisectFix428 default:429 return nil, false, fmt.Errorf("bad job type %v", job.Type)430 }431 return resp, false, nil432}433// doneJob is called by syz-ci to mark completion of a job.434func doneJob(c context.Context, req *dashapi.JobDoneReq) error {435 jobID := req.ID436 jobKey, err := jobID2Key(c, req.ID)437 if err != nil {438 return err439 }440 now := timeNow(c)441 tx := func(c context.Context) error {442 job := new(Job)443 if err := db.Get(c, jobKey, job); err != nil {444 return fmt.Errorf("job %v: failed to get job: %v", jobID, err)445 }446 if !job.Finished.IsZero() {447 return fmt.Errorf("job %v: already finished", jobID)448 }449 ns := job.Namespace450 if req.Build.ID != "" {451 if _, isNewBuild, err := uploadBuild(c, now, ns, &req.Build, BuildJob); err != nil {452 return err453 } else if !isNewBuild {454 log.Errorf(c, "job %v: duplicate build %v", jobID, req.Build.ID)455 }456 }457 if job.Log, err = putText(c, ns, textLog, req.Log, false); err != nil {458 return err459 }460 if job.Error, err = putText(c, ns, textError, req.Error, false); err != nil {461 return err462 }463 if job.CrashLog, err = putText(c, ns, textCrashLog, req.CrashLog, false); err != nil {464 return err465 }466 if job.CrashReport, err = putText(c, ns, textCrashReport, req.CrashReport, false); err != nil {467 return err468 }469 for _, com := range req.Commits {470 job.Commits = append(job.Commits, Commit{471 Hash: com.Hash,472 Title: com.Title,473 Author: com.Author,474 AuthorName: com.AuthorName,475 CC: strings.Join(sanitizeCC(c, com.CC), "|"),476 Date: com.Date,477 })478 }479 job.BuildID = req.Build.ID480 job.CrashTitle = req.CrashTitle481 job.Finished = now482 job.Flags = JobFlags(req.Flags)483 if job.Type == JobBisectCause || job.Type == JobBisectFix {484 // Update bug.BisectCause/Fix status and also remember current bug reporting to send results.485 if err := updateBugBisection(c, job, jobKey, req, now); err != nil {486 return err487 }488 }489 if _, err := db.Put(c, jobKey, job); err != nil {490 return fmt.Errorf("failed to put job: %v", err)491 }492 log.Infof(c, "DONE JOB %v: reported=%v reporting=%v", jobID, job.Reported, job.Reporting)493 return nil494 }495 return db.RunInTransaction(c, tx, &db.TransactionOptions{XG: true, Attempts: 30})496}497func updateBugBisection(c context.Context, job *Job, jobKey *db.Key, req *dashapi.JobDoneReq, now time.Time) error {498 bug := new(Bug)499 bugKey := jobKey.Parent()500 if err := db.Get(c, bugKey, bug); err != nil {501 return fmt.Errorf("job %v: failed to get bug: %v", req.ID, err)502 }503 result := BisectYes504 if len(req.Error) != 0 {505 result = BisectError506 }507 if job.Type == JobBisectCause {508 bug.BisectCause = result509 } else {510 bug.BisectFix = result511 }512 // If the crash still occurs on HEAD, update the bug's LastTime so that it will be513 // retried after 30 days.514 if job.Type == JobBisectFix && req.Error == nil && len(req.Commits) == 0 && len(req.CrashLog) != 0 {515 bug.BisectFix = BisectNot516 bug.LastTime = now517 }518 if _, err := db.Put(c, bugKey, bug); err != nil {519 return fmt.Errorf("failed to put bug: %v", err)520 }521 _, bugReporting, _, _, _ := currentReporting(c, bug)522 // The bug is either already closed or not yet reported in the current reporting,523 // either way we don't need to report it. If it wasn't reported, it will be reported524 // with the bisection results.525 if bugReporting == nil || bugReporting.Reported.IsZero() ||526 // Don't report errors for non-user-initiated jobs.527 job.Error != 0 ||528 // Don't report unreliable/wrong bisections.529 job.isUnreliableBisect() {530 job.Reported = true531 } else {532 job.Reporting = bugReporting.Name533 }534 return nil535}536// TODO: this is temporal for gradual bisection rollout.537// Notify only about successful cause bisection for now.538// For now we only enable this in tests.539var notifyAboutUnsuccessfulBisections = false540func pollCompletedJobs(c context.Context, typ string) ([]*dashapi.BugReport, error) {541 var jobs []*Job542 keys, err := db.NewQuery("Job").543 Filter("Finished>", time.Time{}).544 Filter("Reported=", false).545 GetAll(c, &jobs)546 if err != nil {547 return nil, fmt.Errorf("failed to query jobs: %v", err)548 }549 var reports []*dashapi.BugReport550 for i, job := range jobs {551 if job.Reporting == "" {552 log.Criticalf(c, "no reporting for job %v", extJobID(keys[i]))553 continue554 }555 reporting := config.Namespaces[job.Namespace].ReportingByName(job.Reporting)556 if reporting.Config.Type() != typ {557 continue558 }559 if job.Type == JobBisectCause && !notifyAboutUnsuccessfulBisections && len(job.Commits) != 1 {560 continue561 }562 // If BisectFix results in a crash on HEAD, no notification is sent out.563 if job.Type == JobBisectFix && len(job.Commits) != 1 {564 continue565 }566 // If the bug is already known to be fixed, invalid or duplicate, do not report the bisection results.567 if job.Type == JobBisectCause || job.Type == JobBisectFix {568 bug := new(Bug)569 bugKey := keys[i].Parent()570 if err := db.Get(c, bugKey, bug); err != nil {571 return nil, fmt.Errorf("job %v: failed to get bug: %v", extJobID(keys[i]), err)572 }573 if len(bug.Commits) != 0 || bug.Status != BugStatusOpen {574 jobReported(c, extJobID(keys[i]))575 continue576 }577 }578 rep, err := createBugReportForJob(c, job, keys[i], reporting.Config)579 if err != nil {580 log.Errorf(c, "failed to create report for job: %v", err)581 continue582 }583 reports = append(reports, rep)584 }585 return reports, nil586}587func createBugReportForJob(c context.Context, job *Job, jobKey *db.Key, config interface{}) (588 *dashapi.BugReport, error) {589 reportingConfig, err := json.Marshal(config)590 if err != nil {591 return nil, err592 }593 crashLog, _, err := getText(c, textCrashLog, job.CrashLog)594 if err != nil {595 return nil, err596 }597 if len(crashLog) > maxMailLogLen {598 crashLog = crashLog[len(crashLog)-maxMailLogLen:]599 }600 report, _, err := getText(c, textCrashReport, job.CrashReport)601 if err != nil {602 return nil, err603 }604 if len(report) > maxMailReportLen {605 report = report[:maxMailReportLen]606 }607 jobError, _, err := getText(c, textError, job.Error)608 if err != nil {609 return nil, err610 }611 build, err := loadBuild(c, job.Namespace, job.BuildID)612 if err != nil {613 return nil, err614 }615 bugKey := jobKey.Parent()616 crashKey := db.NewKey(c, "Crash", "", job.CrashID, bugKey)617 crash := new(Crash)618 if err := db.Get(c, crashKey, crash); err != nil {619 return nil, fmt.Errorf("failed to get crash: %v", err)620 }621 bug := new(Bug)622 if err := db.Get(c, bugKey, bug); err != nil {623 return nil, fmt.Errorf("failed to load job parent bug: %v", err)624 }625 bugReporting := bugReportingByName(bug, job.Reporting)626 if bugReporting == nil {627 return nil, fmt.Errorf("job bug has no reporting %q", job.Reporting)628 }629 var typ dashapi.ReportType630 switch job.Type {631 case JobTestPatch:632 typ = dashapi.ReportTestPatch633 case JobBisectCause:634 typ = dashapi.ReportBisectCause635 case JobBisectFix:636 typ = dashapi.ReportBisectFix637 default:638 return nil, fmt.Errorf("unknown job type %v", job.Type)639 }640 kernelRepo := kernelRepoInfo(build)641 rep := &dashapi.BugReport{642 Type: typ,643 Config: reportingConfig,644 JobID: extJobID(jobKey),645 ExtID: job.ExtID,646 CC: append(job.CC, kernelRepo.CC...),647 Log: crashLog,648 LogLink: externalLink(c, textCrashLog, job.CrashLog),649 Report: report,650 ReportLink: externalLink(c, textCrashReport, job.CrashReport),651 ReproCLink: externalLink(c, textReproC, crash.ReproC),652 ReproSyzLink: externalLink(c, textReproSyz, crash.ReproSyz),653 CrashTitle: job.CrashTitle,654 Error: jobError,655 ErrorLink: externalLink(c, textError, job.Error),656 PatchLink: externalLink(c, textPatch, job.Patch),657 }658 if job.Type == JobBisectCause || job.Type == JobBisectFix {659 rep.Maintainers = append(crash.Maintainers, kernelRepo.Maintainers...)660 rep.ExtID = bugReporting.ExtID661 if bugReporting.CC != "" {662 rep.CC = strings.Split(bugReporting.CC, "|")663 }664 switch job.Type {665 case JobBisectCause:666 rep.BisectCause = bisectFromJob(c, rep, job)667 case JobBisectFix:668 rep.BisectFix = bisectFromJob(c, rep, job)669 }670 }671 // Build error output and failing VM boot log can be way too long to inline.672 if len(rep.Error) > maxInlineError {673 rep.Error = rep.Error[len(rep.Error)-maxInlineError:]674 rep.ErrorTruncated = true675 }676 if err := fillBugReport(c, rep, bug, bugReporting, build); err != nil {677 return nil, err678 }679 return rep, nil680}681func bisectFromJob(c context.Context, rep *dashapi.BugReport, job *Job) *dashapi.BisectResult {682 bisect := &dashapi.BisectResult{683 LogLink: externalLink(c, textLog, job.Log),684 CrashLogLink: externalLink(c, textCrashLog, job.CrashLog),685 CrashReportLink: externalLink(c, textCrashReport, job.CrashReport),...

Full Screen

Full Screen

log

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println(bisect.Log(8))4}5import (6func main() {7 fmt.Println(bisect.Log(8))8}9import (10func main() {11 fmt.Println(bisect.Log(8))12}13import (14func main() {15 fmt.Println(bisect.Log(8))16}17import (18func main() {19 fmt.Println(bisect.Log(8))20}21import (22func main() {23 fmt.Println(bisect.Log(8))24}25import (26func main() {27 fmt.Println(bisect.Log(8))28}29import (30func main() {31 fmt.Println(bisect.Log(8))32}33import (34func main() {35 fmt.Println(bisect.Log(8))36}37import (38func main() {39 fmt.Println(bisect.Log(8))40}41import (42func main()

Full Screen

Full Screen

log

Using AI Code Generation

copy

Full Screen

1import "fmt"2import "bisect"3func main() {4 bisect.log("Hello, world.")5}6import "fmt"7func log(msg string) {8 fmt.Printf(msg)9}10I am new to go and I am trying to learn how to use go. I am trying to create a package and use it in another file. I am trying to create a package bisect and use it in another file 2.go. I am getting the error "cannot find package "bisect" in any of: /usr/local/go/src/bisect (from $GOROOT) /home/username/go/src/bisect (from $GOPATH)". I am not sure what I am doing wrong. I have tried changing the path to the package but that does not seem to work. I have also tried adding the path to the package to the GOPATH but that does not seem to work either. Here is my code:

Full Screen

Full Screen

log

Using AI Code Generation

copy

Full Screen

1import (2type Bisect struct {3}4func (b Bisect) Log(x float64, y float64) float64 {5 return math.Log(x) / math.Log(y)6}7func main() {8 b := Bisect{}9 fmt.Println("Enter the number to be checked")10 fmt.Scanf("%f", &number)11 fmt.Println("Enter the base")12 fmt.Scanf("%f", &base)13 fmt.Println("The result is " + strconv.FormatFloat(b.Log(number, base), 'f', 6, 64))14}

Full Screen

Full Screen

log

Using AI Code Generation

copy

Full Screen

1import "fmt"2func main() {3 fmt.Println("Hello, World!")4 bisect := new(Bisect)5 bisect.log(1)6}7import "fmt"8func main() {9 fmt.Println("Hello, World!")10 bisect := new(Bisect)11 bisect.log(1)12 bisect.log(2)13}14import "fmt"15func main() {16 fmt.Println("Hello, World!")17 bisect := new(Bisect)18 bisect.log(1)19 bisect.log(2)20 bisect.log(3)21}22import "fmt"23func main() {24 fmt.Println("Hello, World!")25 bisect := new(Bisect)26 bisect.log(1)27 bisect.log(2)28 bisect.log(3)29 bisect.log(4)30}31import "fmt"32func main() {33 fmt.Println("Hello, World!")34 bisect := new(Bisect)35 bisect.log(1)36 bisect.log(2)37 bisect.log(3)38 bisect.log(4)39 bisect.log(5)40}41import "fmt"42func main() {43 fmt.Println("Hello, World!")44 bisect := new(Bisect)45 bisect.log(1)46 bisect.log(2)47 bisect.log(3)48 bisect.log(4)49 bisect.log(5)50 bisect.log(6)51}52import "fmt"53func main() {54 fmt.Println("Hello, World!")55 bisect := new(Bisect)56 bisect.log(1)57 bisect.log(2)58 bisect.log(3)59 bisect.log(4)60 bisect.log(5)61 bisect.log(6

Full Screen

Full Screen

log

Using AI Code Generation

copy

Full Screen

1import "fmt"2import "bisect"3func main() {4 fmt.Println("Hello, playground")5 bisect.log(10)6}7import "fmt"8func log(x int) {9 fmt.Println(x)10}11Your name to display (optional):12Your name to display (optional):13Your name to display (optional):14Your name to display (optional):15Your name to display (optional):16Your name to display (optional):17import "fmt"18func log(x int) {19 fmt.Println(x)20}21Your name to display (optional):22Your name to display (optional):23import "fmt"24func log(x int) {25 fmt.Println(x)26}27Your name to display (optional):28Your name to display (optional):

Full Screen

Full Screen

log

Using AI Code Generation

copy

Full Screen

1import "bisect"2func main(){3 bisect.Log("Hello World")4}5func Log(message string){6 fmt.Println(message)7}

Full Screen

Full Screen

log

Using AI Code Generation

copy

Full Screen

1import ( 2func main() { 3 log.Println("Hello World") 4}5Related Posts: How to use log.Fatal() in Go?6How to use log.Panic() in Go?7How to use log.Printf() in Go?8How to use log.Panicf() in Go?9How to use log.Fatalln() in Go?10How to use log.Panicln() in Go?11How to use log.Output() in Go?12How to use log.Flags() in Go?13How to use log.SetFlags() in Go?14How to use log.Prefix() in Go?15How to use log.SetPrefix() in Go?16How to use log.Writer()

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful