How to use markCrashReported method of main Package

Best Syzkaller code snippet using main.markCrashReported

jobs.go

Source:jobs.go Github

copy

Full Screen

...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)...

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