github.com/google/syzkaller@v0.0.0-20251211124644-a066d2bc4b02/dashboard/app/graphs_test.go (about) 1 // Copyright 2020 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 4 package main 5 6 import ( 7 "testing" 8 "time" 9 10 "github.com/google/syzkaller/dashboard/dashapi" 11 ) 12 13 func TestManagersGraphs(t *testing.T) { 14 c := NewCtx(t) 15 defer c.Close() 16 17 build1 := testBuild(1) 18 c.client2.UploadBuild(build1) 19 build2 := testBuild(2) 20 c.client2.UploadBuild(build2) 21 22 c.expectOK(c.client2.UploadManagerStats(&dashapi.ManagerStatsReq{ 23 Name: build1.Manager, 24 Corpus: 100, 25 PCs: 1000, 26 Cover: 2000, 27 })) 28 c.expectOK(c.client2.UploadManagerStats(&dashapi.ManagerStatsReq{ 29 Name: build2.Manager, 30 Corpus: 200, 31 PCs: 2000, 32 Cover: 4000, 33 })) 34 c.advanceTime(25 * time.Hour) 35 c.expectOK(c.client2.UploadManagerStats(&dashapi.ManagerStatsReq{ 36 Name: build1.Manager, 37 Corpus: 110, 38 PCs: 1100, 39 Cover: 2200, 40 })) 41 c.expectOK(c.client2.UploadManagerStats(&dashapi.ManagerStatsReq{ 42 Name: build2.Manager, 43 Corpus: 220, 44 PCs: 2200, 45 Cover: 4400, 46 })) 47 c.advanceTime(25 * time.Hour) 48 c.expectOK(c.client2.UploadManagerStats(&dashapi.ManagerStatsReq{ 49 Name: build1.Manager, 50 Corpus: 150, 51 PCs: 1500, 52 Cover: 2900, 53 })) 54 c.expectOK(c.client2.UploadManagerStats(&dashapi.ManagerStatsReq{ 55 Name: build2.Manager, 56 Corpus: 270, 57 PCs: 2700, 58 Cover: 5400, 59 })) 60 c.advanceTime(25 * time.Hour) 61 c.expectOK(c.client2.UploadManagerStats(&dashapi.ManagerStatsReq{ 62 Name: build1.Manager, 63 Corpus: 50, 64 PCs: 500, 65 Cover: 900, 66 })) 67 c.expectOK(c.client2.UploadManagerStats(&dashapi.ManagerStatsReq{ 68 Name: build2.Manager, 69 Corpus: 70, 70 PCs: 700, 71 Cover: 400, 72 })) 73 74 for i := 0; i < 3; i++ { 75 c.advanceTime(7 * 25 * time.Hour) 76 for j := 0; j <= i; j++ { 77 crash := testCrash(build1, i*i+j) 78 c.client2.ReportCrash(crash) 79 } 80 } 81 82 for { 83 c.advanceTime(7 * 25 * time.Hour) 84 _, err := c.GET("/cron/email_poll") 85 c.expectOK(err) 86 if len(c.emailSink) == 0 { 87 break 88 } 89 for len(c.emailSink) != 0 { 90 <-c.emailSink 91 } 92 } 93 94 reply, err := c.AuthGET(AccessAdmin, "/test2/graph/bugs") 95 c.expectOK(err) 96 // TODO: check reply 97 _ = reply 98 99 reply, err = c.AuthGET(AccessAdmin, "/test2/graph/lifetimes") 100 c.expectOK(err) 101 // TODO: check reply 102 _ = reply 103 104 reply, err = c.AuthGET(AccessAdmin, "/test2/graph/fuzzing") 105 c.expectOK(err) 106 // TODO: check reply 107 _ = reply 108 109 reply, err = c.AuthGET(AccessAdmin, "/test2/graph/crashes") 110 c.expectOK(err) 111 // TODO: check reply 112 _ = reply 113 114 reply, err = c.AuthGET(AccessAdmin, "/test2/graph/found-bugs") 115 c.expectOK(err) 116 // TODO: check reply 117 _ = reply 118 } 119 120 func managersGraphFixture(t *testing.T) *Ctx { 121 c := NewCtx(t) 122 t.Cleanup(c.Close) 123 124 build1 := testBuild(1) 125 c.client2.UploadBuild(build1) 126 127 c.client2.UploadManagerStats(&dashapi.ManagerStatsReq{ 128 Name: build1.Manager, 129 Corpus: 100, 130 PCs: 1000, 131 Cover: 2000, 132 }) 133 134 return c 135 } 136 137 func TestManagersGraph_FuzzingMetric_OK_OnValidInput(t *testing.T) { 138 c := managersGraphFixture(t) 139 _, err := c.AuthGET(AccessAdmin, "/test2/graph/fuzzing?Metrics=MaxCorpus") 140 c.expectOK(err) 141 } 142 143 func TestManagersGraph_FuzzingMetric_BadRequest_OnMalformedInput(t *testing.T) { 144 c := managersGraphFixture(t) 145 _, err := c.AuthGET(AccessAdmin, "/test2/graph/fuzzing?Metrics=MaxCorpus'%2F*%22ZYLQ%22*%2F+AND+'0'%3D'0&Months=27") 146 c.expectBadReqest(err) 147 }