How to use canonicalBug method of main Package

Best Syzkaller code snippet using main.canonicalBug

api.go

Source:api.go Github

copy

Full Screen

...507 if err := addCommitsToBug(c, bug, manager, managers, fixCommits, presentCommits); err != nil {508 return err509 }510 if bug.Status == BugStatusDup {511 canon, err := canonicalBug(c, bug)512 if err != nil {513 return err514 }515 if canon.Status == BugStatusOpen && len(bug.Commits) == 0 {516 if err := addCommitsToBug(c, canon, manager, managers,517 fixCommits, presentCommits); err != nil {518 return err519 }520 }521 }522 }523 return nil524}525func addCommitsToBug(c context.Context, bug *Bug, manager string, managers []string,526 fixCommits []string, presentCommits map[string]bool) error {527 if !bugNeedsCommitUpdate(c, bug, manager, fixCommits, presentCommits, true) {528 return nil529 }530 now := timeNow(c)531 bugKey := bug.key(c)532 tx := func(c context.Context) error {533 bug := new(Bug)534 if err := db.Get(c, bugKey, bug); err != nil {535 return fmt.Errorf("failed to get bug %v: %v", bugKey.StringID(), err)536 }537 if !bugNeedsCommitUpdate(c, bug, manager, fixCommits, presentCommits, false) {538 return nil539 }540 if len(fixCommits) != 0 && !reflect.DeepEqual(bug.Commits, fixCommits) {541 bug.updateCommits(fixCommits, now)542 }543 if manager != "" {544 bug.PatchedOn = append(bug.PatchedOn, manager)545 if bug.Status == BugStatusOpen {546 fixed := true547 for _, mgr := range managers {548 if !stringInList(bug.PatchedOn, mgr) {549 fixed = false550 break551 }552 }553 if fixed {554 bug.Status = BugStatusFixed555 bug.Closed = now556 }557 }558 }559 if _, err := db.Put(c, bugKey, bug); err != nil {560 return fmt.Errorf("failed to put bug: %v", err)561 }562 return nil563 }564 return db.RunInTransaction(c, tx, nil)565}566func bugNeedsCommitUpdate(c context.Context, bug *Bug, manager string, fixCommits []string,567 presentCommits map[string]bool, dolog bool) bool {568 if len(fixCommits) != 0 && !reflect.DeepEqual(bug.Commits, fixCommits) {569 if dolog {570 log.Infof(c, "bug %q is fixed with %q", bug.Title, fixCommits)571 }572 return true573 }574 if len(bug.Commits) == 0 || manager == "" || stringInList(bug.PatchedOn, manager) {575 return false576 }577 for _, com := range bug.Commits {578 if !presentCommits[com] {579 return false580 }581 }582 return true583}584func managerList(c context.Context, ns string) ([]string, error) {585 var builds []*Build586 _, err := db.NewQuery("Build").587 Filter("Namespace=", ns).588 Project("Manager").589 Distinct().590 GetAll(c, &builds)591 if err != nil {592 return nil, fmt.Errorf("failed to query builds: %v", err)593 }594 configManagers := config.Namespaces[ns].Managers595 var managers []string596 for _, build := range builds {597 if configManagers[build.Manager].Decommissioned {598 continue599 }600 managers = append(managers, build.Manager)601 }602 return managers, nil603}604func stringInList(list []string, str string) bool {605 for _, s := range list {606 if s == str {607 return true608 }609 }610 return false611}612func apiReportBuildError(c context.Context, ns string, r *http.Request, payload []byte) (interface{}, error) {613 req := new(dashapi.BuildErrorReq)614 if err := json.Unmarshal(payload, req); err != nil {615 return nil, fmt.Errorf("failed to unmarshal request: %v", err)616 }617 now := timeNow(c)618 build, _, err := uploadBuild(c, now, ns, &req.Build, BuildFailed)619 if err != nil {620 return nil, err621 }622 req.Crash.BuildID = req.Build.ID623 bug, err := reportCrash(c, build, &req.Crash)624 if err != nil {625 return nil, err626 }627 if err := updateManager(c, ns, req.Build.Manager, func(mgr *Manager, stats *ManagerStats) error {628 log.Infof(c, "failed build on %v: kernel=%v", req.Build.Manager, req.Build.KernelCommit)629 if req.Build.KernelCommit != "" {630 mgr.FailedBuildBug = bug.keyHash()631 } else {632 mgr.FailedSyzBuildBug = bug.keyHash()633 }634 return nil635 }); err != nil {636 return nil, err637 }638 return nil, nil639}640const corruptedReportTitle = "corrupted report"641func apiReportCrash(c context.Context, ns string, r *http.Request, payload []byte) (interface{}, error) {642 req := new(dashapi.Crash)643 if err := json.Unmarshal(payload, req); err != nil {644 return nil, fmt.Errorf("failed to unmarshal request: %v", err)645 }646 build, err := loadBuild(c, ns, req.BuildID)647 if err != nil {648 return nil, err649 }650 if !config.Namespaces[ns].TransformCrash(build, req) {651 return new(dashapi.ReportCrashResp), nil652 }653 bug, err := reportCrash(c, build, req)654 if err != nil {655 return nil, err656 }657 resp := &dashapi.ReportCrashResp{658 NeedRepro: needRepro(c, bug),659 }660 return resp, nil661}662func reportCrash(c context.Context, build *Build, req *dashapi.Crash) (*Bug, error) {663 req.Title = limitLength(req.Title, maxTextLen)664 req.Maintainers = email.MergeEmailLists(req.Maintainers)665 if req.Corrupted {666 // The report is corrupted and the title is most likely invalid.667 // Such reports are usually unactionable and are discarded.668 // Collect them into a single bin.669 req.Title = corruptedReportTitle670 }671 ns := build.Namespace672 bug, bugKey, err := findBugForCrash(c, ns, req.Title)673 if err != nil {674 return nil, err675 }676 if active, err := isActiveBug(c, bug); err != nil {677 return nil, err678 } else if !active {679 bug, bugKey, err = createBugForCrash(c, ns, req)680 if err != nil {681 return nil, err682 }683 }684 now := timeNow(c)685 reproLevel := ReproLevelNone686 if len(req.ReproC) != 0 {687 reproLevel = ReproLevelC688 } else if len(req.ReproSyz) != 0 {689 reproLevel = ReproLevelSyz690 }691 save := reproLevel != ReproLevelNone ||692 bug.NumCrashes < maxCrashes ||693 now.Sub(bug.LastSavedCrash) > time.Hour ||694 bug.NumCrashes%20 == 0695 if save {696 if err := saveCrash(c, ns, req, bugKey, build); err != nil {697 return nil, err698 }699 } else {700 log.Infof(c, "not saving crash for %q", bug.Title)701 }702 tx := func(c context.Context) error {703 bug = new(Bug)704 if err := db.Get(c, bugKey, bug); err != nil {705 return fmt.Errorf("failed to get bug: %v", err)706 }707 bug.NumCrashes++708 bug.LastTime = now709 if save {710 bug.LastSavedCrash = now711 }712 if reproLevel != ReproLevelNone {713 bug.NumRepro++714 bug.LastReproTime = now715 }716 if bug.ReproLevel < reproLevel {717 bug.ReproLevel = reproLevel718 }719 if len(req.Report) != 0 {720 bug.HasReport = true721 }722 if !stringInList(bug.HappenedOn, build.Manager) {723 bug.HappenedOn = append(bug.HappenedOn, build.Manager)724 }725 if _, err = db.Put(c, bugKey, bug); err != nil {726 return fmt.Errorf("failed to put bug: %v", err)727 }728 return nil729 }730 if err := db.RunInTransaction(c, tx, &db.TransactionOptions{XG: true}); err != nil {731 return nil, err732 }733 if save {734 purgeOldCrashes(c, bug, bugKey)735 }736 return bug, nil737}738func saveCrash(c context.Context, ns string, req *dashapi.Crash, bugKey *db.Key, build *Build) error {739 // Reporting priority of this crash.740 prio := int64(kernelRepoInfo(build).ReportingPriority) * 1e6741 if len(req.ReproC) != 0 {742 prio += 4e12743 } else if len(req.ReproSyz) != 0 {744 prio += 2e12745 }746 if build.Arch == "amd64" {747 prio += 1e3748 }749 crash := &Crash{750 Manager: build.Manager,751 BuildID: req.BuildID,752 Time: timeNow(c),753 Maintainers: req.Maintainers,754 ReproOpts: req.ReproOpts,755 ReportLen: prio,756 }757 var err error758 if crash.Log, err = putText(c, ns, textCrashLog, req.Log, false); err != nil {759 return err760 }761 if crash.Report, err = putText(c, ns, textCrashReport, req.Report, false); err != nil {762 return err763 }764 if crash.ReproSyz, err = putText(c, ns, textReproSyz, req.ReproSyz, false); err != nil {765 return err766 }767 if crash.ReproC, err = putText(c, ns, textReproC, req.ReproC, false); err != nil {768 return err769 }770 crashKey := db.NewIncompleteKey(c, "Crash", bugKey)771 if _, err = db.Put(c, crashKey, crash); err != nil {772 return fmt.Errorf("failed to put crash: %v", err)773 }774 return nil775}776func purgeOldCrashes(c context.Context, bug *Bug, bugKey *db.Key) {777 const purgeEvery = 10778 if bug.NumCrashes <= 2*maxCrashes || (bug.NumCrashes-1)%purgeEvery != 0 {779 return780 }781 var crashes []*Crash782 keys, err := db.NewQuery("Crash").783 Ancestor(bugKey).784 Filter("Reported=", time.Time{}).785 GetAll(c, &crashes)786 if err != nil {787 log.Errorf(c, "failed to fetch purge crashes: %v", err)788 return789 }790 keyMap := make(map[*Crash]*db.Key)791 for i, crash := range crashes {792 keyMap[crash] = keys[i]793 }794 // Newest first.795 sort.Slice(crashes, func(i, j int) bool {796 return crashes[i].Time.After(crashes[j].Time)797 })798 var toDelete []*db.Key799 latestOnManager := make(map[string]bool)800 deleted, reproCount, noreproCount := 0, 0, 0801 for _, crash := range crashes {802 if !crash.Reported.IsZero() {803 log.Errorf(c, "purging reported crash?")804 continue805 }806 // Preserve latest crash on each manager.807 if !latestOnManager[crash.Manager] {808 latestOnManager[crash.Manager] = true809 continue810 }811 // Preserve maxCrashes latest crashes with repro and without repro.812 count := &noreproCount813 if crash.ReproSyz != 0 || crash.ReproC != 0 {814 count = &reproCount815 }816 if *count < maxCrashes {817 *count++818 continue819 }820 toDelete = append(toDelete, keyMap[crash])821 if crash.Log != 0 {822 toDelete = append(toDelete, db.NewKey(c, textCrashLog, "", crash.Log, nil))823 }824 if crash.Report != 0 {825 toDelete = append(toDelete, db.NewKey(c, textCrashReport, "", crash.Report, nil))826 }827 if crash.ReproSyz != 0 {828 toDelete = append(toDelete, db.NewKey(c, textReproSyz, "", crash.ReproSyz, nil))829 }830 if crash.ReproC != 0 {831 toDelete = append(toDelete, db.NewKey(c, textReproC, "", crash.ReproC, nil))832 }833 deleted++834 if deleted == 2*purgeEvery {835 break836 }837 }838 if len(toDelete) == 0 {839 return840 }841 if err := db.DeleteMulti(c, toDelete); err != nil {842 log.Errorf(c, "failed to delete old crashes: %v", err)843 return844 }845 log.Infof(c, "deleted %v crashes for bug %q", deleted, bug.Title)846}847func apiReportFailedRepro(c context.Context, ns string, r *http.Request, payload []byte) (interface{}, error) {848 req := new(dashapi.CrashID)849 if err := json.Unmarshal(payload, req); err != nil {850 return nil, fmt.Errorf("failed to unmarshal request: %v", err)851 }852 req.Title = limitLength(req.Title, maxTextLen)853 bug, bugKey, err := findBugForCrash(c, ns, req.Title)854 if err != nil {855 return nil, err856 }857 if bug == nil {858 return nil, fmt.Errorf("%v: can't find bug for crash %q", ns, req.Title)859 }860 now := timeNow(c)861 tx := func(c context.Context) error {862 bug := new(Bug)863 if err := db.Get(c, bugKey, bug); err != nil {864 return fmt.Errorf("failed to get bug: %v", err)865 }866 bug.NumRepro++867 bug.LastReproTime = now868 if _, err := db.Put(c, bugKey, bug); err != nil {869 return fmt.Errorf("failed to put bug: %v", err)870 }871 return nil872 }873 err = db.RunInTransaction(c, tx, &db.TransactionOptions{874 XG: true,875 Attempts: 30,876 })877 return nil, err878}879func apiNeedRepro(c context.Context, ns string, r *http.Request, payload []byte) (interface{}, error) {880 req := new(dashapi.CrashID)881 if err := json.Unmarshal(payload, req); err != nil {882 return nil, fmt.Errorf("failed to unmarshal request: %v", err)883 }884 if req.Corrupted {885 resp := &dashapi.NeedReproResp{886 NeedRepro: false,887 }888 return resp, nil889 }890 req.Title = limitLength(req.Title, maxTextLen)891 bug, _, err := findBugForCrash(c, ns, req.Title)892 if err != nil {893 return nil, err894 }895 if bug == nil {896 return nil, fmt.Errorf("%v: can't find bug for crash %q", ns, req.Title)897 }898 resp := &dashapi.NeedReproResp{899 NeedRepro: needRepro(c, bug),900 }901 return resp, nil902}903func apiManagerStats(c context.Context, ns string, r *http.Request, payload []byte) (interface{}, error) {904 req := new(dashapi.ManagerStatsReq)905 if err := json.Unmarshal(payload, req); err != nil {906 return nil, fmt.Errorf("failed to unmarshal request: %v", err)907 }908 now := timeNow(c)909 err := updateManager(c, ns, req.Name, func(mgr *Manager, stats *ManagerStats) error {910 mgr.Link = req.Addr911 mgr.LastAlive = now912 mgr.CurrentUpTime = req.UpTime913 if cur := int64(req.Corpus); cur > stats.MaxCorpus {914 stats.MaxCorpus = cur915 }916 if cur := int64(req.PCs); cur > stats.MaxPCs {917 stats.MaxPCs = cur918 }919 if cur := int64(req.Cover); cur > stats.MaxCover {920 stats.MaxCover = cur921 }922 if cur := int64(req.CrashTypes); cur > stats.CrashTypes {923 stats.CrashTypes = cur924 }925 stats.TotalFuzzingTime += req.FuzzingTime926 stats.TotalCrashes += int64(req.Crashes)927 stats.SuppressedCrashes += int64(req.SuppressedCrashes)928 stats.TotalExecs += int64(req.Execs)929 return nil930 })931 return nil, err932}933func apiBugList(c context.Context, ns string, r *http.Request, payload []byte) (interface{}, error) {934 keys, err := db.NewQuery("Bug").935 Filter("Namespace=", ns).936 KeysOnly().937 GetAll(c, nil)938 if err != nil {939 return nil, fmt.Errorf("failed to query bugs: %v", err)940 }941 resp := &dashapi.BugListResp{}942 for _, key := range keys {943 resp.List = append(resp.List, key.StringID())944 }945 return resp, nil946}947func apiLoadBug(c context.Context, ns string, r *http.Request, payload []byte) (interface{}, error) {948 req := new(dashapi.LoadBugReq)949 if err := json.Unmarshal(payload, req); err != nil {950 return nil, fmt.Errorf("failed to unmarshal request: %v", err)951 }952 bug := new(Bug)953 bugKey := db.NewKey(c, "Bug", req.ID, 0, nil)954 if err := db.Get(c, bugKey, bug); err != nil {955 return nil, fmt.Errorf("failed to get bug: %v", err)956 }957 if bug.Namespace != ns {958 return nil, fmt.Errorf("no such bug")959 }960 if bug.sanitizeAccess(AccessPublic) > AccessPublic {961 return nil, nil962 }963 crash, _, err := findCrashForBug(c, bug)964 if err != nil {965 return nil, err966 }967 build, err := loadBuild(c, ns, crash.BuildID)968 if err != nil {969 return nil, err970 }971 reproSyz, _, err := getText(c, textReproSyz, crash.ReproSyz)972 if err != nil {973 return nil, err974 }975 reproC, _, err := getText(c, textReproC, crash.ReproC)976 if err != nil {977 return nil, err978 }979 statuses := map[int]string{980 BugStatusOpen: "open",981 BugStatusFixed: "fixed",982 BugStatusInvalid: "invalid",983 BugStatusDup: "dup",984 }985 resp := &dashapi.LoadBugResp{986 ID: req.ID,987 Title: bug.displayTitle(),988 Status: statuses[bug.Status],989 SyzkallerCommit: build.SyzkallerCommit,990 ReproOpts: crash.ReproOpts,991 ReproSyz: reproSyz,992 ReproC: reproC,993 }994 return resp, nil995}996func findBugForCrash(c context.Context, ns, title string) (*Bug, *db.Key, error) {997 var bugs []*Bug998 keys, err := db.NewQuery("Bug").999 Filter("Namespace=", ns).1000 Filter("Title=", title).1001 Order("-Seq").1002 Limit(1).1003 GetAll(c, &bugs)1004 if err != nil {1005 return nil, nil, fmt.Errorf("failed to query bugs: %v", err)1006 }1007 if len(bugs) == 0 {1008 return nil, nil, nil1009 }1010 return bugs[0], keys[0], nil1011}1012func createBugForCrash(c context.Context, ns string, req *dashapi.Crash) (*Bug, *db.Key, error) {1013 var bug *Bug1014 var bugKey *db.Key1015 now := timeNow(c)1016 tx := func(c context.Context) error {1017 for seq := int64(0); ; seq++ {1018 bug = new(Bug)1019 bugHash := bugKeyHash(ns, req.Title, seq)1020 bugKey = db.NewKey(c, "Bug", bugHash, 0, nil)1021 if err := db.Get(c, bugKey, bug); err != nil {1022 if err != db.ErrNoSuchEntity {1023 return fmt.Errorf("failed to get bug: %v", err)1024 }1025 bug = &Bug{1026 Namespace: ns,1027 Seq: seq,1028 Title: req.Title,1029 Status: BugStatusOpen,1030 NumCrashes: 0,1031 NumRepro: 0,1032 ReproLevel: ReproLevelNone,1033 HasReport: false,1034 FirstTime: now,1035 LastTime: now,1036 }1037 createBugReporting(bug, config.Namespaces[ns])1038 if bugKey, err = db.Put(c, bugKey, bug); err != nil {1039 return fmt.Errorf("failed to put new bug: %v", err)1040 }1041 return nil1042 }1043 canon, err := canonicalBug(c, bug)1044 if err != nil {1045 return err1046 }1047 if canon.Status != BugStatusOpen {1048 continue1049 }1050 return nil1051 }1052 }1053 if err := db.RunInTransaction(c, tx, &db.TransactionOptions{1054 XG: true,1055 Attempts: 30,1056 }); err != nil {1057 return nil, nil, err1058 }1059 return bug, bugKey, nil1060}1061func createBugReporting(bug *Bug, cfg *Config) {1062 for len(bug.Reporting) < len(cfg.Reporting) {1063 rep := &cfg.Reporting[len(bug.Reporting)]1064 bug.Reporting = append(bug.Reporting, BugReporting{1065 Name: rep.Name,1066 ID: bugReportingHash(bug.keyHash(), rep.Name),1067 })1068 }1069}1070func isActiveBug(c context.Context, bug *Bug) (bool, error) {1071 if bug == nil {1072 return false, nil1073 }1074 canon, err := canonicalBug(c, bug)1075 if err != nil {1076 return false, err1077 }1078 return canon.Status == BugStatusOpen, nil1079}1080func needRepro(c context.Context, bug *Bug) bool {1081 if !needReproForBug(c, bug) {1082 return false1083 }1084 canon, err := canonicalBug(c, bug)1085 if err != nil {1086 log.Errorf(c, "failed to get canonical bug: %v", err)1087 return false1088 }1089 return needReproForBug(c, canon)1090}1091func needReproForBug(c context.Context, bug *Bug) bool {1092 return bug.ReproLevel < ReproLevelC &&1093 len(bug.Commits) == 0 &&1094 bug.Title != corruptedReportTitle &&1095 config.Namespaces[bug.Namespace].NeedRepro(bug) &&1096 (bug.NumRepro < maxReproPerBug ||1097 bug.ReproLevel == ReproLevelNone &&1098 timeSince(c, bug.LastReproTime) > reproRetryPeriod)...

Full Screen

Full Screen

reporting.go

Source:reporting.go Github

copy

Full Screen

...298 if bug == nil {299 continue300 }301 bugReporting, _ := bugReportingByID(bug, id)302 bug, err = canonicalBug(c, bug)303 if err != nil {304 log.Errorf(c, "%v", err)305 continue306 }307 if bug.Status >= BugStatusFixed || !bugReporting.Closed.IsZero() {308 closed = append(closed, id)309 }310 }311 return closed, nil312}313// incomingCommand is entry point to bug status updates.314func incomingCommand(c context.Context, cmd *dashapi.BugUpdate) (bool, string, error) {315 log.Infof(c, "got command: %+v", cmd)316 ok, reason, err := incomingCommandImpl(c, cmd)317 if err != nil {318 log.Errorf(c, "%v (%v)", reason, err)319 } else if !ok && reason != "" {320 log.Errorf(c, "invalid update: %v", reason)321 }322 return ok, reason, err323}324func incomingCommandImpl(c context.Context, cmd *dashapi.BugUpdate) (bool, string, error) {325 for i, com := range cmd.FixCommits {326 if len(com) >= 2 && com[0] == '"' && com[len(com)-1] == '"' {327 com = com[1 : len(com)-1]328 cmd.FixCommits[i] = com329 }330 if len(com) < 3 {331 return false, fmt.Sprintf("bad commit title: %q", com), nil332 }333 }334 bug, bugKey, err := findBugByReportingID(c, cmd.ID)335 if err != nil {336 return false, internalError, err337 }338 now := timeNow(c)339 dupHash := ""340 if cmd.Status == dashapi.BugStatusDup {341 bugReporting, _ := bugReportingByID(bug, cmd.ID)342 dup, dupKey, err := findBugByReportingID(c, cmd.DupOf)343 if err != nil {344 // Email reporting passes bug title in cmd.DupOf, try to find bug by title.345 dup, dupKey, err = findDupByTitle(c, bug.Namespace, cmd.DupOf)346 if err != nil {347 return false, "can't find the dup bug", err348 }349 dupReporting := bugReportingByName(dup, bugReporting.Name)350 if dupReporting == nil {351 return false, "can't find the dup bug",352 fmt.Errorf("dup does not have reporting %q", bugReporting.Name)353 }354 cmd.DupOf = dupReporting.ID355 }356 dupReporting, _ := bugReportingByID(dup, cmd.DupOf)357 if bugReporting == nil || dupReporting == nil {358 return false, internalError, fmt.Errorf("can't find bug reporting")359 }360 if bugKey.StringID() == dupKey.StringID() {361 if bugReporting.Name == dupReporting.Name {362 return false, "Can't dup bug to itself.", nil363 }364 return false, fmt.Sprintf("Can't dup bug to itself in different reporting (%v->%v).\n"+365 "Please dup syzbot bugs only onto syzbot bugs for the same kernel/reporting.",366 bugReporting.Name, dupReporting.Name), nil367 }368 if bug.Namespace != dup.Namespace {369 return false, fmt.Sprintf("Duplicate bug corresponds to a different kernel (%v->%v).\n"+370 "Please dup syzbot bugs only onto syzbot bugs for the same kernel.",371 bug.Namespace, dup.Namespace), nil372 }373 if bugReporting.Name != dupReporting.Name {374 return false, fmt.Sprintf("Can't dup bug to a bug in different reporting (%v->%v)."+375 "Please dup syzbot bugs only onto syzbot bugs for the same kernel/reporting.",376 bugReporting.Name, dupReporting.Name), nil377 }378 dupCanon, err := canonicalBug(c, dup)379 if err != nil {380 return false, internalError, fmt.Errorf("failed to get canonical bug for dup: %v", err)381 }382 if !dupReporting.Closed.IsZero() && dupCanon.Status == BugStatusOpen {383 return false, "Dup bug is already upstreamed.", nil384 }385 dupHash = bugKeyHash(dup.Namespace, dup.Title, dup.Seq)386 }387 ok, reply := false, ""388 tx := func(c context.Context) error {389 var err error390 ok, reply, err = incomingCommandTx(c, now, cmd, bugKey, dupHash)391 return err392 }393 err = datastore.RunInTransaction(c, tx, &datastore.TransactionOptions{394 XG: true,395 // Default is 3 which fails sometimes.396 // We don't want incoming bug updates to fail,397 // because for e.g. email we won't have an external retry.398 Attempts: 30,399 })400 if err != nil {401 return false, internalError, err402 }403 return ok, reply, nil404}405func incomingCommandTx(c context.Context, now time.Time, cmd *dashapi.BugUpdate,406 bugKey *datastore.Key, dupHash string) (bool, string, error) {407 bug := new(Bug)408 if err := datastore.Get(c, bugKey, bug); err != nil {409 return false, internalError, fmt.Errorf("can't find the corresponding bug: %v", err)410 }411 bugReporting, final := bugReportingByID(bug, cmd.ID)412 if bugReporting == nil {413 return false, internalError, fmt.Errorf("can't find bug reporting")414 }415 if ok, reply, err := checkBugStatus(c, cmd, bug, bugReporting); !ok {416 return false, reply, err417 }418 state, err := loadReportingState(c)419 if err != nil {420 return false, internalError, err421 }422 stateEnt := state.getEntry(now, bug.Namespace, bugReporting.Name)423 switch cmd.Status {424 case dashapi.BugStatusOpen:425 bug.Status = BugStatusOpen426 bug.Closed = time.Time{}427 if bugReporting.Reported.IsZero() {428 bugReporting.Reported = now429 stateEnt.Sent++ // sending repro does not count against the quota430 }431 // Close all previous reporting if they are not closed yet432 // (can happen due to Status == ReportingDisabled).433 for i := range bug.Reporting {434 if bugReporting == &bug.Reporting[i] {435 break436 }437 if bug.Reporting[i].Closed.IsZero() {438 bug.Reporting[i].Closed = now439 }440 }441 if bug.ReproLevel < cmd.ReproLevel {442 return false, internalError,443 fmt.Errorf("bug update with invalid repro level: %v/%v",444 bug.ReproLevel, cmd.ReproLevel)445 }446 case dashapi.BugStatusUpstream:447 if final {448 return false, "Can't upstream, this is final destination.", nil449 }450 if len(bug.Commits) != 0 {451 // We could handle this case, but how/when it will occur452 // in real life is unclear now.453 return false, "Can't upstream this bug, the bug has fixing commits.", nil454 }455 bug.Status = BugStatusOpen456 bug.Closed = time.Time{}457 bugReporting.Closed = now458 case dashapi.BugStatusInvalid:459 bugReporting.Closed = now460 bug.Closed = now461 bug.Status = BugStatusInvalid462 case dashapi.BugStatusDup:463 bug.Status = BugStatusDup464 bug.Closed = now465 bug.DupOf = dupHash466 case dashapi.BugStatusUpdate:467 // Just update Link, Commits, etc below.468 default:469 return false, internalError, fmt.Errorf("unknown bug status %v", cmd.Status)470 }471 if len(cmd.FixCommits) != 0 && (bug.Status == BugStatusOpen || bug.Status == BugStatusDup) {472 sort.Strings(cmd.FixCommits)473 if !reflect.DeepEqual(bug.Commits, cmd.FixCommits) {474 bug.Commits = cmd.FixCommits475 bug.PatchedOn = nil476 }477 }478 if cmd.CrashID != 0 {479 // Rememeber that we've reported this crash.480 crash := new(Crash)481 crashKey := datastore.NewKey(c, "Crash", "", cmd.CrashID, bugKey)482 if err := datastore.Get(c, crashKey, crash); err != nil {483 return false, internalError, fmt.Errorf("failed to get reported crash %v: %v",484 cmd.CrashID, err)485 }486 crash.Reported = now487 if _, err := datastore.Put(c, crashKey, crash); err != nil {488 return false, internalError, fmt.Errorf("failed to put reported crash %v: %v",489 cmd.CrashID, err)490 }491 bugReporting.CrashID = cmd.CrashID492 }493 if bugReporting.ExtID == "" {494 bugReporting.ExtID = cmd.ExtID495 }496 if bugReporting.Link == "" {497 bugReporting.Link = cmd.Link498 }499 if len(cmd.CC) != 0 {500 merged := email.MergeEmailLists(strings.Split(bugReporting.CC, "|"), cmd.CC)501 bugReporting.CC = strings.Join(merged, "|")502 }503 if bugReporting.ReproLevel < cmd.ReproLevel {504 bugReporting.ReproLevel = cmd.ReproLevel505 }506 if bug.Status != BugStatusDup {507 bug.DupOf = ""508 }509 if _, err := datastore.Put(c, bugKey, bug); err != nil {510 return false, internalError, fmt.Errorf("failed to put bug: %v", err)511 }512 if err := saveReportingState(c, state); err != nil {513 return false, internalError, err514 }515 return true, "", nil516}517func checkBugStatus(c context.Context, cmd *dashapi.BugUpdate, bug *Bug, bugReporting *BugReporting) (518 bool, string, error) {519 switch bug.Status {520 case BugStatusOpen:521 case BugStatusDup:522 canon, err := canonicalBug(c, bug)523 if err != nil {524 return false, internalError, err525 }526 if canon.Status != BugStatusOpen {527 // We used to reject updates to closed bugs,528 // but this is confusing and non-actionable for users.529 // So now we fail the update, but give empty reason,530 // which means "don't notify user".531 if cmd.Status == dashapi.BugStatusUpdate {532 // This happens when people discuss old bugs.533 log.Infof(c, "Dup bug is already closed")534 } else {535 log.Errorf(c, "Dup bug is already closed")536 }...

Full Screen

Full Screen

canonicalBug

Using AI Code Generation

copy

Full Screen

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

Full Screen

Full Screen

canonicalBug

Using AI Code Generation

copy

Full Screen

1import "golang.org/x/tools/go/analysis/unitchecker"2func main() { unitchecker.Main(main.Analyzer) }3import "golang.org/x/tools/go/analysis/unitchecker"4func main() { unitchecker.Main(main.Analyzer) }5import "golang.org/x/tools/go/analysis/unitchecker"6func main() { unitchecker.Main(main.Analyzer) }7import "golang.org/x/tools/go/analysis/unitchecker"8func main() { unitchecker.Main(main.Analyzer) }9import "golang.org/x/tools/go/analysis/unitchecker"10func main() { unitchecker.Main(main.Analyzer) }11import "golang.org/x/tools/go/analysis/unitchecker"12func main() { unitchecker.Main(main.Analyzer) }13import "golang.org/x/tools/go/analysis/unitchecker"14func main() { unitchecker.Main(main.Analyzer) }15import "golang.org/x/tools/go/analysis/unitchecker"16func main() { unitchecker.Main(main.Analyzer) }17import "golang.org/x/tools/go/analysis/unitchecker"18func main() { unitchecker.Main(main.Analyzer) }19import "golang.org/x/tools/go/analysis/unitchecker"20func main() { unitchecker.Main(main.Analyzer) }21import "golang.org/x/tools/go/analysis/unitchecker"22func main() { unitchecker.Main(main.Analyzer) }

Full Screen

Full Screen

canonicalBug

Using AI Code Generation

copy

Full Screen

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

Full Screen

Full Screen

canonicalBug

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Hello World")4 main1 := new(main1)5 main1.canonicalBug()6}7import (8type main1 struct {9}10func (m *main1) canonicalBug() {11 fmt.Println("Canonical bug")12}

Full Screen

Full Screen

canonicalBug

Using AI Code Generation

copy

Full Screen

1import "fmt"2func main() {3 fmt.Println(main.CanonicalBug("test"))4}5import (6func main() {7 fmt.Println(a)8}9Why is there no semicolon after the import statement?10import (11func main() {12 fmt.Println(a)13}14Why is there no semicolon after the import statement?15import (16func main() {17 fmt.Println(a)18}19Why is there no semicolon after the import statement?20import (21func main() {22 fmt.Println(a)23}24Why is there no semicolon after the import statement?25import (26func main() {27 fmt.Println(a)28}29Why is there no semicolon after the import statement?

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