]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
build-sys: add --enable-asan and --memcheck-asan for tests
authorKarel Zak <kzak@redhat.com>
Thu, 23 Nov 2017 13:59:05 +0000 (14:59 +0100)
committerKarel Zak <kzak@redhat.com>
Thu, 23 Nov 2017 13:59:05 +0000 (14:59 +0100)
The command ./configure --enable-asan adds -fsanitize=address
to the compiler command line. In the regression tests leaks detection
is disabled by default. You have to use --memcheck-asan on test
command line to enable.

Signed-off-by: Karel Zak <kzak@redhat.com>
configure.ac
tests/functions.sh
tests/run.sh

index eebe922591a5c338bf1882c0f3b15a91f9edf3fb..28fd7760ce33ae55c1f7f6aad70adc3b7a54c68a 100644 (file)
@@ -141,6 +141,17 @@ AC_SUBST([BSD_WARN_CFLAGS])
 UL_WARN_ADD([-Wno-unused-parameter], [NO_UNUSED_WARN_CFLAGS])
 AC_SUBST([NO_UNUSED_WARN_CFLAGS])
 
+
+AC_ARG_ENABLE([asan],
+  AS_HELP_STRING([--enable-asan], [compile with Address Sanitizer]),
+  [], [enable_asan=no]
+)
+AS_IF([test "x$enable_asan" == xyes], [
+  UL_WARN_ADD([-fsanitize=address])
+])
+
+
+
 dnl libtool-2
 LT_INIT
 
index 7152a4e33a25295ccab33eaef1ce20bf82cc8f87..5b9b61c05c32b7c5e9122c35d1a43d74be362d72 100644 (file)
@@ -230,8 +230,9 @@ function ts_init_env {
        LANGUAGE="POSIX"
        LC_ALL="POSIX"
        CHARSET="UTF-8"
+       ASAN_OPTIONS="detect_leaks=0"
 
-       export LANG LANGUAGE LC_ALL CHARSET
+       export LANG LANGUAGE LC_ALL CHARSET ASAN_OPTIONS
 
        mydir=$(ts_canonicalize "$mydir")
 
@@ -284,6 +285,10 @@ function ts_init_env {
        if [ "$tmp" == "yes" -a -f /usr/bin/valgrind ]; then
                TS_VALGRIND_CMD="/usr/bin/valgrind"
        fi
+       tmp=$( ts_has_option "memcheck-asan" "$*")
+       if [ "$tmp" == "yes" ]; then
+               TS_ENABLE_ASAN="yes"
+       fi
 
        BLKID_FILE="$TS_OUTDIR/${TS_TESTNAME}.blkidtab"
 
@@ -384,6 +389,11 @@ function ts_run {
                $TS_VALGRIND_CMD --tool=memcheck --leak-check=full \
                                 --leak-resolution=high --num-callers=20 \
                                 --log-file="$TS_VGDUMP" "$@"
+       #
+       # ASAN mode
+       #
+       elif [ "$TS_ENABLE_ASAN" == "yes" ]; then
+               ASAN_OPTIONS='detect_leaks=1' "$@"
 
        #
        # Default mode
index 1d4cc9d218a1f960d29130aef39b0a358b6bf7c3..15e6c6baa80a0ef4d6725c1d2d62759f490c5ab2 100755 (executable)
@@ -46,6 +46,7 @@ while [ -n "$1" ]; do
        --force |\
        --fake |\
        --memcheck-valgrind |\
+       --memcheck-asan |\
        --show-diff |\
        --verbose  |\
        --skip-loopdevs |\
@@ -82,6 +83,7 @@ while [ -n "$1" ]; do
                echo "  --force              execute demanding tests"
                echo "  --fake               do not run, setup tests only"
                echo "  --memcheck-valgrind  run with valgrind"
+               echo "  --memcheck-asan      enable ASAN (requires ./configure --enable-asan)"
                echo "  --verbose            verbose mode"
                echo "  --show-diff          show diff from failed tests"
                echo "  --nonroot            ignore test suite if user is root"