How to use reportCrash method of main Package

Best Syzkaller code snippet using main.reportCrash

reporting_test.go

Source:reporting_test.go Github

copy

Full Screen

1// Copyright 2017 syzkaller project authors. All rights reserved.2// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.3package main4import (5 "fmt"6 "html"7 "regexp"8 "testing"9 "time"10 "github.com/google/syzkaller/dashboard/dashapi"11 "github.com/google/syzkaller/sys/targets"12)13func TestReportBug(t *testing.T) {14 c := NewCtx(t)15 defer c.Close()16 build := testBuild(1)17 c.client.UploadBuild(build)18 crash1 := &dashapi.Crash{19 BuildID: "build1",20 Title: "title1",21 Maintainers: []string{`"Foo Bar" <foo@bar.com>`, `bar@foo.com`},22 Log: []byte("log1"),23 Report: []byte("report1"),24 MachineInfo: []byte("machine info 1"),25 }26 c.client.ReportCrash(crash1)27 // Must get no reports for "unknown" type.28 resp, _ := c.client.ReportingPollBugs("unknown")29 c.expectEQ(len(resp.Reports), 0)30 // Must get a proper report for "test" type.31 resp, _ = c.client.ReportingPollBugs("test")32 c.expectEQ(len(resp.Reports), 1)33 rep := resp.Reports[0]34 c.expectNE(rep.ID, "")35 _, dbCrash, dbBuild := c.loadBug(rep.ID)36 want := &dashapi.BugReport{37 Type: dashapi.ReportNew,38 BugStatus: dashapi.BugStatusOpen,39 Namespace: "test1",40 Config: []byte(`{"Index":1}`),41 ID: rep.ID,42 OS: targets.Linux,43 Arch: targets.AMD64,44 VMArch: targets.AMD64,45 First: true,46 Moderation: true,47 Title: "title1",48 Link: fmt.Sprintf("https://testapp.appspot.com/bug?extid=%v", rep.ID),49 CreditEmail: fmt.Sprintf("syzbot+%v@testapp.appspotmail.com", rep.ID),50 Maintainers: []string{"bar@foo.com", "foo@bar.com"},51 CompilerID: "compiler1",52 BuildID: "build1",53 BuildTime: timeNow(c.ctx),54 KernelRepo: "repo1",55 KernelRepoAlias: "repo1 branch1",56 KernelBranch: "branch1",57 KernelCommit: "1111111111111111111111111111111111111111",58 KernelCommitTitle: build.KernelCommitTitle,59 KernelCommitDate: buildCommitDate,60 KernelConfig: []byte("config1"),61 KernelConfigLink: externalLink(c.ctx, textKernelConfig, dbBuild.KernelConfig),62 SyzkallerCommit: "syzkaller_commit1",63 MachineInfo: []byte("machine info 1"),64 MachineInfoLink: externalLink(c.ctx, textMachineInfo, dbCrash.MachineInfo),65 Log: []byte("log1"),66 LogLink: externalLink(c.ctx, textCrashLog, dbCrash.Log),67 Report: []byte("report1"),68 ReportLink: externalLink(c.ctx, textCrashReport, dbCrash.Report),69 ReproOpts: []uint8{},70 CrashID: rep.CrashID,71 CrashTime: timeNow(c.ctx),72 NumCrashes: 1,73 HappenedOn: []string{"repo1 branch1"},74 }75 c.expectEQ(want, rep)76 // Since we did not update bug status yet, should get the same report again.77 c.expectEQ(c.client.pollBug(), want)78 // Now add syz repro and check that we get another bug report.79 crash1.ReproOpts = []byte("some opts")80 crash1.ReproSyz = []byte("getpid()")81 want.Type = dashapi.ReportRepro82 want.First = false83 want.ReproSyz = []byte(syzReproPrefix + "#some opts\ngetpid()")84 want.ReproOpts = []byte("some opts")85 c.client.ReportCrash(crash1)86 rep1 := c.client.pollBug()87 c.expectNE(want.CrashID, rep1.CrashID)88 _, dbCrash, _ = c.loadBug(rep.ID)89 want.CrashID = rep1.CrashID90 want.NumCrashes = 291 want.ReproSyzLink = externalLink(c.ctx, textReproSyz, dbCrash.ReproSyz)92 want.LogLink = externalLink(c.ctx, textCrashLog, dbCrash.Log)93 want.ReportLink = externalLink(c.ctx, textCrashReport, dbCrash.Report)94 c.expectEQ(want, rep1)95 reply, _ := c.client.ReportingUpdate(&dashapi.BugUpdate{96 ID: rep.ID,97 Status: dashapi.BugStatusOpen,98 ReproLevel: dashapi.ReproLevelSyz,99 })100 c.expectEQ(reply.OK, true)101 // After bug update should not get the report again.102 c.client.pollBugs(0)103 // Now close the bug in the first reporting.104 c.client.updateBug(rep.ID, dashapi.BugStatusUpstream, "")105 // Check that bug updates for the first reporting fail now.106 reply, _ = c.client.ReportingUpdate(&dashapi.BugUpdate{ID: rep.ID, Status: dashapi.BugStatusOpen})107 c.expectEQ(reply.OK, false)108 // Report another crash with syz repro for this bug,109 // ensure that we report the new crash in the next reporting.110 crash1.Report = []byte("report2")111 c.client.ReportCrash(crash1)112 // Check that we get the report in the second reporting.113 rep2 := c.client.pollBug()114 c.expectNE(rep2.ID, "")115 c.expectNE(rep2.ID, rep.ID)116 want.Type = dashapi.ReportNew117 want.ID = rep2.ID118 want.Report = []byte("report2")119 want.LogLink = rep2.LogLink120 want.ReportLink = rep2.ReportLink121 want.CrashID = rep2.CrashID122 want.ReproSyzLink = rep2.ReproSyzLink123 want.ReproOpts = []byte("some opts")124 want.Link = fmt.Sprintf("https://testapp.appspot.com/bug?extid=%v", rep2.ID)125 want.CreditEmail = fmt.Sprintf("syzbot+%v@testapp.appspotmail.com", rep2.ID)126 want.First = true127 want.Moderation = false128 want.Config = []byte(`{"Index":2}`)129 want.NumCrashes = 3130 c.expectEQ(want, rep2)131 // Check that that we can't upstream the bug in the final reporting.132 reply, _ = c.client.ReportingUpdate(&dashapi.BugUpdate{133 ID: rep2.ID,134 Status: dashapi.BugStatusUpstream,135 })136 c.expectEQ(reply.OK, false)137}138func TestInvalidBug(t *testing.T) {139 c := NewCtx(t)140 defer c.Close()141 build := testBuild(1)142 c.client.UploadBuild(build)143 crash1 := testCrashWithRepro(build, 1)144 c.client.ReportCrash(crash1)145 rep := c.client.pollBug()146 c.expectEQ(rep.Title, "title1")147 reply, _ := c.client.ReportingUpdate(&dashapi.BugUpdate{148 ID: rep.ID,149 Status: dashapi.BugStatusOpen,150 ReproLevel: dashapi.ReproLevelC,151 })152 c.expectEQ(reply.OK, true)153 {154 closed, _ := c.client.ReportingPollClosed([]string{rep.ID, "foobar"})155 c.expectEQ(len(closed), 0)156 }157 // Mark the bug as invalid.158 c.client.updateBug(rep.ID, dashapi.BugStatusInvalid, "")159 {160 closed, _ := c.client.ReportingPollClosed([]string{rep.ID, "foobar"})161 c.expectEQ(len(closed), 1)162 c.expectEQ(closed[0], rep.ID)163 }164 // Now it should not be reported in either reporting.165 c.client.pollBugs(0)166 // Now a similar crash happens again.167 crash2 := &dashapi.Crash{168 BuildID: "build1",169 Title: "title1",170 Log: []byte("log2"),171 Report: []byte("report2"),172 ReproC: []byte("int main() { return 1; }"),173 }174 c.client.ReportCrash(crash2)175 // Now it should be reported again.176 rep = c.client.pollBug()177 c.expectNE(rep.ID, "")178 _, dbCrash, dbBuild := c.loadBug(rep.ID)179 want := &dashapi.BugReport{180 Type: dashapi.ReportNew,181 BugStatus: dashapi.BugStatusOpen,182 Namespace: "test1",183 Config: []byte(`{"Index":1}`),184 ID: rep.ID,185 OS: targets.Linux,186 Arch: targets.AMD64,187 VMArch: targets.AMD64,188 First: true,189 Moderation: true,190 Title: "title1 (2)",191 Link: fmt.Sprintf("https://testapp.appspot.com/bug?extid=%v", rep.ID),192 CreditEmail: fmt.Sprintf("syzbot+%v@testapp.appspotmail.com", rep.ID),193 BuildID: "build1",194 BuildTime: timeNow(c.ctx),195 CompilerID: "compiler1",196 KernelRepo: "repo1",197 KernelRepoAlias: "repo1 branch1",198 KernelBranch: "branch1",199 KernelCommit: "1111111111111111111111111111111111111111",200 KernelCommitTitle: build.KernelCommitTitle,201 KernelCommitDate: buildCommitDate,202 KernelConfig: []byte("config1"),203 KernelConfigLink: externalLink(c.ctx, textKernelConfig, dbBuild.KernelConfig),204 SyzkallerCommit: "syzkaller_commit1",205 Log: []byte("log2"),206 LogLink: externalLink(c.ctx, textCrashLog, dbCrash.Log),207 Report: []byte("report2"),208 ReportLink: externalLink(c.ctx, textCrashReport, dbCrash.Report),209 ReproC: []byte("int main() { return 1; }"),210 ReproCLink: externalLink(c.ctx, textReproC, dbCrash.ReproC),211 ReproOpts: []uint8{},212 CrashID: rep.CrashID,213 CrashTime: timeNow(c.ctx),214 NumCrashes: 1,215 HappenedOn: []string{"repo1 branch1"},216 }217 c.expectEQ(want, rep)218 c.client.ReportFailedRepro(testCrashID(crash1))219}220func TestReportingQuota(t *testing.T) {221 c := NewCtx(t)222 defer c.Close()223 build := testBuild(1)224 c.client.UploadBuild(build)225 const numReports = 8 // quota is 3 per day226 for i := 0; i < numReports; i++ {227 c.client.ReportCrash(testCrash(build, i))228 }229 for _, reports := range []int{3, 3, 2, 0, 0} {230 c.advanceTime(24 * time.Hour)231 c.client.pollBugs(reports)232 // Out of quota for today, so must get 0 reports.233 c.client.pollBugs(0)234 }235}236// Basic dup scenario: mark one bug as dup of another.237func TestReportingDup(t *testing.T) {238 c := NewCtx(t)239 defer c.Close()240 build := testBuild(1)241 c.client.UploadBuild(build)242 crash1 := testCrash(build, 1)243 c.client.ReportCrash(crash1)244 crash2 := testCrash(build, 2)245 c.client.ReportCrash(crash2)246 reports := c.client.pollBugs(2)247 rep1 := reports[0]248 rep2 := reports[1]249 // Dup.250 c.client.updateBug(rep2.ID, dashapi.BugStatusDup, rep1.ID)251 {252 // Both must be reported as open.253 closed, _ := c.client.ReportingPollClosed([]string{rep1.ID, rep2.ID})254 c.expectEQ(len(closed), 0)255 }256 // Undup.257 c.client.updateBug(rep2.ID, dashapi.BugStatusOpen, "")258 // Dup again.259 c.client.updateBug(rep2.ID, dashapi.BugStatusDup, rep1.ID)260 // Dup crash happens again, new bug must not be created.261 c.client.ReportCrash(crash2)262 c.client.pollBugs(0)263 // Now close the original bug, and check that new bugs for dup are now created.264 c.client.updateBug(rep1.ID, dashapi.BugStatusInvalid, "")265 {266 // Now both must be reported as closed.267 closed, _ := c.client.ReportingPollClosed([]string{rep1.ID, rep2.ID})268 c.expectEQ(len(closed), 2)269 c.expectEQ(closed[0], rep1.ID)270 c.expectEQ(closed[1], rep2.ID)271 }272 c.client.ReportCrash(crash2)273 rep3 := c.client.pollBug()274 c.expectEQ(rep3.Title, crash2.Title+" (2)")275 // Unduping after the canonical bugs was closed must not work276 // (we already created new bug for this report).277 reply, _ := c.client.ReportingUpdate(&dashapi.BugUpdate{278 ID: rep2.ID,279 Status: dashapi.BugStatusOpen,280 })281 c.expectEQ(reply.OK, false)282}283// Dup bug onto a closed bug.284// A new crash report must create a new bug.285func TestReportingDupToClosed(t *testing.T) {286 c := NewCtx(t)287 defer c.Close()288 build := testBuild(1)289 c.client.UploadBuild(build)290 crash1 := testCrash(build, 1)291 c.client.ReportCrash(crash1)292 crash2 := testCrash(build, 2)293 c.client.ReportCrash(crash2)294 reports := c.client.pollBugs(2)295 c.client.updateBug(reports[0].ID, dashapi.BugStatusInvalid, "")296 c.client.updateBug(reports[1].ID, dashapi.BugStatusDup, reports[0].ID)297 c.client.ReportCrash(crash2)298 rep2 := c.client.pollBug()299 c.expectEQ(rep2.Title, crash2.Title+" (2)")300}301// Test that marking dups across reporting levels is not permitted.302func TestReportingDupCrossReporting(t *testing.T) {303 c := NewCtx(t)304 defer c.Close()305 build := testBuild(1)306 c.client.UploadBuild(build)307 crash1 := testCrash(build, 1)308 c.client.ReportCrash(crash1)309 crash2 := testCrash(build, 2)310 c.client.ReportCrash(crash2)311 reports := c.client.pollBugs(2)312 rep1 := reports[0]313 rep2 := reports[1]314 // Upstream second bug.315 c.client.updateBug(rep2.ID, dashapi.BugStatusUpstream, "")316 rep3 := c.client.pollBug()317 {318 closed, _ := c.client.ReportingPollClosed([]string{rep1.ID, rep2.ID, rep3.ID})319 c.expectEQ(len(closed), 1)320 c.expectEQ(closed[0], rep2.ID)321 }322 // Duping must fail all ways.323 cmds := []*dashapi.BugUpdate{324 {ID: rep1.ID, DupOf: rep1.ID},325 {ID: rep1.ID, DupOf: rep2.ID},326 {ID: rep2.ID, DupOf: rep1.ID},327 {ID: rep2.ID, DupOf: rep2.ID},328 {ID: rep2.ID, DupOf: rep3.ID},329 {ID: rep3.ID, DupOf: rep1.ID},330 {ID: rep3.ID, DupOf: rep2.ID},331 {ID: rep3.ID, DupOf: rep3.ID},332 }333 for _, cmd := range cmds {334 t.Logf("duping %v -> %v", cmd.ID, cmd.DupOf)335 cmd.Status = dashapi.BugStatusDup336 reply, _ := c.client.ReportingUpdate(cmd)337 c.expectEQ(reply.OK, false)338 }339 // Special case of cross-reporting duping:340 cmd := &dashapi.BugUpdate{341 Status: dashapi.BugStatusDup,342 ID: rep1.ID,343 DupOf: rep3.ID,344 }345 t.Logf("duping %v -> %v", cmd.ID, cmd.DupOf)346 reply, _ := c.client.ReportingUpdate(cmd)347 c.expectTrue(reply.OK)348}349// Test that dups can't form a cycle.350// The test builds cycles of length 1..4.351func TestReportingDupCycle(t *testing.T) {352 c := NewCtx(t)353 defer c.Close()354 build := testBuild(1)355 c.client.UploadBuild(build)356 const N = 4357 reps := make([]*dashapi.BugReport, N)358 for i := 0; i < N; i++ {359 t.Logf("*************** %v ***************", i)360 c.client.ReportCrash(testCrash(build, i))361 reps[i] = c.client.pollBug()362 replyError := "Can't dup bug to itself."363 if i != 0 {364 replyError = "Setting this dup would lead to a bug cycle, cycles are not allowed."365 reply, _ := c.client.ReportingUpdate(&dashapi.BugUpdate{366 Status: dashapi.BugStatusDup,367 ID: reps[i-1].ID,368 DupOf: reps[i].ID,369 })370 c.expectEQ(reply.OK, true)371 }372 reply, _ := c.client.ReportingUpdate(&dashapi.BugUpdate{373 Status: dashapi.BugStatusDup,374 ID: reps[i].ID,375 DupOf: reps[0].ID,376 })377 c.expectEQ(reply.OK, false)378 c.expectEQ(reply.Error, false)379 c.expectEQ(reply.Text, replyError)380 c.advanceTime(24 * time.Hour)381 }382}383func TestReportingFilter(t *testing.T) {384 c := NewCtx(t)385 defer c.Close()386 build := testBuild(1)387 c.client.UploadBuild(build)388 crash1 := testCrash(build, 1)389 crash1.Title = "skip with repro 1"390 c.client.ReportCrash(crash1)391 // This does not skip first reporting, because it does not have repro.392 rep1 := c.client.pollBug()393 c.expectEQ(string(rep1.Config), `{"Index":1}`)394 crash1.ReproSyz = []byte("getpid()")395 c.client.ReportCrash(crash1)396 // This has repro but was already reported to first reporting,397 // so repro must go to the first reporting as well.398 rep2 := c.client.pollBug()399 c.expectEQ(string(rep2.Config), `{"Index":1}`)400 // Now upstream it and it must go to the second reporting.401 c.client.updateBug(rep1.ID, dashapi.BugStatusUpstream, "")402 rep3 := c.client.pollBug()403 c.expectEQ(string(rep3.Config), `{"Index":2}`)404 // Now report a bug that must go to the second reporting right away.405 crash2 := testCrash(build, 2)406 crash2.Title = "skip with repro 2"407 crash2.ReproSyz = []byte("getpid()")408 c.client.ReportCrash(crash2)409 rep4 := c.client.pollBug()410 c.expectEQ(string(rep4.Config), `{"Index":2}`)411}412func TestMachineInfo(t *testing.T) {413 c := NewCtx(t)414 defer c.Close()415 build := testBuild(1)416 c.client.UploadBuild(build)417 machineInfo := []byte("info1")418 // Create a crash with machine information and check the returned machine419 // information field is equal.420 crash := &dashapi.Crash{421 BuildID: "build1",422 Title: "title1",423 Maintainers: []string{`"Foo Bar" <foo@bar.com>`, `bar@foo.com`},424 Log: []byte("log1"),425 Report: []byte("report1"),426 MachineInfo: machineInfo,427 }428 c.client.ReportCrash(crash)429 rep := c.client.pollBug()430 c.expectEQ(machineInfo, rep.MachineInfo)431 // Check that a link to machine information page is created on the dashboard,432 // and the content is correct.433 indexPage, err := c.AuthGET(AccessAdmin, "/test1")434 c.expectOK(err)435 bugLinkRegex := regexp.MustCompile(`<a href="(/bug\?id=[^"]+)">title1</a>`)436 bugLinkSubmatch := bugLinkRegex.FindSubmatch(indexPage)437 c.expectEQ(len(bugLinkSubmatch), 2)438 bugURL := html.UnescapeString(string(bugLinkSubmatch[1]))439 bugPage, err := c.AuthGET(AccessAdmin, bugURL)440 c.expectOK(err)441 infoLinkRegex := regexp.MustCompile(`<a href="(/text\?tag=MachineInfo[^"]+)">info</a>`)442 infoLinkSubmatch := infoLinkRegex.FindSubmatch(bugPage)443 c.expectEQ(len(infoLinkSubmatch), 2)444 infoURL := html.UnescapeString(string(infoLinkSubmatch[1]))445 receivedInfo, err := c.AuthGET(AccessAdmin, infoURL)446 c.expectOK(err)447 c.expectEQ(receivedInfo, machineInfo)448}449func TestAltTitles1(t *testing.T) {450 c := NewCtx(t)451 defer c.Close()452 build := testBuild(1)453 c.client.UploadBuild(build)454 // crash2.AltTitles matches crash1.Title.455 crash1 := testCrash(build, 1)456 crash2 := testCrashWithRepro(build, 2)457 crash2.AltTitles = []string{crash1.Title}458 c.client.ReportCrash(crash1)459 rep := c.client.pollBug()460 c.expectEQ(rep.Title, crash1.Title)461 c.expectEQ(rep.Log, crash1.Log)462 c.client.ReportCrash(crash2)463 rep = c.client.pollBug()464 c.expectEQ(rep.Title, crash1.Title)465 c.expectEQ(rep.Log, crash2.Log)466}467func TestAltTitles2(t *testing.T) {468 c := NewCtx(t)469 defer c.Close()470 build := testBuild(1)471 c.client.UploadBuild(build)472 // crash2.Title matches crash1.AltTitles, but reported in opposite order.473 crash1 := testCrash(build, 1)474 crash2 := testCrash(build, 2)475 crash2.AltTitles = []string{crash1.Title}476 c.client.ReportCrash(crash2)477 rep := c.client.pollBug()478 c.expectEQ(rep.Title, crash2.Title)479 c.expectEQ(rep.Log, crash2.Log)480 c.client.ReportCrash(crash1)481 c.client.pollBugs(0)482}483func TestAltTitles3(t *testing.T) {484 c := NewCtx(t)485 defer c.Close()486 build := testBuild(1)487 c.client.UploadBuild(build)488 // crash2.AltTitles matches crash1.AltTitles.489 crash1 := testCrash(build, 1)490 crash1.AltTitles = []string{"foobar"}491 crash2 := testCrash(build, 2)492 crash2.AltTitles = crash1.AltTitles493 c.client.ReportCrash(crash1)494 c.client.pollBugs(1)495 c.client.ReportCrash(crash2)496 c.client.pollBugs(0)497}498func TestAltTitles4(t *testing.T) {499 c := NewCtx(t)500 defer c.Close()501 build := testBuild(1)502 c.client.UploadBuild(build)503 // crash1.AltTitles matches crash2.AltTitles which matches crash3.AltTitles.504 crash1 := testCrash(build, 1)505 crash1.AltTitles = []string{"foobar1"}506 crash2 := testCrash(build, 2)507 crash2.AltTitles = []string{"foobar1", "foobar2"}508 crash3 := testCrash(build, 3)509 crash3.AltTitles = []string{"foobar2"}510 c.client.ReportCrash(crash1)511 c.client.pollBugs(1)512 c.client.ReportCrash(crash2)513 c.client.pollBugs(0)514 c.client.ReportCrash(crash3)515 c.client.pollBugs(0)516}517func TestAltTitles5(t *testing.T) {518 c := NewCtx(t)519 defer c.Close()520 build := testBuild(1)521 c.client.UploadBuild(build)522 // Test which of the possible existing bugs we choose for merging.523 crash1 := testCrash(build, 1)524 crash1.AltTitles = []string{"foo"}525 c.client.ReportCrash(crash1)526 c.client.pollBugs(1)527 crash2 := testCrash(build, 2)528 crash2.Title = "bar"529 c.client.ReportCrash(crash2)530 c.client.pollBugs(1)531 crash3 := testCrash(build, 3)532 c.client.ReportCrash(crash3)533 c.client.pollBugs(1)534 crash3.AltTitles = []string{"bar"}535 c.client.ReportCrash(crash3)536 c.client.pollBugs(0)537 crash := testCrashWithRepro(build, 10)538 crash.Title = "foo"539 crash.AltTitles = []string{"bar"}540 c.client.ReportCrash(crash)541 rep := c.client.pollBug()542 c.expectEQ(rep.Title, crash2.Title)543 c.expectEQ(rep.Log, crash.Log)544}545func TestAltTitles6(t *testing.T) {546 c := NewCtx(t)547 defer c.Close()548 build := testBuild(1)549 c.client.UploadBuild(build)550 // Test which of the possible existing bugs we choose for merging in presence of closed bugs.551 crash1 := testCrash(build, 1)552 crash1.AltTitles = []string{"foo"}553 c.client.ReportCrash(crash1)554 rep := c.client.pollBug()555 c.client.updateBug(rep.ID, dashapi.BugStatusInvalid, "")556 c.client.ReportCrash(crash1)557 c.client.pollBug()558 crash2 := testCrash(build, 2)559 crash2.Title = "bar"560 c.client.ReportCrash(crash2)561 rep = c.client.pollBug()562 c.client.updateBug(rep.ID, dashapi.BugStatusInvalid, "")563 c.advanceTime(24 * time.Hour)564 crash3 := testCrash(build, 3)565 c.client.ReportCrash(crash3)566 c.client.pollBugs(1)567 crash3.AltTitles = []string{"foo"}568 c.client.ReportCrash(crash3)569 c.client.pollBugs(0)570 crash := testCrashWithRepro(build, 10)571 crash.Title = "foo"572 crash.AltTitles = []string{"bar"}573 c.client.ReportCrash(crash)574 rep = c.client.pollBug()575 c.expectEQ(rep.Title, crash1.Title+" (2)")576 c.expectEQ(rep.Log, crash.Log)577}578func TestAltTitles7(t *testing.T) {579 c := NewCtx(t)580 defer c.Close()581 build := testBuild(1)582 c.client.UploadBuild(build)583 // Test that bug merging is stable: if we started merging into a bug, we continue merging into that bug584 // even if a better candidate appears.585 crash1 := testCrash(build, 1)586 crash1.AltTitles = []string{"foo"}587 c.client.ReportCrash(crash1)588 c.client.pollBug()589 // This will be merged into crash1.590 crash2 := testCrash(build, 2)591 crash2.AltTitles = []string{"foo"}592 c.client.ReportCrash(crash2)593 c.client.pollBugs(0)594 // Now report a better candidate.595 crash3 := testCrash(build, 3)596 crash3.Title = "aaa"597 c.client.ReportCrash(crash3)598 c.client.pollBug()599 crash3.AltTitles = []string{crash2.Title}600 c.client.ReportCrash(crash3)601 c.client.pollBugs(0)602 // Now report crash2 with a repro and ensure that it's still merged into crash1.603 crash2.ReproOpts = []byte("some opts")604 crash2.ReproSyz = []byte("getpid()")605 c.client.ReportCrash(crash2)606 rep := c.client.pollBug()607 c.expectEQ(rep.Title, crash1.Title)608 c.expectEQ(rep.Log, crash2.Log)609}...

