How to use jobID2Key method of main Package

Best Syzkaller code snippet using main.jobID2Key

jobs.go

Source:jobs.go Github

copy

Full Screen

...432}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),686 Fix: job.Type == JobBisectFix,687 }688 for _, com := range job.Commits {689 bisect.Commits = append(bisect.Commits, &dashapi.Commit{690 Hash: com.Hash,691 Title: com.Title,692 Author: com.Author,693 AuthorName: com.AuthorName,694 Date: com.Date,695 })696 }697 if len(bisect.Commits) == 1 {698 bisect.Commit = bisect.Commits[0]699 bisect.Commits = nil700 com := job.Commits[0]701 rep.Maintainers = append(rep.Maintainers, com.Author)702 rep.Maintainers = append(rep.Maintainers, strings.Split(com.CC, "|")...)703 }704 return bisect705}706func jobReported(c context.Context, jobID string) error {707 jobKey, err := jobID2Key(c, jobID)708 if err != nil {709 return err710 }711 now := timeNow(c)712 tx := func(c context.Context) error {713 job := new(Job)714 if err := db.Get(c, jobKey, job); err != nil {715 return fmt.Errorf("job %v: failed to get job: %v", jobID, err)716 }717 job.Reported = true718 // Auto-mark the bug as fixed by the result of fix bisection,719 // if the setting is enabled for the namespace.720 if job.Type == JobBisectFix &&721 config.Namespaces[job.Namespace].FixBisectionAutoClose &&722 len(job.Commits) == 1 {723 bug := new(Bug)724 bugKey := jobKey.Parent()725 if err := db.Get(c, bugKey, bug); err != nil {726 return fmt.Errorf("failed to get bug: %v", err)727 }728 if bug.Status == BugStatusOpen && len(bug.Commits) == 0 {729 bug.updateCommits([]string{job.Commits[0].Title}, now)730 if _, err := db.Put(c, bugKey, bug); err != nil {731 return fmt.Errorf("failed to put bug: %v", err)732 }733 }734 }735 if _, err := db.Put(c, jobKey, job); err != nil {736 return fmt.Errorf("failed to put job: %v", err)737 }738 return nil739 }740 return db.RunInTransaction(c, tx, nil)741}742func loadPendingJob(c context.Context, managers map[string]dashapi.ManagerJobs) (*Job, *db.Key, error) {743 var jobs []*Job744 keys, err := db.NewQuery("Job").745 Filter("Finished=", time.Time{}).746 Order("Attempts").747 Order("Created").748 GetAll(c, &jobs)749 if err != nil {750 return nil, nil, fmt.Errorf("failed to query jobs: %v", err)751 }752 for i, job := range jobs {753 switch job.Type {754 case JobTestPatch:755 if !managers[job.Manager].TestPatches {756 continue757 }758 case JobBisectCause, JobBisectFix:759 if job.Type == JobBisectCause && !managers[job.Manager].BisectCause ||760 job.Type == JobBisectFix && !managers[job.Manager].BisectFix {761 continue762 }763 // Don't retry bisection jobs too often.764 // This allows to have several syz-ci's doing bisection765 // and protects from bisection job crashing syz-ci.766 const bisectRepeat = 3 * 24 * time.Hour767 if timeSince(c, job.Created) < bisectRepeat ||768 timeSince(c, job.Started) < bisectRepeat {769 continue770 }771 default:772 return nil, nil, fmt.Errorf("bad job type %v", job.Type)773 }774 return job, keys[i], nil775 }776 return nil, nil, nil777}778func extJobID(jobKey *db.Key) string {779 return fmt.Sprintf("%v|%v", jobKey.Parent().StringID(), jobKey.IntID())780}781func jobID2Key(c context.Context, id string) (*db.Key, error) {782 keyStr := strings.Split(id, "|")783 if len(keyStr) != 2 {784 return nil, fmt.Errorf("bad job id %q", id)785 }786 jobKeyID, err := strconv.ParseInt(keyStr[1], 10, 64)787 if err != nil {788 return nil, fmt.Errorf("bad job id %q", id)789 }790 bugKey := db.NewKey(c, "Bug", keyStr[0], 0, nil)791 jobKey := db.NewKey(c, "Job", "", jobKeyID, bugKey)792 return jobKey, nil793}...

Full Screen

Full Screen

jobID2Key

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Code to use jobID2Key method of main class")4 fmt.Println("Job ID: 1")5 fmt.Println("Key: " + jobID2Key(1))6 fmt.Println("Job ID: 2")7 fmt.Println("Key: " + jobID2Key(2))8 fmt.Println("Job ID: 3")9 fmt.Println("Key: " + jobID2Key(3))10 fmt.Println("Job ID: 4")11 fmt.Println("Key: " + jobID2Key(4))12 fmt.Println("Job ID: 5")13 fmt.Println("Key: " + jobID2Key(5))14 fmt.Println("Job ID: 6")15 fmt.Println("Key: " + jobID2Key(6))16 fmt.Println("Job ID: 7")17 fmt.Println("Key: " + jobID2Key(7))18 fmt.Println("Job ID: 8")19 fmt.Println("Key: " + jobID2Key(8))20 fmt.Println("Job ID: 9")21 fmt.Println("Key: " + jobID2Key(9))22 fmt.Println("Job ID: 10")23 fmt.Println("Key: " + jobID2Key(10))24 fmt.Println("Job ID: 11")25 fmt.Println("Key: " + jobID2Key(11))26 fmt.Println("Job ID: 12")27 fmt.Println("Key: " + jobID2Key(12))28 fmt.Println("Job ID: 13")29 fmt.Println("Key: " + jobID2Key(13))30 fmt.Println("Job ID: 14")31 fmt.Println("Key: " + jobID2Key(14))32 fmt.Println("Job ID: 15")33 fmt.Println("Key: " + jobID2Key(15))34 fmt.Println("Job ID: 16")35 fmt.Println("Key: " + jobID2Key(16))36 fmt.Println("Job ID: 17")37 fmt.Println("Key: " + jobID2Key(17))38 fmt.Println("Job ID: 18")39 fmt.Println("Key: " + jobID2Key(18))40 fmt.Println("Job ID: 19")41 fmt.Println("Key: " + jobID2Key(19))42 fmt.Println("Job ID: 20")43 fmt.Println("Key: " +

Full Screen

Full Screen

jobID2Key

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 key := jobID2Key(jobID)4 fmt.Println("Key for jobID: ", jobID, " is: ", key)5}6func jobID2Key(jobID int) string {7 return "job:" + strconv.Itoa(jobID)8}

Full Screen

Full Screen

jobID2Key

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 key := chakra.JobID2Key(jobID)4 logger.Log("key", key)5 fmt.Println(key)6}

Full Screen

Full Screen

jobID2Key

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println(jobID2Key.JobID2Key("jobID"))4}5import (6func main() {7 fmt.Println(jobID2Key.JobID2Key("jobID"))8}9import (10func main() {11 fmt.Println(jobID2Key.JobID2Key("jobID"))12}13import (14func main() {15 fmt.Println(jobID2Key.JobID2Key("jobID"))16}17import (18func main() {19 fmt.Println(jobID2Key.JobID2Key("jobID"))20}21import (22func main() {23 fmt.Println(jobID2Key.JobID2Key("jobID"))24}25import (26func main() {27 fmt.Println(jobID2Key.JobID2Key("jobID"))28}29import (30func main() {

Full Screen

Full Screen

jobID2Key

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 jobID := [32]byte{100, 200, 300, 400, 500, 600, 700, 800, 900, 1000}4 jobID2Key := crypto.Keccak256Hash(jobID[:])5 fmt.Println("jobID2Key: ", jobID2Key)6 fmt.Println("jobID2Key as hex: ", common.ToHex(jobID2Key[:]))7}

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