Skip to content

Commit 8d4ae02

Browse files
committed
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 ca013fe commit 8d4ae02

File tree

2 files changed

+131
-126
lines changed

2 files changed

+131
-126
lines changed

contrib/_test.sh

Lines changed: 129 additions & 0 deletions
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

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

0 commit comments

Comments
 (0)