Full Screen

Full Screen

repro_test.go

Source:repro_test.go Github

copy

Full Screen

1// Copyright 2018 syzkaller project authors. All rights reserved.2// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.3package main4import (5 "testing"6 "time"7 "github.com/google/syzkaller/dashboard/dashapi"8)9// Normal workflow:10// - upload crash -> need repro11// - upload syz repro -> still need repro12// - upload C repro -> don't need repro13func testNeedRepro1(t *testing.T, crashCtor func(c *Ctx) *dashapi.Crash, newBug bool) {14 c := NewCtx(t)15 defer c.Close()16 crash1 := crashCtor(c)17 resp, _ := c.client.ReportCrash(crash1)18 c.expectEQ(resp.NeedRepro, true)19 cid := testCrashID(crash1)20 needRepro, _ := c.client.NeedRepro(cid)21 c.expectEQ(needRepro, true)22 // Still need repro for this crash.23 resp, _ = c.client.ReportCrash(crash1)24 c.expectEQ(resp.NeedRepro, true)25 needRepro, _ = c.client.NeedRepro(cid)26 c.expectEQ(needRepro, true)27 crash2 := new(dashapi.Crash)28 *crash2 = *crash129 crash2.ReproOpts = []byte("opts")30 crash2.ReproSyz = []byte("repro syz")31 resp, _ = c.client.ReportCrash(crash2)32 c.expectEQ(resp.NeedRepro, true)33 needRepro, _ = c.client.NeedRepro(cid)34 c.expectEQ(needRepro, true)35 crash2.ReproC = []byte("repro C")36 resp, _ = c.client.ReportCrash(crash2)37 c.expectEQ(resp.NeedRepro, false)38 needRepro, _ = c.client.NeedRepro(cid)39 c.expectEQ(needRepro, false)40 resp, _ = c.client.ReportCrash(crash2)41 c.expectEQ(resp.NeedRepro, false)42 if newBug {43 c.client.pollBug()44 }45}46func TestNeedRepro1_normal(t *testing.T) { testNeedRepro1(t, normalCrash, true) }47func TestNeedRepro1_dup(t *testing.T) { testNeedRepro1(t, dupCrash, false) }48func TestNeedRepro1_closed(t *testing.T) { testNeedRepro1(t, closedCrash, true) }49func TestNeedRepro1_closedRepro(t *testing.T) { testNeedRepro1(t, closedWithReproCrash, true) }50// Upload C repro with first crash -> don't need repro.51func testNeedRepro2(t *testing.T, crashCtor func(c *Ctx) *dashapi.Crash, newBug bool) {52 c := NewCtx(t)53 defer c.Close()54 crash1 := crashCtor(c)55 crash1.ReproOpts = []byte("opts")56 crash1.ReproSyz = []byte("repro syz")57 crash1.ReproC = []byte("repro C")58 resp, _ := c.client.ReportCrash(crash1)59 c.expectEQ(resp.NeedRepro, false)60 needRepro, _ := c.client.NeedRepro(testCrashID(crash1))61 c.expectEQ(needRepro, false)62 if newBug {63 c.client.pollBug()64 }65}66func TestNeedRepro2_normal(t *testing.T) { testNeedRepro2(t, normalCrash, true) }67func TestNeedRepro2_dup(t *testing.T) { testNeedRepro2(t, dupCrash, false) }68func TestNeedRepro2_closed(t *testing.T) { testNeedRepro2(t, closedCrash, true) }69func TestNeedRepro2_closedRepro(t *testing.T) { testNeedRepro2(t, closedWithReproCrash, true) }70// Test that after uploading 5 failed repros, app stops requesting repros.71func testNeedRepro3(t *testing.T, crashCtor func(c *Ctx) *dashapi.Crash) {72 c := NewCtx(t)73 defer c.Close()74 crash1 := crashCtor(c)75 for i := 0; i < maxReproPerBug; i++ {76 resp, _ := c.client.ReportCrash(crash1)77 c.expectEQ(resp.NeedRepro, true)78 needRepro, _ := c.client.NeedRepro(testCrashID(crash1))79 c.expectEQ(needRepro, true)80 c.client.ReportFailedRepro(testCrashID(crash1))81 }82 for i := 0; i < 3; i++ {83 // No more repros today.84 c.advanceTime(time.Hour)85 resp, _ := c.client.ReportCrash(crash1)86 c.expectEQ(resp.NeedRepro, false)87 needRepro, _ := c.client.NeedRepro(testCrashID(crash1))88 c.expectEQ(needRepro, false)89 // Then another repro after a day.90 c.advanceTime(25 * time.Hour)91 for j := 0; j < 2; j++ {92 resp, _ := c.client.ReportCrash(crash1)93 c.expectEQ(resp.NeedRepro, true)94 needRepro, _ := c.client.NeedRepro(testCrashID(crash1))95 c.expectEQ(needRepro, true)96 }97 c.client.ReportFailedRepro(testCrashID(crash1))98 }99}100func TestNeedRepro3_normal(t *testing.T) { testNeedRepro3(t, normalCrash) }101func TestNeedRepro3_dup(t *testing.T) { testNeedRepro3(t, dupCrash) }102func TestNeedRepro3_closed(t *testing.T) { testNeedRepro3(t, closedCrash) }103func TestNeedRepro3_closedRepro(t *testing.T) { testNeedRepro3(t, closedWithReproCrash) }104// Test that after uploading 5 syz repros, app stops requesting repros.105func testNeedRepro4(t *testing.T, crashCtor func(c *Ctx) *dashapi.Crash, newBug bool) {106 c := NewCtx(t)107 defer c.Close()108 crash1 := crashCtor(c)109 crash1.ReproOpts = []byte("opts")110 crash1.ReproSyz = []byte("repro syz")111 for i := 0; i < maxReproPerBug-1; i++ {112 resp, _ := c.client.ReportCrash(crash1)113 c.expectEQ(resp.NeedRepro, true)114 needRepro, _ := c.client.NeedRepro(testCrashID(crash1))115 c.expectEQ(needRepro, true)116 }117 resp, _ := c.client.ReportCrash(crash1)118 c.expectEQ(resp.NeedRepro, false)119 needRepro, _ := c.client.NeedRepro(testCrashID(crash1))120 c.expectEQ(needRepro, false)121 // No more repros even after a day.122 c.advanceTime(25 * time.Hour)123 crash1.ReproOpts = nil124 crash1.ReproSyz = nil125 resp, _ = c.client.ReportCrash(crash1)126 c.expectEQ(resp.NeedRepro, false)127 needRepro, _ = c.client.NeedRepro(testCrashID(crash1))128 c.expectEQ(needRepro, false)129 if newBug {130 c.client.pollBug()131 }132}133func TestNeedRepro4_normal(t *testing.T) { testNeedRepro4(t, normalCrash, true) }134func TestNeedRepro4_dup(t *testing.T) { testNeedRepro4(t, dupCrash, false) }135func TestNeedRepro4_closed(t *testing.T) { testNeedRepro4(t, closedCrash, true) }136func TestNeedRepro4_closedRepro(t *testing.T) { testNeedRepro4(t, closedWithReproCrash, true) }137func normalCrash(c *Ctx) *dashapi.Crash {138 build := testBuild(1)139 c.client.UploadBuild(build)140 crash := testCrash(build, 1)141 c.client.ReportCrash(crash)142 c.client.pollBug()143 return crash144}145func dupCrash(c *Ctx) *dashapi.Crash {146 build := testBuild(1)147 c.client.UploadBuild(build)148 c.client.ReportCrash(testCrash(build, 1))149 crash2 := testCrash(build, 2)150 c.client.ReportCrash(crash2)151 reports := c.client.pollBugs(2)152 c.client.updateBug(reports[1].ID, dashapi.BugStatusDup, reports[0].ID)153 return crash2154}155func closedCrash(c *Ctx) *dashapi.Crash {156 return closedCrashImpl(c, false)157}158func closedWithReproCrash(c *Ctx) *dashapi.Crash {159 return closedCrashImpl(c, true)160}161func closedCrashImpl(c *Ctx, withRepro bool) *dashapi.Crash {162 build := testBuild(1)163 c.client.UploadBuild(build)164 crash := testCrash(build, 1)165 if withRepro {166 crash.ReproC = []byte("repro C")167 }168 resp, _ := c.client.ReportCrash(crash)169 c.expectEQ(resp.NeedRepro, !withRepro)170 rep := c.client.pollBug()171 c.client.updateBug(rep.ID, dashapi.BugStatusInvalid, "")172 crash.ReproC = nil173 c.client.ReportCrash(crash)174 c.client.pollBug()175 return crash176}...

