Best Syzkaller code snippet using dashapi.JobPoll
proxy.go
Source:proxy.go
...166 p.dashMu.RUnlock()167}168func (p *proxy) jobPoll(c *gin.Context, client, key string) {169 var (170 jobPollReq dashapi.JobPollReq171 payload = c.PostForm("payload")172 buf = bytes.NewBufferString(payload)173 )174 r, err := gzip.NewReader(buf)175 if err != nil {176 c.JSON(http.StatusBadRequest, gin.H{"error": errUnknownMethod.Error()})177 return178 }179 d := json.NewDecoder(r)180 if err := d.Decode(&jobPollReq); err != nil {181 c.JSON(http.StatusBadRequest, gin.H{"error": errUnknownMethod.Error()})182 return183 }184 if err := r.Close(); err != nil {185 c.JSON(http.StatusBadRequest, gin.H{"error": errUnknownMethod.Error()})186 return187 }188 p.dashMu.RLock()189 for _, dash := range p.dashes {190 _, err := dash.JobPoll(&jobPollReq)191 if err != nil {192 p.dashMu.RUnlock()193 c.JSON(http.StatusBadRequest, gin.H{"error": errUnknownMethod.Error()})194 return195 }196 }197 p.dashMu.RUnlock()198}199func (p *proxy) jobDone(c *gin.Context, client, key string) {200 var (201 jobDoneReq dashapi.JobDoneReq202 payload = c.PostForm("payload")203 buf = bytes.NewBufferString(payload)204 )...
jobs_test.go
Source:jobs_test.go
...65 c.incomingEmail(sender, "#syz test: git://git.git/git.git kernel-branch\n"+patch,66 EmailOptFrom("\"foo\" <blAcklisteD@dOmain.COM>"))67 c.expectOK(c.GET("/email_poll"))68 c.expectEQ(len(c.emailSink), 0)69 pollResp, _ := c.client2.JobPoll([]string{build.Manager})70 c.expectEQ(pollResp.ID, "")71 c.incomingEmail(sender, "#syz test: git://git.git/git.git kernel-branch\n"+patch,72 EmailOptMessageID(1), EmailOptFrom("test@requester.com"),73 EmailOptCC([]string{"somebody@else.com"}))74 c.expectOK(c.GET("/email_poll"))75 c.expectEQ(len(c.emailSink), 0)76 // A dup of the same request with the same Message-ID.77 c.incomingEmail(sender, "#syz test: git://git.git/git.git kernel-branch\n"+patch,78 EmailOptMessageID(1), EmailOptFrom("test@requester.com"),79 EmailOptCC([]string{"somebody@else.com"}))80 c.expectOK(c.GET("/email_poll"))81 c.expectEQ(len(c.emailSink), 0)82 pollResp, _ = c.client2.JobPoll([]string{"foobar"})83 c.expectEQ(pollResp.ID, "")84 pollResp, _ = c.client2.JobPoll([]string{build.Manager})85 c.expectEQ(pollResp.ID != "", true)86 c.expectEQ(pollResp.Manager, build.Manager)87 c.expectEQ(pollResp.KernelRepo, "git://git.git/git.git")88 c.expectEQ(pollResp.KernelBranch, "kernel-branch")89 c.expectEQ(pollResp.KernelConfig, build.KernelConfig)90 c.expectEQ(pollResp.SyzkallerCommit, build.SyzkallerCommit)91 c.expectEQ(pollResp.Patch, []byte(patch))92 c.expectEQ(pollResp.ReproOpts, []byte("repro opts"))93 c.expectEQ(pollResp.ReproSyz, []byte("repro syz"))94 c.expectEQ(pollResp.ReproC, []byte("repro C"))95 pollResp2, _ := c.client2.JobPoll([]string{build.Manager})96 c.expectEQ(pollResp2, pollResp)97 jobDoneReq := &dashapi.JobDoneReq{98 ID: pollResp.ID,99 Build: *build,100 CrashTitle: "test crash title",101 CrashLog: []byte("test crash log"),102 CrashReport: []byte("test crash report"),103 }104 c.client2.JobDone(jobDoneReq)105 c.expectOK(c.GET("/email_poll"))106 c.expectEQ(len(c.emailSink), 1)107 {108 dbJob, dbBuild := c.loadJob(pollResp.ID)109 patchLink := externalLink(c.ctx, textPatch, dbJob.Patch)110 kernelConfigLink := externalLink(c.ctx, textKernelConfig, dbBuild.KernelConfig)111 logLink := externalLink(c.ctx, textCrashLog, dbJob.CrashLog)112 msg := <-c.emailSink113 to := email.MergeEmailLists([]string{"test@requester.com", "somebody@else.com", mailingList})114 c.expectEQ(msg.To, to)115 c.expectEQ(msg.Subject, "Re: "+crash.Title)116 c.expectEQ(len(msg.Attachments), 0)117 body := fmt.Sprintf(`Hello,118syzbot has tested the proposed patch but the reproducer still triggered crash:119test crash title120test crash report121Tested on:122commit: 111111111111 kernel_commit_title1123git tree: repo1/branch1124console output: %[3]v125kernel config: %[2]v126compiler: compiler1127patch: %[1]v128`, patchLink, kernelConfigLink, logLink)129 if msg.Body != body {130 t.Fatalf("got email body:\n%s\n\nwant:\n%s", msg.Body, body)131 }132 c.checkURLContents(patchLink, []byte(patch))133 c.checkURLContents(kernelConfigLink, build.KernelConfig)134 c.checkURLContents(logLink, jobDoneReq.CrashLog)135 }136 // Testing fails with an error.137 c.incomingEmail(sender, "#syz test: git://git.git/git.git kernel-branch\n"+patch, EmailOptMessageID(2))138 pollResp, _ = c.client2.JobPoll([]string{build.Manager})139 jobDoneReq = &dashapi.JobDoneReq{140 ID: pollResp.ID,141 Build: *build,142 Error: []byte("failed to apply patch"),143 }144 c.client2.JobDone(jobDoneReq)145 c.expectOK(c.GET("/email_poll"))146 c.expectEQ(len(c.emailSink), 1)147 {148 dbJob, dbBuild := c.loadJob(pollResp.ID)149 patchLink := externalLink(c.ctx, textPatch, dbJob.Patch)150 kernelConfigLink := externalLink(c.ctx, textKernelConfig, dbBuild.KernelConfig)151 msg := <-c.emailSink152 c.expectEQ(len(msg.Attachments), 0)153 body := fmt.Sprintf(`Hello,154syzbot tried to test the proposed patch but build/boot failed:155failed to apply patch156Tested on:157commit: 111111111111 kernel_commit_title1158git tree: repo1/branch1159kernel config: %[2]v160compiler: compiler1161patch: %[1]v162`, patchLink, kernelConfigLink)163 if msg.Body != body {164 t.Fatalf("got email body:\n%s\n\nwant:\n%s", msg.Body, body)165 }166 c.checkURLContents(patchLink, []byte(patch))167 c.checkURLContents(kernelConfigLink, build.KernelConfig)168 }169 // Testing fails with a huge error that can't be inlined in email.170 c.incomingEmail(sender, "#syz test: git://git.git/git.git kernel-branch\n"+patch, EmailOptMessageID(3))171 pollResp, _ = c.client2.JobPoll([]string{build.Manager})172 jobDoneReq = &dashapi.JobDoneReq{173 ID: pollResp.ID,174 Build: *build,175 Error: bytes.Repeat([]byte{'a', 'b', 'c'}, (maxInlineError+100)/3),176 }177 c.client2.JobDone(jobDoneReq)178 c.expectOK(c.GET("/email_poll"))179 c.expectEQ(len(c.emailSink), 1)180 {181 dbJob, dbBuild := c.loadJob(pollResp.ID)182 patchLink := externalLink(c.ctx, textPatch, dbJob.Patch)183 errorLink := externalLink(c.ctx, textError, dbJob.Error)184 kernelConfigLink := externalLink(c.ctx, textKernelConfig, dbBuild.KernelConfig)185 msg := <-c.emailSink186 c.expectEQ(len(msg.Attachments), 0)187 truncatedError := string(jobDoneReq.Error[len(jobDoneReq.Error)-maxInlineError:])188 body := fmt.Sprintf(`Hello,189syzbot tried to test the proposed patch but build/boot failed:190%[1]v191Error text is too large and was truncated, full error text is at:192%[2]v193Tested on:194commit: 111111111111 kernel_commit_title1195git tree: repo1/branch1196kernel config: %[4]v197compiler: compiler1198patch: %[3]v199`, truncatedError, errorLink, patchLink, kernelConfigLink)200 if msg.Body != body {201 t.Fatalf("got email body:\n%s\n\nwant:\n%s", msg.Body, body)202 }203 c.checkURLContents(patchLink, []byte(patch))204 c.checkURLContents(errorLink, jobDoneReq.Error)205 c.checkURLContents(kernelConfigLink, build.KernelConfig)206 }207 c.incomingEmail(sender, "#syz test: git://git.git/git.git kernel-branch\n"+patch, EmailOptMessageID(4))208 pollResp, _ = c.client2.JobPoll([]string{build.Manager})209 jobDoneReq = &dashapi.JobDoneReq{210 ID: pollResp.ID,211 Build: *build,212 }213 c.client2.JobDone(jobDoneReq)214 c.expectOK(c.GET("/email_poll"))215 c.expectEQ(len(c.emailSink), 1)216 {217 dbJob, dbBuild := c.loadJob(pollResp.ID)218 patchLink := externalLink(c.ctx, textPatch, dbJob.Patch)219 kernelConfigLink := externalLink(c.ctx, textKernelConfig, dbBuild.KernelConfig)220 msg := <-c.emailSink221 c.expectEQ(len(msg.Attachments), 0)222 body := fmt.Sprintf(`Hello,223syzbot has tested the proposed patch and the reproducer did not trigger crash:224Reported-and-tested-by: syzbot+%v@testapp.appspotmail.com225Tested on:226commit: 111111111111 kernel_commit_title1227git tree: repo1/branch1228kernel config: %[3]v229compiler: compiler1230patch: %[2]v231Note: testing is done by a robot and is best-effort only.232`, extBugID, patchLink, kernelConfigLink)233 if msg.Body != body {234 t.Fatalf("got email body:\n%s\n\nwant:\n%s", msg.Body, body)235 }236 c.checkURLContents(patchLink, []byte(patch))237 c.checkURLContents(kernelConfigLink, build.KernelConfig)238 }239 pollResp, _ = c.client2.JobPoll([]string{build.Manager})240 c.expectEQ(pollResp.ID, "")241}242// Test on particular commit and without a patch.243func TestJobWithoutPatch(t *testing.T) {244 c := NewCtx(t)245 defer c.Close()246 build := testBuild(1)247 c.client2.UploadBuild(build)248 crash := testCrash(build, 1)249 crash.ReproOpts = []byte("repro opts")250 crash.ReproSyz = []byte("repro syz")251 c.client2.ReportCrash(crash)252 c.expectOK(c.GET("/email_poll"))253 c.expectEQ(len(c.emailSink), 1)254 sender := (<-c.emailSink).Sender255 _, extBugID, err := email.RemoveAddrContext(sender)256 if err != nil {257 t.Fatal(err)258 }259 c.incomingEmail(sender, "#syz test: git://mygit.com/git.git 5e6a2eea\n", EmailOptMessageID(1))260 pollResp, _ := c.client2.JobPoll([]string{build.Manager})261 testBuild := testBuild(2)262 testBuild.KernelRepo = "git://mygit.com/git.git"263 testBuild.KernelBranch = ""264 testBuild.KernelCommit = "5e6a2eea5e6a2eea5e6a2eea5e6a2eea5e6a2eea"265 jobDoneReq := &dashapi.JobDoneReq{266 ID: pollResp.ID,267 Build: *testBuild,268 }269 c.client2.JobDone(jobDoneReq)270 c.expectOK(c.GET("/email_poll"))271 c.expectEQ(len(c.emailSink), 1)272 {273 _, dbBuild := c.loadJob(pollResp.ID)274 kernelConfigLink := externalLink(c.ctx, textKernelConfig, dbBuild.KernelConfig)275 msg := <-c.emailSink276 c.expectEQ(len(msg.Attachments), 0)277 body := fmt.Sprintf(`Hello,278syzbot has tested the proposed patch and the reproducer did not trigger crash:279Reported-and-tested-by: syzbot+%v@testapp.appspotmail.com280Tested on:281commit: 5e6a2eea5e6a kernel_commit_title2282git tree: git://mygit.com/git.git283kernel config: %[2]v284compiler: compiler2285Note: testing is done by a robot and is best-effort only.286`, extBugID, kernelConfigLink)287 if msg.Body != body {288 t.Fatalf("got email body:\n%s\n\nwant:\n%s", msg.Body, body)289 }290 c.checkURLContents(kernelConfigLink, testBuild.KernelConfig)291 }292 pollResp, _ = c.client2.JobPoll([]string{build.Manager})293 c.expectEQ(pollResp.ID, "")294}295// Test on a restricted manager.296func TestJobRestrictedManager(t *testing.T) {297 c := NewCtx(t)298 defer c.Close()299 build := testBuild(1)300 build.Manager = "restricted-manager"301 c.client2.UploadBuild(build)302 crash := testCrash(build, 1)303 crash.ReproSyz = []byte("repro syz")304 c.client2.ReportCrash(crash)305 c.expectOK(c.GET("/email_poll"))306 c.expectEQ(len(c.emailSink), 1)307 sender := (<-c.emailSink).Sender308 // Testing on a wrong repo must fail and no test jobs passed to manager.309 c.incomingEmail(sender, "#syz test: git://mygit.com/git.git master\n", EmailOptMessageID(1))310 c.expectEQ(strings.Contains((<-c.emailSink).Body, "you should test only on restricted.git"), true)311 pollResp, _ := c.client2.JobPoll([]string{build.Manager})312 c.expectEQ(pollResp.ID, "")313 // Testing on the right repo must succeed.314 c.incomingEmail(sender, "#syz test: git://restricted.git/restricted.git master\n", EmailOptMessageID(2))315 pollResp, _ = c.client2.JobPoll([]string{build.Manager})316 c.expectEQ(pollResp.ID != "", true)317 c.expectEQ(pollResp.Manager, build.Manager)318 c.expectEQ(pollResp.KernelRepo, "git://restricted.git/restricted.git")319}...
JobPoll
Using AI Code Generation
1import (2func main() {3 sess := session.New()4 service := services.GetAccountService(sess)5 accounts, err := service.Mask("id;name;companyName").Filter("id > 0").GetAllObjects()6 if err != nil {7 fmt.Println("Unable to get account list. Reason: ", err)8 }9 for _, account := range accounts {10 fmt.Println("Account Name: ", *account.CompanyName)11 }12}13import (14func main() {15 sess := session.New()16 service := services.GetAccountService(sess)17 accounts, err := service.Mask("id;name;companyName").Filter("id > 0").GetAllObjects()18 if err != nil {19 fmt.Println("Unable to get account list. Reason: ", err)20 }21 for _, account := range accounts {22 fmt.Println("Account Name: ", *account.CompanyName)23 }24}25import (26func main() {27 sess := session.New()28 service := services.GetAccountService(sess)
JobPoll
Using AI Code Generation
1import (2func main() {3 jobParams := make(map[string]string)4 jobStatus := dash.JobPoll(jobParams)5 fmt.Println(jobStatus)6}7import (8func main() {9 jobParams := make(map[string]string)10 dash.JobCancel(jobParams)11}12import (13func main() {14 jobParams := make(map[string]string)15 dash.JobSubmit(jobParams)16}17import (18func main() {19 jobParams := make(map[string]string)20 dash.JobDelete(jobParams)21}
JobPoll
Using AI Code Generation
1import (2func main() {3 job := sg.NewJob()4 job.SetJobType("Register")5 job.SetJobParameters("AssetName", "test")6 job.SetJobParameters("AssetAddress", "test")7 job.SetJobParameters("AssetPort", "test")8 job.SetJobParameters("Username", "test")9 job.SetJobParameters("Password", "test")10 job.SetJobParameters("AssetType", "Windows")11 job.SetJobParameters("AssetProvider", "Local")
JobPoll
Using AI Code Generation
1import (2func main() {3 jobStatus := dash.JobPoll("jobID")4 fmt.Println(jobStatus)5}6import (7func main() {8 jobCancel := dash.JobCancel("jobID")9 fmt.Println(jobCancel)10}11import (12func main() {13 jobDelete := dash.JobDelete("jobID")14 fmt.Println(jobDelete)15}16import (17func main() {18 jobDeleteAll := dash.JobDeleteAll()19 fmt.Println(jobDeleteAll)20}21import (22func main() {
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!