]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
tests: use env and support both unbuffer/stdbuf
authorPatrick Steinhardt <ps@pks.im>
Wed, 28 Aug 2019 06:56:24 +0000 (08:56 +0200)
committerKarel Zak <kzak@redhat.com>
Wed, 28 Aug 2019 06:56:24 +0000 (08:56 +0200)
Triggered by commit f612c4c67 (tests: fix --unbuffered mode with
ASAN, 2019-08-27), which says:

    Well, this patch sucks. It would be nice to have things in
    the way how it has been original expected by Patrick's patch,
    but ...

So this commit here effectively reverts it and instead tries to
improve the shortcomings of the original patch. First, it uses
env(1) to set ASAN_OPTIONS instead of directly adding it to the
args array to fix execution of "${args[@]}" "$@".

Second, it now supports both unbuffer(1) and stdbuf(1). The
latter uses LD_PRELOAD tricks, which doesn't play nicely with
ASAN, so it will not be used if ASAN has been requested. It's
still valuable to have support for both, as many more systems
will have stdbuf(1) from coreutils installed but not unbuffer(1)
from expect.

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

index 0718a61474c5a88ecca0fc699d440dff939cc092..1c693d43b7a8cfc6250c4bc79313c2ecb71e4b22 100644 (file)
@@ -425,9 +425,7 @@ function ts_run {
        while true; do
                case "$1" in
                        --unbuffered)
        while true; do
                case "$1" in
                        --unbuffered)
-                               if type unbuffer >/dev/null 2>&1; then
-                                       UNBUFFERED=1
-                               fi
+                               UNBUFFERED=1
                                shift;;
                        --)
                                shift
                                shift;;
                        --)
                                shift
@@ -437,34 +435,35 @@ function ts_run {
                esac
        done
 
                esac
        done
 
+       declare -a args
+
        #
        # ASAN mode
        #
        if [ "$TS_ENABLE_ASAN" == "yes" ]; then
        #
        # ASAN mode
        #
        if [ "$TS_ENABLE_ASAN" == "yes" ]; then
-               if [ -n "$UNBUFFERED" ]; then
-                       ASAN_OPTIONS='detect_leaks=1' unbuffer "$@"
-               else
-                       ASAN_OPTIONS='detect_leaks=1' "$@"
-               fi
+               args+=(env ASAN_OPTIONS=detect_leaks=1)
+       fi
 
        #
 
        #
-       # valgrind mode
+       # Disable buffering of stdout
        #
        #
-       elif [ -n "$TS_VALGRIND_CMD" ]; then
-                libtool --mode=execute \
-                $TS_VALGRIND_CMD --tool=memcheck --leak-check=full \
-                                 --leak-resolution=high --num-callers=20 \
-                                 --log-file="$TS_VGDUMP" "$@"
+       if [ -n "$UNBUFFERED" ]; then
+               if type unbuffer >/dev/null 2>&1; then
+                       args+=(unbuffer)
+               elif type stdbuf >/dev/null 2>&1 && [ "$TS_ENABLE_ASAN" != "yes" ]; then
+                       args+=(stdbuf --output=0)
+               fi
+       fi
+
        #
        #
-       # default mode
+       # valgrind mode
        #
        #
-       else
-               if [ -n "$UNBUFFERED" ]; then
-                       unbuffer "$@"
-               else
-                       "$@"
-               fi
+       if [ -n "$TS_VALGRIND_CMD" ]; then
+               args+=(libtool --mode=execute "$TS_VALGRIND_CMD" --tool=memcheck --leak-check=full)
+               args+=(--leak-resolution=high --num-callers=20 --log-file="$TS_VGDUMP")
        fi
        fi
+
+       "${args[@]}" "$@"
 }
 
 function ts_gen_diff {
 }
 
 function ts_gen_diff {