2023-06-07 18:01:32 +00:00
package main
import (
"flag"
2023-06-11 22:40:03 +00:00
"github.com/ledgerwatch/erigon/turbo/debug"
2023-06-07 18:01:32 +00:00
"github.com/ledgerwatch/erigon/cl/cltypes"
"github.com/ledgerwatch/erigon/cl/phase1/forkchoice"
"github.com/ledgerwatch/erigon/cmd/caplin-regression/regression"
"github.com/ledgerwatch/log/v3"
2023-06-09 12:38:28 +00:00
"golang.org/x/exp/slices"
_ "net/http/pprof" //nolint:gosec
2023-06-07 18:01:32 +00:00
)
var nameTestsMap = map [ string ] func ( * forkchoice . ForkChoiceStore , * cltypes . SignedBeaconBlock ) error {
"TestRegressionWithValidation" : regression . TestRegressionWithValidation ,
"TestRegressionWithoutValidation" : regression . TestRegressionWithoutValidation ,
"TestRegressionBadBlocks" : regression . TestRegressionBadBlocks ,
}
2023-06-09 12:38:28 +00:00
var excludeTests = [ ] string { "TestRegressionBadBlocks" }
2023-06-07 18:01:32 +00:00
func main ( ) {
log . Root ( ) . SetHandler ( log . LvlFilterHandler ( log . LvlInfo , log . StderrHandler ) )
test := flag . String ( "test" , "TestRegressionWithValidation" , "select test to run. can be TestRegressionWithValidation, TestRegressionWithoutValidation and TestRegressionBadBlocks" )
2023-06-09 12:38:28 +00:00
step := flag . Int ( "step" , 32 , "how often to log performance" )
2023-06-07 18:01:32 +00:00
pprof := flag . Bool ( "pprof" , true , "turn on profiling" )
2023-06-09 12:38:28 +00:00
loop := flag . Bool ( "loop" , true , "loop the test in an infinite loop" )
2023-06-10 06:53:24 +00:00
testsDir := flag . String ( "testsDir" , "cmd/caplin-regression/caplin-tests" , "directory to the tests" )
2023-06-09 12:38:28 +00:00
all := flag . Bool ( "all" , true , "loop trhough all the test" )
2023-06-07 18:01:32 +00:00
flag . Parse ( )
if _ , ok := nameTestsMap [ * test ] ; ! ok {
log . Error ( "Could not start regression tests" , "err" , "test not found" )
return
}
r , err := regression . NewRegressionTester (
2023-06-10 06:53:24 +00:00
* testsDir ,
2023-06-07 18:01:32 +00:00
)
if * pprof {
// Server for pprof
2023-06-11 22:40:03 +00:00
debug . StartPProf ( "localhost:6060" , true )
2023-06-07 18:01:32 +00:00
}
if err != nil {
log . Error ( "Could not start regression tests" , "err" , err )
return
}
2023-06-09 12:38:28 +00:00
for val := true ; val ; val = * loop {
if * all {
for name , t := range nameTestsMap {
if slices . Contains ( excludeTests , name ) {
continue
}
if err := r . Run ( name , t , * step ) ; err != nil {
log . Error ( "Could not do regression tests" , "err" , err )
}
}
continue
}
if err := r . Run ( * test , nameTestsMap [ * test ] , * step ) ; err != nil {
log . Error ( "Could not do regression tests" , "err" , err )
}
2023-06-07 18:01:32 +00:00
}
}