From 461bae92447d84565ece5aac5172bedd1c8edb45 Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Fri, 21 Jul 2023 11:06:21 +1000 Subject: [PATCH 1/5] Move recent/minimal lock files A while back we added two lock files that were to track dependencies of two successful test runs, one with a minimal set of dependencies and one with a recent set of dependencies (ie, recent dependency versions). We never used these lock files in CI however. In preparation for using the lock files in CI, and in order to be uniform with `rust-bitcoin`, move the lock files to the crate root and rename them to: - Cargo-minimal.lock - Cargo-recent.lock --- contrib/Cargo.minimal.lock => Cargo-minimal.lock | 0 contrib/Cargo.latest.lock => Cargo-recent.lock | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename contrib/Cargo.minimal.lock => Cargo-minimal.lock (100%) rename contrib/Cargo.latest.lock => Cargo-recent.lock (100%) diff --git a/contrib/Cargo.minimal.lock b/Cargo-minimal.lock similarity index 100% rename from contrib/Cargo.minimal.lock rename to Cargo-minimal.lock diff --git a/contrib/Cargo.latest.lock b/Cargo-recent.lock similarity index 100% rename from contrib/Cargo.latest.lock rename to Cargo-recent.lock From d9b70d27b0f436ca37d06d40e9d369e0c513c917 Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Thu, 20 Jul 2023 10:52:26 +1000 Subject: [PATCH 2/5] Remove trailing whitespace --- contrib/test.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/test.sh b/contrib/test.sh index 379059e..7303a5d 100755 --- a/contrib/test.sh +++ b/contrib/test.sh @@ -51,7 +51,7 @@ if [ "$DO_FEATURE_MATRIX" = true ]; then cargo build --all --no-default-features --features="std,$feature" cargo test --all --no-default-features --features="std,$feature" done - # Other combos + # Other combos RUSTFLAGS='--cfg=secp256k1_fuzz' RUSTDOCFLAGS='--cfg=secp256k1_fuzz' cargo test --all RUSTFLAGS='--cfg=secp256k1_fuzz' RUSTDOCFLAGS='--cfg=secp256k1_fuzz' cargo test --all --features="$FEATURES" cargo test --all --features="rand serde" From 637d08f1fe98444fe943b68f36e12cafa8140488 Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Thu, 20 Jul 2023 10:53:01 +1000 Subject: [PATCH 3/5] Add a layer of indirection to the test script We would like to be able to run the test script with different lock files, in preparation for doing so move the `test.sh` script to `_test.sh` and add a new `test.sh` that runs `_test.sh`. Keep the outer script as `test.sh` so that we do not change the workflow for those running the script including the github actions. --- contrib/_test.sh | 138 +++++++++++++++++++++++++++++++++++++++++++++++ contrib/test.sh | 133 +-------------------------------------------- 2 files changed, 139 insertions(+), 132 deletions(-) create mode 100755 contrib/_test.sh diff --git a/contrib/_test.sh b/contrib/_test.sh new file mode 100755 index 0000000..7303a5d --- /dev/null +++ b/contrib/_test.sh @@ -0,0 +1,138 @@ +#!/usr/bin/env bash + +set -ex + +REPO_DIR=$(git rev-parse --show-toplevel) +FEATURES="bitcoin-hashes global-context lowmemory rand recovery serde std alloc bitcoin-hashes-std rand-std" + +cargo --version +rustc --version + +# Work out if we are using a nightly toolchain. +NIGHTLY=false +if cargo --version | grep nightly; then + NIGHTLY=true +fi + +# Pin dependencies as required if we are using MSRV toolchain. +if cargo --version | grep "1\.48"; then + cargo update -p wasm-bindgen-test --precise 0.3.34 + cargo update -p serde_test --precise 1.0.175 +fi + +# Test if panic in C code aborts the process (either with a real panic or with SIGILL) +cargo test -- --ignored --exact 'tests::test_panic_raw_ctx_should_terminate_abnormally' 2>&1 \ + | tee /dev/stderr \ + | grep "SIGILL\\|\[libsecp256k1] illegal argument. !rustsecp256k1_v0_._._fe_is_zero(&ge->x)" + +# Make all cargo invocations verbose +export CARGO_TERM_VERBOSE=true + +# Defaults / sanity checks +cargo build --all +cargo test --all + +if [ "$DO_FEATURE_MATRIX" = true ]; then + cargo build --all --no-default-features + cargo test --all --no-default-features + + # 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 + # Features tested with 'std' feature enabled. + for feature in ${FEATURES} + do + cargo build --all --no-default-features --features="std,$feature" + cargo test --all --no-default-features --features="std,$feature" + done + # Other combos + RUSTFLAGS='--cfg=secp256k1_fuzz' RUSTDOCFLAGS='--cfg=secp256k1_fuzz' cargo test --all + RUSTFLAGS='--cfg=secp256k1_fuzz' RUSTDOCFLAGS='--cfg=secp256k1_fuzz' cargo test --all --features="$FEATURES" + cargo test --all --features="rand serde" + + if [ "$NIGHTLY" = true ]; then + cargo test --all --all-features + RUSTFLAGS='--cfg=secp256k1_fuzz' RUSTDOCFLAGS='--cfg=secp256k1_fuzz' cargo test --all --all-features + fi + + # Examples + cargo run --example sign_verify --features=bitcoin-hashes-std + cargo run --example sign_verify_recovery --features=recovery,bitcoin-hashes-std + cargo run --example generate_keys --features=rand-std +fi + +if [ "$DO_LINT" = true ] +then + cargo clippy --all-features --all-targets -- -D warnings + cargo clippy --example sign_verify --features=bitcoin-hashes-std -- -D warnings + cargo clippy --example sign_verify_recovery --features=recovery,bitcoin-hashes-std -- -D warnings + cargo clippy --example generate_keys --features=rand-std -- -D warnings +fi + +# Build the docs if told to (this only works with the nightly toolchain) +if [ "$DO_DOCSRS" = true ]; then + RUSTDOCFLAGS="--cfg docsrs -D warnings -D rustdoc::broken-intra-doc-links" cargo +nightly doc --all-features +fi + +# Build the docs with a stable toolchain, in unison with the DO_DOCSRS command +# above this checks that we feature guarded docs imports correctly. +if [ "$DO_DOCS" = true ]; then + RUSTDOCFLAGS="-D warnings" cargo +stable doc --all-features +fi + +# Webassembly stuff +if [ "$DO_WASM" = true ]; then + clang --version + CARGO_TARGET_DIR=wasm cargo install --force wasm-pack + printf '\n[lib]\ncrate-type = ["cdylib", "rlib"]\n' >> Cargo.toml + CC=clang wasm-pack build + CC=clang wasm-pack test --node +fi + +# Address Sanitizer +if [ "$DO_ASAN" = true ]; then + clang --version + cargo clean + CC='clang -fsanitize=address -fno-omit-frame-pointer' \ + RUSTFLAGS='-Zsanitizer=address -Clinker=clang -Cforce-frame-pointers=yes' \ + ASAN_OPTIONS='detect_leaks=1 detect_invalid_pointer_pairs=1 detect_stack_use_after_return=1' \ + cargo test --lib --all --features="$FEATURES" -Zbuild-std --target x86_64-unknown-linux-gnu + cargo clean + # The -Cllvm-args=-msan-eager-checks=0 flag was added to overcome this issue: + # https://github.com/rust-bitcoin/rust-secp256k1/pull/573#issuecomment-1399465995 + CC='clang -fsanitize=memory -fno-omit-frame-pointer' \ + RUSTFLAGS='-Zsanitizer=memory -Zsanitizer-memory-track-origins -Cforce-frame-pointers=yes -Cllvm-args=-msan-eager-checks=0' \ + cargo test --lib --all --features="$FEATURES" -Zbuild-std --target x86_64-unknown-linux-gnu + + pushd "$REPO_DIR/no_std_test" > /dev/null || exit 1 + # See https://github.com/rust-bitcoin/rust-secp256k1/pull/641#issuecomment-1671598914 + cargo update -p cc --precise 1.0.79 + popd > /dev/null || exit 1 + + cargo run --release --manifest-path=./no_std_test/Cargo.toml | grep -q "Verified Successfully" + cargo run --release --features=alloc --manifest-path=./no_std_test/Cargo.toml | grep -q "Verified alloc Successfully" +fi + +# Run formatter if told to. +if [ "$DO_FMT" = true ]; then + if [ "$NIGHTLY" = false ]; then + echo "DO_FMT requires a nightly toolchain (consider using RUSTUP_TOOLCHAIN)" + exit 1 + fi + rustup component add rustfmt + cargo fmt --check || exit 1 +fi + +# Bench if told to, only works with non-stable toolchain (nightly, beta). +if [ "$DO_BENCH" = true ] +then + RUSTFLAGS='--cfg=bench' cargo bench --features=recovery,rand-std +fi + +exit 0 diff --git a/contrib/test.sh b/contrib/test.sh index 7303a5d..109601f 100755 --- a/contrib/test.sh +++ b/contrib/test.sh @@ -3,136 +3,5 @@ set -ex REPO_DIR=$(git rev-parse --show-toplevel) -FEATURES="bitcoin-hashes global-context lowmemory rand recovery serde std alloc bitcoin-hashes-std rand-std" -cargo --version -rustc --version - -# Work out if we are using a nightly toolchain. -NIGHTLY=false -if cargo --version | grep nightly; then - NIGHTLY=true -fi - -# Pin dependencies as required if we are using MSRV toolchain. -if cargo --version | grep "1\.48"; then - cargo update -p wasm-bindgen-test --precise 0.3.34 - cargo update -p serde_test --precise 1.0.175 -fi - -# Test if panic in C code aborts the process (either with a real panic or with SIGILL) -cargo test -- --ignored --exact 'tests::test_panic_raw_ctx_should_terminate_abnormally' 2>&1 \ - | tee /dev/stderr \ - | grep "SIGILL\\|\[libsecp256k1] illegal argument. !rustsecp256k1_v0_._._fe_is_zero(&ge->x)" - -# Make all cargo invocations verbose -export CARGO_TERM_VERBOSE=true - -# Defaults / sanity checks -cargo build --all -cargo test --all - -if [ "$DO_FEATURE_MATRIX" = true ]; then - cargo build --all --no-default-features - cargo test --all --no-default-features - - # 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 - # Features tested with 'std' feature enabled. - for feature in ${FEATURES} - do - cargo build --all --no-default-features --features="std,$feature" - cargo test --all --no-default-features --features="std,$feature" - done - # Other combos - RUSTFLAGS='--cfg=secp256k1_fuzz' RUSTDOCFLAGS='--cfg=secp256k1_fuzz' cargo test --all - RUSTFLAGS='--cfg=secp256k1_fuzz' RUSTDOCFLAGS='--cfg=secp256k1_fuzz' cargo test --all --features="$FEATURES" - cargo test --all --features="rand serde" - - if [ "$NIGHTLY" = true ]; then - cargo test --all --all-features - RUSTFLAGS='--cfg=secp256k1_fuzz' RUSTDOCFLAGS='--cfg=secp256k1_fuzz' cargo test --all --all-features - fi - - # Examples - cargo run --example sign_verify --features=bitcoin-hashes-std - cargo run --example sign_verify_recovery --features=recovery,bitcoin-hashes-std - cargo run --example generate_keys --features=rand-std -fi - -if [ "$DO_LINT" = true ] -then - cargo clippy --all-features --all-targets -- -D warnings - cargo clippy --example sign_verify --features=bitcoin-hashes-std -- -D warnings - cargo clippy --example sign_verify_recovery --features=recovery,bitcoin-hashes-std -- -D warnings - cargo clippy --example generate_keys --features=rand-std -- -D warnings -fi - -# Build the docs if told to (this only works with the nightly toolchain) -if [ "$DO_DOCSRS" = true ]; then - RUSTDOCFLAGS="--cfg docsrs -D warnings -D rustdoc::broken-intra-doc-links" cargo +nightly doc --all-features -fi - -# Build the docs with a stable toolchain, in unison with the DO_DOCSRS command -# above this checks that we feature guarded docs imports correctly. -if [ "$DO_DOCS" = true ]; then - RUSTDOCFLAGS="-D warnings" cargo +stable doc --all-features -fi - -# Webassembly stuff -if [ "$DO_WASM" = true ]; then - clang --version - CARGO_TARGET_DIR=wasm cargo install --force wasm-pack - printf '\n[lib]\ncrate-type = ["cdylib", "rlib"]\n' >> Cargo.toml - CC=clang wasm-pack build - CC=clang wasm-pack test --node -fi - -# Address Sanitizer -if [ "$DO_ASAN" = true ]; then - clang --version - cargo clean - CC='clang -fsanitize=address -fno-omit-frame-pointer' \ - RUSTFLAGS='-Zsanitizer=address -Clinker=clang -Cforce-frame-pointers=yes' \ - ASAN_OPTIONS='detect_leaks=1 detect_invalid_pointer_pairs=1 detect_stack_use_after_return=1' \ - cargo test --lib --all --features="$FEATURES" -Zbuild-std --target x86_64-unknown-linux-gnu - cargo clean - # The -Cllvm-args=-msan-eager-checks=0 flag was added to overcome this issue: - # https://github.com/rust-bitcoin/rust-secp256k1/pull/573#issuecomment-1399465995 - CC='clang -fsanitize=memory -fno-omit-frame-pointer' \ - RUSTFLAGS='-Zsanitizer=memory -Zsanitizer-memory-track-origins -Cforce-frame-pointers=yes -Cllvm-args=-msan-eager-checks=0' \ - cargo test --lib --all --features="$FEATURES" -Zbuild-std --target x86_64-unknown-linux-gnu - - pushd "$REPO_DIR/no_std_test" > /dev/null || exit 1 - # See https://github.com/rust-bitcoin/rust-secp256k1/pull/641#issuecomment-1671598914 - cargo update -p cc --precise 1.0.79 - popd > /dev/null || exit 1 - - cargo run --release --manifest-path=./no_std_test/Cargo.toml | grep -q "Verified Successfully" - cargo run --release --features=alloc --manifest-path=./no_std_test/Cargo.toml | grep -q "Verified alloc Successfully" -fi - -# Run formatter if told to. -if [ "$DO_FMT" = true ]; then - if [ "$NIGHTLY" = false ]; then - echo "DO_FMT requires a nightly toolchain (consider using RUSTUP_TOOLCHAIN)" - exit 1 - fi - rustup component add rustfmt - cargo fmt --check || exit 1 -fi - -# Bench if told to, only works with non-stable toolchain (nightly, beta). -if [ "$DO_BENCH" = true ] -then - RUSTFLAGS='--cfg=bench' cargo bench --features=recovery,rand-std -fi - -exit 0 +$REPO_DIR/contrib/_test.sh From 4b9168ca2555119570264ff753b6e465dbcea8ed Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Fri, 21 Jul 2023 11:39:08 +1000 Subject: [PATCH 4/5] Run WASM tests from test wrapper script The `wasm-pack` command does not honour `cargo` flags passed to it so we cannot use `--locked` and test against pre-made lock files. Instead just run the WASM test from the test script wrapper. --- contrib/_test.sh | 9 --------- contrib/test.sh | 14 ++++++++++++++ 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/contrib/_test.sh b/contrib/_test.sh index 7303a5d..38c7315 100755 --- a/contrib/_test.sh +++ b/contrib/_test.sh @@ -86,15 +86,6 @@ if [ "$DO_DOCS" = true ]; then RUSTDOCFLAGS="-D warnings" cargo +stable doc --all-features fi -# Webassembly stuff -if [ "$DO_WASM" = true ]; then - clang --version - CARGO_TARGET_DIR=wasm cargo install --force wasm-pack - printf '\n[lib]\ncrate-type = ["cdylib", "rlib"]\n' >> Cargo.toml - CC=clang wasm-pack build - CC=clang wasm-pack test --node -fi - # Address Sanitizer if [ "$DO_ASAN" = true ]; then clang --version diff --git a/contrib/test.sh b/contrib/test.sh index 109601f..cd742e2 100755 --- a/contrib/test.sh +++ b/contrib/test.sh @@ -4,4 +4,18 @@ set -ex REPO_DIR=$(git rev-parse --show-toplevel) +# Webassembly stuff +# +# The wasm-pack command does not correctly pass args to cargo so we cannot use --locked and test +# with per-commited lockfiles (recent/minimal). Just run the WASM tests from here instead. +if [ "$DO_WASM" = true ]; then + clang --version + CARGO_TARGET_DIR=wasm cargo install --force wasm-pack + printf '\n[lib]\ncrate-type = ["cdylib", "rlib"]\n' >> Cargo.toml + CC=clang wasm-pack build + CC=clang wasm-pack test --node + + exit 0 +fi + $REPO_DIR/contrib/_test.sh From 3da39c6fb6131469a8cb0ec23292625d0a37b0e5 Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Thu, 20 Jul 2023 11:00:34 +1000 Subject: [PATCH 5/5] Run test with recent/minimal lock files Update the CI scripts to use the minimal/recent lockfiles, requires using `--locked` for various `cargo` incantations. --- contrib/_test.sh | 44 ++++++++++++++++++++++---------------------- contrib/test.sh | 21 ++++++++++++++++++++- 2 files changed, 42 insertions(+), 23 deletions(-) diff --git a/contrib/_test.sh b/contrib/_test.sh index 38c7315..c2f057e 100755 --- a/contrib/_test.sh +++ b/contrib/_test.sh @@ -29,50 +29,50 @@ cargo test -- --ignored --exact 'tests::test_panic_raw_ctx_should_terminate_abno export CARGO_TERM_VERBOSE=true # Defaults / sanity checks -cargo build --all -cargo test --all +cargo build --locked --all +cargo test --locked --all if [ "$DO_FEATURE_MATRIX" = true ]; then - cargo build --all --no-default-features - cargo test --all --no-default-features + cargo build --locked --all --no-default-features + cargo test --locked --all --no-default-features # All features - cargo build --all --no-default-features --features="$FEATURES" - cargo test --all --no-default-features --features="$FEATURES" + cargo build --locked --all --no-default-features --features="$FEATURES" + cargo test --locked --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" + cargo build --locked --all --no-default-features --features="$feature" + cargo test --locked --all --no-default-features --features="$feature" done # Features tested with 'std' feature enabled. for feature in ${FEATURES} do - cargo build --all --no-default-features --features="std,$feature" - cargo test --all --no-default-features --features="std,$feature" + cargo build --locked --all --no-default-features --features="std,$feature" + cargo test --locked --all --no-default-features --features="std,$feature" done # Other combos - RUSTFLAGS='--cfg=secp256k1_fuzz' RUSTDOCFLAGS='--cfg=secp256k1_fuzz' cargo test --all - RUSTFLAGS='--cfg=secp256k1_fuzz' RUSTDOCFLAGS='--cfg=secp256k1_fuzz' cargo test --all --features="$FEATURES" - cargo test --all --features="rand serde" + RUSTFLAGS='--cfg=secp256k1_fuzz' RUSTDOCFLAGS='--cfg=secp256k1_fuzz' cargo test --locked --all + RUSTFLAGS='--cfg=secp256k1_fuzz' RUSTDOCFLAGS='--cfg=secp256k1_fuzz' cargo test --locked --all --features="$FEATURES" + cargo test --locked --all --features="rand serde" if [ "$NIGHTLY" = true ]; then - cargo test --all --all-features - RUSTFLAGS='--cfg=secp256k1_fuzz' RUSTDOCFLAGS='--cfg=secp256k1_fuzz' cargo test --all --all-features + cargo test --locked --all --all-features + RUSTFLAGS='--cfg=secp256k1_fuzz' RUSTDOCFLAGS='--cfg=secp256k1_fuzz' cargo test --locked --all --all-features fi # Examples - cargo run --example sign_verify --features=bitcoin-hashes-std - cargo run --example sign_verify_recovery --features=recovery,bitcoin-hashes-std - cargo run --example generate_keys --features=rand-std + cargo run --locked --example sign_verify --features=bitcoin-hashes-std + cargo run --locked --example sign_verify_recovery --features=recovery,bitcoin-hashes-std + cargo run --locked --example generate_keys --features=rand-std fi if [ "$DO_LINT" = true ] then - cargo clippy --all-features --all-targets -- -D warnings - cargo clippy --example sign_verify --features=bitcoin-hashes-std -- -D warnings - cargo clippy --example sign_verify_recovery --features=recovery,bitcoin-hashes-std -- -D warnings - cargo clippy --example generate_keys --features=rand-std -- -D warnings + cargo clippy --locked --all-features --all-targets -- -D warnings + cargo clippy --locked --example sign_verify --features=bitcoin-hashes-std -- -D warnings + cargo clippy --locked --example sign_verify_recovery --features=recovery,bitcoin-hashes-std -- -D warnings + cargo clippy --locked --example generate_keys --features=rand-std -- -D warnings fi # Build the docs if told to (this only works with the nightly toolchain) diff --git a/contrib/test.sh b/contrib/test.sh index cd742e2..fa6c14a 100755 --- a/contrib/test.sh +++ b/contrib/test.sh @@ -3,6 +3,7 @@ set -ex REPO_DIR=$(git rev-parse --show-toplevel) +DEPS="recent minimal" # Webassembly stuff # @@ -18,4 +19,22 @@ if [ "$DO_WASM" = true ]; then exit 0 fi -$REPO_DIR/contrib/_test.sh +for dep in $DEPS +do + cp "Cargo-$dep.lock" Cargo.lock + $REPO_DIR/contrib/_test.sh + + if [ "$dep" = recent ]; + then + # We always test committed dependencies but we want to warn if they could've been updated + cargo update + if diff Cargo-recent.lock Cargo.lock; + then + echo "Dependencies are up to date" + else + echo "::warning file=Cargo-recent.lock::Dependencies could be updated" + fi + fi +done + +exit 0