Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NIT-2851] Use flag instead of env var for system_test #2802

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 4 additions & 10 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -142,33 +142,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 hash

- 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'
Expand Down
13 changes: 12 additions & 1 deletion .github/workflows/gotestsum.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ check_missing_value() {
timeout=""
tags=""
run=""
test_state_scheme=""
race=false
cover=false
while [[ $# -gt 0 ]]; do
Expand All @@ -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
Expand All @@ -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"
Expand All @@ -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 ""
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 12 additions & 8 deletions arbos/programs/cgo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
Expand Down
21 changes: 13 additions & 8 deletions das/aggregator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"bytes"
"context"
"errors"
"flag"
"fmt"
"io"
"math/rand"
Expand All @@ -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()
Expand Down Expand Up @@ -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()
}

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
)
2 changes: 1 addition & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
9 changes: 5 additions & 4 deletions system_tests/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1789,11 +1789,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))
Expand Down Expand Up @@ -1829,6 +1829,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.
Expand Down
25 changes: 1 addition & 24 deletions system_tests/das_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -195,7 +190,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()

Expand Down Expand Up @@ -305,24 +300,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()
Expand Down
7 changes: 0 additions & 7 deletions system_tests/full_challenge_impl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"context"
"io"
"math/big"
"os"
"strings"
"testing"
"time"
Expand All @@ -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"
Expand Down Expand Up @@ -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()

Expand Down
14 changes: 9 additions & 5 deletions util/redisutil/test_redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,25 @@ package redisutil

import (
"context"
"flag"
"fmt"
"os"
"testing"

"github.com/alicebob/miniredis/v2"

"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)
Expand Down
12 changes: 8 additions & 4 deletions util/testhelpers/env/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading