tests: remove reliance on buffer behaviour of stderr/stdout streams
In the test cases "rename::exit_codes" and "rename::exit_codes", we rely on the flushing behaviour of stderr and stdout streams relative to each other. Streams in glibc will not flush on newlines if stdout is pointing to a non-TTY file descriptor, but relying on this is fragile and may break on systems with a different behaviour like musl libc. Fix this by introducing a new parameter "--unbuffered" to `ts_run`. If this parameter is passed and stdbuf(1) from coreutils is available, then it will use it to disable buffering of standard output completely. Like this, we can selectively run tests with this if ordering of messages from stdout and stderr is being checked. Signed-off-by: Patrick Steinhardt <ps@pks.im> x
This commit is contained in:
parent
85efb65621
commit
801d689e47
|
@ -1,7 +1,7 @@
|
|||
mkswap: error: swap area needs to be at least 10 pages
|
||||
mkswap: <swapfile>: insecure permissions <perm>, 0600 suggested.
|
||||
mkswap: Label was truncated.
|
||||
Setting up swapspace version 1, size = 9 pages (9xPGSZ bytes)
|
||||
mkswap: Label was truncated.
|
||||
LABEL=1234567890abcde, UUID=12345678-abcd-abcd-abcd-1234567890ab
|
||||
LABEL: 1234567890abcde
|
||||
UUID: 12345678-abcd-abcd-abcd-1234567890ab
|
||||
|
|
|
@ -2,6 +2,6 @@ RENAME_EXIT_NOTHING: 4
|
|||
`rename_exit_codes.1' -> `rename_exit_values.1'
|
||||
`rename_exit_codes.2' -> `rename_exit_values.2'
|
||||
EXIT_SUCCESS: 0
|
||||
rename: rename_exit_values.2: rename to rename_exit_codes.2 failed: Is a directory
|
||||
`rename_exit_values.1' -> `rename_exit_codes.1'
|
||||
rename: rename_exit_values.2: rename to rename_exit_codes.2 failed: Is a directory
|
||||
RENAME_EXIT_SOMEOK: 2
|
||||
|
|
|
@ -420,26 +420,48 @@ function ts_init_py {
|
|||
}
|
||||
|
||||
function ts_run {
|
||||
local UNBUFFERED=
|
||||
|
||||
while true; do
|
||||
case "$1" in
|
||||
--unbuffered)
|
||||
UNBUFFERED=1
|
||||
shift;;
|
||||
--)
|
||||
shift
|
||||
break;;
|
||||
*)
|
||||
break;;
|
||||
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)
|
||||
fi
|
||||
fi
|
||||
|
||||
#
|
||||
# valgrind mode
|
||||
#
|
||||
if [ -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" "$@"
|
||||
#
|
||||
# ASAN mode
|
||||
#
|
||||
elif [ "$TS_ENABLE_ASAN" == "yes" ]; then
|
||||
ASAN_OPTIONS='detect_leaks=1' "$@"
|
||||
|
||||
#
|
||||
# Default mode
|
||||
#
|
||||
else
|
||||
"$@"
|
||||
args+=(libtool --mode=execute "$TS_VALGRIND_CMD" --tool=memcheck --leak-check=full)
|
||||
args+=(--leak-resolution=high --num-callers=20 --log-file="$TS_VGDUMP")
|
||||
fi
|
||||
|
||||
"${args[@]}" "$@"
|
||||
}
|
||||
|
||||
function ts_gen_diff {
|
||||
|
@ -977,4 +999,3 @@ function ts_has_ncurses_support {
|
|||
echo "no"
|
||||
fi
|
||||
}
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ MIN_SWAP_SIZE_KB=$(( MIN_SWAP_SIZE / 1024 ))
|
|||
|
||||
rm -f $IMAGE
|
||||
fallocate_or_skip $(( $MIN_SWAP_SIZE - 1 )) $IMAGE
|
||||
$TS_CMD_MKSWAP \
|
||||
ts_run --unbuffered $TS_CMD_MKSWAP \
|
||||
--label 1234567890abcdef \
|
||||
--uuid 12345678-abcd-abcd-abcd-1234567890ab \
|
||||
$IMAGE 2>&1 |\
|
||||
|
@ -50,7 +50,7 @@ $TS_CMD_MKSWAP \
|
|||
|
||||
rm -f $IMAGE
|
||||
fallocate_or_skip $MIN_SWAP_SIZE $IMAGE
|
||||
$TS_CMD_MKSWAP \
|
||||
ts_run --unbuffered $TS_CMD_MKSWAP \
|
||||
--label 1234567890abcdef \
|
||||
--uuid 12345678-abcd-abcd-abcd-1234567890ab \
|
||||
$IMAGE 2>&1 |\
|
||||
|
|
|
@ -32,7 +32,7 @@ $TS_CMD_RENAME -v codes values rename_exit_codes.? >> $TS_OUTPUT 2>&1
|
|||
echo "EXIT_SUCCESS: $?" >> $TS_OUTPUT
|
||||
|
||||
mkdir rename_exit_codes.2
|
||||
$TS_CMD_RENAME -v values codes rename_exit_values.? >> $TS_OUTPUT 2>&1
|
||||
ts_run --unbuffered $TS_CMD_RENAME -v values codes rename_exit_values.? >> $TS_OUTPUT 2>&1
|
||||
echo "RENAME_EXIT_SOMEOK: $?" >> $TS_OUTPUT
|
||||
|
||||
rmdir rename_exit_codes.2
|
||||
|
|
Loading…
Reference in New Issue