Skip to content

Commit 3dc8c07

Browse files
committed
Merge bitcoin#846: ci: Run ASan/LSan and reorganize sanitizer and Valgrind jobs
02dcea1 ci: Make test iterations configurable and tweak for sanitizer builds (Tim Ruffing) 489ff5c tests: Treat empty SECP2561_TEST_ITERS as if it was unset (Tim Ruffing) fcfcb97 ci: Simplify to use generic wrapper for QEMU, Valgrind, etc (Tim Ruffing) de4157f ci: Run ASan/LSan and reorganize sanitizer and Valgrind jobs (Tim Ruffing) Pull request description: ACKs for top commit: sipa: utACK 02dcea1 jonasnick: ACK 02dcea1 spot-checked ci output, checked that when `valgrind ./tests` crashes then `LOG_COMPILER=valgrind make check` also crashes. Tree-SHA512: 5f4a2fe186eca0b4ca29190eb18e20d0804934df614cdc8eb8cf0145ff36ded43194325572bb77eaaeba85c369f6effe69b7bdf7df97ba418d72cf36c9749a8c
2 parents 399722a + 02dcea1 commit 3dc8c07

File tree

4 files changed

+70
-65
lines changed

4 files changed

+70
-65
lines changed

.cirrus.yml

Lines changed: 58 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ env:
55
ASM: no
66
BUILD: check
77
WITH_VALGRIND: yes
8-
RUN_VALGRIND: no
98
EXTRAFLAGS:
109
HOST:
1110
ECDH: no
@@ -14,7 +13,8 @@ env:
1413
EXPERIMENTAL: no
1514
CTIMETEST: yes
1615
BENCH: yes
17-
ITERS: 2
16+
TEST_ITERS:
17+
BENCH_ITERS: 2
1818
MAKEFLAGS: -j2
1919

2020
cat_logs_snippet: &CAT_LOGS
@@ -63,27 +63,8 @@ task:
6363
- env: {BUILD: distcheck, WITH_VALGRIND: no, CTIMETEST: no, BENCH: no}
6464
- env: {CPPFLAGS: -DDETERMINISTIC}
6565
- env: {CFLAGS: -O0, CTIMETEST: no}
66-
- env:
67-
CFLAGS: "-fsanitize=undefined -fno-omit-frame-pointer"
68-
LDFLAGS: "-fsanitize=undefined -fno-omit-frame-pointer"
69-
UBSAN_OPTIONS: "print_stacktrace=1:halt_on_error=1"
70-
ASM: x86_64
71-
ECDH: yes
72-
RECOVERY: yes
73-
EXPERIMENTAL: yes
74-
SCHNORRSIG: yes
75-
CTIMETEST: no
7666
- env: { ECMULTGENPRECISION: 2 }
7767
- env: { ECMULTGENPRECISION: 8 }
78-
- env:
79-
RUN_VALGRIND: yes
80-
ASM: x86_64
81-
ECDH: yes
82-
RECOVERY: yes
83-
EXPERIMENTAL: yes
84-
SCHNORRSIG: yes
85-
EXTRAFLAGS: "--disable-openssl-tests"
86-
BUILD:
8768
matrix:
8869
- env:
8970
CC: gcc
@@ -181,9 +162,9 @@ task:
181162
cpu: 1
182163
memory: 1G
183164
env:
184-
QEMU_CMD: qemu-s390x
165+
WRAPPER_CMD: qemu-s390x
166+
TEST_ITERS: 16
185167
HOST: s390x-linux-gnu
186-
BUILD:
187168
WITH_VALGRIND: no
188169
ECDH: yes
189170
RECOVERY: yes
@@ -204,9 +185,9 @@ task:
204185
cpu: 1
205186
memory: 1G
206187
env:
207-
QEMU_CMD: qemu-arm
188+
WRAPPER_CMD: qemu-arm
189+
TEST_ITERS: 16
208190
HOST: arm-linux-gnueabihf
209-
BUILD:
210191
WITH_VALGRIND: no
211192
ECDH: yes
212193
RECOVERY: yes
@@ -228,9 +209,9 @@ task:
228209
cpu: 1
229210
memory: 1G
230211
env:
231-
QEMU_CMD: qemu-aarch64
212+
WRAPPER_CMD: qemu-aarch64
213+
TEST_ITERS: 16
232214
HOST: aarch64-linux-gnu
233-
BUILD:
234215
WITH_VALGRIND: no
235216
ECDH: yes
236217
RECOVERY: yes
@@ -249,9 +230,9 @@ task:
249230
cpu: 1
250231
memory: 1G
251232
env:
252-
WINE_CMD: wine64-stable
233+
WRAPPER_CMD: wine64-stable
234+
TEST_ITERS: 16
253235
HOST: x86_64-w64-mingw32
254-
BUILD:
255236
WITH_VALGRIND: no
256237
ECDH: yes
257238
RECOVERY: yes
@@ -262,3 +243,51 @@ task:
262243
test_script:
263244
- ./ci/cirrus.sh
264245
<< : *CAT_LOGS
246+
247+
# Sanitizers
248+
task:
249+
container:
250+
dockerfile: ci/linux-debian.Dockerfile
251+
cpu: 1
252+
memory: 1G
253+
env:
254+
ECDH: yes
255+
RECOVERY: yes
256+
EXPERIMENTAL: yes
257+
SCHNORRSIG: yes
258+
CTIMETEST: no
259+
EXTRAFLAGS: "--disable-openssl-tests"
260+
matrix:
261+
- name: "Valgrind (memcheck)"
262+
env:
263+
# The `--error-exitcode` is required to make the test fail if valgrind found errors, otherwise it'll return 0 (https://www.valgrind.org/docs/manual/manual-core.html)
264+
WRAPPER_CMD: "valgrind --error-exitcode=42"
265+
TEST_ITERS: 16
266+
- name: "UBSan, ASan, LSan"
267+
env:
268+
CFLAGS: "-fsanitize=undefined,address"
269+
CFLAGS_FOR_BUILD: "-fsanitize=undefined,address"
270+
UBSAN_OPTIONS: "print_stacktrace=1:halt_on_error=1"
271+
ASAN_OPTIONS: "strict_string_checks=1:detect_stack_use_after_return=1:detect_leaks=1"
272+
LSAN_OPTIONS: "use_unaligned=1"
273+
TEST_ITERS: 32
274+
# Try to cover many configurations with just a tiny matrix.
275+
matrix:
276+
- env:
277+
ASM: auto
278+
STATICPRECOMPUTATION: yes
279+
- env:
280+
ASM: no
281+
STATICPRECOMPUTATION: no
282+
ECMULTGENPRECISION: 2
283+
matrix:
284+
- env:
285+
CC: clang
286+
- env:
287+
HOST: i686-linux-gnu
288+
CC: i686-linux-gnu-gcc
289+
<< : *MERGE_BASE
290+
test_script:
291+
- ./ci/cirrus.sh
292+
<< : *CAT_LOGS
293+

ci/cirrus.sh

Lines changed: 8 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -29,48 +29,23 @@ file *tests* || true
2929
file bench_* || true
3030
file .libs/* || true
3131

32-
if [ -n "$BUILD" ]
33-
then
34-
make "$BUILD"
35-
fi
32+
# This tells `make check` to wrap test invocations.
33+
export LOG_COMPILER="$WRAPPER_CMD"
3634

37-
if [ "$RUN_VALGRIND" = "yes" ]
38-
then
39-
# the `--error-exitcode` is required to make the test fail if valgrind found errors, otherwise it'll return 0 (https://www.valgrind.org/docs/manual/manual-core.html)
40-
valgrind --error-exitcode=42 ./tests 16
41-
valgrind --error-exitcode=42 ./exhaustive_tests
42-
fi
35+
# This limits the iterations in the tests and benchmarks.
36+
export SECP256K1_TEST_ITERS="$TEST_ITERS"
37+
export SECP256K1_BENCH_ITERS="$BENCH_ITERS"
4338

44-
if [ -n "$QEMU_CMD" ]
45-
then
46-
$QEMU_CMD ./tests 16
47-
$QEMU_CMD ./exhaustive_tests
48-
fi
49-
50-
if [ -n "$WINE_CMD" ]
51-
then
52-
$WINE_CMD ./tests 16
53-
$WINE_CMD ./exhaustive_tests
54-
fi
39+
make "$BUILD"
5540

5641
if [ "$BENCH" = "yes" ]
5742
then
5843
# Using the local `libtool` because on macOS the system's libtool has nothing to do with GNU libtool
5944
EXEC='./libtool --mode=execute'
60-
if [ -n "$QEMU_CMD" ]
61-
then
62-
EXEC="$EXEC $QEMU_CMD"
63-
fi
64-
if [ "$RUN_VALGRIND" = "yes" ]
65-
then
66-
EXEC="$EXEC valgrind --error-exitcode=42"
67-
fi
68-
if [ -n "$WINE_CMD" ]
45+
if [ -n "$WRAPPER_CMD" ]
6946
then
70-
EXEC="$WINE_CMD"
47+
EXEC="$EXEC $WRAPPER_CMD"
7148
fi
72-
# This limits the iterations in the benchmarks below to ITER iterations.
73-
export SECP256K1_BENCH_ITERS="$ITERS"
7449
{
7550
$EXEC ./bench_ecmult
7651
$EXEC ./bench_internal

ci/linux-debian.Dockerfile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@ RUN dpkg --add-architecture arm64
77
RUN apt-get update
88

99
# dkpg-dev: to make pkg-config work in cross-builds
10+
# llvm: for llvm-symbolizer, which is used by clang's UBSan for symbolized stack traces
1011
RUN apt-get install --no-install-recommends --no-upgrade -y \
1112
git ca-certificates \
1213
make automake libtool pkg-config dpkg-dev valgrind qemu-user \
13-
gcc clang libc6-dbg \
14-
gcc-i686-linux-gnu libc6-dev-i386-cross libc6-dbg:i386 \
14+
gcc clang llvm libc6-dbg \
15+
gcc-i686-linux-gnu libc6-dev-i386-cross libc6-dbg:i386 libubsan1:i386 libasan5:i386 \
1516
gcc-s390x-linux-gnu libc6-dev-s390x-cross libc6-dbg:s390x \
1617
gcc-arm-linux-gnueabihf libc6-dev-armhf-cross libc6-dbg:armhf \
1718
gcc-aarch64-linux-gnu libc6-dev-arm64-cross libc6-dbg:arm64 \

src/tests.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6471,7 +6471,7 @@ int main(int argc, char **argv) {
64716471
count = strtol(argv[1], NULL, 0);
64726472
} else {
64736473
const char* env = getenv("SECP256K1_TEST_ITERS");
6474-
if (env) {
6474+
if (env && strlen(env) > 0) {
64756475
count = strtol(env, NULL, 0);
64766476
}
64776477
}

0 commit comments

Comments
 (0)