Skip to content

Commit b586df6

Browse files
committed
ci: 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.
1 parent e086fb3 commit b586df6

File tree

2 files changed

+131
-124
lines changed

2 files changed

+131
-124
lines changed

contrib/_test.sh

+129
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
#!/bin/sh
2+
3+
set -ex
4+
5+
FEATURES="bitcoin-hashes global-context lowmemory rand recovery serde std alloc bitcoin-hashes-std rand-std"
6+
7+
cargo --version
8+
rustc --version
9+
10+
# Work out if we are using a nightly toolchain.
11+
NIGHTLY=false
12+
if cargo --version | grep nightly; then
13+
NIGHTLY=true
14+
fi
15+
16+
# Pin dependencies as required if we are using MSRV toolchain.
17+
if cargo --version | grep "1\.48"; then
18+
cargo update -p wasm-bindgen-test --precise 0.3.34
19+
cargo update -p serde --precise 1.0.156
20+
fi
21+
22+
# Test if panic in C code aborts the process (either with a real panic or with SIGILL)
23+
cargo test -- --ignored --exact 'tests::test_panic_raw_ctx_should_terminate_abnormally' 2>&1 | tee /dev/stderr | grep "SIGILL\\|panicked at '\[libsecp256k1\]"
24+
25+
# Make all cargo invocations verbose
26+
export CARGO_TERM_VERBOSE=true
27+
28+
# Defaults / sanity checks
29+
cargo build --all
30+
cargo test --all
31+
32+
if [ "$DO_FEATURE_MATRIX" = true ]; then
33+
cargo build --all --no-default-features
34+
cargo test --all --no-default-features
35+
36+
# All features
37+
cargo build --all --no-default-features --features="$FEATURES"
38+
cargo test --all --no-default-features --features="$FEATURES"
39+
# Single features
40+
for feature in ${FEATURES}
41+
do
42+
cargo build --all --no-default-features --features="$feature"
43+
cargo test --all --no-default-features --features="$feature"
44+
done
45+
# Features tested with 'std' feature enabled.
46+
for feature in ${FEATURES}
47+
do
48+
cargo build --all --no-default-features --features="std,$feature"
49+
cargo test --all --no-default-features --features="std,$feature"
50+
done
51+
# Other combos
52+
RUSTFLAGS='--cfg=secp256k1_fuzz' RUSTDOCFLAGS='--cfg=secp256k1_fuzz' cargo test --all
53+
RUSTFLAGS='--cfg=secp256k1_fuzz' RUSTDOCFLAGS='--cfg=secp256k1_fuzz' cargo test --all --features="$FEATURES"
54+
cargo test --all --features="rand serde"
55+
56+
if [ "$NIGHTLY" = true ]; then
57+
cargo test --all --all-features
58+
RUSTFLAGS='--cfg=secp256k1_fuzz' RUSTDOCFLAGS='--cfg=secp256k1_fuzz' cargo test --all --all-features
59+
fi
60+
61+
# Examples
62+
cargo run --example sign_verify --features=bitcoin-hashes-std
63+
cargo run --example sign_verify_recovery --features=recovery,bitcoin-hashes-std
64+
cargo run --example generate_keys --features=rand-std
65+
fi
66+
67+
if [ "$DO_LINT" = true ]
68+
then
69+
cargo clippy --all-features --all-targets -- -D warnings
70+
cargo clippy --example sign_verify --features=bitcoin-hashes-std -- -D warnings
71+
cargo clippy --example sign_verify_recovery --features=recovery,bitcoin-hashes-std -- -D warnings
72+
cargo clippy --example generate_keys --features=rand-std -- -D warnings
73+
fi
74+
75+
# Build the docs if told to (this only works with the nightly toolchain)
76+
if [ "$DO_DOCSRS" = true ]; then
77+
RUSTDOCFLAGS="--cfg docsrs -D warnings -D rustdoc::broken-intra-doc-links" cargo +nightly doc --all-features
78+
fi
79+
80+
# Build the docs with a stable toolchain, in unison with the DO_DOCSRS command
81+
# above this checks that we feature guarded docs imports correctly.
82+
if [ "$DO_DOCS" = true ]; then
83+
RUSTDOCFLAGS="-D warnings" cargo +stable doc --all-features
84+
fi
85+
86+
# Webassembly stuff
87+
if [ "$DO_WASM" = true ]; then
88+
clang --version
89+
CARGO_TARGET_DIR=wasm cargo install --force wasm-pack
90+
printf '\n[lib]\ncrate-type = ["cdylib", "rlib"]\n' >> Cargo.toml
91+
CC=clang wasm-pack build
92+
CC=clang wasm-pack test --node
93+
fi
94+
95+
# Address Sanitizer
96+
if [ "$DO_ASAN" = true ]; then
97+
clang --version
98+
cargo clean
99+
CC='clang -fsanitize=address -fno-omit-frame-pointer' \
100+
RUSTFLAGS='-Zsanitizer=address -Clinker=clang -Cforce-frame-pointers=yes' \
101+
ASAN_OPTIONS='detect_leaks=1 detect_invalid_pointer_pairs=1 detect_stack_use_after_return=1' \
102+
cargo test --lib --all --features="$FEATURES" -Zbuild-std --target x86_64-unknown-linux-gnu
103+
cargo clean
104+
# The -Cllvm-args=-msan-eager-checks=0 flag was added to overcome this issue:
105+
# https://github.com/rust-bitcoin/rust-secp256k1/pull/573#issuecomment-1399465995
106+
CC='clang -fsanitize=memory -fno-omit-frame-pointer' \
107+
RUSTFLAGS='-Zsanitizer=memory -Zsanitizer-memory-track-origins -Cforce-frame-pointers=yes -Cllvm-args=-msan-eager-checks=0' \
108+
cargo test --lib --all --features="$FEATURES" -Zbuild-std --target x86_64-unknown-linux-gnu
109+
cargo run --release --manifest-path=./no_std_test/Cargo.toml | grep -q "Verified Successfully"
110+
cargo run --release --features=alloc --manifest-path=./no_std_test/Cargo.toml | grep -q "Verified alloc Successfully"
111+
fi
112+
113+
# Run formatter if told to.
114+
if [ "$DO_FMT" = true ]; then
115+
if [ "$NIGHTLY" = false ]; then
116+
echo "DO_FMT requires a nightly toolchain (consider using RUSTUP_TOOLCHAIN)"
117+
exit 1
118+
fi
119+
rustup component add rustfmt
120+
cargo fmt --check || exit 1
121+
fi
122+
123+
# Bench if told to, only works with non-stable toolchain (nightly, beta).
124+
if [ "$DO_BENCH" = true ]
125+
then
126+
RUSTFLAGS='--cfg=bench' cargo bench --features=recovery,rand-std
127+
fi
128+
129+
exit 0

