How to use addCommitsToBugs method of main Package

Best Syzkaller code snippet using main.addCommitsToBugs

api.go

Source:api.go Github

copy

Full Screen

...240 if err := json.Unmarshal(payload, req); err != nil {241 return nil, fmt.Errorf("failed to unmarshal request: %v", err)242 }243 // This adds fixing commits to bugs.244 err := addCommitsToBugs(c, ns, "", nil, req.Commits)245 if err != nil {246 return nil, err247 }248 // Now add commit info to commits.249 for _, com := range req.Commits {250 if com.Hash == "" {251 continue252 }253 if err := addCommitInfo(c, ns, com); err != nil {254 return nil, err255 }256 }257 return nil, nil258}259func addCommitInfo(c context.Context, ns string, com dashapi.Commit) error {260 var bugs []*Bug261 keys, err := db.NewQuery("Bug").262 Filter("Namespace=", ns).263 Filter("Commits=", com.Title).264 GetAll(c, &bugs)265 if err != nil {266 return fmt.Errorf("failed to query bugs: %v", err)267 }268 for i, bug := range bugs {269 if err := addCommitInfoToBug(c, bug, keys[i], com); err != nil {270 return err271 }272 }273 return nil274}275func addCommitInfoToBug(c context.Context, bug *Bug, bugKey *db.Key, com dashapi.Commit) error {276 if needUpdate, err := addCommitInfoToBugImpl(c, bug, com); err != nil {277 return err278 } else if !needUpdate {279 return nil280 }281 tx := func(c context.Context) error {282 bug := new(Bug)283 if err := db.Get(c, bugKey, bug); err != nil {284 return fmt.Errorf("failed to get bug %v: %v", bugKey.StringID(), err)285 }286 if needUpdate, err := addCommitInfoToBugImpl(c, bug, com); err != nil {287 return err288 } else if !needUpdate {289 return nil290 }291 if _, err := db.Put(c, bugKey, bug); err != nil {292 return fmt.Errorf("failed to put bug: %v", err)293 }294 return nil295 }296 return db.RunInTransaction(c, tx, nil)297}298func addCommitInfoToBugImpl(c context.Context, bug *Bug, com dashapi.Commit) (bool, error) {299 ci := -1300 for i, title := range bug.Commits {301 if title == com.Title {302 ci = i303 break304 }305 }306 if ci < 0 {307 return false, nil308 }309 for len(bug.CommitInfo) < len(bug.Commits) {310 bug.CommitInfo = append(bug.CommitInfo, Commit{})311 }312 hash0 := bug.CommitInfo[ci].Hash313 date0 := bug.CommitInfo[ci].Date314 author0 := bug.CommitInfo[ci].Author315 needCommitInfo0 := bug.NeedCommitInfo316 bug.CommitInfo[ci].Hash = com.Hash317 bug.CommitInfo[ci].Date = com.Date318 bug.CommitInfo[ci].Author = com.Author319 bug.NeedCommitInfo = false320 for i := range bug.CommitInfo {321 if bug.CommitInfo[i].Hash == "" {322 bug.NeedCommitInfo = true323 break324 }325 }326 changed := hash0 != bug.CommitInfo[ci].Hash ||327 date0 != bug.CommitInfo[ci].Date ||328 author0 != bug.CommitInfo[ci].Author ||329 needCommitInfo0 != bug.NeedCommitInfo330 return changed, nil331}332func apiJobPoll(c context.Context, r *http.Request, payload []byte) (interface{}, error) {333 req := new(dashapi.JobPollReq)334 if err := json.Unmarshal(payload, req); err != nil {335 return nil, fmt.Errorf("failed to unmarshal request: %v", err)336 }337 if len(req.Managers) == 0 {338 return nil, fmt.Errorf("no managers")339 }340 return pollPendingJobs(c, req.Managers)341}342func apiJobDone(c context.Context, r *http.Request, payload []byte) (interface{}, error) {343 req := new(dashapi.JobDoneReq)344 if err := json.Unmarshal(payload, req); err != nil {345 return nil, fmt.Errorf("failed to unmarshal request: %v", err)346 }347 err := doneJob(c, req)348 return nil, err349}350func apiUploadBuild(c context.Context, ns string, r *http.Request, payload []byte) (interface{}, error) {351 req := new(dashapi.Build)352 if err := json.Unmarshal(payload, req); err != nil {353 return nil, fmt.Errorf("failed to unmarshal request: %v", err)354 }355 now := timeNow(c)356 _, isNewBuild, err := uploadBuild(c, now, ns, req, BuildNormal)357 if err != nil {358 return nil, err359 }360 if isNewBuild {361 err := updateManager(c, ns, req.Manager, func(mgr *Manager, stats *ManagerStats) error {362 prevKernel, prevSyzkaller := "", ""363 if mgr.CurrentBuild != "" {364 prevBuild, err := loadBuild(c, ns, mgr.CurrentBuild)365 if err != nil {366 return err367 }368 prevKernel = prevBuild.KernelCommit369 prevSyzkaller = prevBuild.SyzkallerCommit370 }371 log.Infof(c, "new build on %v: kernel %v->%v syzkaller %v->%v",372 req.Manager, prevKernel, req.KernelCommit, prevSyzkaller, req.SyzkallerCommit)373 mgr.CurrentBuild = req.ID374 if req.KernelCommit != prevKernel {375 mgr.FailedBuildBug = ""376 }377 if req.SyzkallerCommit != prevSyzkaller {378 mgr.FailedSyzBuildBug = ""379 }380 return nil381 })382 if err != nil {383 return nil, err384 }385 }386 if len(req.Commits) != 0 || len(req.FixCommits) != 0 {387 for i := range req.FixCommits {388 // Reset hashes just to make sure,389 // the build does not necessary come from the master repo, so we must not remember hashes.390 req.FixCommits[i].Hash = ""391 }392 if err := addCommitsToBugs(c, ns, req.Manager, req.Commits, req.FixCommits); err != nil {393 // We've already uploaded the build successfully and manager can use it.394 // Moreover, addCommitsToBugs scans all bugs and can take long time.395 // So just log the error.396 log.Errorf(c, "failed to add commits to bugs: %v", err)397 }398 }399 return nil, nil400}401func uploadBuild(c context.Context, now time.Time, ns string, req *dashapi.Build, typ BuildType) (402 *Build, bool, error) {403 if build, err := loadBuild(c, ns, req.ID); err == nil {404 return build, false, nil405 }406 checkStrLen := func(str, name string, maxLen int) error {407 if str == "" {408 return fmt.Errorf("%v is empty", name)409 }410 if len(str) > maxLen {411 return fmt.Errorf("%v is too long (%v)", name, len(str))412 }413 return nil414 }415 if err := checkStrLen(req.Manager, "Build.Manager", MaxStringLen); err != nil {416 return nil, false, err417 }418 if err := checkStrLen(req.ID, "Build.ID", MaxStringLen); err != nil {419 return nil, false, err420 }421 if err := checkStrLen(req.KernelRepo, "Build.KernelRepo", MaxStringLen); err != nil {422 return nil, false, err423 }424 if len(req.KernelBranch) > MaxStringLen {425 return nil, false, fmt.Errorf("Build.KernelBranch is too long (%v)", len(req.KernelBranch))426 }427 if err := checkStrLen(req.SyzkallerCommit, "Build.SyzkallerCommit", MaxStringLen); err != nil {428 return nil, false, err429 }430 if len(req.CompilerID) > MaxStringLen {431 return nil, false, fmt.Errorf("Build.CompilerID is too long (%v)", len(req.CompilerID))432 }433 if len(req.KernelCommit) > MaxStringLen {434 return nil, false, fmt.Errorf("Build.KernelCommit is too long (%v)", len(req.KernelCommit))435 }436 configID, err := putText(c, ns, textKernelConfig, req.KernelConfig, true)437 if err != nil {438 return nil, false, err439 }440 build := &Build{441 Namespace: ns,442 Manager: req.Manager,443 ID: req.ID,444 Type: typ,445 Time: now,446 OS: req.OS,447 Arch: req.Arch,448 VMArch: req.VMArch,449 SyzkallerCommit: req.SyzkallerCommit,450 SyzkallerCommitDate: req.SyzkallerCommitDate,451 CompilerID: req.CompilerID,452 KernelRepo: req.KernelRepo,453 KernelBranch: req.KernelBranch,454 KernelCommit: req.KernelCommit,455 KernelCommitTitle: req.KernelCommitTitle,456 KernelCommitDate: req.KernelCommitDate,457 KernelConfig: configID,458 }459 if _, err := db.Put(c, buildKey(c, ns, req.ID), build); err != nil {460 return nil, false, err461 }462 return build, true, nil463}464func addCommitsToBugs(c context.Context, ns, manager string, titles []string, fixCommits []dashapi.Commit) error {465 presentCommits := make(map[string]bool)466 bugFixedBy := make(map[string][]string)467 for _, com := range titles {468 presentCommits[com] = true469 }470 for _, com := range fixCommits {471 presentCommits[com.Title] = true472 for _, bugID := range com.BugIDs {473 bugFixedBy[bugID] = append(bugFixedBy[bugID], com.Title)474 }475 }476 managers, err := managerList(c, ns)477 if err != nil {478 return err479 }480 // Fetching all bugs in a namespace can be slow, and there is no way to filter only Open/Dup statuses.481 // So we run a separate query for each status, this both avoids fetching unnecessary data482 // and splits a long query into two (two smaller queries have lower chances of trigerring483 // timeouts than one huge).484 for _, status := range []int{BugStatusOpen, BugStatusDup} {485 err := addCommitsToBugsInStatus(c, status, ns, manager, managers, presentCommits, bugFixedBy)486 if err != nil {487 return err488 }489 }490 return nil491}492func addCommitsToBugsInStatus(c context.Context, status int, ns, manager string, managers []string,493 presentCommits map[string]bool, bugFixedBy map[string][]string) error {494 bugs, _, err := loadAllBugs(c, func(query *db.Query) *db.Query {495 return query.Filter("Namespace=", ns).496 Filter("Status=", status)497 })498 if err != nil {499 return err500 }501 for _, bug := range bugs {502 var fixCommits []string503 for i := range bug.Reporting {504 fixCommits = append(fixCommits, bugFixedBy[bug.Reporting[i].ID]...)505 }506 sort.Strings(fixCommits)...

