]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
tests: remove reliance on buffer behaviour of stderr/stdout streams
authorPatrick Steinhardt <ps@pks.im>
Fri, 23 Aug 2019 13:32:53 +0000 (15:32 +0200)
committerKarel Zak <kzak@redhat.com>
Tue, 27 Aug 2019 07:36:05 +0000 (09:36 +0200)
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

tests/expected/misc/swaplabel
tests/expected/rename/exit_codes
tests/functions.sh
tests/ts/misc/swaplabel
tests/ts/rename/exit_codes

index 172f876afa7e383b4e51bdfd32d7d76d2d447c93..790a28c6cfeb1d1b779698e6cd6a3e35e8850fdd 100644 (file)
@@ -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
index c577817883e01715147bc3caacca54fadf4263e8..3d53010b2df1623a1bf434cc34de6b50d324ed48 100644 (file)
@@ -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
index 0605a1320a5311a5380af666e8b2a1f0c5ef2a4b..3d7bb89bc9e5570bd277723e7402021e03bde746 100644 (file)
@@ -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
+
        #
-       # valgrind mode
+       # ASAN 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" "$@"
+       if [ "$TS_ENABLE_ASAN" == "yes" ]; then
+               args+=(ASAN_OPTIONS='detect_leaks=1')
+       fi
+
        #
-       # ASAN mode
+       # Disable buffering of stdout
        #
-       elif [ "$TS_ENABLE_ASAN" == "yes" ]; then
-               ASAN_OPTIONS='detect_leaks=1' "$@"
+       if [ -n "$UNBUFFERED" ]; then
+               if type stdbuf >/dev/null 2>&1; then
+                       args+=(stdbuf --output=0)
+               fi
+       fi
 
        #
-       # Default mode
+       # valgrind mode
        #
-       else
-               "$@"
+       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
+
+       "${args[@]}" "$@"
 }
 
 function ts_gen_diff {
@@ -977,4 +999,3 @@ function ts_has_ncurses_support {
                echo "no"
        fi
 }
-
index 22858b0ac2a1a34a78672ec19809e14d8984495b..106cb7d213a48c4f05678171963b9e7ba2358f9e 100755 (executable)
@@ -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 |\
index 37028162b006753612270ca0391896f5ab7073fe..d3012ae59d1ec5c27f9c80f6e3f4e0615155d2ce 100755 (executable)
@@ -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