contrib/test.sh

+2-124
Original file line numberDiff line numberDiff line change
@@ -2,128 +2,6 @@
22

33
set -ex
44

5-
FEATURES="bitcoin-hashes global-context lowmemory rand recovery serde std alloc bitcoin-hashes-std rand-std"
5+
REPO_DIR=$(git rev-parse --show-toplevel)
66

7-
cargo --version
8-
rustc --version
9-
10-
# Work out if we are using a nightly toolchain.
11-
NIGHTLY=false
12-
if cargo --version | grep nightly; then
13-
NIGHTLY=true
14-
fi
15-
16-
# Pin dependencies as required if we are using MSRV toolchain.
17-
if cargo --version | grep "1\.48"; then
18-
cargo update -p wasm-bindgen-test --precise 0.3.34
19-
cargo update -p serde --precise 1.0.156
20-
fi
21-
22-
# Test if panic in C code aborts the process (either with a real panic or with SIGILL)
23-
cargo test -- --ignored --exact 'tests::test_panic_raw_ctx_should_terminate_abnormally' 2>&1 | tee /dev/stderr | grep "SIGILL\\|panicked at '\[libsecp256k1\]"
24-
25-
# Make all cargo invocations verbose
26-
export CARGO_TERM_VERBOSE=true
27-
28-
# Defaults / sanity checks
29-
cargo build --all
30-
cargo test --all
31-
32-
if [ "$DO_FEATURE_MATRIX" = true ]; then
33-
cargo build --all --no-default-features
34-
cargo test --all --no-default-features
35-
36-
# All features
37-
cargo build --all --no-default-features --features="$FEATURES"
38-
cargo test --all --no-default-features --features="$FEATURES"
39-
# Single features
40-
for feature in ${FEATURES}
41-
do
42-
cargo build --all --no-default-features --features="$feature"
43-
cargo test --all --no-default-features --features="$feature"
44-
done
45-
# Features tested with 'std' feature enabled.
46-
for feature in ${FEATURES}
47-
do
48-
cargo build --all --no-default-features --features="std,$feature"
49-
cargo test --all --no-default-features --features="std,$feature"
50-
done
51-
# Other combos
52-
RUSTFLAGS='--cfg=secp256k1_fuzz' RUSTDOCFLAGS='--cfg=secp256k1_fuzz' cargo test --all
53-
RUSTFLAGS='--cfg=secp256k1_fuzz' RUSTDOCFLAGS='--cfg=secp256k1_fuzz' cargo test --all --features="$FEATURES"
54-
cargo test --all --features="rand serde"
55-
56-
if [ "$NIGHTLY" = true ]; then
57-
cargo test --all --all-features
58-
RUSTFLAGS='--cfg=secp256k1_fuzz' RUSTDOCFLAGS='--cfg=secp256k1_fuzz' cargo test --all --all-features
59-
fi
60-
61-
# Examples
62-
cargo run --example sign_verify --features=bitcoin-hashes-std
63-
cargo run --example sign_verify_recovery --features=recovery,bitcoin-hashes-std
64-
cargo run --example generate_keys --features=rand-std
65-
fi
66-
67-
if [ "$DO_LINT" = true ]
68-
then
69-
cargo clippy --all-features --all-targets -- -D warnings
70-
cargo clippy --example sign_verify --features=bitcoin-hashes-std -- -D warnings
71-
cargo clippy --example sign_verify_recovery --features=recovery,bitcoin-hashes-std -- -D warnings
72-
cargo clippy --example generate_keys --features=rand-std -- -D warnings
73-
fi
74-
75-
# Build the docs if told to (this only works with the nightly toolchain)
76-
if [ "$DO_DOCSRS" = true ]; then
77-
RUSTDOCFLAGS="--cfg docsrs -D warnings -D rustdoc::broken-intra-doc-links" cargo +nightly doc --all-features
78-
fi
79-
80-
# Build the docs with a stable toolchain, in unison with the DO_DOCSRS command
81-
# above this checks that we feature guarded docs imports correctly.
82-
if [ "$DO_DOCS" = true ]; then
83-
RUSTDOCFLAGS="-D warnings" cargo +stable doc --all-features
84-
fi
85-
86-
# Webassembly stuff
87-
if [ "$DO_WASM" = true ]; then
88-
clang --version
89-
CARGO_TARGET_DIR=wasm cargo install --force wasm-pack
90-
printf '\n[lib]\ncrate-type = ["cdylib", "rlib"]\n' >> Cargo.toml
91-
CC=clang wasm-pack build
92-
CC=clang wasm-pack test --node
93-
fi
94-
95-
# Address Sanitizer
96-
if [ "$DO_ASAN" = true ]; then
97-
clang --version
98-
cargo clean
99-
CC='clang -fsanitize=address -fno-omit-frame-pointer' \
100-
RUSTFLAGS='-Zsanitizer=address -Clinker=clang -Cforce-frame-pointers=yes' \
101-
ASAN_OPTIONS='detect_leaks=1 detect_invalid_pointer_pairs=1 detect_stack_use_after_return=1' \
102-
cargo test --lib --all --features="$FEATURES" -Zbuild-std --target x86_64-unknown-linux-gnu
103-
cargo clean
104-
# The -Cllvm-args=-msan-eager-checks=0 flag was added to overcome this issue:
105-
# https://github.com/rust-bitcoin/rust-secp256k1/pull/573#issuecomment-1399465995
106-
CC='clang -fsanitize=memory -fno-omit-frame-pointer' \
107-
RUSTFLAGS='-Zsanitizer=memory -Zsanitizer-memory-track-origins -Cforce-frame-pointers=yes -Cllvm-args=-msan-eager-checks=0' \
108-
cargo test --lib --all --features="$FEATURES" -Zbuild-std --target x86_64-unknown-linux-gnu
109-
cargo run --release --manifest-path=./no_std_test/Cargo.toml | grep -q "Verified Successfully"
110-
cargo run --release --features=alloc --manifest-path=./no_std_test/Cargo.toml | grep -q "Verified alloc Successfully"
111-
fi
112-
113-
# Run formatter if told to.
114-
if [ "$DO_FMT" = true ]; then
115-
if [ "$NIGHTLY" = false ]; then
116-
echo "DO_FMT requires a nightly toolchain (consider using RUSTUP_TOOLCHAIN)"
117-
exit 1
118-
fi
119-
rustup component add rustfmt
120-
cargo fmt --check || exit 1
121-
fi
122-
123-
# Bench if told to, only works with non-stable toolchain (nightly, beta).
124-
if [ "$DO_BENCH" = true ]
125-
then
126-
RUSTFLAGS='--cfg=bench' cargo bench --features=recovery,rand-std
127-
fi
128-
129-
exit 0
7+
$REPO_DIR/contrib/_test.sh

0 commit comments

Comments
 (0)