tests: fix --unbuffered mode with ASAN

Unfortunately, ASAN is pretty sensitive to LD_PRELOAD, but stdbuf from
coreutils is based on LD_PRELOAD. So, I have replaced stdbuf with
unbuffer (from expect pkg).

The another problem is "${args[@]}" "$@" which does not work as expected.

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 ...

Signed-off-by: Karel Zak <kzak@redhat.com>
This commit is contained in:
Karel Zak 2019-08-27 13:02:38 +02:00
parent f7f25faae0
commit f612c4c674
4 changed files with 25 additions and 18 deletions

View File

@ -425,7 +425,9 @@ function ts_run {
while true; do
case "$1" in
--unbuffered)
UNBUFFERED=1
if type stdbuf >/dev/null 2>&1; then
UNBUFFERED=1
fi
shift;;
--)
shift
@ -435,33 +437,34 @@ function ts_run {
esac
done
declare -a args
#
# ASAN mode
#
if [ "$TS_ENABLE_ASAN" == "yes" ]; then
args+=(ASAN_OPTIONS='detect_leaks=1')
fi
#
# Disable buffering of stdout
#
if [ -n "$UNBUFFERED" ]; then
if type stdbuf >/dev/null 2>&1; then
args+=(stdbuf --output=0)
if [ -n "$UNBUFFERED" ]; then
ASAN_OPTIONS='detect_leaks=1' unbuffer "$@"
else
ASAN_OPTIONS='detect_leaks=1' "$@"
fi
fi
#
# valgrind mode
#
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")
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" "$@"
#
# default mode
#
else
if [ -n "$UNBUFFERED" ]; then
unbuffer "$@"
else
"$@"
fi
fi
"${args[@]}" "$@"
}
function ts_gen_diff {

View File

@ -27,6 +27,7 @@ TESTPROG="$TS_HELPER_LIBFDISK_MKPART_FULLSPEC"
ts_check_test_command "$TESTPROG"
ts_check_test_command "$TS_CMD_SFDISK"
ts_check_test_command "$TS_CMD_WIPEFS"
ts_check_prog unbuffer
TEST_IMAGE_NAME=$(ts_image_init 15)

View File

@ -21,6 +21,7 @@ ts_init "$*"
ts_check_test_command "$TS_CMD_MKSWAP"
ts_check_test_command "$TS_CMD_SWAPLABEL"
ts_check_test_command "$TS_HELPER_SYSINFO"
ts_check_prog unbuffer
# fallocate does not work on most file systems
function fallocate_or_skip()

View File

@ -22,6 +22,8 @@ TS_DESC="exit codes"
ts_init "$*"
ts_check_test_command "$TS_CMD_RENAME"
ts_check_prog unbuffer
ts_cd "$TS_OUTDIR"
touch rename_exit_codes.{1..2}