From 1c1ca1d12f1a517b69f5419e9fbb2917747d38ab Mon Sep 17 00:00:00 2001 From: Miroslav Lichvar Date: Wed, 1 Dec 2021 10:13:14 +0100 Subject: [PATCH] test: update and improve 003-sanitizers test --- test/compilation/003-sanitizers | 44 +++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/test/compilation/003-sanitizers b/test/compilation/003-sanitizers index 4648a64..2cf5258 100755 --- a/test/compilation/003-sanitizers +++ b/test/compilation/003-sanitizers @@ -13,16 +13,23 @@ fi if [ "$ID" = "fedora" ]; then echo Checking test dependencies: - rpm -q {valgrind,gcc,clang}.x86_64 {libgcc,clang-libs}.{x86_64,i686} || exit 1 + rpm -q {gcc,clang}.x86_64 {valgrind,libgcc,clang-libs}.{x86_64,i686} || exit 1 rpm -q {libseccomp,nettle,nss-softokn-freebl,libtomcrypt,gnutls}-devel.{x86_64,i686} || exit 1 echo fi touch Makefile -for CC in gcc clang; do - export CC - +for extra_config_opts in \ + "--all-privops" \ + "--disable-ipv6" \ + "--disable-scfilter" \ + "--without-gnutls" \ + "--without-nettle" \ + "--without-nettle --without-nss" \ + "--without-nettle --without-nss --without-tomcrypt" \ + "--without-nettle --without-nss --without-tomcrypt --without-gnutls"; \ +do for arch_opts in "-m32" ""; do pushd test/simulation/clknetsim || exit 1 make clean > /dev/null 2>&1 @@ -31,28 +38,21 @@ for CC in gcc clang; do popd - for extra_config_opts in \ - "--all-privops" \ - "--disable-ipv6" \ - "--disable-scfilter" \ - "--without-gnutls" \ - "--without-nettle" \ - "--without-nettle --without-nss" \ - "--without-nettle --without-nss --without-tomcrypt" \ - "--without-nettle --without-nss --without-tomcrypt --without-gnutls"; \ - do + for CC in gcc clang; do + export CC + for san_options in "" "-fsanitize=address" "-fsanitize=memory"; do export CFLAGS="-O2 -g -fsanitize=undefined -fsanitize=float-divide-by-zero -fno-sanitize-recover=undefined,float-divide-by-zero $san_options $arch_opts" # clang msan doesn't work on i686 and otherwise requires patches echo $CFLAGS | grep -q 'sanitize=memory' && continue - # build fails with clang ubsan on i686 (Fedora only?) - [ "$arch_opts" = "-m32" -a "$CC" = "clang" ] && continue + [ -n "$TEST_NO_M32_CLANG" -a "$arch_opts" = "-m32" -a "$CC" = "clang" ] && continue - [ "$CC" = "gcc" ] && echo $CFLAGS | grep -q 'sanitize=address' && CFLAGS="$CFLAGS -static-libasan" + [ -n "$TEST_GCC_STATIC_ASAN" -a "$CC" = "gcc" ] && + echo $CFLAGS | grep -q 'sanitize=address' && CFLAGS="$CFLAGS -static-libasan" - config_opts="--with-user=chrony --enable-debug --enable-scfilter --enable-ntp-signd $extra_config_opts" + config_opts="--with-user=chrony --with-ntp-era=1000000000 --enable-debug --enable-scfilter --enable-ntp-signd $extra_config_opts" echo ----------------------------------------------------------------------------- echo CC=\"$CC\" CFLAGS=\"$CFLAGS\" ./configure $config_opts @@ -69,10 +69,11 @@ for CC in gcc clang; do make "$@" || exit 1 - [ -n "$BUILD_TEST_ONLY" ] && continue + [ -n "$TEST_BUILD_ONLY" ] && continue echo pushd test/unit || exit 1 + make "$@" || exit 1 if [ "$san_options" = "" ]; then make check TEST_WRAPPER="valgrind --error-exitcode=1" || exit 1 else @@ -80,11 +81,16 @@ for CC in gcc clang; do fi popd + [ -n "$TEST_UNIT_ONLY" ] && continue + echo pushd test/simulation || exit 1 export CLKNETSIM_RANDOM_SEED=101 if [ "$arch_opts" = "" -a "$san_options" = "" ]; then CLKNETSIM_CLIENT_WRAPPER=valgrind ./run -i 1 || exit 1 + elif [ "$CC" = "gcc" ] && ! echo $CFLAGS | grep -q "-static-libasan"; then + libasan=$(ldd ../../chronyd | grep -o '/.*lib.*/libasan.so.[0-9]') + CLKNETSIM_PRELOAD=$libasan ./run -i 1 || exit 1 else ./run -i 1 || exit 1 fi