How to use loadOpenBugs method of main Package

Best Syzkaller code snippet using main.loadOpenBugs

reporting.go

Source:reporting.go Github

copy

Full Screen

...37 if err != nil {38 log.Errorf(c, "%v", err)39 return nil40 }41 bugs, _, err := loadOpenBugs(c)42 if err != nil {43 log.Errorf(c, "%v", err)44 return nil45 }46 log.Infof(c, "fetched %v bugs", len(bugs))47 sort.Sort(bugReportSorter(bugs))48 var reports []*dashapi.BugReport49 for _, bug := range bugs {50 rep, err := handleReportBug(c, typ, state, bug)51 if err != nil {52 log.Errorf(c, "%v: failed to report bug %v: %v", bug.Namespace, bug.Title, err)53 continue54 }55 if rep == nil {56 continue57 }58 reports = append(reports, rep)59 }60 return reports61}62func handleReportBug(c context.Context, typ string, state *ReportingState, bug *Bug) (63 *dashapi.BugReport, error) {64 reporting, bugReporting, crash, crashKey, _, _, _, err := needReport(c, typ, state, bug)65 if err != nil || reporting == nil {66 return nil, err67 }68 rep, err := createBugReport(c, bug, crash, crashKey, bugReporting, reporting)69 if err != nil {70 return nil, err71 }72 log.Infof(c, "bug %q: reporting to %v", bug.Title, reporting.Name)73 return rep, nil74}75func needReport(c context.Context, typ string, state *ReportingState, bug *Bug) (76 reporting *Reporting, bugReporting *BugReporting, crash *Crash,77 crashKey *db.Key, reportingIdx int, status, link string, err error) {78 reporting, bugReporting, reportingIdx, status, err = currentReporting(c, bug)79 if err != nil || reporting == nil {80 return81 }82 if typ != "" && typ != reporting.Config.Type() {83 status = "on a different reporting"84 reporting, bugReporting = nil, nil85 return86 }87 link = bugReporting.Link88 if !bugReporting.Reported.IsZero() && bugReporting.ReproLevel >= bug.ReproLevel {89 status = fmt.Sprintf("%v: reported%v on %v",90 reporting.DisplayTitle, reproStr(bugReporting.ReproLevel),91 html.FormatTime(bugReporting.Reported))92 reporting, bugReporting = nil, nil93 return94 }95 ent := state.getEntry(timeNow(c), bug.Namespace, reporting.Name)96 cfg := config.Namespaces[bug.Namespace]97 if timeSince(c, bug.FirstTime) < cfg.ReportingDelay {98 status = fmt.Sprintf("%v: initial reporting delay", reporting.DisplayTitle)99 reporting, bugReporting = nil, nil100 return101 }102 if bug.ReproLevel < ReproLevelC && timeSince(c, bug.FirstTime) < cfg.WaitForRepro {103 status = fmt.Sprintf("%v: waiting for C repro", reporting.DisplayTitle)104 reporting, bugReporting = nil, nil105 return106 }107 if !cfg.MailWithoutReport && !bug.HasReport {108 status = fmt.Sprintf("%v: no report", reporting.DisplayTitle)109 reporting, bugReporting = nil, nil110 return111 }112 crash, crashKey, err = findCrashForBug(c, bug)113 if err != nil {114 status = fmt.Sprintf("%v: no crashes!", reporting.DisplayTitle)115 reporting, bugReporting = nil, nil116 return117 }118 // Limit number of reports sent per day,119 // but don't limit sending repros to already reported bugs.120 if bugReporting.Reported.IsZero() && ent.Sent >= reporting.DailyLimit {121 status = fmt.Sprintf("%v: out of quota for today", reporting.DisplayTitle)122 reporting, bugReporting = nil, nil123 return124 }125 // Ready to be reported.126 if bugReporting.Reported.IsZero() {127 // This update won't be committed, but it will prevent us from128 // reporting too many bugs in a single poll.129 ent.Sent++130 }131 status = fmt.Sprintf("%v: ready to report", reporting.DisplayTitle)132 if !bugReporting.Reported.IsZero() {133 status += fmt.Sprintf(" (reported%v on %v)",134 reproStr(bugReporting.ReproLevel), html.FormatTime(bugReporting.Reported))135 }136 return137}138func reportingPollNotifications(c context.Context, typ string) []*dashapi.BugNotification {139 bugs, _, err := loadOpenBugs(c)140 if err != nil {141 log.Errorf(c, "%v", err)142 return nil143 }144 log.Infof(c, "fetched %v bugs", len(bugs))145 var notifs []*dashapi.BugNotification146 for _, bug := range bugs {147 if config.Namespaces[bug.Namespace].Decommissioned {148 continue149 }150 notif, err := handleReportNotif(c, typ, bug)151 if err != nil {152 log.Errorf(c, "%v: failed to create bug notif %v: %v", bug.Namespace, bug.Title, err)153 continue154 }155 if notif == nil {156 continue157 }158 notifs = append(notifs, notif)159 if len(notifs) >= 10 {160 break // don't send too many at once just in case161 }162 }163 return notifs164}165func handleReportNotif(c context.Context, typ string, bug *Bug) (*dashapi.BugNotification, error) {166 reporting, bugReporting, _, _, err := currentReporting(c, bug)167 if err != nil || reporting == nil {168 return nil, nil169 }170 if typ != "" && typ != reporting.Config.Type() {171 return nil, nil172 }173 if bug.Status != BugStatusOpen || bugReporting.Reported.IsZero() {174 return nil, nil175 }176 if reporting.moderation &&177 reporting.Embargo != 0 &&178 len(bug.Commits) == 0 &&179 bugReporting.OnHold.IsZero() &&180 timeSince(c, bugReporting.Reported) > reporting.Embargo {181 log.Infof(c, "%v: upstreaming (embargo): %v", bug.Namespace, bug.Title)182 return createNotification(c, dashapi.BugNotifUpstream, true, "", bug, reporting, bugReporting)183 }184 if reporting.moderation &&185 len(bug.Commits) == 0 &&186 bugReporting.OnHold.IsZero() &&187 reporting.Filter(bug) == FilterSkip {188 log.Infof(c, "%v: upstreaming (skip): %v", bug.Namespace, bug.Title)189 return createNotification(c, dashapi.BugNotifUpstream, true, "", bug, reporting, bugReporting)190 }191 if len(bug.Commits) == 0 &&192 bug.wontBeFixBisected() &&193 timeSince(c, bug.LastActivity) > notifyResendPeriod &&194 timeSince(c, bug.LastTime) > bug.obsoletePeriod() {195 log.Infof(c, "%v: obsoleting: %v", bug.Namespace, bug.Title)196 return createNotification(c, dashapi.BugNotifObsoleted, false, "", bug, reporting, bugReporting)197 }198 if len(bug.Commits) > 0 &&199 len(bug.PatchedOn) == 0 &&200 timeSince(c, bug.LastActivity) > notifyResendPeriod &&201 timeSince(c, bug.FixTime) > notifyAboutBadCommitPeriod {202 log.Infof(c, "%v: bad fix commit: %v", bug.Namespace, bug.Title)203 commits := strings.Join(bug.Commits, "\n")204 return createNotification(c, dashapi.BugNotifBadCommit, true, commits, bug, reporting, bugReporting)205 }206 return nil, nil207}208// TODO: this is what we would like to do, but we need to figure out209// KMSAN story: we don't do fix bisection on it (rebased),210// do we want to close all old KMSAN bugs with repros?211// For now we only enable this in tests.212var obsoleteWhatWontBeFixBisected = false213func (bug *Bug) wontBeFixBisected() bool {214 if bug.ReproLevel == ReproLevelNone {215 return true216 }217 if obsoleteWhatWontBeFixBisected {218 cfg := config.Namespaces[bug.Namespace]219 for _, mgr := range bug.HappenedOn {220 if !cfg.Managers[mgr].FixBisectionDisabled {221 return false222 }223 }224 return true225 }226 return false227}228func (bug *Bug) obsoletePeriod() time.Duration {229 period := never230 if config.Obsoleting.MinPeriod == 0 {231 return period232 }233 // Before we have at least 10 crashes, any estimation of frequency is too imprecise.234 // In such case we conservatively assume it still happens.235 if bug.NumCrashes >= 10 {236 // This is linear extrapolation for when the next crash should happen.237 period = bug.LastTime.Sub(bug.FirstTime) / time.Duration(bug.NumCrashes-1)238 // Let's be conservative with obsoleting too early.239 period *= 100240 }241 min, max := config.Obsoleting.MinPeriod, config.Obsoleting.MaxPeriod242 if config.Obsoleting.NonFinalMinPeriod != 0 &&243 bug.Reporting[len(bug.Reporting)-1].Reported.IsZero() {244 min, max = config.Obsoleting.NonFinalMinPeriod, config.Obsoleting.NonFinalMaxPeriod245 }246 if len(bug.HappenedOn) == 1 {247 mgr := config.Namespaces[bug.Namespace].Managers[bug.HappenedOn[0]]248 if mgr.ObsoletingMinPeriod != 0 {249 min, max = mgr.ObsoletingMinPeriod, mgr.ObsoletingMaxPeriod250 }251 }252 if period < min {253 period = min254 }255 if period > max {256 period = max257 }258 return period259}260func createNotification(c context.Context, typ dashapi.BugNotif, public bool, text string, bug *Bug,261 reporting *Reporting, bugReporting *BugReporting) (*dashapi.BugNotification, error) {262 reportingConfig, err := json.Marshal(reporting.Config)263 if err != nil {264 return nil, err265 }266 crash, _, err := findCrashForBug(c, bug)267 if err != nil {268 return nil, fmt.Errorf("no crashes for bug")269 }270 build, err := loadBuild(c, bug.Namespace, crash.BuildID)271 if err != nil {272 return nil, err273 }274 kernelRepo := kernelRepoInfo(build)275 notif := &dashapi.BugNotification{276 Type: typ,277 Namespace: bug.Namespace,278 Config: reportingConfig,279 ID: bugReporting.ID,280 ExtID: bugReporting.ExtID,281 Title: bug.displayTitle(),282 Text: text,283 Public: public,284 CC: kernelRepo.CC,285 }286 if public {287 notif.Maintainers = append(crash.Maintainers, kernelRepo.Maintainers...)288 }289 if (public || reporting.moderation) && bugReporting.CC != "" {290 notif.CC = append(notif.CC, strings.Split(bugReporting.CC, "|")...)291 }292 return notif, nil293}294func currentReporting(c context.Context, bug *Bug) (*Reporting, *BugReporting, int, string, error) {295 for i := range bug.Reporting {296 bugReporting := &bug.Reporting[i]297 if !bugReporting.Closed.IsZero() {298 continue299 }300 reporting := config.Namespaces[bug.Namespace].ReportingByName(bugReporting.Name)301 if reporting == nil {302 return nil, nil, 0, "", fmt.Errorf("%v: missing in config", bugReporting.Name)303 }304 if reporting.DailyLimit == 0 {305 return nil, nil, 0, fmt.Sprintf("%v: reporting has daily limit 0", reporting.DisplayTitle), nil306 }307 switch reporting.Filter(bug) {308 case FilterSkip:309 if bugReporting.Reported.IsZero() {310 continue311 }312 fallthrough313 case FilterReport:314 return reporting, bugReporting, i, "", nil315 case FilterHold:316 return nil, nil, 0, fmt.Sprintf("%v: reporting suspended", reporting.DisplayTitle), nil317 }318 }319 return nil, nil, 0, "", fmt.Errorf("no reporting left")320}321func reproStr(level dashapi.ReproLevel) string {322 switch level {323 case ReproLevelSyz:324 return " syz repro"325 case ReproLevelC:326 return " C repro"327 default:328 return ""329 }330}331func createBugReport(c context.Context, bug *Bug, crash *Crash, crashKey *db.Key,332 bugReporting *BugReporting, reporting *Reporting) (*dashapi.BugReport, error) {333 reportingConfig, err := json.Marshal(reporting.Config)334 if err != nil {335 return nil, err336 }337 var job *Job338 if bug.BisectCause == BisectYes {339 // If we have bisection results, report the crash/repro used for bisection.340 job1, crash1, _, crashKey1, err := loadBisectJob(c, bug, JobBisectCause)341 if err != nil {342 return nil, err343 }344 job = job1345 if !job.isUnreliableBisect() && (crash1.ReproC != 0 || crash.ReproC == 0) {346 // Don't override the crash in this case,347 // otherwise we will always think that we haven't reported the C repro.348 crash, crashKey = crash1, crashKey1349 }350 }351 crashLog, _, err := getText(c, textCrashLog, crash.Log)352 if err != nil {353 return nil, err354 }355 if len(crashLog) > maxMailLogLen {356 crashLog = crashLog[len(crashLog)-maxMailLogLen:]357 }358 report, _, err := getText(c, textCrashReport, crash.Report)359 if err != nil {360 return nil, err361 }362 if len(report) > maxMailReportLen {363 report = report[:maxMailReportLen]364 }365 reproC, _, err := getText(c, textReproC, crash.ReproC)366 if err != nil {367 return nil, err368 }369 reproSyz, _, err := getText(c, textReproSyz, crash.ReproSyz)370 if err != nil {371 return nil, err372 }373 if len(reproSyz) != 0 {374 buf := new(bytes.Buffer)375 buf.WriteString(syzReproPrefix)376 if len(crash.ReproOpts) != 0 {377 fmt.Fprintf(buf, "#%s\n", crash.ReproOpts)378 }379 buf.Write(reproSyz)380 reproSyz = buf.Bytes()381 }382 build, err := loadBuild(c, bug.Namespace, crash.BuildID)383 if err != nil {384 return nil, err385 }386 typ := dashapi.ReportNew387 if !bugReporting.Reported.IsZero() {388 typ = dashapi.ReportRepro389 }390 kernelRepo := kernelRepoInfo(build)391 rep := &dashapi.BugReport{392 Type: typ,393 Config: reportingConfig,394 ExtID: bugReporting.ExtID,395 First: bugReporting.Reported.IsZero(),396 Moderation: reporting.moderation,397 Log: crashLog,398 LogLink: externalLink(c, textCrashLog, crash.Log),399 Report: report,400 ReportLink: externalLink(c, textCrashReport, crash.Report),401 CC: kernelRepo.CC,402 Maintainers: append(crash.Maintainers, kernelRepo.Maintainers...),403 ReproC: reproC,404 ReproCLink: externalLink(c, textReproC, crash.ReproC),405 ReproSyz: reproSyz,406 ReproSyzLink: externalLink(c, textReproSyz, crash.ReproSyz),407 CrashID: crashKey.IntID(),408 NumCrashes: bug.NumCrashes,409 HappenedOn: managersToRepos(c, bug.Namespace, bug.HappenedOn),410 }411 if bugReporting.CC != "" {412 rep.CC = append(rep.CC, strings.Split(bugReporting.CC, "|")...)413 }414 if build.Type == BuildFailed {415 rep.Maintainers = append(rep.Maintainers, kernelRepo.BuildMaintainers...)416 }417 if bug.BisectCause == BisectYes && !job.isUnreliableBisect() {418 rep.BisectCause = bisectFromJob(c, rep, job)419 }420 if err := fillBugReport(c, rep, bug, bugReporting, build); err != nil {421 return nil, err422 }423 return rep, nil424}425// fillBugReport fills common report fields for bug and job reports.426func fillBugReport(c context.Context, rep *dashapi.BugReport, bug *Bug, bugReporting *BugReporting,427 build *Build) error {428 kernelConfig, _, err := getText(c, textKernelConfig, build.KernelConfig)429 if err != nil {430 return err431 }432 creditEmail, err := email.AddAddrContext(ownEmail(c), bugReporting.ID)433 if err != nil {434 return err435 }436 rep.Namespace = bug.Namespace437 rep.ID = bugReporting.ID438 rep.Title = bug.displayTitle()439 rep.Link = fmt.Sprintf("%v/bug?extid=%v", appURL(c), bugReporting.ID)440 rep.CreditEmail = creditEmail441 rep.OS = build.OS442 rep.Arch = build.Arch443 rep.VMArch = build.VMArch444 rep.UserSpaceArch = kernelArch(build.Arch)445 rep.CompilerID = build.CompilerID446 rep.KernelRepo = build.KernelRepo447 rep.KernelRepoAlias = kernelRepoInfo(build).Alias448 rep.KernelBranch = build.KernelBranch449 rep.KernelCommit = build.KernelCommit450 rep.KernelCommitTitle = build.KernelCommitTitle451 rep.KernelCommitDate = build.KernelCommitDate452 rep.KernelConfig = kernelConfig453 rep.KernelConfigLink = externalLink(c, textKernelConfig, build.KernelConfig)454 rep.NoRepro = build.Type == BuildFailed455 for _, addr := range bug.UNCC {456 rep.CC = email.RemoveFromEmailList(rep.CC, addr)457 rep.Maintainers = email.RemoveFromEmailList(rep.Maintainers, addr)458 }459 return nil460}461func loadBisectJob(c context.Context, bug *Bug, jobType JobType) (*Job, *Crash, *db.Key, *db.Key, error) {462 bugKey := bug.key(c)463 var jobs []*Job464 keys, err := db.NewQuery("Job").465 Ancestor(bugKey).466 Filter("Type=", jobType).467 Filter("Finished>", time.Time{}).468 Order("-Finished").469 Limit(1).470 GetAll(c, &jobs)471 if err != nil {472 return nil, nil, nil, nil, fmt.Errorf("failed to query jobs: %v", err)473 }474 if len(jobs) == 0 {475 jobStr := map[JobType]string{476 JobBisectCause: "bisect cause",477 JobBisectFix: "bisect fix",478 }479 return nil, nil, nil, nil, fmt.Errorf("can't find %s job for bug", jobStr[jobType])480 }481 job := jobs[0]482 crash := new(Crash)483 crashKey := db.NewKey(c, "Crash", "", job.CrashID, bugKey)484 if err := db.Get(c, crashKey, crash); err != nil {485 return nil, nil, nil, nil, fmt.Errorf("failed to get crash: %v", err)486 }487 return job, crash, keys[0], crashKey, nil488}489func managersToRepos(c context.Context, ns string, managers []string) []string {490 var repos []string491 dedup := make(map[string]bool)492 for _, manager := range managers {493 build, err := lastManagerBuild(c, ns, manager)494 if err != nil {495 log.Errorf(c, "failed to get manager %q build: %v", manager, err)496 continue497 }498 repo := kernelRepoInfo(build).Alias499 if dedup[repo] {500 continue501 }502 dedup[repo] = true503 repos = append(repos, repo)504 }505 sort.Strings(repos)506 return repos507}508func loadAllBugs(c context.Context, filter func(*db.Query) *db.Query) ([]*Bug, []*db.Key, error) {509 var bugs []*Bug510 var keys []*db.Key511 err := foreachBug(c, filter, func(bug *Bug, key *db.Key) error {512 bugs = append(bugs, bug)513 keys = append(keys, key)514 return nil515 })516 if err != nil {517 return nil, nil, err518 }519 return bugs, keys, nil520}521func loadNamespaceBugs(c context.Context, ns string) ([]*Bug, []*db.Key, error) {522 return loadAllBugs(c, func(query *db.Query) *db.Query {523 return query.Filter("Namespace=", ns)524 })525}526func loadOpenBugs(c context.Context) ([]*Bug, []*db.Key, error) {527 return loadAllBugs(c, func(query *db.Query) *db.Query {528 return query.Filter("Status<", BugStatusFixed)529 })530}531func foreachBug(c context.Context, filter func(*db.Query) *db.Query, fn func(bug *Bug, key *db.Key) error) error {532 const batchSize = 1000533 var cursor *db.Cursor534 for {535 query := db.NewQuery("Bug").Limit(batchSize)536 if filter != nil {537 query = filter(query)538 }539 if cursor != nil {540 query = query.Start(*cursor)...

Full Screen

Full Screen

loadOpenBugs

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 loadOpenBugs()4}5func loadOpenBugs() {6 resp, err := http.Get(url)7 if err != nil {8 log.Fatal(err)9 }10 defer resp.Body.Close()11 body, err := ioutil.ReadAll(resp.Body)12 if err != nil {13 log.Fatal(err)14 }15 err = json.Unmarshal(body, &bugs)16 if err != nil {17 log.Fatal(err)18 }19 fmt.Println(bugs)20}21type Bug struct {22}

