diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 32f50917d1..4551fb3bce 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -146,33 +146,27 @@ jobs: - name: run tests without race detection and path state scheme if: matrix.test-mode == 'defaults' - env: - TEST_STATE_SCHEME: path run: | echo "Running tests with Path Scheme" >> full.log - ${{ github.workspace }}/.github/workflows/gotestsum.sh --tags cionly --timeout 20m --cover + ${{ github.workspace }}/.github/workflows/gotestsum.sh --tags cionly --timeout 20m --cover --test_state_scheme path - name: run tests without race detection and hash state scheme if: matrix.test-mode == 'defaults' - env: - TEST_STATE_SCHEME: hash run: | echo "Running tests with Hash Scheme" >> full.log - ${{ github.workspace }}/.github/workflows/gotestsum.sh --tags cionly --timeout 20m + ${{ github.workspace }}/.github/workflows/gotestsum.sh --tags cionly --timeout 20m --test_state_scheme hash - name: run tests with race detection and hash state scheme if: matrix.test-mode == 'race' - env: - TEST_STATE_SCHEME: hash run: | echo "Running tests with Hash Scheme" >> full.log - ${{ github.workspace }}/.github/workflows/gotestsum.sh --race --timeout 30m + ${{ github.workspace }}/.github/workflows/gotestsum.sh --race --timeout 30m --test_state_scheme hash - name: run redis tests if: matrix.test-mode == 'defaults' run: | echo "Running redis tests" >> full.log - TEST_REDIS=redis://localhost:6379/0 gotestsum --format short-verbose -- -p 1 -run TestRedis ./arbnode/... ./system_tests/... -coverprofile=coverage-redis.txt -covermode=atomic -coverpkg=./... + gotestsum --format short-verbose -- -p 1 -run TestRedis ./arbnode/... ./system_tests/... -coverprofile=coverage-redis.txt -covermode=atomic -coverpkg=./... -test_redis=redis://localhost:6379/0 - name: create block input json file if: matrix.test-mode == 'defaults' diff --git a/.github/workflows/gotestsum.sh b/.github/workflows/gotestsum.sh index ed631847b7..93aaa8a935 100755 --- a/.github/workflows/gotestsum.sh +++ b/.github/workflows/gotestsum.sh @@ -10,6 +10,7 @@ check_missing_value() { timeout="" tags="" run="" +test_state_scheme="" race=false cover=false while [[ $# -gt 0 ]]; do @@ -32,6 +33,12 @@ while [[ $# -gt 0 ]]; do run=$1 shift ;; + --test_state_scheme) + shift + check_missing_value $# "$1" "--test_state_scheme" + test_state_scheme=$1 + shift + ;; --race) race=true shift @@ -49,7 +56,7 @@ done packages=$(go list ./...) for package in $packages; do - cmd="stdbuf -oL gotestsum --format short-verbose --packages=\"$package\" --rerun-fails=2 --no-color=false --" + cmd="stdbuf -oL gotestsum --format short-verbose --no-color=false -- \"$package\"" if [ "$timeout" != "" ]; then cmd="$cmd -timeout $timeout" @@ -71,6 +78,10 @@ for package in $packages; do cmd="$cmd -coverprofile=coverage.txt -covermode=atomic -coverpkg=./...,./go-ethereum/..." fi + if [ "$test_state_scheme" != "" ]; then + cmd="$cmd -- -test_state_scheme=$test_state_scheme" + fi + cmd="$cmd > >(stdbuf -oL tee -a full.log | grep -vE \"INFO|seal\")" echo "" diff --git a/Makefile b/Makefile index f11896d504..8929886c69 100644 --- a/Makefile +++ b/Makefile @@ -240,7 +240,7 @@ test-go-stylus: test-go-deps .PHONY: test-go-redis test-go-redis: test-go-deps - TEST_REDIS=redis://localhost:6379/0 gotestsum --format short-verbose --no-color=false -- -p 1 -run TestRedis ./system_tests/... ./arbnode/... + gotestsum --format short-verbose --no-color=false -- -p 1 -run TestRedis ./system_tests/... ./arbnode/... -test_redis=redis://localhost:6379/0 @printf $(done) .PHONY: test-gen-proofs diff --git a/arbos/programs/cgo_test.go b/arbos/programs/cgo_test.go index e16c362ef8..a2605143d5 100644 --- a/arbos/programs/cgo_test.go +++ b/arbos/programs/cgo_test.go @@ -7,12 +7,16 @@ package programs import ( + "flag" "fmt" - "os" "strings" "testing" ) +var ( + compileFlag = flag.String("test_compile", "", "[STORE|LOAD] to allow store/load in compile test") +) + func TestConstants(t *testing.T) { err := testConstants() if err != nil { @@ -22,20 +26,20 @@ func TestConstants(t *testing.T) { // normal test will not write anything to disk // to test cross-compilation: -// * run test with TEST_COMPILE=STORE on one machine +// * run test with -test_compile=STORE on one machine // * copy target/testdata to the other machine -// * run test with TEST_COMPILE=LOAD on the other machine +// * run test with -test_compile=LOAD on the other machine func TestCompileArch(t *testing.T) { - compile_env := os.Getenv("TEST_COMPILE") - if compile_env == "" { - fmt.Print("use TEST_COMPILE=[STORE|LOAD] to allow store/load in compile test") + flag.Parse() + if *compileFlag == "" { + fmt.Print("use -test_compile=[STORE|LOAD] to allow store/load in compile test") } - store := strings.Contains(compile_env, "STORE") + store := strings.Contains(*compileFlag, "STORE") err := testCompileArch(store) if err != nil { t.Fatal(err) } - if store || strings.Contains(compile_env, "LOAD") { + if store || strings.Contains(*compileFlag, "LOAD") { err = testCompileLoad() if err != nil { t.Fatal(err) diff --git a/das/aggregator_test.go b/das/aggregator_test.go index b14c2961ce..d9e65fa493 100644 --- a/das/aggregator_test.go +++ b/das/aggregator_test.go @@ -7,6 +7,7 @@ import ( "bytes" "context" "errors" + "flag" "fmt" "io" "math/rand" @@ -22,6 +23,12 @@ import ( "github.com/offchainlabs/nitro/blsSignatures" ) +var ( + seedFlag = flag.String("seed", "", "Seed for random number generator") + runsFlag = flag.String("runs", "", "Number of runs for test") + loggingFlag = flag.String("logging", "", "Enable logging") +) + func TestDAS_BasicAggregationLocal(t *testing.T) { ctx, cancel := context.WithCancel(context.Background()) defer cancel() @@ -243,25 +250,23 @@ func testConfigurableStorageFailures(t *testing.T, shouldFailAggregation bool) { func initTest(t *testing.T) int { t.Parallel() seed := time.Now().UnixNano() - seedStr := os.Getenv("SEED") - if len(seedStr) > 0 { + flag.Parse() + if len(*seedFlag) > 0 { var err error - intSeed, err := strconv.Atoi(seedStr) + intSeed, err := strconv.Atoi(*seedFlag) Require(t, err, "Failed to parse string") seed = int64(intSeed) } rand.Seed(seed) - runsStr := os.Getenv("RUNS") runs := 2 ^ 32 - if len(runsStr) > 0 { + if len(*runsFlag) > 0 { var err error - runs, err = strconv.Atoi(runsStr) + runs, err = strconv.Atoi(*runsFlag) Require(t, err, "Failed to parse string") } - loggingStr := os.Getenv("LOGGING") - if len(loggingStr) > 0 { + if len(*loggingFlag) > 0 { enableLogging() } diff --git a/go.mod b/go.mod index 562ab073d4..68063ac035 100644 --- a/go.mod +++ b/go.mod @@ -200,4 +200,4 @@ require ( golang.org/x/time v0.5.0 // indirect google.golang.org/protobuf v1.34.2 // indirect rsc.io/tmplfunc v0.0.3 // indirect -) +) \ No newline at end of file diff --git a/go.sum b/go.sum index 285e4fb872..2f21a4c508 100644 --- a/go.sum +++ b/go.sum @@ -716,4 +716,4 @@ gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= rsc.io/tmplfunc v0.0.3 h1:53XFQh69AfOa8Tw0Jm7t+GV7KZhOi6jzsCzTtKbMvzU= -rsc.io/tmplfunc v0.0.3/go.mod h1:AG3sTPzElb1Io3Yg4voV9AGZJuleGAwaVRxL9M49PhA= +rsc.io/tmplfunc v0.0.3/go.mod h1:AG3sTPzElb1Io3Yg4voV9AGZJuleGAwaVRxL9M49PhA= \ No newline at end of file diff --git a/system_tests/common_test.go b/system_tests/common_test.go index d3d4b33ab9..1792b9ae90 100644 --- a/system_tests/common_test.go +++ b/system_tests/common_test.go @@ -1791,11 +1791,11 @@ func doUntil(t *testing.T, delay time.Duration, max int, lambda func() bool) { } func TestMain(m *testing.M) { - logLevelEnv := os.Getenv("TEST_LOGLEVEL") - if logLevelEnv != "" { - logLevel, err := strconv.ParseInt(logLevelEnv, 10, 32) + flag.Parse() + if *logLevelFlag != "" { + logLevel, err := strconv.ParseInt(*logLevelFlag, 10, 32) if err != nil || logLevel > int64(log.LevelCrit) { - log.Warn("TEST_LOGLEVEL exists but out of bound, ignoring", "logLevel", logLevelEnv, "max", log.LvlTrace) + log.Warn("-test_loglevel exists but out of bound, ignoring", "logLevel", *logLevelFlag, "max", log.LvlTrace) } glogger := log.NewGlogHandler( log.NewTerminalHandler(io.Writer(os.Stderr), false)) @@ -1831,6 +1831,7 @@ var ( recordBlockInputsWithBaseDir = flag.String("recordBlockInputs.WithBaseDir", "", "Base directory for validationInputsWriter") recordBlockInputsWithTimestampDirEnabled = flag.Bool("recordBlockInputs.WithTimestampDirEnabled", true, "Whether to add timestamp directory while recording block inputs") recordBlockInputsWithBlockIdInFileNameEnabled = flag.Bool("recordBlockInputs.WithBlockIdInFileNameEnabled", true, "Whether to record block inputs using test specific block_id") + logLevelFlag = flag.String("test_loglevel", "", "Log level for tests") ) // recordBlock writes a json file with all of the data needed to validate a block. diff --git a/system_tests/das_test.go b/system_tests/das_test.go index ba50dcfff2..c90852fe75 100644 --- a/system_tests/das_test.go +++ b/system_tests/das_test.go @@ -7,20 +7,15 @@ import ( "context" "encoding/base64" "errors" - "io" - "log/slog" "math/big" "net" "net/http" - "os" - "strconv" "testing" "time" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/ethclient" - "github.com/ethereum/go-ethereum/log" "github.com/offchainlabs/nitro/arbnode" "github.com/offchainlabs/nitro/blsSignatures" @@ -196,7 +191,7 @@ func checkBatchPosting(t *testing.T, ctx context.Context, l1client, l2clientA *e } func TestDASComplexConfigAndRestMirror(t *testing.T) { - initTest(t) + t.Parallel() ctx, cancel := context.WithCancel(context.Background()) defer cancel() @@ -306,24 +301,6 @@ func TestDASComplexConfigAndRestMirror(t *testing.T) { Require(t, err) } -func enableLogging(logLvl int) { - glogger := log.NewGlogHandler( - log.NewTerminalHandler(io.Writer(os.Stderr), false)) - glogger.Verbosity(slog.Level(logLvl)) - log.SetDefault(log.NewLogger(glogger)) -} - -func initTest(t *testing.T) { - t.Parallel() - loggingStr := os.Getenv("LOGGING") - if len(loggingStr) > 0 { - var err error - logLvl, err := strconv.Atoi(loggingStr) - Require(t, err, "Failed to parse string") - enableLogging(logLvl) - } -} - func TestDASBatchPosterFallback(t *testing.T) { ctx, cancel := context.WithCancel(context.Background()) defer cancel() diff --git a/system_tests/full_challenge_impl_test.go b/system_tests/full_challenge_impl_test.go index 4d902f87ba..bcd698711a 100644 --- a/system_tests/full_challenge_impl_test.go +++ b/system_tests/full_challenge_impl_test.go @@ -8,7 +8,6 @@ import ( "context" "io" "math/big" - "os" "strings" "testing" "time" @@ -18,7 +17,6 @@ import ( "github.com/ethereum/go-ethereum/core/rawdb" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/ethclient" - "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/node" "github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/rlp" @@ -235,11 +233,6 @@ func setupSequencerInboxStub(ctx context.Context, t *testing.T, l1Info *Blockcha } func RunChallengeTest(t *testing.T, asserterIsCorrect bool, useStubs bool, challengeMsgIdx int64, wasmRootDir string) { - glogger := log.NewGlogHandler( - log.NewTerminalHandler(io.Writer(os.Stderr), false)) - glogger.Verbosity(log.LvlInfo) - log.SetDefault(log.NewLogger(glogger)) - ctx, cancel := context.WithCancel(context.Background()) defer cancel() diff --git a/util/redisutil/test_redis.go b/util/redisutil/test_redis.go index 9cabfc23d6..f855a7bc7a 100644 --- a/util/redisutil/test_redis.go +++ b/util/redisutil/test_redis.go @@ -5,8 +5,8 @@ package redisutil import ( "context" + "flag" "fmt" - "os" "testing" "github.com/alicebob/miniredis/v2" @@ -14,12 +14,16 @@ import ( "github.com/offchainlabs/nitro/util/testhelpers" ) -// CreateTestRedis Provides external redis url, this is only done in TEST_REDIS env, +var ( + redisFlag = flag.String("test_redis", "", "Redis URL for testing") +) + +// CreateTestRedis Provides external redis url, this is only done with -test_redis flag, // else creates a new miniredis and returns its url. func CreateTestRedis(ctx context.Context, t *testing.T) string { - redisUrl := os.Getenv("TEST_REDIS") - if redisUrl != "" { - return redisUrl + flag.Parse() + if *redisFlag != "" { + return *redisFlag } redisServer, err := miniredis.Run() testhelpers.RequireImpl(t, err) diff --git a/util/testhelpers/env/env.go b/util/testhelpers/env/env.go index 2a8090c212..319df96be3 100644 --- a/util/testhelpers/env/env.go +++ b/util/testhelpers/env/env.go @@ -4,19 +4,23 @@ package env import ( - "os" + "flag" "github.com/ethereum/go-ethereum/core/rawdb" "github.com/ethereum/go-ethereum/log" ) +var ( + stateSchemeFlag = flag.String("test_state_scheme", "", "State scheme to use for tests") +) + // There are two CI steps, one to run tests using the path state scheme, and one to run tests using the hash state scheme. // An environment variable controls that behavior. func GetTestStateScheme() string { - envTestStateScheme := os.Getenv("TEST_STATE_SCHEME") + flag.Parse() stateScheme := rawdb.HashScheme - if envTestStateScheme == rawdb.PathScheme || envTestStateScheme == rawdb.HashScheme { - stateScheme = envTestStateScheme + if *stateSchemeFlag == rawdb.PathScheme || *stateSchemeFlag == rawdb.HashScheme { + stateScheme = *stateSchemeFlag } log.Debug("test state scheme", "testStateScheme", stateScheme) return stateScheme