Full Screen

Full Screen

reportCrash

Using AI Code Generation

copy

Full Screen

1import "fmt"2func main() {3 fmt.Println("In main")4 reportCrash()5}6import "fmt"7func main() {8 fmt.Println("In main")9 reportCrash()10}11main.reportCrash()12main.main()13os/signal.signal_recv(0x0)14os/signal.loop()15main.main.func1()16main.reportCrash()17main.main()18os/signal.signal_recv(0x0)

Full Screen

Full Screen

reportCrash

Using AI Code Generation

copy

Full Screen

1import "fmt"2func reportCrash() {3 fmt.Println("Crash reported")4}5func main() {6 reportCrash()7}8import "fmt"9func reportCrash() {10 fmt.Println("Crash reported")11}12func main() {13 reportCrash()14}15import "fmt"16func reportCrash() {17 fmt.Println("Crash reported")18}19func main() {20 reportCrash()21}22import "fmt"23func reportCrash() {24 fmt.Println("Crash reported")25}26func main() {27 reportCrash()28}29import "fmt"30func reportCrash() {31 fmt.Println("Crash reported")32}33func main() {34 reportCrash()35}36import "fmt"37func reportCrash() {38 fmt.Println("Crash reported")39}40func main() {41 reportCrash()42}43import "fmt"44func reportCrash() {45 fmt.Println("Crash reported")46}47func main() {48 reportCrash()49}50import "fmt"51func reportCrash() {52 fmt.Println("Crash reported")53}54func main() {55 reportCrash()56}57import "fmt"58func reportCrash() {59 fmt.Println("Crash reported")60}61func main() {62 reportCrash()63}64import "fmt"65func reportCrash() {66 fmt.Println("Crash reported")67}68func main() {69 reportCrash()70}

