From 6e029b2fd854c23eaf0c05d0433ebc9b4a7d4920 Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Tue, 26 Apr 2022 17:54:27 +1000 Subject: [PATCH 1/6] Use DO_FMT instead of DO_LINT The `test.sh` has some code if guarded on an env var `DO_LINT` this variable is mis-named because the code only runs `cargo fmt` - this is not a linter, `clippy` is a linter. Re-name `DO_LINT` -> `DO_FMT` in the CI script and the CI workflow. --- .github/workflows/rust.yml | 6 +++--- contrib/test.sh | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 7d163918a..7bfc18824 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -3,8 +3,8 @@ on: [push, pull_request] name: Continuous integration jobs: - lint_fuzz_stable: - name: Lint + Fuzz + fmt_fuzz_stable: + name: Fmt + Fuzz runs-on: ubuntu-latest strategy: matrix: @@ -24,7 +24,7 @@ jobs: - name: Running fuzzer env: DO_FUZZ: true - DO_LINT: true + DO_FMT: true run: ./contrib/test.sh bench_nightly: diff --git a/contrib/test.sh b/contrib/test.sh index 6b5403380..c70e9e38d 100755 --- a/contrib/test.sh +++ b/contrib/test.sh @@ -9,7 +9,7 @@ then fi # Lint if told to -if [ "$DO_LINT" = true ] +if [ "$DO_FMT" = true ] then ( rustup component add rustfmt From db0e67bdb43909a4bad31908a6e9a2bf632eedf4 Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Tue, 26 Apr 2022 17:59:39 +1000 Subject: [PATCH 2/6] Run examples by name Currently the build output directory is hardcoded into the `test.sh` script, this means that for folks who use a different build output directory the test script fails to run the examples. We can overcome this by running the examples directly using `cargo`. --- contrib/test.sh | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/contrib/test.sh b/contrib/test.sh index c70e9e38d..2c1ff1e84 100755 --- a/contrib/test.sh +++ b/contrib/test.sh @@ -41,8 +41,13 @@ done # Also build and run each example to catch regressions cargo build --examples -# run all examples -run-parts ./target/debug/examples + +EXAMPLES="parse psbt sign_multisig verify_tx xpub_descriptors" +for example in ${EXAMPLES} +do + cargo run --example $example +done +cargo run --example htlc --features=compiler # Bench if told to if [ "$DO_BENCH" = true ] From 294c606a99e2a8c473fca8a83bfcf6ab54027873 Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Tue, 26 Apr 2022 18:04:34 +1000 Subject: [PATCH 3/6] Exit script if command fails Use `set -e` to fail the script if any command fails. Add sanity calls to `cargo` and `rustc`. --- contrib/test.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/contrib/test.sh b/contrib/test.sh index 2c1ff1e84..9afc32130 100755 --- a/contrib/test.sh +++ b/contrib/test.sh @@ -1,5 +1,7 @@ #!/bin/sh -ex +set -e + FEATURES="compiler use-serde rand" # Use toolchain if explicitly specified @@ -8,6 +10,9 @@ then alias cargo="cargo +$TOOLCHAIN" fi +cargo --version +rustc --version + # Lint if told to if [ "$DO_FMT" = true ] then From 10b34390a25ecd21e35ba3ce5a0b4307c6e9fbf1 Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Tue, 26 Apr 2022 18:13:34 +1000 Subject: [PATCH 4/6] Move fuzz code to bottom of script To help keep the script executing in order of importance put the fuzzing stuff at the bottom near the benching stuff, this way all sanity checks will have been run. --- contrib/test.sh | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/contrib/test.sh b/contrib/test.sh index 9afc32130..593c3329b 100755 --- a/contrib/test.sh +++ b/contrib/test.sh @@ -22,19 +22,6 @@ then ) fi -# Fuzz if told to -if [ "$DO_FUZZ" = true ] -then - ( - cd fuzz - cargo test --verbose - ./travis-fuzz.sh - # Exit out of the fuzzer, - # run stable tests in other CI vms - exit 0 - ) -fi - # Test without any features first cargo test --verbose @@ -60,6 +47,19 @@ then cargo bench --features="unstable compiler" fi +# Fuzz if told to +if [ "$DO_FUZZ" = true ] +then + ( + cd fuzz + cargo test --verbose + ./travis-fuzz.sh + # Exit out of the fuzzer, + # run stable tests in other CI vms + exit 0 + ) +fi + # Run Integration tests if told so if [ -n "$BITCOINVERSION" ]; then set -e From 0ca8488095feb6fb89dd70f015428fde16c3c379 Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Tue, 26 Apr 2022 18:16:31 +1000 Subject: [PATCH 5/6] Add DO_FEATURE_MATRIX section In an effort to make CI more efficient add an if guard on env var `DO_FEATURE_MATRIX` that: - Runs tests for all features - Runs tests for each feature individually - Runs all the examples Add default sanity tests (build and test) that will always be run irrespective of env vars used when executing the script. This is similar to how we test in `rust-secp256k1`. --- contrib/test.sh | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/contrib/test.sh b/contrib/test.sh index 593c3329b..8c028720c 100755 --- a/contrib/test.sh +++ b/contrib/test.sh @@ -22,24 +22,31 @@ then ) fi -# Test without any features first -cargo test --verbose +# Defaults / sanity checks +cargo build --all +cargo test --all -# Test each feature -for feature in ${FEATURES} -do - cargo test --verbose --features="$feature" -done +if [ "$DO_FEATURE_MATRIX" = true ] +then + # All features + cargo build --all --no-default-features --features="$FEATURES" + cargo test --all --no-default-features --features="$FEATURES" + # Single features + for feature in ${FEATURES} + do + cargo build --all --no-default-features --features="$feature" + cargo test --all --no-default-features --features="$feature" + done -# Also build and run each example to catch regressions -cargo build --examples + # Also build and run each example to catch regressions + cargo build --examples -EXAMPLES="parse psbt sign_multisig verify_tx xpub_descriptors" -for example in ${EXAMPLES} -do - cargo run --example $example -done -cargo run --example htlc --features=compiler + cargo run --example htlc --features=compiler + for example in "parse psbt sign_multisig verify_tx xpub_descriptors" + do + cargo run --example $example + done +fi # Bench if told to if [ "$DO_BENCH" = true ] From 3333b8b7d81c9368292537eb43942d8220a3166f Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Tue, 26 Apr 2022 18:32:57 +1000 Subject: [PATCH 6/6] Re-work CI workflow Re-work the CI work flow based on new changes to the `test.sh` stript. - Put `cargo fmt` in its own job (implies sanity tests also) - Run the feature matrix of tests in a separate job - Do bench marks in a separate job - Put fuzzing in a separate job - Do integration tests in a separate job --- .github/workflows/rust.yml | 80 +++++++++++++++++++------------------- 1 file changed, 40 insertions(+), 40 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 7bfc18824..2a47c458f 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -3,37 +3,32 @@ on: [push, pull_request] name: Continuous integration jobs: - fmt_fuzz_stable: - name: Fmt + Fuzz - runs-on: ubuntu-latest - strategy: - matrix: - rust: - - 1.58.0 + Sanity: + name: Sanity + Fmt steps: - name: Checkout Crate uses: actions/checkout@v2 - - name: Install hongfuzz dependancies - run: sudo apt install build-essential binutils-dev libunwind-dev libblocksruntime-dev liblzma-dev - name: Checkout Toolchain uses: actions-rs/toolchain@v1 with: profile: minimal - toolchain: ${{ matrix.rust }} + toolchain: stable override: true - - name: Running fuzzer + - name: Running cargo fmt env: - DO_FUZZ: true DO_FMT: true run: ./contrib/test.sh + - name: Running integration tests + env: + BITCOINVERSION: '22.0' + run: ./contrib/test.sh - bench_nightly: - name: Bench + Tests + Tests: + name: Tests runs-on: ubuntu-latest strategy: matrix: - rust: - - nightly + rust: [stable, beta, nightly, 1.41.1] steps: - name: Checkout Crate uses: actions/checkout@v2 @@ -43,45 +38,50 @@ jobs: profile: minimal toolchain: ${{ matrix.rust }} override: true - - name: Running cargo test + - name: Running cargo + env: + DO_FEATURE_MATRIX: true + run: ./contrib/test.sh + + Bench: + name: Bench + runs-on: ubuntu-latest + steps: + - name: Checkout Crate + uses: actions/checkout@v2 + - name: Checkout Toolchain + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: nightly + override: true + - name: Running benchmarks env: DO_BENCH: true run: ./contrib/test.sh - UnitTests: - name: Tests + Fuzz: + name: Fuzz runs-on: ubuntu-latest - strategy: - matrix: - rust: - - 1.29.0 - - beta steps: - name: Checkout Crate uses: actions/checkout@v2 + - name: Install hongfuzz dependencies + run: sudo apt install build-essential binutils-dev libunwind-dev libblocksruntime-dev liblzma-dev - name: Checkout Toolchain uses: actions-rs/toolchain@v1 with: profile: minimal - toolchain: ${{ matrix.rust }} + toolchain: stable override: true - - name: Pin deps if rust 1.29 - if: matrix.rust == '1.29.0' - run: | - cargo generate-lockfile --verbose && \ - cargo update --verbose --package "cc" --precise "1.0.41" && \ - cargo update --verbose --package "serde" --precise "1.0.98" && \ - cargo update --verbose --package "serde_derive" --precise "1.0.98" - - name: Running cargo + - name: Running fuzzer + env: + DO_FUZZ: true run: ./contrib/test.sh - AllTests: - name: Unit + Int tests + Integration: + name: Integration tests against bitcoind runs-on: ubuntu-latest - strategy: - matrix: - rust: - - stable steps: - name: Checkout Crate uses: actions/checkout@v2 @@ -89,7 +89,7 @@ jobs: uses: actions-rs/toolchain@v1 with: profile: minimal - toolchain: ${{ matrix.rust }} + toolchain: stable override: true - name: Running cargo env: