Best Syzkaller code snippet using dashapi.String
proxy.go
Source:proxy.go
...106 var (107 build dashapi.Build108 // Payload is gzip'd json.109 payload = c.PostForm("payload")110 buf = bytes.NewBufferString(payload)111 )112 r, err := gzip.NewReader(buf)113 if err != nil {114 c.JSON(http.StatusBadRequest, gin.H{"error": errUnknownMethod.Error()})115 return116 }117 d := json.NewDecoder(r)118 if err := d.Decode(&build); err != nil {119 c.JSON(http.StatusBadRequest, gin.H{"error": errUnknownMethod.Error()})120 return121 }122 if err := r.Close(); err != nil {123 c.JSON(http.StatusBadRequest, gin.H{"error": errUnknownMethod.Error()})124 return125 }126 p.dashMu.RLock()127 for _, dash := range p.dashes {128 err := dash.UploadBuild(&build)129 if err != nil {130 p.dashMu.RUnlock()131 c.JSON(http.StatusBadRequest, gin.H{"error": errUnknownMethod.Error()})132 return133 }134 }135 p.dashMu.RUnlock()136}137func (p *proxy) builderPoll(c *gin.Context, client, key string) {138 var (139 pollReq dashapi.BuilderPollReq140 payload = c.PostForm("payload")141 buf = bytes.NewBufferString(payload)142 )143 r, err := gzip.NewReader(buf)144 if err != nil {145 c.JSON(http.StatusBadRequest, gin.H{"error": errUnknownMethod.Error()})146 return147 }148 d := json.NewDecoder(r)149 if err := d.Decode(&pollReq); err != nil {150 c.JSON(http.StatusBadRequest, gin.H{"error": errUnknownMethod.Error()})151 return152 }153 if err := r.Close(); err != nil {154 c.JSON(http.StatusBadRequest, gin.H{"error": errUnknownMethod.Error()})155 return156 }157 p.dashMu.RLock()158 for _, dash := range p.dashes {159 _, err := dash.BuilderPoll(pollReq.Manager)160 if err != nil {161 p.dashMu.RUnlock()162 c.JSON(http.StatusBadRequest, gin.H{"error": errUnknownMethod.Error()})163 return164 }165 }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 )205 r, err := gzip.NewReader(buf)206 if err != nil {207 c.JSON(http.StatusBadRequest, gin.H{"error": errUnknownMethod.Error()})208 return209 }210 d := json.NewDecoder(r)211 if err := d.Decode(&jobDoneReq); err != nil {212 c.JSON(http.StatusBadRequest, gin.H{"error": errUnknownMethod.Error()})213 return214 }215 if err := r.Close(); err != nil {216 c.JSON(http.StatusBadRequest, gin.H{"error": errUnknownMethod.Error()})217 return218 }219 p.dashMu.RLock()220 for _, dash := range p.dashes {221 err := dash.JobDone(&jobDoneReq)222 if err != nil {223 p.dashMu.RUnlock()224 c.JSON(http.StatusBadRequest, gin.H{"error": errUnknownMethod.Error()})225 return226 }227 }228 p.dashMu.RUnlock()229}230func (p *proxy) reportBuildError(c *gin.Context, client, key string) {231 var (232 buildErrReq dashapi.BuildErrorReq233 payload = c.PostForm("payload")234 buf = bytes.NewBufferString(payload)235 )236 r, err := gzip.NewReader(buf)237 if err != nil {238 c.JSON(http.StatusBadRequest, gin.H{"error": errUnknownMethod.Error()})239 return240 }241 d := json.NewDecoder(r)242 if err := d.Decode(&buildErrReq); err != nil {243 c.JSON(http.StatusBadRequest, gin.H{"error": errUnknownMethod.Error()})244 return245 }246 if err := r.Close(); err != nil {247 c.JSON(http.StatusBadRequest, gin.H{"error": errUnknownMethod.Error()})248 return249 }250 p.dashMu.RLock()251 for _, dash := range p.dashes {252 err := dash.ReportBuildError(&buildErrReq)253 if err != nil {254 p.dashMu.RUnlock()255 c.JSON(http.StatusBadRequest, gin.H{"error": errUnknownMethod.Error()})256 return257 }258 }259 p.dashMu.RUnlock()260}261func (p *proxy) commitPoll(c *gin.Context, client, key string) {262 p.dashMu.RLock()263 for _, dash := range p.dashes {264 _, err := dash.CommitPoll()265 if err != nil {266 p.dashMu.RUnlock()267 c.JSON(http.StatusBadRequest, gin.H{"error": errUnknownMethod.Error()})268 return269 }270 }271 p.dashMu.RUnlock()272}273func (p *proxy) uploadCommits(c *gin.Context, client, key string) {274 var (275 req dashapi.CommitPollResultReq276 payload = c.PostForm("payload")277 buf = bytes.NewBufferString(payload)278 )279 r, err := gzip.NewReader(buf)280 if err != nil {281 c.JSON(http.StatusBadRequest, gin.H{"error": errUnknownMethod.Error()})282 return283 }284 d := json.NewDecoder(r)285 if err := d.Decode(&req); err != nil {286 c.JSON(http.StatusBadRequest, gin.H{"error": errUnknownMethod.Error()})287 return288 }289 if err := r.Close(); err != nil {290 c.JSON(http.StatusBadRequest, gin.H{"error": errUnknownMethod.Error()})291 return292 }293 p.dashMu.RLock()294 for _, dash := range p.dashes {295 err := dash.UploadCommits(req.Commits)296 if err != nil {297 p.dashMu.RUnlock()298 c.JSON(http.StatusBadRequest, gin.H{"error": errUnknownMethod.Error()})299 return300 }301 }302 p.dashMu.RUnlock()303}304func (p *proxy) reportCrash(c *gin.Context, client, key string) {305 var (306 req dashapi.Crash307 payload = c.PostForm("payload")308 buf = bytes.NewBufferString(payload)309 )310 r, err := gzip.NewReader(buf)311 if err != nil {312 c.JSON(http.StatusBadRequest, gin.H{"error": errUnknownMethod.Error()})313 return314 }315 d := json.NewDecoder(r)316 if err := d.Decode(&req); err != nil {317 c.JSON(http.StatusBadRequest, gin.H{"error": errUnknownMethod.Error()})318 return319 }320 if err := r.Close(); err != nil {321 c.JSON(http.StatusBadRequest, gin.H{"error": errUnknownMethod.Error()})322 return323 }324 p.dashMu.RLock()325 for _, dash := range p.dashes {326 _, err := dash.ReportCrash(&req)327 if err != nil {328 p.dashMu.RUnlock()329 c.JSON(http.StatusBadRequest, gin.H{"error": errUnknownMethod.Error()})330 return331 }332 }333 p.dashMu.RUnlock()334}335func (p *proxy) needRepro(c *gin.Context, client, key string) {336 var (337 req dashapi.CrashID338 payload = c.PostForm("payload")339 buf = bytes.NewBufferString(payload)340 )341 r, err := gzip.NewReader(buf)342 if err != nil {343 c.JSON(http.StatusBadRequest, gin.H{"error": errUnknownMethod.Error()})344 return345 }346 d := json.NewDecoder(r)347 if err := d.Decode(&req); err != nil {348 c.JSON(http.StatusBadRequest, gin.H{"error": errUnknownMethod.Error()})349 return350 }351 if err := r.Close(); err != nil {352 c.JSON(http.StatusBadRequest, gin.H{"error": errUnknownMethod.Error()})353 return354 }355 p.dashMu.RLock()356 for _, dash := range p.dashes {357 _, err := dash.NeedRepro(&req)358 if err != nil {359 p.dashMu.RUnlock()360 c.JSON(http.StatusBadRequest, gin.H{"error": errUnknownMethod.Error()})361 return362 }363 }364 p.dashMu.RUnlock()365}366func (p *proxy) reportFailedRepro(c *gin.Context, client, key string) {367 var (368 req dashapi.CrashID369 payload = c.PostForm("payload")370 buf = bytes.NewBufferString(payload)371 )372 r, err := gzip.NewReader(buf)373 if err != nil {374 c.JSON(http.StatusBadRequest, gin.H{"error": errUnknownMethod.Error()})375 return376 }377 d := json.NewDecoder(r)378 if err := d.Decode(&req); err != nil {379 c.JSON(http.StatusBadRequest, gin.H{"error": errUnknownMethod.Error()})380 return381 }382 if err := r.Close(); err != nil {383 c.JSON(http.StatusBadRequest, gin.H{"error": errUnknownMethod.Error()})384 return385 }386 p.dashMu.RLock()387 for _, dash := range p.dashes {388 err := dash.ReportFailedRepro(&req)389 if err != nil {390 p.dashMu.RUnlock()391 c.JSON(http.StatusBadRequest, gin.H{"error": errUnknownMethod.Error()})392 return393 }394 }395 p.dashMu.RUnlock()396}397func (p *proxy) logError(c *gin.Context, client, key string) {398 var (399 req dashapi.LogEntry400 payload = c.PostForm("payload")401 buf = bytes.NewBufferString(payload)402 )403 r, err := gzip.NewReader(buf)404 if err != nil {405 c.JSON(http.StatusBadRequest, gin.H{"error": errUnknownMethod.Error()})406 return407 }408 d := json.NewDecoder(r)409 if err := d.Decode(&req); err != nil {410 c.JSON(http.StatusBadRequest, gin.H{"error": errUnknownMethod.Error()})411 return412 }413 if err := r.Close(); err != nil {414 c.JSON(http.StatusBadRequest, gin.H{"error": errUnknownMethod.Error()})415 return416 }417 p.dashMu.RLock()418 for _, dash := range p.dashes {419 dash.LogError(req.Name, req.Text)420 }421 p.dashMu.RUnlock()422}423func (p *proxy) reportingPollBugs(c *gin.Context, client, key string) {424 var (425 req dashapi.PollBugsRequest426 payload = c.PostForm("payload")427 buf = bytes.NewBufferString(payload)428 )429 r, err := gzip.NewReader(buf)430 if err != nil {431 c.JSON(http.StatusBadRequest, gin.H{"error": errUnknownMethod.Error()})432 return433 }434 d := json.NewDecoder(r)435 if err := d.Decode(&req); err != nil {436 c.JSON(http.StatusBadRequest, gin.H{"error": errUnknownMethod.Error()})437 return438 }439 if err := r.Close(); err != nil {440 c.JSON(http.StatusBadRequest, gin.H{"error": errUnknownMethod.Error()})441 return442 }443 p.dashMu.RLock()444 for _, dash := range p.dashes {445 _, err := dash.ReportingPollBugs(req.Type)446 if err != nil {447 p.dashMu.RUnlock()448 c.JSON(http.StatusBadRequest, gin.H{"error": errUnknownMethod.Error()})449 return450 }451 }452 p.dashMu.RUnlock()453}454func (p *proxy) reportingPollNotifs(c *gin.Context, client, key string) {455 var (456 req dashapi.PollNotificationsRequest457 payload = c.PostForm("payload")458 buf = bytes.NewBufferString(payload)459 )460 r, err := gzip.NewReader(buf)461 if err != nil {462 c.JSON(http.StatusBadRequest, gin.H{"error": errUnknownMethod.Error()})463 return464 }465 d := json.NewDecoder(r)466 if err := d.Decode(&req); err != nil {467 c.JSON(http.StatusBadRequest, gin.H{"error": errUnknownMethod.Error()})468 return469 }470 if err := r.Close(); err != nil {471 c.JSON(http.StatusBadRequest, gin.H{"error": errUnknownMethod.Error()})472 return473 }474 p.dashMu.RLock()475 for _, dash := range p.dashes {476 _, err := dash.ReportingPollNotifications(req.Type)477 if err != nil {478 p.dashMu.RUnlock()479 c.JSON(http.StatusBadRequest, gin.H{"error": errUnknownMethod.Error()})480 return481 }482 }483 p.dashMu.RUnlock()484}485func (p *proxy) reportingPollClosed(c *gin.Context, client, key string) {486 var (487 req dashapi.PollClosedRequest488 payload = c.PostForm("payload")489 buf = bytes.NewBufferString(payload)490 )491 r, err := gzip.NewReader(buf)492 if err != nil {493 c.JSON(http.StatusBadRequest, gin.H{"error": errUnknownMethod.Error()})494 return495 }496 d := json.NewDecoder(r)497 if err := d.Decode(&req); err != nil {498 c.JSON(http.StatusBadRequest, gin.H{"error": errUnknownMethod.Error()})499 return500 }501 if err := r.Close(); err != nil {502 c.JSON(http.StatusBadRequest, gin.H{"error": errUnknownMethod.Error()})503 return504 }505 p.dashMu.RLock()506 for _, dash := range p.dashes {507 _, err := dash.ReportingPollClosed(req.IDs)508 if err != nil {509 p.dashMu.RUnlock()510 c.JSON(http.StatusBadRequest, gin.H{"error": errUnknownMethod.Error()})511 return512 }513 }514 p.dashMu.RUnlock()515}516func (p *proxy) reportingUpdate(c *gin.Context, client, key string) {517 var (518 req dashapi.BugUpdate519 payload = c.PostForm("payload")520 buf = bytes.NewBufferString(payload)521 )522 r, err := gzip.NewReader(buf)523 if err != nil {524 c.JSON(http.StatusBadRequest, gin.H{"error": errUnknownMethod.Error()})525 return526 }527 d := json.NewDecoder(r)528 if err := d.Decode(&req); err != nil {529 c.JSON(http.StatusBadRequest, gin.H{"error": errUnknownMethod.Error()})530 return531 }532 if err := r.Close(); err != nil {533 c.JSON(http.StatusBadRequest, gin.H{"error": errUnknownMethod.Error()})534 return535 }536 p.dashMu.RLock()537 for _, dash := range p.dashes {538 _, err := dash.ReportingUpdate(&req)539 if err != nil {540 p.dashMu.RUnlock()541 c.JSON(http.StatusBadRequest, gin.H{"error": errUnknownMethod.Error()})542 return543 }544 }545 p.dashMu.RUnlock()546}547func (p *proxy) managerStats(c *gin.Context, client, key string) {548 var (549 req dashapi.ManagerStatsReq550 payload = c.PostForm("payload")551 buf = bytes.NewBufferString(payload)552 )553 r, err := gzip.NewReader(buf)554 if err != nil {555 c.JSON(http.StatusBadRequest, gin.H{"error": errUnknownMethod.Error()})556 return557 }558 d := json.NewDecoder(r)559 if err := d.Decode(&req); err != nil {560 c.JSON(http.StatusBadRequest, gin.H{"error": errUnknownMethod.Error()})561 return562 }563 if err := r.Close(); err != nil {564 c.JSON(http.StatusBadRequest, gin.H{"error": errUnknownMethod.Error()})565 return566 }567 managerUptimeGauges.WithLabelValues(req.Name).Set(float64(req.UpTime))568 managerCorpusGauges.WithLabelValues(req.Name).Set(float64(req.Corpus))569 managerPCsGauges.WithLabelValues(req.Name).Set(float64(req.PCs))570 managerCoverageGauges.WithLabelValues(req.Name).Set(float64(req.Cover))571 managerCrashesCounters.WithLabelValues(req.Name).Add(float64(req.Crashes))572 managerExecsCounters.WithLabelValues(req.Name).Add(float64(req.Execs))573 managerSuppCrashesCounters.WithLabelValues(req.Name).Add(float64(req.SuppressedCrashes))574 managerFuzzingDurCounters.WithLabelValues(req.Name).Add(float64(req.FuzzingTime))575 p.dashMu.RLock()576 for _, dash := range p.dashes {577 err := dash.UploadManagerStats(&req)578 if err != nil {579 p.dashMu.RUnlock()580 c.JSON(http.StatusBadRequest, gin.H{"error": errUnknownMethod.Error()})581 return582 }583 }584 p.dashMu.RUnlock()585}586func (p *proxy) bugList(c *gin.Context, client, key string) {587 p.dashMu.RLock()588 for _, dash := range p.dashes {589 _, err := dash.BugList()590 if err != nil {591 p.dashMu.RUnlock()592 c.JSON(http.StatusBadRequest, gin.H{"error": errUnknownMethod.Error()})593 return594 }595 }596 p.dashMu.RUnlock()597}598func (p *proxy) loadBug(c *gin.Context, client, key string) {599 var (600 req dashapi.LoadBugReq601 payload = c.PostForm("payload")602 buf = bytes.NewBufferString(payload)603 )604 r, err := gzip.NewReader(buf)605 if err != nil {606 c.JSON(http.StatusBadRequest, gin.H{"error": errUnknownMethod.Error()})607 return608 }609 d := json.NewDecoder(r)610 if err := d.Decode(&req); err != nil {611 c.JSON(http.StatusBadRequest, gin.H{"error": errUnknownMethod.Error()})612 return613 }614 if err := r.Close(); err != nil {615 c.JSON(http.StatusBadRequest, gin.H{"error": errUnknownMethod.Error()})616 return...
app_test.go
Source:app_test.go
1// Copyright 2017 syzkaller project authors. All rights reserved.2// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.3// +build aetest4package dash5import (6 "fmt"7 "testing"8 "github.com/google/syzkaller/dashboard/dashapi"9)10// Config used in tests.11var config = GlobalConfig{12 AuthDomain: "@foo.com",13 Clients: map[string]string{14 "reporting": "reportingkeyreportingkeyreportingkey",15 },16 Namespaces: map[string]*Config{17 "test1": &Config{18 Key: "test1keytest1keytest1key",19 Clients: map[string]string{20 client1: key1,21 },22 Reporting: []Reporting{23 {24 Name: "reporting1",25 DailyLimit: 3,26 Config: &TestConfig{27 Index: 1,28 },29 },30 {31 Name: "reporting2",32 DailyLimit: 3,33 Config: &TestConfig{34 Index: 2,35 },36 },37 },38 },39 "test2": &Config{40 Key: "test2keytest2keytest2key",41 Clients: map[string]string{42 client2: key2,43 },44 Reporting: []Reporting{45 {46 Name: "reporting1",47 DailyLimit: 5,48 Config: &EmailConfig{49 Email: "test@syzkaller.com",50 Moderation: true,51 },52 },53 {54 Name: "reporting2",55 DailyLimit: 3,56 Config: &EmailConfig{57 Email: "bugs@syzkaller.com",58 MailMaintainers: true,59 },60 },61 },62 },63 },64}65const (66 client1 = "client1"67 client2 = "client2"68 key1 = "client1keyclient1keyclient1key"69 key2 = "client2keyclient2keyclient2key"70)71type TestConfig struct {72 Index int73}74func (cfg *TestConfig) Type() string {75 return "test"76}77func (cfg *TestConfig) NeedMaintainers() bool {78 return false79}80func (cfg *TestConfig) Validate() error {81 return nil82}83func testBuild(id int) *dashapi.Build {84 return &dashapi.Build{85 Manager: fmt.Sprintf("manager%v", id),86 ID: fmt.Sprintf("build%v", id),87 SyzkallerCommit: fmt.Sprintf("syzkaller_commit%v", id),88 CompilerID: fmt.Sprintf("compiler%v", id),89 KernelRepo: fmt.Sprintf("repo%v", id),90 KernelBranch: fmt.Sprintf("branch%v", id),91 KernelCommit: fmt.Sprintf("kernel_commit%v", id),92 KernelConfig: []byte(fmt.Sprintf("config%v", id)),93 }94}95func testCrash(build *dashapi.Build, id int) *dashapi.Crash {96 return &dashapi.Crash{97 BuildID: build.ID,98 Title: fmt.Sprintf("title%v", id),99 Log: []byte(fmt.Sprintf("log%v", id)),100 Report: []byte(fmt.Sprintf("report%v", id)),101 }102}103func testCrashID(crash *dashapi.Crash) *dashapi.CrashID {104 return &dashapi.CrashID{105 BuildID: crash.BuildID,106 Title: crash.Title,107 }108}109func TestApp(t *testing.T) {110 c := NewCtx(t)111 defer c.Close()112 c.expectOK(c.GET("/"))113 c.expectFail("unknown api method", c.API(client1, key1, "unsupported_method", nil, nil))114 ent := &dashapi.LogEntry{115 Name: "name",116 Text: "text",117 }118 c.expectOK(c.API(client1, key1, "log_error", ent, nil))119 build := testBuild(1)120 c.expectOK(c.API(client1, key1, "upload_build", build, nil))121 // Uploading the same build must be OK.122 c.expectOK(c.API(client1, key1, "upload_build", build, nil))123 // Some bad combinations of client/key.124 c.expectFail("unauthorized request", c.API(client1, "", "upload_build", build, nil))125 c.expectFail("unauthorized request", c.API("unknown", key1, "upload_build", build, nil))126 c.expectFail("unauthorized request", c.API(client1, key2, "upload_build", build, nil))127 crash1 := &dashapi.Crash{128 BuildID: "build1",129 Title: "title1",130 Maintainers: []string{`"Foo Bar" <foo@bar.com>`, `bar@foo.com`},131 Log: []byte("log1"),132 Report: []byte("report1"),133 }134 c.expectOK(c.API(client1, key1, "report_crash", crash1, nil))135 // Test that namespace isolation works.136 c.expectFail("unknown build", c.API(client2, key2, "report_crash", crash1, nil))137 crash2 := &dashapi.Crash{138 BuildID: "build1",139 Title: "title2",140 Maintainers: []string{`bar@foo.com`},141 Log: []byte("log2"),142 Report: []byte("report2"),143 ReproOpts: []byte("opts"),144 ReproSyz: []byte("syz repro"),145 ReproC: []byte("c repro"),146 }147 c.expectOK(c.API(client1, key1, "report_crash", crash2, nil))148 // Provoke purgeOldCrashes.149 for i := 0; i < 30; i++ {150 crash := &dashapi.Crash{151 BuildID: "build1",152 Title: "title1",153 Maintainers: []string{`bar@foo.com`},154 Log: []byte(fmt.Sprintf("log%v", i)),155 Report: []byte(fmt.Sprintf("report%v", i)),156 }157 c.expectOK(c.API(client1, key1, "report_crash", crash, nil))158 }159 cid := &dashapi.CrashID{160 BuildID: "build1",161 Title: "title1",162 }163 c.expectOK(c.API(client1, key1, "report_failed_repro", cid, nil))164 pr := &dashapi.PollRequest{165 Type: "test",166 }167 resp := new(dashapi.PollResponse)168 c.expectOK(c.API(client1, key1, "reporting_poll", pr, resp))169 cmd := &dashapi.BugUpdate{170 ID: "id",171 Status: dashapi.BugStatusOpen,172 ReproLevel: dashapi.ReproLevelC,173 DupOf: "",174 }175 c.expectOK(c.API(client1, key1, "reporting_update", cmd, nil))176}177// Normal workflow:178// - upload crash -> need repro179// - upload syz repro -> still need repro180// - upload C repro -> don't need repro181func testNeedRepro1(t *testing.T, crashCtor func(c *Ctx) *dashapi.Crash) {182 c := NewCtx(t)183 defer c.Close()184 crash1 := crashCtor(c)185 resp := new(dashapi.ReportCrashResp)186 c.expectOK(c.API(client1, key1, "report_crash", crash1, resp))187 c.expectEQ(resp.NeedRepro, true)188 cid := testCrashID(crash1)189 needReproResp := new(dashapi.NeedReproResp)190 c.expectOK(c.API(client1, key1, "need_repro", cid, needReproResp))191 c.expectEQ(needReproResp.NeedRepro, true)192 // Still need repro for this crash.193 c.expectOK(c.API(client1, key1, "report_crash", crash1, resp))194 c.expectEQ(resp.NeedRepro, true)195 c.expectOK(c.API(client1, key1, "need_repro", cid, needReproResp))196 c.expectEQ(needReproResp.NeedRepro, true)197 crash2 := new(dashapi.Crash)198 *crash2 = *crash1199 crash2.ReproOpts = []byte("opts")200 crash2.ReproSyz = []byte("repro syz")201 c.expectOK(c.API(client1, key1, "report_crash", crash2, resp))202 c.expectEQ(resp.NeedRepro, true)203 c.expectOK(c.API(client1, key1, "need_repro", cid, needReproResp))204 c.expectEQ(needReproResp.NeedRepro, true)205 crash2.ReproC = []byte("repro C")206 c.expectOK(c.API(client1, key1, "report_crash", crash2, resp))207 c.expectEQ(resp.NeedRepro, false)208 c.expectOK(c.API(client1, key1, "need_repro", cid, needReproResp))209 c.expectEQ(needReproResp.NeedRepro, false)210 c.expectOK(c.API(client1, key1, "report_crash", crash1, resp))211 c.expectEQ(resp.NeedRepro, false)212}213func TestNeedRepro1_normal(t *testing.T) { testNeedRepro1(t, normalCrash) }214func TestNeedRepro1_dup(t *testing.T) { testNeedRepro1(t, dupCrash) }215func TestNeedRepro1_closed(t *testing.T) { testNeedRepro1(t, closedCrash) }216func TestNeedRepro1_closedRepro(t *testing.T) { testNeedRepro1(t, closedWithReproCrash) }217// Upload C repro with first crash -> don't need repro.218func testNeedRepro2(t *testing.T, crashCtor func(c *Ctx) *dashapi.Crash) {219 c := NewCtx(t)220 defer c.Close()221 crash1 := crashCtor(c)222 crash1.ReproOpts = []byte("opts")223 crash1.ReproSyz = []byte("repro syz")224 crash1.ReproC = []byte("repro C")225 resp := new(dashapi.ReportCrashResp)226 c.expectOK(c.API(client1, key1, "report_crash", crash1, resp))227 c.expectEQ(resp.NeedRepro, false)228 cid := testCrashID(crash1)229 needReproResp := new(dashapi.NeedReproResp)230 c.expectOK(c.API(client1, key1, "need_repro", cid, needReproResp))231 c.expectEQ(needReproResp.NeedRepro, false)232}233func TestNeedRepro2_normal(t *testing.T) { testNeedRepro2(t, normalCrash) }234func TestNeedRepro2_dup(t *testing.T) { testNeedRepro2(t, dupCrash) }235func TestNeedRepro2_closed(t *testing.T) { testNeedRepro2(t, closedCrash) }236func TestNeedRepro2_closedRepro(t *testing.T) { testNeedRepro2(t, closedWithReproCrash) }237// Test that after uploading 5 failed repros, app stops requesting repros.238func testNeedRepro3(t *testing.T, crashCtor func(c *Ctx) *dashapi.Crash) {239 c := NewCtx(t)240 defer c.Close()241 crash1 := crashCtor(c)242 resp := new(dashapi.ReportCrashResp)243 cid := testCrashID(crash1)244 needReproResp := new(dashapi.NeedReproResp)245 for i := 0; i < 5; i++ {246 c.expectOK(c.API(client1, key1, "report_crash", crash1, resp))247 c.expectEQ(resp.NeedRepro, true)248 c.expectOK(c.API(client1, key1, "need_repro", cid, needReproResp))249 c.expectEQ(needReproResp.NeedRepro, true)250 c.expectOK(c.API(client1, key1, "report_failed_repro", cid, nil))251 }252 c.expectOK(c.API(client1, key1, "report_crash", crash1, resp))253 c.expectEQ(resp.NeedRepro, false)254 c.expectOK(c.API(client1, key1, "need_repro", cid, needReproResp))255 c.expectEQ(needReproResp.NeedRepro, false)256}257func TestNeedRepro3_normal(t *testing.T) { testNeedRepro3(t, normalCrash) }258func TestNeedRepro3_dup(t *testing.T) { testNeedRepro3(t, dupCrash) }259func TestNeedRepro3_closed(t *testing.T) { testNeedRepro3(t, closedCrash) }260func TestNeedRepro3_closedRepro(t *testing.T) { testNeedRepro3(t, closedWithReproCrash) }261// Test that after uploading 5 syz repros, app stops requesting repros.262func testNeedRepro4(t *testing.T, crashCtor func(c *Ctx) *dashapi.Crash) {263 c := NewCtx(t)264 defer c.Close()265 crash1 := crashCtor(c)266 crash1.ReproOpts = []byte("opts")267 crash1.ReproSyz = []byte("repro syz")268 resp := new(dashapi.ReportCrashResp)269 cid := testCrashID(crash1)270 needReproResp := new(dashapi.NeedReproResp)271 for i := 0; i < 4; i++ {272 c.expectOK(c.API(client1, key1, "report_crash", crash1, resp))273 c.expectEQ(resp.NeedRepro, true)274 c.expectOK(c.API(client1, key1, "need_repro", cid, needReproResp))275 c.expectEQ(needReproResp.NeedRepro, true)276 }277 c.expectOK(c.API(client1, key1, "report_crash", crash1, resp))278 c.expectEQ(resp.NeedRepro, false)279 c.expectOK(c.API(client1, key1, "need_repro", cid, needReproResp))280 c.expectEQ(needReproResp.NeedRepro, false)281}282func TestNeedRepro4_normal(t *testing.T) { testNeedRepro4(t, normalCrash) }283func TestNeedRepro4_dup(t *testing.T) { testNeedRepro4(t, dupCrash) }284func TestNeedRepro4_closed(t *testing.T) { testNeedRepro4(t, closedCrash) }285func TestNeedRepro4_closedRepro(t *testing.T) { testNeedRepro4(t, closedWithReproCrash) }286func testNeedRepro5(t *testing.T, crashCtor func(c *Ctx) *dashapi.Crash) {287 c := NewCtx(t)288 defer c.Close()289 crash1 := crashCtor(c)290 crash1.ReproOpts = []byte("opts")291 crash1.ReproSyz = []byte("repro syz")292 resp := new(dashapi.ReportCrashResp)293 cid := testCrashID(crash1)294 needReproResp := new(dashapi.NeedReproResp)295 for i := 0; i < 4; i++ {296 c.expectOK(c.API(client1, key1, "report_crash", crash1, resp))297 c.expectEQ(resp.NeedRepro, true)298 c.expectOK(c.API(client1, key1, "need_repro", cid, needReproResp))299 c.expectEQ(needReproResp.NeedRepro, true)300 }301 c.expectOK(c.API(client1, key1, "report_crash", crash1, resp))302 c.expectEQ(resp.NeedRepro, false)303 c.expectOK(c.API(client1, key1, "need_repro", cid, needReproResp))304 c.expectEQ(needReproResp.NeedRepro, false)305}306func TestNeedRepro5_normal(t *testing.T) { testNeedRepro5(t, normalCrash) }307func TestNeedRepro5_dup(t *testing.T) { testNeedRepro5(t, dupCrash) }308func TestNeedRepro5_closed(t *testing.T) { testNeedRepro5(t, closedCrash) }309func TestNeedRepro5_closedRepro(t *testing.T) { testNeedRepro5(t, closedWithReproCrash) }310func normalCrash(c *Ctx) *dashapi.Crash {311 build := testBuild(1)312 c.expectOK(c.API(client1, key1, "upload_build", build, nil))313 return testCrash(build, 1)314}315func dupCrash(c *Ctx) *dashapi.Crash {316 build := testBuild(1)317 c.expectOK(c.API(client1, key1, "upload_build", build, nil))318 crash1 := testCrash(build, 1)319 c.expectOK(c.API(client1, key1, "report_crash", crash1, nil))320 crash2 := testCrash(build, 2)321 c.expectOK(c.API(client1, key1, "report_crash", crash2, nil))322 pr := &dashapi.PollRequest{323 Type: "test",324 }325 resp := new(dashapi.PollResponse)326 c.expectOK(c.API(client1, key1, "reporting_poll", pr, resp))327 c.expectEQ(len(resp.Reports), 2)328 rep1 := resp.Reports[0]329 rep2 := resp.Reports[1]330 cmd := &dashapi.BugUpdate{331 ID: rep2.ID,332 Status: dashapi.BugStatusDup,333 DupOf: rep1.ID,334 }335 reply := new(dashapi.BugUpdateReply)336 c.expectOK(c.API(client1, key1, "reporting_update", cmd, reply))337 c.expectEQ(reply.OK, true)338 return crash2339}340func closedCrash(c *Ctx) *dashapi.Crash {341 return closedCrashImpl(c, false)342}343func closedWithReproCrash(c *Ctx) *dashapi.Crash {344 return closedCrashImpl(c, true)345}346func closedCrashImpl(c *Ctx, withRepro bool) *dashapi.Crash {347 build := testBuild(1)348 c.expectOK(c.API(client1, key1, "upload_build", build, nil))349 crash := testCrash(build, 1)350 if withRepro {351 crash.ReproC = []byte("repro C")352 }353 resp := new(dashapi.ReportCrashResp)354 c.expectOK(c.API(client1, key1, "report_crash", crash, resp))355 c.expectEQ(resp.NeedRepro, !withRepro)356 pr := &dashapi.PollRequest{357 Type: "test",358 }359 pollResp := new(dashapi.PollResponse)360 c.expectOK(c.API(client1, key1, "reporting_poll", pr, pollResp))361 c.expectEQ(len(pollResp.Reports), 1)362 rep := pollResp.Reports[0]363 cmd := &dashapi.BugUpdate{364 ID: rep.ID,365 Status: dashapi.BugStatusInvalid,366 }367 reply := new(dashapi.BugUpdateReply)368 c.expectOK(c.API(client1, key1, "reporting_update", cmd, reply))369 c.expectEQ(reply.OK, true)370 crash.ReproC = nil371 return crash372}...
metrics.go
Source:metrics.go
1// Copyright © 2020 Daniel Hodges <hodges.daniel.scott@gmail.com>2//3// Licensed under the Apache License, Version 2.0 (the "License");4// you may not use this file except in compliance with the License.5// You may obtain a copy of the License at6//7// http://www.apache.org/licenses/LICENSE-2.08//9// Unless required by applicable law or agreed to in writing, software10// distributed under the License is distributed on an "AS IS" BASIS,11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.12// See the License for the specific language governing permissions and13// limitations under the License.14package proxy15import "github.com/prometheus/client_golang/prometheus"16var (17 rpcCounters = prometheus.NewCounterVec(18 prometheus.CounterOpts{19 Name: "requests_total",20 Help: "Number of requests.",21 },22 []string{"client", "method"},23 )24)25// dashapi.Build metrics26var (27 buildCounters = prometheus.NewCounterVec(28 prometheus.CounterOpts{29 Name: "builds_total",30 Help: "Number of builds.",31 },32 []string{"manager", "id", "os", "arch", "vmarch"},33 )34)35// dashapi.JobPollReq metrics36var (37 jobPollCounters = prometheus.NewCounterVec(38 prometheus.CounterOpts{39 Name: "job_poll_total",40 Help: "Number of job polls.",41 },42 []string{"manager"},43 )44)45// dashapi.JobDoneReq metrics46var (47 jobDoneCounters = prometheus.NewCounterVec(48 prometheus.CounterOpts{49 Name: "job_done_total",50 Help: "Number of jobs completed.",51 },52 []string{"id", "manager", "build_id", "os", "arch", "vmarch"},53 )54)55// dashapi.BuildErrorReq metrics56var (57 buildErrorCounters = prometheus.NewCounterVec(58 prometheus.CounterOpts{59 Name: "build_error_total",60 Help: "Number of job build errors.",61 },62 []string{"manager", "id", "os", "arch", "vmarch"},63 )64)65// dashapi.ManagerStatsReq metrics66var (67 managerUptimeGauges = prometheus.NewGaugeVec(68 prometheus.GaugeOpts{69 Name: "manager_uptime_total",70 Help: "Manager uptime.",71 },72 []string{"manager"},73 )74 managerCorpusGauges = prometheus.NewGaugeVec(75 prometheus.GaugeOpts{76 Name: "manager_corpus_total",77 Help: "Manager corpus total.",78 },79 []string{"manager"},80 )81 managerPCsGauges = prometheus.NewGaugeVec(82 prometheus.GaugeOpts{83 Name: "manager_pcs_total",84 Help: "Manager pcs total.",85 },86 []string{"manager"},87 )88 managerCoverageGauges = prometheus.NewGaugeVec(89 prometheus.GaugeOpts{90 Name: "manager_coverage_total",91 Help: "Manager coverage total.",92 },93 []string{"manager"},94 )95 managerCrashesCounters = prometheus.NewCounterVec(96 prometheus.CounterOpts{97 Name: "manager_crashes_total",98 Help: "Manager crashes total.",99 },100 []string{"manager"},101 )102 managerSuppCrashesCounters = prometheus.NewCounterVec(103 prometheus.CounterOpts{104 Name: "manager_supp_crashes_total",105 Help: "Manager suppressed crashes total.",106 },107 []string{"manager"},108 )109 managerExecsCounters = prometheus.NewCounterVec(110 prometheus.CounterOpts{111 Name: "manager_execs_total",112 Help: "Manager execs total.",113 },114 []string{"manager"},115 )116 managerFuzzingDurCounters = prometheus.NewCounterVec(117 prometheus.CounterOpts{118 Name: "manager_fuzzing_dur_total",119 Help: "Manager fuzzing duration total.",120 },121 []string{"manager"},122 )123)124func init() {125 prometheus.MustRegister(rpcCounters)126 prometheus.MustRegister(buildCounters)127 prometheus.MustRegister(jobPollCounters)128 prometheus.MustRegister(buildErrorCounters)129 prometheus.MustRegister(managerUptimeGauges)130 prometheus.MustRegister(managerCorpusGauges)131 prometheus.MustRegister(managerPCsGauges)132 prometheus.MustRegister(managerCoverageGauges)133 prometheus.MustRegister(managerCrashesCounters)134 prometheus.MustRegister(managerSuppCrashesCounters)135 prometheus.MustRegister(managerExecsCounters)136 prometheus.MustRegister(managerFuzzingDurCounters)137}...
String
Using AI Code Generation
1import (2func main() {3 fmt.Println(dashapi.String())4}5func String() string {6}7import (8func TestString(t *testing.T) {9 if String() != "dashapi" {10 t.Errorf("String() = %s; want dashapi", String())11 }12}
String
Using AI Code Generation
1import (2func main() {3 fmt.Println(dashapi.String())4}5func String() string {6}
String
Using AI Code Generation
1var dash = new dashapi();2var dash = new dashapi();3var dash = new dashapi();4var dash = new dashapi();5var dash = new dashapi();6var dash = new dashapi();7var dash = new dashapi();8var dash = new dashapi();9var dash = new dashapi();10var dash = new dashapi();11var dash = new dashapi();12var dash = new dashapi();13var dash = new dashapi();14var dash = new dashapi();15var dash = new dashapi();
String
Using AI Code Generation
1import (2func main() {3 d := dashapi.NewDashapi()4 fmt.Println(d.String())5}6import (7func main() {8 d := dashapi.NewDashapi()9 fmt.Println(d.String())10}11import (12func main() {13 d := dashapi.NewDashapi()14 fmt.Println(d.String())15}16import (17func main() {18 d := dashapi.NewDashapi()19 fmt.Println(d.String())20}21import (22func main() {23 d := dashapi.NewDashapi()24 fmt.Println(d.String())25}26import (27func main() {28 d := dashapi.NewDashapi()29 fmt.Println(d.String())30}31import (32func main() {33 d := dashapi.NewDashapi()34 fmt.Println(d.String())35}
String
Using AI Code Generation
1import (2func main() {3 fmt.Println(dashapi.String(123))4}5type Stringer interface {6 String() string7}8func Stringer(v interface{}) string9import (10type Employee struct {11}12func (e Employee) String() string {13 return fmt.Sprintf("Name: %s, Age: %d", e.name, e.age)14}15func main() {16 e := Employee{17 }18 fmt.Println(fmt.Stringer(e))19}20func FormatInt(i int64, base int) string21func Itoa(i int) string22func FormatUint(i uint64, base int) string23func FormatFloat(f float64, fmt byte, prec, bitSize int) string24func AppendInt(dst []byte, i int64, base int) []byte25func AppendUint(dst []byte, i uint64, base int) []byte26func AppendFloat(dst []byte, f float64, fmt byte, prec, bitSize int) []byte
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!!