Skip to content

Commit 5f47cd0

Browse files
real-or-randomFabcien
authored andcommitted
[secp256k1] ci: Run ASan/LSan and reorganize sanitizer and Valgrind jobs
Summary: ``` This enables asan (including lsan), and restructures the sanitizer builds. It also removes -fno-omit-frame-pointer again. This is debatable. The main reason for removing this is that GCC (but not clang) fails to build (runs out of registers) when combining asan, -fno-omit-frame-pointer, and the x86_64 asm. But I believe without -fno-omit-frame-pointer, the instrumented binary may be closer to the real binary, which is good. If we get unusable debugging output on CI without frame pointers, we can still reproduce the build locally. ``` Backport of [[bitcoin-core/secp256k1#846 | secp256k1#846]]. Completes backport of [[bitcoin-core/secp256k1#969 | secp256k1#969]]: bitcoin-core/secp256k1@3d2f492 Depends on D12957. Test Plan: ninja check-secp256k1 Tested the cirrus build against my personal github forked repo. Reviewers: #bitcoin_abc, sdulfari Reviewed By: #bitcoin_abc, sdulfari Subscribers: sdulfari Differential Revision: https://reviews.bitcoinabc.org/D12960
1 parent 73f49d5 commit 5f47cd0

File tree

4 files changed

+66
-47
lines changed

4 files changed

+66
-47
lines changed

src/secp256k1/.cirrus.yml

+53-24
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ env:
88
AUTOTOOLS_EXTRA_FLAGS:
99
CMAKE_EXTRA_FLAGS:
1010
WITH_VALGRIND: yes
11-
RUN_VALGRIND: no
1211
HOST:
1312
ECDH: no
1413
RECOVERY: no
@@ -19,7 +18,8 @@ env:
1918
MULTISET: no
2019
CTIMETEST: yes
2120
BENCH: yes
22-
ITERS: 2
21+
TEST_ITERS:
22+
BENCH_ITERS: 2
2323
MAKEFLAGS: -j2
2424

2525
cat_logs_snippet: &CAT_LOGS
@@ -56,29 +56,8 @@ task:
5656
# The Cirrus macOS VM has no java installed
5757
only_if: $CIRRUS_OS == 'linux'
5858
- env: {SCHNORR: no}
59-
- env:
60-
CFLAGS: "-fsanitize=undefined -fno-omit-frame-pointer"
61-
LDFLAGS: "-fsanitize=undefined -fno-omit-frame-pointer"
62-
UBSAN_OPTIONS: "print_stacktrace=1:halt_on_error=1"
63-
ASM: x86_64
64-
ECDH: yes
65-
RECOVERY: yes
66-
EXPERIMENTAL: yes
67-
MULTISET: yes
68-
SCHNORRSIG: yes
69-
CTIMETEST: no
7059
- env: { ECMULTGENPRECISION: 2 }
7160
- env: { ECMULTGENPRECISION: 8 }
72-
- env:
73-
RUN_VALGRIND: yes
74-
ASM: x86_64
75-
ECDH: yes
76-
RECOVERY: yes
77-
EXPERIMENTAL: yes
78-
MULTISET: yes
79-
SCHNORRSIG: yes
80-
AUTOTOOLS_TARGET:
81-
CMAKE_TARGET: "secp256k1-tests secp256k1-exhaustive_tests"
8261
matrix:
8362
- env:
8463
CC: gcc
@@ -178,7 +157,8 @@ task:
178157
cpu: 1
179158
memory: 1G
180159
env:
181-
QEMU_CMD: qemu-s390x
160+
WRAPPER_CMD: qemu-s390x
161+
TEST_ITERS: 16
182162
HOST: s390x-linux-gnu
183163
WITH_VALGRIND: no
184164
ECDH: yes
@@ -193,3 +173,52 @@ task:
193173
- rm /etc/ld.so.cache
194174
- ./ci/build_autotools.sh
195175
<< : *CAT_LOGS
176+
177+
# Sanitizers
178+
task:
179+
container:
180+
dockerfile: ci/linux-debian.Dockerfile
181+
cpu: 1
182+
memory: 1G
183+
env:
184+
ECDH: yes
185+
RECOVERY: yes
186+
EXPERIMENTAL: yes
187+
MULTISET: yes
188+
SCHNORRSIG: yes
189+
CTIMETEST: no
190+
matrix:
191+
- name: "Valgrind (memcheck)"
192+
env:
193+
# The `--error-exitcode` is required to make the test fail if valgrind
194+
# found errors, otherwise it'll return 0
195+
# (https://www.valgrind.org/docs/manual/manual-core.html)
196+
WRAPPER_CMD: "valgrind --error-exitcode=42"
197+
TEST_ITERS: 16
198+
AUTOTOOLS_TARGET:
199+
CMAKE_TARGET: "secp256k1-tests secp256k1-exhaustive_tests"
200+
- name: "UBSan, ASan, LSan"
201+
env:
202+
CFLAGS: "-fsanitize=undefined,address"
203+
CFLAGS_FOR_BUILD: "-fsanitize=undefined,address"
204+
UBSAN_OPTIONS: "print_stacktrace=1:halt_on_error=1"
205+
ASAN_OPTIONS: "strict_string_checks=1:detect_stack_use_after_return=1:detect_leaks=1"
206+
LSAN_OPTIONS: "use_unaligned=1"
207+
TEST_ITERS: 32
208+
# Try to cover many configurations with just a tiny matrix.
209+
matrix:
210+
- env:
211+
STATICPRECOMPUTATION: yes
212+
- env:
213+
STATICPRECOMPUTATION: no
214+
ECMULTGENPRECISION: 2
215+
matrix:
216+
- env:
217+
CC: clang
218+
- env:
219+
HOST: i686-linux-gnu
220+
CC: i686-linux-gnu-gcc
221+
test_script:
222+
- ./ci/build_autotools.sh
223+
- ./ci/build_cmake.sh
224+
<< : *CAT_LOGS

src/secp256k1/ci/build_autotools.sh

+9-20
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,13 @@ print_logs() {
5555
}
5656
trap 'print_logs' ERR
5757

58+
# This tells `make check` to wrap test invocations.
59+
export LOG_COMPILER="$WRAPPER_CMD"
60+
61+
# This limits the iterations in the tests and benchmarks.
62+
export SECP256K1_TEST_ITERS="$TEST_ITERS"
63+
export SECP256K1_BENCH_ITERS="$BENCH_ITERS"
64+
5865
# We have set "-j<n>" in MAKEFLAGS.
5966
make $AUTOTOOLS_TARGET
6067

@@ -63,32 +70,14 @@ file *tests || true
6370
file bench_* || true
6471
file .libs/* || true
6572

66-
if [ "$RUN_VALGRIND" = "yes" ]; then
67-
# the `--error-exitcode` is required to make the test fail if valgrind found
68-
# errors, otherwise it'll return 0
69-
# (https://www.valgrind.org/docs/manual/manual-core.html)
70-
valgrind --error-exitcode=42 ./tests 16
71-
valgrind --error-exitcode=42 ./exhaustive_tests
72-
fi
73-
74-
if [ -n "$QEMU_CMD" ]; then
75-
$QEMU_CMD ./tests 16
76-
$QEMU_CMD ./exhaustive_tests
77-
fi
78-
7973
if [ "$BENCH" = "yes" ]; then
8074
# Using the local `libtool` because on macOS the system's libtool has
8175
# nothing to do with GNU libtool
8276
EXEC='./libtool --mode=execute'
83-
if [ -n "$QEMU_CMD" ]; then
84-
EXEC="$EXEC $QEMU_CMD"
85-
fi
86-
if [ "$RUN_VALGRIND" = "yes" ]; then
87-
EXEC="$EXEC valgrind --error-exitcode=42"
77+
if [ -n "$WRAPPER_CMD" ]; then
78+
EXEC="$EXEC $WRAPPER_CMD"
8879
fi
8980

90-
# This limits the iterations in the benchmarks below to ITER iterations.
91-
export SECP256K1_BENCH_ITERS="$ITERS"
9281
{
9382
$EXEC ./bench_ecmult
9483
$EXEC ./bench_internal

src/secp256k1/ci/linux-debian.Dockerfile

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ RUN dpkg --add-architecture s390x
55
RUN apt-get update
66

77
# dkpg-dev: to make pkg-config work in cross-builds
8+
# llvm: for llvm-symbolizer, which is used by clang's UBSan for symbolized stack traces
89
RUN apt-get install --no-install-recommends --no-upgrade -y \
910
automake cmake default-jdk dpkg-dev libssl-dev libtool make ninja-build pkg-config python3 qemu-user valgrind \
10-
gcc clang libc6-dbg \
11-
gcc-i686-linux-gnu libc6-dev-i386-cross libc6-dbg:i386 \
11+
gcc clang llvm libc6-dbg \
12+
gcc-i686-linux-gnu libc6-dev-i386-cross libc6-dbg:i386 libubsan1:i386 libasan6:i386 \
1213
gcc-s390x-linux-gnu libc6-dev-s390x-cross libc6-dbg:s390x

src/secp256k1/src/tests.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -5701,7 +5701,7 @@ int main(int argc, char **argv) {
57015701
count = strtol(argv[1], NULL, 0);
57025702
} else {
57035703
const char* env = getenv("SECP256K1_TEST_ITERS");
5704-
if (env) {
5704+
if (env && strlen(env) > 0) {
57055705
count = strtol(env, NULL, 0);
57065706
}
57075707
}

0 commit comments

Comments
 (0)