diff --git a/.github/scripts/fuzz.sh b/.github/scripts/fuzz.sh index 9e598d49a..b77d4330d 100755 --- a/.github/scripts/fuzz.sh +++ b/.github/scripts/fuzz.sh @@ -1,16 +1,23 @@ #!/bin/bash - -# Runs fuzz tests using `cargo test-fuzz`. These should only be run after a `cargo test` has been executed once: https://github.com/trailofbits/test-fuzz#usage +# Runs fuzz tests using `cargo test-fuzz`. PACKAGE=$1 TEST_TIME=${2:-5} +echo "::group::$PACKAGE" + +echo Building corpus. +cargo test -p $PACKAGE --no-run --all-features + # Gets the list of tests present in the package. TESTS=$(cargo test-fuzz --list -p $PACKAGE | head -n -3 | tail -n+9 | cat - <(echo \"--list\"]) | cat - | jq -r ".[]") for test in $TESTS do + echo Running test: $test set -x cargo test-fuzz --no-ui -p "$PACKAGE" $test -- -V $TEST_TIME set +x -done; \ No newline at end of file +done; + +echo "::endgroup::" \ No newline at end of file diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 43c8f0c10..631b6bf1f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -34,6 +34,26 @@ jobs: command: nextest args: run --locked --workspace --all-features + - name: Install fuzzer + run: cargo install cargo-test-fuzz afl + + fuzz: + runs-on: ubuntu-latest + steps: + - name: Checkout sources + uses: actions/checkout@v3 + - name: Install toolchain + uses: dtolnay/rust-toolchain@nightly + - uses: Swatinem/rust-cache@v2 + with: + cache-on-failure: true + + - name: Install fuzzer + uses: actions-rs/cargo@v1 + with: + command: install + args: cargo-test-fuzz afl + - name: Run fuzz tests run: | ./.github/scripts/fuzz.sh reth-primitives