github.com/google/syzkaller@v0.0.0-20240517125934-c0f1611a36d6/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  
   115  func managersGraphFixture(t *testing.T) *Ctx {
   116  	c := NewCtx(t)
   117  	t.Cleanup(c.Close)
   118  
   119  	build1 := testBuild(1)
   120  	c.client2.UploadBuild(build1)
   121  
   122  	c.client2.UploadManagerStats(&dashapi.ManagerStatsReq{
   123  		Name:   build1.Manager,
   124  		Corpus: 100,
   125  		PCs:    1000,
   126  		Cover:  2000,
   127  	})
   128  
   129  	return c
   130  }
   131  
   132  func TestManagersGraph_FuzzingMetric_OK_OnValidInput(t *testing.T) {
   133  	c := managersGraphFixture(t)
   134  	_, err := c.AuthGET(AccessAdmin, "/test2/graph/fuzzing?Metrics=MaxCorpus")
   135  	c.expectOK(err)
   136  }
   137  
   138  func TestManagersGraph_FuzzingMetric_BadRequest_OnMalformedInput(t *testing.T) {
   139  	c := managersGraphFixture(t)
   140  	_, err := c.AuthGET(AccessAdmin, "/test2/graph/fuzzing?Metrics=MaxCorpus'%2F*%22ZYLQ%22*%2F+AND+'0'%3D'0&Months=27")
   141  	c.expectBadReqest(err)
   142  }