From de4157f13acc43d521e3133ff1d2e7d67484f0ac Mon Sep 17 00:00:00 2001 From: Tim Ruffing Date: Mon, 9 Nov 2020 17:52:12 +0100 Subject: [PATCH 1/4] ci: Run ASan/LSan and reorganize sanitizer and Valgrind jobs --- .cirrus.yml | 64 +++++++++++++++++++++++++++----------- ci/linux-debian.Dockerfile | 5 +-- 2 files changed, 48 insertions(+), 21 deletions(-) diff --git a/.cirrus.yml b/.cirrus.yml index c829835..6a3b4b2 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -63,27 +63,8 @@ task: - env: {BUILD: distcheck, WITH_VALGRIND: no, CTIMETEST: no, BENCH: no} - env: {CPPFLAGS: -DDETERMINISTIC} - env: {CFLAGS: -O0, CTIMETEST: no} - - env: - CFLAGS: "-fsanitize=undefined -fno-omit-frame-pointer" - LDFLAGS: "-fsanitize=undefined -fno-omit-frame-pointer" - UBSAN_OPTIONS: "print_stacktrace=1:halt_on_error=1" - ASM: x86_64 - ECDH: yes - RECOVERY: yes - EXPERIMENTAL: yes - SCHNORRSIG: yes - CTIMETEST: no - env: { ECMULTGENPRECISION: 2 } - env: { ECMULTGENPRECISION: 8 } - - env: - RUN_VALGRIND: yes - ASM: x86_64 - ECDH: yes - RECOVERY: yes - EXPERIMENTAL: yes - SCHNORRSIG: yes - EXTRAFLAGS: "--disable-openssl-tests" - BUILD: matrix: - env: CC: gcc @@ -262,3 +243,48 @@ task: test_script: - ./ci/cirrus.sh << : *CAT_LOGS + +# Sanitizers +task: + container: + dockerfile: ci/linux-debian.Dockerfile + cpu: 1 + memory: 1G + env: + ECDH: yes + RECOVERY: yes + EXPERIMENTAL: yes + SCHNORRSIG: yes + CTIMETEST: no + EXTRAFLAGS: "--disable-openssl-tests" + matrix: + - name: "Valgrind (memcheck)" + env: + RUN_VALGRIND: yes + - name: "UBSan, ASan, LSan" + env: + CFLAGS: "-fsanitize=undefined,address" + CFLAGS_FOR_BUILD: "-fsanitize=undefined,address" + UBSAN_OPTIONS: "print_stacktrace=1:halt_on_error=1" + ASAN_OPTIONS: "strict_string_checks=1:detect_stack_use_after_return=1:detect_leaks=1" + LSAN_OPTIONS: "use_unaligned=1" + # Try to cover many configurations with just a tiny matrix. + matrix: + - env: + ASM: auto + STATICPRECOMPUTATION: yes + - env: + ASM: no + STATICPRECOMPUTATION: no + ECMULTGENPRECISION: 2 + matrix: + - env: + CC: clang + - env: + HOST: i686-linux-gnu + CC: i686-linux-gnu-gcc + << : *MERGE_BASE + test_script: + - ./ci/cirrus.sh + << : *CAT_LOGS + diff --git a/ci/linux-debian.Dockerfile b/ci/linux-debian.Dockerfile index 6559c58..e06c816 100644 --- a/ci/linux-debian.Dockerfile +++ b/ci/linux-debian.Dockerfile @@ -7,11 +7,12 @@ RUN dpkg --add-architecture arm64 RUN apt-get update # dkpg-dev: to make pkg-config work in cross-builds +# llvm: for llvm-symbolizer, which is used by clang's UBSan for symbolized stack traces RUN apt-get install --no-install-recommends --no-upgrade -y \ git ca-certificates \ make automake libtool pkg-config dpkg-dev valgrind qemu-user \ - gcc clang libc6-dbg \ - gcc-i686-linux-gnu libc6-dev-i386-cross libc6-dbg:i386 \ + gcc clang llvm libc6-dbg \ + gcc-i686-linux-gnu libc6-dev-i386-cross libc6-dbg:i386 libubsan1:i386 libasan5:i386 \ gcc-s390x-linux-gnu libc6-dev-s390x-cross libc6-dbg:s390x \ gcc-arm-linux-gnueabihf libc6-dev-armhf-cross libc6-dbg:armhf \ gcc-aarch64-linux-gnu libc6-dev-arm64-cross libc6-dbg:arm64 \ From fcfcb97e74b55a107290d44c81c049d6168e954f Mon Sep 17 00:00:00 2001 From: Tim Ruffing Date: Mon, 17 May 2021 17:19:01 +0200 Subject: [PATCH 2/4] ci: Simplify to use generic wrapper for QEMU, Valgrind, etc --- .cirrus.yml | 16 ++++++---------- ci/cirrus.sh | 37 +++++-------------------------------- 2 files changed, 11 insertions(+), 42 deletions(-) diff --git a/.cirrus.yml b/.cirrus.yml index 6a3b4b2..25579d9 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -5,7 +5,6 @@ env: ASM: no BUILD: check WITH_VALGRIND: yes - RUN_VALGRIND: no EXTRAFLAGS: HOST: ECDH: no @@ -162,9 +161,8 @@ task: cpu: 1 memory: 1G env: - QEMU_CMD: qemu-s390x + WRAPPER_CMD: qemu-s390x HOST: s390x-linux-gnu - BUILD: WITH_VALGRIND: no ECDH: yes RECOVERY: yes @@ -185,9 +183,8 @@ task: cpu: 1 memory: 1G env: - QEMU_CMD: qemu-arm + WRAPPER_CMD: qemu-arm HOST: arm-linux-gnueabihf - BUILD: WITH_VALGRIND: no ECDH: yes RECOVERY: yes @@ -209,9 +206,8 @@ task: cpu: 1 memory: 1G env: - QEMU_CMD: qemu-aarch64 + WRAPPER_CMD: qemu-aarch64 HOST: aarch64-linux-gnu - BUILD: WITH_VALGRIND: no ECDH: yes RECOVERY: yes @@ -230,9 +226,8 @@ task: cpu: 1 memory: 1G env: - WINE_CMD: wine64-stable + WRAPPER_CMD: wine64-stable HOST: x86_64-w64-mingw32 - BUILD: WITH_VALGRIND: no ECDH: yes RECOVERY: yes @@ -260,7 +255,8 @@ task: matrix: - name: "Valgrind (memcheck)" env: - RUN_VALGRIND: yes + # 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) + WRAPPER_CMD: "valgrind --error-exitcode=42" - name: "UBSan, ASan, LSan" env: CFLAGS: "-fsanitize=undefined,address" diff --git a/ci/cirrus.sh b/ci/cirrus.sh index dafab8a..060335e 100755 --- a/ci/cirrus.sh +++ b/ci/cirrus.sh @@ -29,45 +29,18 @@ file *tests* || true file bench_* || true file .libs/* || true -if [ -n "$BUILD" ] -then - make "$BUILD" -fi +# This tells `make check` to wrap test invocations. +export LOG_COMPILER="$WRAPPER_CMD" -if [ "$RUN_VALGRIND" = "yes" ] -then - # 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) - valgrind --error-exitcode=42 ./tests 16 - valgrind --error-exitcode=42 ./exhaustive_tests -fi - -if [ -n "$QEMU_CMD" ] -then - $QEMU_CMD ./tests 16 - $QEMU_CMD ./exhaustive_tests -fi - -if [ -n "$WINE_CMD" ] -then - $WINE_CMD ./tests 16 - $WINE_CMD ./exhaustive_tests -fi +make "$BUILD" if [ "$BENCH" = "yes" ] then # Using the local `libtool` because on macOS the system's libtool has nothing to do with GNU libtool EXEC='./libtool --mode=execute' - if [ -n "$QEMU_CMD" ] + if [ -n "$WRAPPER_CMD" ] then - EXEC="$EXEC $QEMU_CMD" - fi - if [ "$RUN_VALGRIND" = "yes" ] - then - EXEC="$EXEC valgrind --error-exitcode=42" - fi - if [ -n "$WINE_CMD" ] - then - EXEC="$WINE_CMD" + EXEC="$EXEC $WRAPPER_CMD" fi # This limits the iterations in the benchmarks below to ITER iterations. export SECP256K1_BENCH_ITERS="$ITERS" From 489ff5c20a1457d0e7d765c8f05856c50c4777a8 Mon Sep 17 00:00:00 2001 From: Tim Ruffing Date: Fri, 21 May 2021 11:24:30 +0200 Subject: [PATCH 3/4] tests: Treat empty SECP2561_TEST_ITERS as if it was unset --- src/tests.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tests.c b/src/tests.c index 9c2d6cb..6ceaba5 100644 --- a/src/tests.c +++ b/src/tests.c @@ -6471,7 +6471,7 @@ int main(int argc, char **argv) { count = strtol(argv[1], NULL, 0); } else { const char* env = getenv("SECP256K1_TEST_ITERS"); - if (env) { + if (env && strlen(env) > 0) { count = strtol(env, NULL, 0); } } From 02dcea1ad9441f857c7768e2b7d304bb19fd2a0c Mon Sep 17 00:00:00 2001 From: Tim Ruffing Date: Mon, 17 May 2021 20:41:15 +0200 Subject: [PATCH 4/4] ci: Make test iterations configurable and tweak for sanitizer builds --- .cirrus.yml | 9 ++++++++- ci/cirrus.sh | 6 ++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/.cirrus.yml b/.cirrus.yml index 25579d9..1ba9315 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -13,7 +13,8 @@ env: EXPERIMENTAL: no CTIMETEST: yes BENCH: yes - ITERS: 2 + TEST_ITERS: + BENCH_ITERS: 2 MAKEFLAGS: -j2 cat_logs_snippet: &CAT_LOGS @@ -162,6 +163,7 @@ task: memory: 1G env: WRAPPER_CMD: qemu-s390x + TEST_ITERS: 16 HOST: s390x-linux-gnu WITH_VALGRIND: no ECDH: yes @@ -184,6 +186,7 @@ task: memory: 1G env: WRAPPER_CMD: qemu-arm + TEST_ITERS: 16 HOST: arm-linux-gnueabihf WITH_VALGRIND: no ECDH: yes @@ -207,6 +210,7 @@ task: memory: 1G env: WRAPPER_CMD: qemu-aarch64 + TEST_ITERS: 16 HOST: aarch64-linux-gnu WITH_VALGRIND: no ECDH: yes @@ -227,6 +231,7 @@ task: memory: 1G env: WRAPPER_CMD: wine64-stable + TEST_ITERS: 16 HOST: x86_64-w64-mingw32 WITH_VALGRIND: no ECDH: yes @@ -257,6 +262,7 @@ task: env: # 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) WRAPPER_CMD: "valgrind --error-exitcode=42" + TEST_ITERS: 16 - name: "UBSan, ASan, LSan" env: CFLAGS: "-fsanitize=undefined,address" @@ -264,6 +270,7 @@ task: UBSAN_OPTIONS: "print_stacktrace=1:halt_on_error=1" ASAN_OPTIONS: "strict_string_checks=1:detect_stack_use_after_return=1:detect_leaks=1" LSAN_OPTIONS: "use_unaligned=1" + TEST_ITERS: 32 # Try to cover many configurations with just a tiny matrix. matrix: - env: diff --git a/ci/cirrus.sh b/ci/cirrus.sh index 060335e..27db1e6 100755 --- a/ci/cirrus.sh +++ b/ci/cirrus.sh @@ -32,6 +32,10 @@ file .libs/* || true # This tells `make check` to wrap test invocations. export LOG_COMPILER="$WRAPPER_CMD" +# This limits the iterations in the tests and benchmarks. +export SECP256K1_TEST_ITERS="$TEST_ITERS" +export SECP256K1_BENCH_ITERS="$BENCH_ITERS" + make "$BUILD" if [ "$BENCH" = "yes" ] @@ -42,8 +46,6 @@ then then EXEC="$EXEC $WRAPPER_CMD" fi - # This limits the iterations in the benchmarks below to ITER iterations. - export SECP256K1_BENCH_ITERS="$ITERS" { $EXEC ./bench_ecmult $EXEC ./bench_internal