Full Screen

Full Screen

loadOpenBugs

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Hello, playground")4 main.loadOpenBugs()5}6import (7func main() {8 fmt.Println("Hello, playground")9 main.loadOpenBugs()10}11import (12func main() {13 fmt.Println("Hello, playground")14 main.loadOpenBugs()15}16import (17func main() {18 fmt.Println("Hello, playground")19 main.loadOpenBugs()20}21import (22func main() {23 fmt.Println("Hello, playground")24 main.loadOpenBugs()25}26import (27func main() {28 fmt.Println("Hello, playground")29 main.loadOpenBugs()30}31import (32func main() {33 fmt.Println("Hello, playground")34 main.loadOpenBugs()35}36import (37func main() {38 fmt.Println("Hello, playground")39 main.loadOpenBugs()40}41import (42func main() {43 fmt.Println("Hello, playground")44 main.loadOpenBugs()45}46import (47func main() {48 fmt.Println("Hello, playground")49 main.loadOpenBugs()50}

Full Screen

Full Screen

loadOpenBugs

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Hello, playground")4 bugList := main.loadOpenBugs()5 fmt.Println(bugList)6}7 /usr/local/go/src/main (from $GOROOT)8 /Users/abhishek/go/src/main (from $GOPATH)

Full Screen

Full Screen

loadOpenBugs

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 mainClass := reflect.TypeOf((*main)(nil)).Elem()4 loadOpenBugsMethod, _ := mainClass.MethodByName("loadOpenBugs")5 if !loadOpenBugsValue.IsValid() {6 fmt.Println("loadOpenBugs method is not valid")7 }8 if !loadOpenBugsValue.CanInterface() {9 fmt.Println("loadOpenBugs method is not exported")10 }11 if loadOpenBugsType.Kind() != reflect.Func {12 fmt.Println("loadOpenBugs method is not a function")13 }14 if loadOpenBugsType.NumIn() != 2 {15 fmt.Println("loadOpenBugs method has the wrong number of parameters")16 }17 if loadOpenBugsType.In(0) != mainClass {18 fmt.Println("loadOpenBugs method has the wrong first parameter")19 }20 if loadOpenBugsType.In(1) != reflect.TypeOf(time.Time{}) {21 fmt.Println("loadOpenBugs method has the wrong second parameter")22 }23 if loadOpenBugsType.NumOut() != 1 {24 fmt.Println("loadOpenBugs method has the wrong number of return values")25 }26 if loadOpenBugsType.Out(0) != reflect.TypeOf((*error)(nil)).Elem() {27 fmt.Println("loadOpenBugs method has the wrong return value")28 }29 result := loadOpenBugsValue.Call([]reflect.Value{reflect

Full Screen

Full Screen

loadOpenBugs

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 db, err := sql.Open("mysql", "root:root@/bug")4 if err != nil {5 panic(err.Error())6 }7 defer db.Close()8 rows, err := db.Query("select * from bugs")9 if err != nil {10 panic(err.Error())11 }12 for rows.Next() {13 err = rows.Scan(&id, &name, &description, &priority, &status, &created, &updated)14 if err != nil {15 panic(err.Error())16 }17 fmt.Println(id, name, description, priority, status, created, updated)18 }19}

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