Full Screen

Full Screen

reportCrash

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Hello, playground")4 reportCrash()5}6import (7func reportCrash() {8 fmt.Println("Crash reported")9}

Full Screen

Full Screen

reportCrash

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Hello, playground")4 reportCrash()5}6import (7func main() {8 fmt.Println("Hello, playground")9}10func reportCrash() {11 fmt.Println("reportCrash")12}13Your name to display (optional):14Your name to display (optional):15If you are trying to use the reportCrash method of 1.go in 2.go , then you need to import 1.go in 2.go . You can do it by adding the following line in 2.go :16import "1"17import (18func main() {19 fmt.Println("Hello, playground")20 reportCrash()21}22Your name to display (optional):

Full Screen

Full Screen

reportCrash

Using AI Code Generation

copy

Full Screen

1public class CrashReport {2 public static void main(String[] args) {3 main.reportCrash();4 }5}6 at CrashReport.main(CrashReport.java:8)7public class CrashReport {8 static {9 main = new main();10 }11 public static void main(String[] args) {12 main.reportCrash();13 }14}15 at main.reportCrash(main.java:6)16 at CrashReport.main(CrashReport.java:11)17public class CrashReport {18 static {19 main = new main();20 }21 public static void main(String[] args) {22 main.reportCrash();23 }24}25 at main.reportCrash(main.java:6)26 at CrashReport.main(CrashReport.java:11)27public class CrashReport {28 static {29 main = new main();30 }31 public static void main(String[] args) {32 main.reportCrash();33 }34}

Full Screen

Full Screen

reportCrash

Using AI Code Generation

copy

Full Screen

1public class Main {2 public static void main(String args[]) {3 System.out.println("Main class");4 new CrashReport().reportCrash();5 }6}7public class CrashReport {8 public void reportCrash() {9 System.out.println("CrashReport");10 }11}12public class Main {13 public static void main(String args[]) {14 System.out.println("Main class");15 new CrashReport().reportCrash();16 }17}18public class CrashReport {19 public void reportCrash() {20 System.out.println("CrashReport");21 }22}23Now, we will create a new class called CrashReport.java in a new package called com.example.crashreport . We will also add a method called reportCrash() in it. We will also add some code in this

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.

Run Syzkaller automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful