Skip to content
Merged
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
15 changes: 2 additions & 13 deletions .github/workflows/ethereum-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,5 @@ jobs:
- name: Install cross
run: cargo install cross

- name: Statetests
run: |
cross run --target ${{matrix.target}} --profile ${{ matrix.profile }} -p revme -- statetest \
ethtests/GeneralStateTests/ \
ethtests/LegacyTests/Constantinople/GeneralStateTests/ \
tests/eof/state_tests \
tests/stable/state_tests \
tests/develop/state_tests
- name: EOF validation
run: |
cross run --target ${{matrix.target}} --profile ${{ matrix.profile }} -p revme -- eof-validation \
tests/eof/eof_tests

- name: Run tests
run: ./scripts/run-tests.sh clean cross ${{ matrix.profile }} ${{ matrix.target }}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,6 @@ rustc-ice-*
/book/book
/book/cache.json
/index.html

# Fixtures
/test-fixtures
196 changes: 196 additions & 0 deletions scripts/run-tests.sh
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks to @kevaundray for the script :)

Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
# ./run-tests --help

#!/bin/bash
set -e

# Version for the execution spec tests
VERSION="v4.1.0"

# Directories
FIXTURES_DIR="test-fixtures"
STABLE_DIR="$FIXTURES_DIR/stable"
DEVELOP_DIR="$FIXTURES_DIR/develop"
EOF_DIR="$FIXTURES_DIR/eof"

# URL and filenames
FIXTURES_URL="https://github.com/ethereum/execution-spec-tests/releases/download/$VERSION"
STABLE_TAR="fixtures_stable.tar.gz"
DEVELOP_TAR="fixtures_develop.tar.gz"
EOF_TAR="fixtures_eip7692.tar.gz"

# Print usage information and exit
usage() {
echo "Usage: $0 [clean] [runner] [profile] [target]"
echo ""
echo "Arguments (after optional 'clean'):"
echo " runner (Optional) Rust runner command. Must be either 'cargo' or 'cross'. Defaults to 'cargo'."
echo " profile (Optional) Rust profile to use. Defaults to 'debug' if not provided."
echo " target (Optional) Rust target. Only used if provided."
echo ""
echo "Examples:"
echo " $0"
echo " Uses runner 'cargo', profile 'debug', and no target."
echo ""
echo " $0 release"
echo " Uses runner 'cargo', profile 'release', and no target."
echo ""
echo " $0 release x86-win"
echo " Uses runner 'cargo', profile 'release', with target 'x86-win'."
echo ""
echo " $0 clean"
echo " Cleans fixtures then uses runner 'cargo', profile 'debug', and no target."
echo ""
echo " $0 clean cross release x86-win"
echo " Cleans fixtures then uses runner 'cross', profile 'release', and target 'x86-win'."
exit 1
}

# Check for help flag in any argument.
for arg in "$@"; do
if [ "$arg" = "-h" ] || [ "$arg" = "--help" ]; then
usage
fi
done

# Deletes the test fixture directory
clean() {
echo "Cleaning test fixtures..."
rm -rf "$FIXTURES_DIR"
echo "Cleaned test fixtures directory."
}

# Check if all required fixture directories exist
check_fixtures() {
if [ -d "$STABLE_DIR" ] && [ -d "$DEVELOP_DIR" ] && [ -d "$EOF_DIR" ]; then
return 0
else
return 1
fi
}

# Download and extract a single fixture
# Arguments: target directory, tar file name, label for logging
download_and_extract() {
local target_dir="$1"
local tar_file="$2"
local label="$3"

echo "Downloading ${label} fixtures..."
curl -L "${FIXTURES_URL}/${tar_file}" -o "${FIXTURES_DIR}/${tar_file}"
echo "Extracting ${label} fixtures..."
# strip-components=1 removes the first top level directory from the flepath
# This is needed because when we extract the tar, it is placed under an
# unnecessary "fixtures/" directory.
tar -xzf "${FIXTURES_DIR}/${tar_file}" --strip-components=1 -C "$target_dir"
}

# Download all fixtures
download_fixtures() {
echo "Creating fixtures directory structure..."
mkdir -p "$STABLE_DIR" "$DEVELOP_DIR" "$EOF_DIR"

download_and_extract "$STABLE_DIR" "$STABLE_TAR" "stable"
download_and_extract "$DEVELOP_DIR" "$DEVELOP_TAR" "develop"
download_and_extract "$EOF_DIR" "$EOF_TAR" "EOF"

echo "Cleaning up tar files..."
rm "${FIXTURES_DIR}/${STABLE_TAR}" "${FIXTURES_DIR}/${DEVELOP_TAR}" "${FIXTURES_DIR}/${EOF_TAR}"
echo "Fixtures download and extraction complete."
}

# Build Cargo options based on provided profile and target.
# For the profile:
# - "debug" is the default (no extra option needed)
# - "release" adds "--release"
# - Any other value adds "--profile <profile>"
# For the target:
# - If provided, add "--target <target>"
build_cargo_options() {
CARGO_OPTS=""

if [ "$RUST_PROFILE" = "release" ]; then
CARGO_OPTS="--release"
elif [ "$RUST_PROFILE" != "debug" ]; then
CARGO_OPTS="--profile $RUST_PROFILE"
fi

if [ -n "$RUST_TARGET" ]; then
CARGO_OPTS="$CARGO_OPTS --target $RUST_TARGET"
fi
}

# Run tests for each set of fixtures using the chosen runner.
run_tests() {
echo "Running stable statetests..."
$RUST_RUNNER run $CARGO_OPTS -p revme -- statetest "$STABLE_DIR/state_tests"

echo "Running develop statetests..."
$RUST_RUNNER run $CARGO_OPTS -p revme -- statetest "$DEVELOP_DIR/state_tests"

echo "Running EOF statetests..."
$RUST_RUNNER run $CARGO_OPTS -p revme -- statetest "$EOF_DIR/state_tests"

echo "Running EOF validation tests..."
$RUST_RUNNER run $CARGO_OPTS -p revme -- eof-validation "$EOF_DIR/eof_tests"
}

##############################
# Main logic

# If the first argument is "clean", perform cleaning and download fixtures.
if [ "$1" = "clean" ]; then
clean
download_fixtures
shift
else
if check_fixtures; then
echo "Using existing test fixtures."
else
echo "Test fixtures not found. Downloading..."
download_fixtures
fi
fi

# Argument parsing for runner, profile, target.
# Expected order (after optional clean): [runner] [profile] [target]
# If the first argument is "cargo" or "cross", then it is the runner.
# Otherwise, runner defaults to "cargo", and the arguments are profile and target.
if [ "$#" -eq 0 ]; then
RUST_RUNNER="cargo"
RUST_PROFILE="debug"
RUST_TARGET=""
elif [ "$#" -eq 1 ]; then
if [ "$1" = "cargo" ] || [ "$1" = "cross" ]; then
RUST_RUNNER="$1"
RUST_PROFILE="debug"
RUST_TARGET=""
else
RUST_RUNNER="cargo"
RUST_PROFILE="$1"
RUST_TARGET=""
fi
elif [ "$#" -eq 2 ]; then
if [ "$1" = "cargo" ] || [ "$1" = "cross" ]; then
RUST_RUNNER="$1"
RUST_PROFILE="$2"
RUST_TARGET=""
else
RUST_RUNNER="cargo"
RUST_PROFILE="$1"
RUST_TARGET="$2"
fi
elif [ "$#" -eq 3 ]; then
if [ "$1" = "cargo" ] || [ "$1" = "cross" ]; then
RUST_RUNNER="$1"
RUST_PROFILE="$2"
RUST_TARGET="$3"
else
usage
fi
else
usage
fi

build_cargo_options
run_tests

Loading