Full Screen

Full Screen

addCommitsToBugs

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 scanner := bufio.NewScanner(os.Stdin)4 for scanner.Scan() {5 line := scanner.Text()6 if strings.Contains(line, "Bug:") {7 bugid := strings.Split(line, " ")[1]8 fmt.Println(bugid)9 }10 }11}

Full Screen

Full Screen

addCommitsToBugs

Using AI Code Generation

copy

Full Screen

1import "fmt"2func main() {3 fmt.Println("Hello, playground")4}5import "fmt"6func main() {7 fmt.Println("Hello, playground")8}9import "fmt"10func main() {11 fmt.Println("Hello, playground")12}13import "fmt"14func main() {15 fmt.Println("Hello, playground")16}

Full Screen

Full Screen

addCommitsToBugs

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 f, err := os.Open("commits.txt")4 if err != nil {5 panic(err)6 }7 scanner := bufio.NewScanner(f)8 for scanner.Scan() {9 parts := strings.SplitN(scanner.Text(), " ", 2)10 i, err := strconv.Atoi(parts[0])11 if err != nil {12 panic(err)13 }14 t, err := time.Parse("Mon Jan 2 15:04:05 2006 -0700", parts[1])15 if err != nil {16 panic(err)17 }18 addCommitsToBugs(i, t)19 }20}21import (22func main() {23 f, err := os.Open("commits.txt")24 if err != nil {25 panic(err)26 }27 scanner := bufio.NewScanner(f)28 for scanner.Scan() {29 parts := strings.SplitN(scanner.Text(), " ", 2)30 i, err := strconv.Atoi(parts[0])31 if err != nil {32 panic(err)33 }34 t, err := time.Parse("Mon Jan 2 15:04:05 2006 -0700", parts[1])35 if err != nil {36 panic(err)37 }38 addCommitsToBugs(i, t)39 }40}41import (

Full Screen

Full Screen

addCommitsToBugs

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 c.init()4 c.addCommitsToBugs()5}6import (7func main() {8 file, err := os.Open("data.txt")9 if err != nil {10 panic(err)11 }12 defer file.Close()13 scanner := bufio.NewScanner(file)14 for scanner.Scan() {15 line := scanner.Text()16 words := strings.Fields(line)17 fmt.Println(words)18 }19 if err := scanner.Err(); err != nil {20 panic(err)21 }22}23import (24func main() {25 file, err := os.Open("data.txt")26 if err != nil {27 panic(err)28 }29 defer file.Close()30 scanner := bufio.NewScanner(file)31 for scanner.Scan() {32 line := scanner.Text()33 words := strings.Fields(line)34 fmt.Println(words)35 }36 if err := scanner.Err(); err != nil {37 panic(err)38 }39}40import (41type mainClass struct {42}43type Commit struct {44}45func (c *mainClass) init() {46 file, err := os.Open("data.txt")47 if err != nil {48 panic(err)49 }50 defer file.Close()51 scanner := bufio.NewScanner(file)52 for scanner.Scan() {53 line := scanner.Text()54 words := strings.Fields(line)55 for i := 1; i < len(words); i++ {56 commit.bugs = append(commit.bugs, words[i])57 }58 c.commits = append(c.commits, commit)59 }60 if err := scanner.Err(); err != nil {61 panic(err)62 }63}64func (c *mainClass) addCommits

Full Screen

Full Screen

addCommitsToBugs

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 bug1 := bug.Bug{Title: "bug1", Desc: "desc1", Status: "open", Priority: "high", ID: 1, Comments: []bug.Comment{}}4 bug2 := bug.Bug{Title: "bug2", Desc: "desc2", Status: "open", Priority: "high", ID: 2, Comments: []bug.Comment{}}5 bug3 := bug.Bug{Title: "bug3", Desc: "desc3", Status: "open", Priority: "high", ID: 3, Comments: []bug.Comment{}}6 bug4 := bug.Bug{Title: "bug4", Desc: "desc4", Status: "open", Priority: "high", ID: 4, Comments: []bug.Comment{}}7 bug5 := bug.Bug{Title: "bug5", Desc: "desc5", Status: "open", Priority: "high", ID: 5, Comments: []bug.Comment{}}8 bug6 := bug.Bug{Title: "bug6", Desc: "desc6", Status: "open", Priority: "high", ID: 6, Comments: []bug.Comment{}}9 bug7 := bug.Bug{Title: "bug7", Desc: "desc7", Status: "open", Priority: "high", ID: 7, Comments: []bug.Comment{}}10 bug8 := bug.Bug{Title: "bug8", Desc: "desc8", Status: "open", Priority: "high", ID: 8, Comments: []bug.Comment{}}11 bug9 := bug.Bug{Title: "bug9", Desc: "desc9", Status: "open", Priority: "high", ID: 9, Comments: []bug.Comment{}}12 bug10 := bug.Bug{Title: "bug10", Desc: "desc10", Status: "open", Priority: "high", ID: 10, Comments: []bug.Comment{}}13 bug11 := bug.Bug{Title: "bug11", Desc: "desc11", Status: "open", Priority: "high", ID: 11, Comments: []bug.Comment{}}14 bug12 := bug.Bug{Title: "bug12

Full Screen

Full Screen

addCommitsToBugs

Using AI Code Generation

copy

Full Screen

1import (2type Bug struct {3}4type Commit struct {5}6func main() {7 bugs, err := addCommitsToBugs("bugs.txt", "commits.txt")8 if err != nil {9 fmt.Println("Error in bugs")10 }11 for _, bug := range bugs {12 fmt.Println("Bug ID: ", bug.id)13 fmt.Println("Commits:")14 for _, commit := range bug.commits {15 fmt.Println("\tCommit ID: ", commit.id)16 fmt.Println("\tCommit Message: ", commit.message)17 fmt.Println("\tCommit Author: ", commit.author)18 fmt.Println("\tCommit Time: ", commit.time)19 }20 }21}22func addCommitsToBugs(bugsFile string, commitsFile string) (BugSet, error) {23 bugs, err := os.Open(bugsFile)24 if err != nil {25 }26 defer bugs.Close()27 commits, err := os.Open(commitsFile)28 if err != nil {29 }30 defer commits.Close()31 bugMap := make(map[int]Bug)32 bugReader := bufio.NewReader(bugs)33 for {34 line, err := bugReader.ReadString('\n')35 if err != nil {36 if err == io.EOF {37 }38 }39 bugNum, err := parseBugLine(line)40 if err != nil {41 }42 bugMap[bugNum] = Bug{bugNum, []Commit{}}43 }44 commitReader := bufio.NewReader(commits)45 for {

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