Util-Linux Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH 0/6] Test suite fixes for musl libc
@ 2019-08-23 10:16 Patrick Steinhardt
  2019-08-23 10:16 ` [PATCH 1/6] tests: remove reliance on buffer behaviour of stderr/stdout streams Patrick Steinhardt
                   ` (6 more replies)
  0 siblings, 7 replies; 25+ messages in thread
From: Patrick Steinhardt @ 2019-08-23 10:16 UTC (permalink / raw)
  To: util-linux; +Cc: Patrick Steinhardt

Hi,

on latest master of util-linux, there's currently 20 test- and
subtest failures on musl based systems. There's three different
categories of failures:

    - Reliance on buffering properties of stdout/stderr.

    - Expectance of non-standard error messages returned by
      strerror(3P).

    - Expectance of EILSEQ with POSIX locale.

This patch set fixes all of the above, bringing down the number
of failures from 20 to a single test failure. The remaining
failure is in getopt(1), which documents and implicitly relies on
the POSIXLY_CORRECT environment variable when calling getopt_long
from glibc. Adhering to this variable isn't implemented by musl
libc, so to get this working correctly one would have to modify
getopt(1) itself, e.g. by automatically prepending a '+' to the
optstr if the envvar is set. But I'll leave that to another patch
series.

Regards
Patrick

Patrick Steinhardt (6):
  tests: remove reliance on buffer behaviour of stderr/stdout streams
  tests: colcrt: fix reliance on EILSEQ in POSIX locale
  tests: column: use actually invalid multibytes to test encoding
  tests: col: avoid hardcoding of errno string
  tests: fdisk: avoid hardcoding of errno string
  tests: libfdisk: remove reliance on buffer behaviour of standard
    streams

 tests/commands.sh                             |  1 +
 tests/expected/col/multibyte                  |  2 +-
 tests/expected/column/invalid-multibyte       |  2 +-
 tests/expected/fdisk/oddinput                 |  4 +-
 tests/expected/libfdisk/mkpart-full-gpt       | 14 +++---
 .../libfdisk/mkpart-full-gpt-err-overlap      |  8 ++--
 .../libfdisk/mkpart-full-gpt-nopartno         | 14 +++---
 .../libfdisk/mkpart-full-gpt-partno-gap       | 14 +++---
 .../libfdisk/mkpart-full-gpt-space-gap        | 10 ++---
 .../libfdisk/mkpart-full-mbr-err-logical      | 14 +++---
 .../libfdisk/mkpart-full-mbr-err-nospace      |  6 +--
 .../libfdisk/mkpart-full-mbr-err-primary      |  6 +--
 .../expected/libfdisk/mkpart-full-mbr-logical | 14 +++---
 .../libfdisk/mkpart-full-mbr-nopartno         | 14 +++---
 .../expected/libfdisk/mkpart-full-mbr-primary |  8 ++--
 .../libfdisk/mkpart-full-mbr-primary-nopartno |  8 ++--
 .../libfdisk/mkpart-full-mbr-space-gap        |  6 +--
 tests/expected/misc/swaplabel                 |  2 +-
 tests/expected/rename/exit_codes              |  2 +-
 tests/functions.sh                            |  7 +++
 tests/helpers/Makemodule.am                   |  3 ++
 tests/helpers/test_strerror.c                 | 44 +++++++++++++++++++
 tests/ts/col/multibyte                        |  5 ++-
 tests/ts/colcrt/regressions                   |  2 +-
 tests/ts/column/invalid-multibyte             |  2 +-
 tests/ts/fdisk/oddinput                       |  6 ++-
 tests/ts/libfdisk/mkpart-full                 | 26 +++++------
 tests/ts/misc/swaplabel                       |  4 +-
 tests/ts/rename/exit_codes                    |  2 +-
 29 files changed, 154 insertions(+), 96 deletions(-)
 create mode 100644 tests/helpers/test_strerror.c

-- 
2.23.0


^ permalink raw reply	[flat|nested] 25+ messages in thread

* [PATCH 1/6] tests: remove reliance on buffer behaviour of stderr/stdout streams
  2019-08-23 10:16 [PATCH 0/6] Test suite fixes for musl libc Patrick Steinhardt
@ 2019-08-23 10:16 ` Patrick Steinhardt
  2019-08-23 10:16 ` [PATCH 2/6] tests: colcrt: fix reliance on EILSEQ in POSIX locale Patrick Steinhardt
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 25+ messages in thread
From: Patrick Steinhardt @ 2019-08-23 10:16 UTC (permalink / raw)
  To: util-linux; +Cc: Patrick Steinhardt

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 function `ts_unbuffered`. If available on
the local system, then it will execute stdbuf(1) from coreutils 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>
---
 tests/expected/misc/swaplabel    | 2 +-
 tests/expected/rename/exit_codes | 2 +-
 tests/functions.sh               | 7 +++++++
 tests/ts/misc/swaplabel          | 4 ++--
 tests/ts/rename/exit_codes       | 2 +-
 5 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/tests/expected/misc/swaplabel b/tests/expected/misc/swaplabel
index 172f876af..790a28c6c 100644
--- a/tests/expected/misc/swaplabel
+++ b/tests/expected/misc/swaplabel
@@ -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
diff --git a/tests/expected/rename/exit_codes b/tests/expected/rename/exit_codes
index c57781788..3d53010b2 100644
--- a/tests/expected/rename/exit_codes
+++ b/tests/expected/rename/exit_codes
@@ -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
diff --git a/tests/functions.sh b/tests/functions.sh
index 0605a1320..95d37bd5f 100644
--- a/tests/functions.sh
+++ b/tests/functions.sh
@@ -978,3 +978,10 @@ function ts_has_ncurses_support {
 	fi
 }
 
+function ts_unbuffered() {
+    if type stdbuf >/dev/null 2>&1; then
+        stdbuf -o0 "$@"
+    else
+        "$@"
+    fi
+}
diff --git a/tests/ts/misc/swaplabel b/tests/ts/misc/swaplabel
index 22858b0ac..681b39a64 100755
--- a/tests/ts/misc/swaplabel
+++ b/tests/ts/misc/swaplabel
@@ -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_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_unbuffered $TS_CMD_MKSWAP \
 	--label 1234567890abcdef \
 	--uuid 12345678-abcd-abcd-abcd-1234567890ab \
 	$IMAGE 2>&1 |\
diff --git a/tests/ts/rename/exit_codes b/tests/ts/rename/exit_codes
index 37028162b..739a8738c 100755
--- a/tests/ts/rename/exit_codes
+++ b/tests/ts/rename/exit_codes
@@ -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_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
-- 
2.23.0


^ permalink raw reply	[flat|nested] 25+ messages in thread

* [PATCH 2/6] tests: colcrt: fix reliance on EILSEQ in POSIX locale
  2019-08-23 10:16 [PATCH 0/6] Test suite fixes for musl libc Patrick Steinhardt
  2019-08-23 10:16 ` [PATCH 1/6] tests: remove reliance on buffer behaviour of stderr/stdout streams Patrick Steinhardt
@ 2019-08-23 10:16 ` Patrick Steinhardt
  2019-08-23 10:17 ` [PATCH 3/6] tests: column: use actually invalid multibytes to test encoding Patrick Steinhardt
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 25+ messages in thread
From: Patrick Steinhardt @ 2019-08-23 10:16 UTC (permalink / raw)
  To: util-linux; +Cc: Patrick Steinhardt

The input file "crash1" in the colcrt/regressions test contains the
illegal byte sequence "\x94\x7e". While "\x7e" is '~', "\x94" is not a
valid character. Thus, the test assumes that getwc(3P) will return
`WEOF` and set `errno=EILSEQ`, causing colcrt(1) to abort reading the
stream and thus not print the trailing '~'.

This assumption holds just fine for glibc as it will dutifully report
EILSEQ, but musl libc will happily read the complete stream without
complaining about the illegal character. But in fact, as tests run with
LC_ALL=POSIX by default, glibc's behaviour is wrong while musl is right.
Quoting mbrtowc(3P) from POSIX.1-2017:

    [EILSEQ] An invalid character sequence is detected. In the POSIX locale an
             [EILSEQ] error cannot occur since all byte values are valid
             characters.

Fix the issue by running the colcrt tests with C.UTF8 locale.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 tests/ts/colcrt/regressions | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tests/ts/colcrt/regressions b/tests/ts/colcrt/regressions
index 394c4e823..2adeea3f3 100755
--- a/tests/ts/colcrt/regressions
+++ b/tests/ts/colcrt/regressions
@@ -24,7 +24,7 @@ ts_check_prog "timeout"
 
 check_input_file() {
 	ts_init_subtest ${1##*/}
-	timeout 2 $TS_CMD_COLCRT < $1 > $TS_OUTPUT 2>&1
+	LC_ALL=C.UTF-8 timeout 2 $TS_CMD_COLCRT < $1 > $TS_OUTPUT 2>&1
 	echo "return value: $?" >> $TS_OUTPUT
 	ts_finalize_subtest
 }
-- 
2.23.0


^ permalink raw reply	[flat|nested] 25+ messages in thread

* [PATCH 3/6] tests: column: use actually invalid multibytes to test encoding
  2019-08-23 10:16 [PATCH 0/6] Test suite fixes for musl libc Patrick Steinhardt
  2019-08-23 10:16 ` [PATCH 1/6] tests: remove reliance on buffer behaviour of stderr/stdout streams Patrick Steinhardt
  2019-08-23 10:16 ` [PATCH 2/6] tests: colcrt: fix reliance on EILSEQ in POSIX locale Patrick Steinhardt
@ 2019-08-23 10:17 ` Patrick Steinhardt
  2019-08-23 10:17 ` [PATCH 4/6] tests: col: avoid hardcoding of errno string Patrick Steinhardt
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 25+ messages in thread
From: Patrick Steinhardt @ 2019-08-23 10:17 UTC (permalink / raw)
  To: util-linux; +Cc: Patrick Steinhardt

[-- Warning: decoded text below may be mangled --]
[-- Attachment #0: Type: text/plain; charset=UTF-8, Size: 1461 bytes --]

If reading an invalid multibyte sequence, column(1) will encode the byte
as "\x<hex>" instead. The tests try to verify that by piping "£" into
column(1). As the tests run with LC_ALL=POSIX by default, though, libc
implementations strictly adhering to the POSIX standard will treat all
characters as valid multibyte characters. As a consequence, no EILSEQ is
raised by mbtowc(3P) and the character is not encoded as hex, breaking
the test.

Fix this by setting LC_ALL=C.UTF-8. As "£" is a valid UTF-8 character,
we also change the test to use a proper illegal multibyte sequence.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 tests/expected/column/invalid-multibyte | 2 +-
 tests/ts/column/invalid-multibyte       | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/tests/expected/column/invalid-multibyte b/tests/expected/column/invalid-multibyte
index ea40a34e9..5b0c74503 100644
--- a/tests/expected/column/invalid-multibyte
+++ b/tests/expected/column/invalid-multibyte
@@ -1 +1 @@
-\xa3
+\x94~
diff --git a/tests/ts/column/invalid-multibyte b/tests/ts/column/invalid-multibyte
index a9e371003..4fcf44eb3 100755
--- a/tests/ts/column/invalid-multibyte
+++ b/tests/ts/column/invalid-multibyte
@@ -25,6 +25,6 @@ ts_check_test_command "$TS_CMD_COLUMN"
 
 ts_cd "$TS_OUTDIR"
 
-printf "£\n" | LC_ALL=C $TS_CMD_COLUMN >> $TS_OUTPUT 2>&1
+printf "\x94\x7e\n" | LC_ALL=C.UTF-8 $TS_CMD_COLUMN >> $TS_OUTPUT 2>&1
 
 ts_finalize
-- 
2.23.0


^ permalink raw reply	[flat|nested] 25+ messages in thread

* [PATCH 4/6] tests: col: avoid hardcoding of errno string
  2019-08-23 10:16 [PATCH 0/6] Test suite fixes for musl libc Patrick Steinhardt
                   ` (2 preceding siblings ...)
  2019-08-23 10:17 ` [PATCH 3/6] tests: column: use actually invalid multibytes to test encoding Patrick Steinhardt
@ 2019-08-23 10:17 ` Patrick Steinhardt
  2019-08-23 10:17 ` [PATCH 5/6] tests: fdisk: " Patrick Steinhardt
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 25+ messages in thread
From: Patrick Steinhardt @ 2019-08-23 10:17 UTC (permalink / raw)
  To: util-linux; +Cc: Patrick Steinhardt

The col/multibyte test has a hardcoded error string as part of its
expected output that is returned by glibc's strerror(3P) function. Even
though many of these strings are the same across libc implementations,
they are not standardiced and some are certainly different. One example
is the string for EILSEQ on musl libc.

To fix this, we introduce a new test helper "test_strerror". The helper
can be invoked with an error code like "EILSEQ", which will cause it to
print out the the respective error message for that code. Note that
"test_strerror" cannot act on the error's value (e.g. 84 for EILSEQ), as
these aren't standardized either. Instead, we thus need to have an array
of the error's string representation ("EILSEQ") to its respective error
code (the define EILSEQ). The array can trivially be extended as
required, thus it is only sparsely populated with EILSEQ right now.

To fix the col/multibyte test, we introduce a call to sed(1) to replace
the strerror(3P) message from EILSEQ with "EILSEQ". Furthermore, as
we're running tests with the POSIX locale by default which treats all
bytes as valid multibyte sequences, we have to change to the C.UTF-8
locale instead to actually get an error.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 tests/commands.sh             |  1 +
 tests/expected/col/multibyte  |  2 +-
 tests/helpers/Makemodule.am   |  3 +++
 tests/helpers/test_strerror.c | 42 +++++++++++++++++++++++++++++++++++
 tests/ts/col/multibyte        |  5 +++--
 5 files changed, 50 insertions(+), 3 deletions(-)
 create mode 100644 tests/helpers/test_strerror.c

diff --git a/tests/commands.sh b/tests/commands.sh
index 5cc34f6b3..9fcd488ce 100644
--- a/tests/commands.sh
+++ b/tests/commands.sh
@@ -33,6 +33,7 @@ TS_HELPER_PARTITIONS="${ts_helpersdir}sample-partitions"
 TS_HELPER_PATHS="${ts_helpersdir}test_pathnames"
 TS_HELPER_SCRIPT="${ts_helpersdir}test_script"
 TS_HELPER_SIGRECEIVE="${ts_helpersdir}test_sigreceive"
+TS_HELPER_STRERROR="${ts_helpersdir}test_strerror"
 TS_HELPER_STRUTILS="${ts_helpersdir}test_strutils"
 TS_HELPER_SYSINFO="${ts_helpersdir}test_sysinfo"
 TS_HELPER_TIOCSTI="${ts_helpersdir}test_tiocsti"
diff --git a/tests/expected/col/multibyte b/tests/expected/col/multibyte
index 4e299adc1..abf607249 100644
--- a/tests/expected/col/multibyte
+++ b/tests/expected/col/multibyte
@@ -1 +1 @@
-col: failed on line 1: Invalid or incomplete multibyte or wide character
+col: failed on line 1: EILSEQ
diff --git a/tests/helpers/Makemodule.am b/tests/helpers/Makemodule.am
index ab0b3cea9..a34cd8d2a 100644
--- a/tests/helpers/Makemodule.am
+++ b/tests/helpers/Makemodule.am
@@ -14,6 +14,9 @@ test_sha1_SOURCES = tests/helpers/test_sha1.c lib/sha1.c
 check_PROGRAMS += test_pathnames
 test_pathnames_SOURCES = tests/helpers/test_pathnames.c
 
+check_PROGRAMS += test_strerror
+test_strerror_SOURCES = tests/helpers/test_strerror.c
+
 check_PROGRAMS += test_sysinfo
 test_sysinfo_SOURCES = tests/helpers/test_sysinfo.c
 
diff --git a/tests/helpers/test_strerror.c b/tests/helpers/test_strerror.c
new file mode 100644
index 000000000..1919698eb
--- /dev/null
+++ b/tests/helpers/test_strerror.c
@@ -0,0 +1,42 @@
+/*
+ * This test program prints errno messages to allow for portable
+ * verification of error messages.
+ *
+ * Copyright (C) 2019 Patrick Steinhardt <ps@pks.im
+ *
+ * This file may be redistributed under the terms of the GNU Public
+ * License.
+ */
+
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#define E(x) { #x, x }
+static struct {
+	const char *str;
+	int error;
+} errors[] = {
+	E(EILSEQ)
+};
+
+int main(int argc, const char *argv[])
+{
+	size_t i;
+
+	if (argc != 2) {
+		fprintf(stderr, "USAGE: %s <errno>\n", argv[0]);
+		return -1;
+	}
+
+	for (i = 0; i < sizeof(errors)/sizeof(*errors); i++) {
+		if (strcmp(errors[i].str, argv[1]))
+			continue;
+		puts(strerror(errors[i].error));
+		return 0;
+	}
+
+	fprintf(stderr, "Invalid errno: %s\n", argv[1]);
+	return -1;
+}
diff --git a/tests/ts/col/multibyte b/tests/ts/col/multibyte
index e9c02922e..1ed4b5ff8 100755
--- a/tests/ts/col/multibyte
+++ b/tests/ts/col/multibyte
@@ -22,8 +22,9 @@ TS_DESC="multibyte input"
 ts_init "$*"
 
 ts_check_test_command "$TS_CMD_COL"
+ts_check_test_command "$TS_HELPER_STRERROR"
 
-cat $TS_SELF/multibyte.data | $TS_CMD_COL > /dev/null  2> $TS_OUTPUT
+cat $TS_SELF/multibyte.data | LC_ALL=C.UTF-8 $TS_CMD_COL 2>&1 > /dev/null |
+    sed -e "s@$($TS_HELPER_STRERROR EILSEQ)@EILSEQ@" > $TS_OUTPUT
 
 ts_finalize
-
-- 
2.23.0


^ permalink raw reply	[flat|nested] 25+ messages in thread

* [PATCH 5/6] tests: fdisk: avoid hardcoding of errno string
  2019-08-23 10:16 [PATCH 0/6] Test suite fixes for musl libc Patrick Steinhardt
                   ` (3 preceding siblings ...)
  2019-08-23 10:17 ` [PATCH 4/6] tests: col: avoid hardcoding of errno string Patrick Steinhardt
@ 2019-08-23 10:17 ` " Patrick Steinhardt
  2019-08-23 10:17 ` [PATCH 6/6] tests: libfdisk: remove reliance on buffer behaviour of standard streams Patrick Steinhardt
  2019-08-23 13:32 ` [PATCH v2 0/6] Test suite fixes for musl libc Patrick Steinhardt
  6 siblings, 0 replies; 25+ messages in thread
From: Patrick Steinhardt @ 2019-08-23 10:17 UTC (permalink / raw)
  To: util-linux; +Cc: Patrick Steinhardt

The test fdisk/oddinput hardcodes strings returned by strerror(3P) for
both the errors ENOENT and ENOTTY. As these strings are unportable,
convert the tests to use the test_strerror helper instead to convert
them with sed(1).

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 tests/expected/fdisk/oddinput | 4 ++--
 tests/helpers/test_strerror.c | 2 ++
 tests/ts/fdisk/oddinput       | 6 ++++--
 3 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/tests/expected/fdisk/oddinput b/tests/expected/fdisk/oddinput
index 2fccc6cd5..219e98b67 100644
--- a/tests/expected/fdisk/oddinput
+++ b/tests/expected/fdisk/oddinput
@@ -6,6 +6,6 @@ Units: cylinders of 16065 * 512 = 8225280 bytes
 Sector size (logical/physical): 512 bytes / 512 bytes
 I/O size (minimum/optimal): 512 bytes / 512 bytes
 Nonexistent file
-fdisk: cannot open _a_file_that_does_not_exist_: No such file or directory
+fdisk: cannot open _a_file_that_does_not_exist_: ENOENT
 Too small file
-fdisk: cannot open oddinput.toosmall: Inappropriate ioctl for device
+fdisk: cannot open oddinput.toosmall: ENOTTY
diff --git a/tests/helpers/test_strerror.c b/tests/helpers/test_strerror.c
index 1919698eb..a063b1165 100644
--- a/tests/helpers/test_strerror.c
+++ b/tests/helpers/test_strerror.c
@@ -18,6 +18,8 @@ static struct {
 	const char *str;
 	int error;
 } errors[] = {
+	E(ENOENT),
+	E(ENOTTY),
 	E(EILSEQ)
 };
 
diff --git a/tests/ts/fdisk/oddinput b/tests/ts/fdisk/oddinput
index 067924264..7b0c8bfd4 100755
--- a/tests/ts/fdisk/oddinput
+++ b/tests/ts/fdisk/oddinput
@@ -38,10 +38,12 @@ ts_log "Empty image listing" # this should report empty partition table
 $TS_CMD_FDISK -c=dos -u=cylinders -l ${TEST_IMAGE_NAME} 2>&1 | sed -e "s/${TEST_IMAGE_NAME//\//\\/}/testimage/" >> $TS_OUTPUT
 
 ts_log "Nonexistent file" # this originally does absolutely nothing
-$TS_CMD_FDISK -c=dos -u=cylinders -l _a_file_that_does_not_exist_ >> $TS_OUTPUT 2>&1
+$TS_CMD_FDISK -c=dos -u=cylinders -l _a_file_that_does_not_exist_ 2>&1 |
+    sed -e "s@$($TS_HELPER_STRERROR ENOENT)@ENOENT@" >> $TS_OUTPUT
 
 ts_log "Too small file" # same here
 echo  "This file is too small" >> oddinput.toosmall
-$TS_CMD_FDISK -c=dos -u=cylinders -l oddinput.toosmall >> $TS_OUTPUT 2>&1
+$TS_CMD_FDISK -c=dos -u=cylinders -l oddinput.toosmall 2>&1 |
+    sed -e "s@$($TS_HELPER_STRERROR ENOTTY)@ENOTTY@" >> $TS_OUTPUT
 rm oddinput.toosmall
 ts_finalize
-- 
2.23.0


^ permalink raw reply	[flat|nested] 25+ messages in thread

* [PATCH 6/6] tests: libfdisk: remove reliance on buffer behaviour of standard streams
  2019-08-23 10:16 [PATCH 0/6] Test suite fixes for musl libc Patrick Steinhardt
                   ` (4 preceding siblings ...)
  2019-08-23 10:17 ` [PATCH 5/6] tests: fdisk: " Patrick Steinhardt
@ 2019-08-23 10:17 ` Patrick Steinhardt
  2019-08-23 12:15   ` Karel Zak
  2019-08-23 13:32 ` [PATCH v2 0/6] Test suite fixes for musl libc Patrick Steinhardt
  6 siblings, 1 reply; 25+ messages in thread
From: Patrick Steinhardt @ 2019-08-23 10:17 UTC (permalink / raw)
  To: util-linux; +Cc: Patrick Steinhardt

The tests in libfdisk/mkpart-full all rely on the buffering behaviour of
standard output and standard error streams, most importantly that stderr
is non-buffering and stdout is buffering. This doesn't hold on all libc
implementations when redirecting to a file, breaking the test suite on
such platforms.

Use the ts_unbuffered function to stop buffering of the standard output
stream to fix this.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 tests/expected/libfdisk/mkpart-full-gpt       | 14 +++++-----
 .../libfdisk/mkpart-full-gpt-err-overlap      |  8 +++---
 .../libfdisk/mkpart-full-gpt-nopartno         | 14 +++++-----
 .../libfdisk/mkpart-full-gpt-partno-gap       | 14 +++++-----
 .../libfdisk/mkpart-full-gpt-space-gap        | 10 +++----
 .../libfdisk/mkpart-full-mbr-err-logical      | 14 +++++-----
 .../libfdisk/mkpart-full-mbr-err-nospace      |  6 ++---
 .../libfdisk/mkpart-full-mbr-err-primary      |  6 ++---
 .../expected/libfdisk/mkpart-full-mbr-logical | 14 +++++-----
 .../libfdisk/mkpart-full-mbr-nopartno         | 14 +++++-----
 .../expected/libfdisk/mkpart-full-mbr-primary |  8 +++---
 .../libfdisk/mkpart-full-mbr-primary-nopartno |  8 +++---
 .../libfdisk/mkpart-full-mbr-space-gap        |  6 ++---
 tests/ts/libfdisk/mkpart-full                 | 26 +++++++++----------
 14 files changed, 81 insertions(+), 81 deletions(-)

diff --git a/tests/expected/libfdisk/mkpart-full-gpt b/tests/expected/libfdisk/mkpart-full-gpt
index d33483ac6..7740454fd 100644
--- a/tests/expected/libfdisk/mkpart-full-gpt
+++ b/tests/expected/libfdisk/mkpart-full-gpt
@@ -1,17 +1,17 @@
-Requested partition: <partno=0,start=2048,size=2048>
-Requested partition: <partno=1,start=4096,size=2048>
-Requested partition: <partno=2,start=6144,size=2048>
-Requested partition: <partno=3,start=8192,size=2048>
-Requested partition: <partno=4,start=10240,size=2048>
-Requested partition: <partno=5,start=12288,size=2048>
-Requested partition: <partno=6,start=14336,size=2048>
 Created a new <removed>.
+Requested partition: <partno=0,start=2048,size=2048>
 Created a new <removed>.
+Requested partition: <partno=1,start=4096,size=2048>
 Created a new <removed>.
+Requested partition: <partno=2,start=6144,size=2048>
 Created a new <removed>.
+Requested partition: <partno=3,start=8192,size=2048>
 Created a new <removed>.
+Requested partition: <partno=4,start=10240,size=2048>
 Created a new <removed>.
+Requested partition: <partno=5,start=12288,size=2048>
 Created a new <removed>.
+Requested partition: <partno=6,start=14336,size=2048>
 Created a new <removed>.
 Disk <removed>: 15 MiB, 15728640 bytes, 30720 sectors
 Units: sectors of 1 * 512 = 512 bytes
diff --git a/tests/expected/libfdisk/mkpart-full-gpt-err-overlap b/tests/expected/libfdisk/mkpart-full-gpt-err-overlap
index 673339230..ebf078415 100644
--- a/tests/expected/libfdisk/mkpart-full-gpt-err-overlap
+++ b/tests/expected/libfdisk/mkpart-full-gpt-err-overlap
@@ -1,11 +1,11 @@
-Requested partition: <partno=0,start=2048,size=2048>
-Requested partition: <partno=1,start=4096,size=2048>
-Requested partition: <partno=2,start=6144,size=2048>
-Requested partition: <partno=3,start=5000,size=2048>
 Created a new <removed>.
+Requested partition: <partno=0,start=2048,size=2048>
 Created a new <removed>.
+Requested partition: <partno=1,start=4096,size=2048>
 Created a new <removed>.
+Requested partition: <partno=2,start=6144,size=2048>
 Created a new <removed>.
+Requested partition: <partno=3,start=5000,size=2048>
 Sector 5000 already used.
 sample-fdisk-mkpart-fullspec: failed to add #4 partition
 Disk <removed>: 15 MiB, 15728640 bytes, 30720 sectors
diff --git a/tests/expected/libfdisk/mkpart-full-gpt-nopartno b/tests/expected/libfdisk/mkpart-full-gpt-nopartno
index 2c1423b75..fc9fdf240 100644
--- a/tests/expected/libfdisk/mkpart-full-gpt-nopartno
+++ b/tests/expected/libfdisk/mkpart-full-gpt-nopartno
@@ -1,17 +1,17 @@
-Requested partition: <partno=<default>,start=2048,size=2048>
-Requested partition: <partno=<default>,start=4096,size=2048>
-Requested partition: <partno=<default>,start=6144,size=2048>
-Requested partition: <partno=<default>,start=8192,size=2048>
-Requested partition: <partno=<default>,start=10240,size=2048>
-Requested partition: <partno=<default>,start=12288,size=2048>
-Requested partition: <partno=<default>,start=14336,size=2048>
 Created a new <removed>.
+Requested partition: <partno=<default>,start=2048,size=2048>
 Created a new <removed>.
+Requested partition: <partno=<default>,start=4096,size=2048>
 Created a new <removed>.
+Requested partition: <partno=<default>,start=6144,size=2048>
 Created a new <removed>.
+Requested partition: <partno=<default>,start=8192,size=2048>
 Created a new <removed>.
+Requested partition: <partno=<default>,start=10240,size=2048>
 Created a new <removed>.
+Requested partition: <partno=<default>,start=12288,size=2048>
 Created a new <removed>.
+Requested partition: <partno=<default>,start=14336,size=2048>
 Created a new <removed>.
 Disk <removed>: 15 MiB, 15728640 bytes, 30720 sectors
 Units: sectors of 1 * 512 = 512 bytes
diff --git a/tests/expected/libfdisk/mkpart-full-gpt-partno-gap b/tests/expected/libfdisk/mkpart-full-gpt-partno-gap
index b142b5efe..3a65d37e4 100644
--- a/tests/expected/libfdisk/mkpart-full-gpt-partno-gap
+++ b/tests/expected/libfdisk/mkpart-full-gpt-partno-gap
@@ -1,17 +1,17 @@
-Requested partition: <partno=0,start=2048,size=2048>
-Requested partition: <partno=1,start=4096,size=2048>
-Requested partition: <partno=3,start=6144,size=2048>
-Requested partition: <partno=4,start=8192,size=2048>
-Requested partition: <partno=6,start=10240,size=2048>
-Requested partition: <partno=7,start=12288,size=2048>
-Requested partition: <partno=8,start=14336,size=2048>
 Created a new <removed>.
+Requested partition: <partno=0,start=2048,size=2048>
 Created a new <removed>.
+Requested partition: <partno=1,start=4096,size=2048>
 Created a new <removed>.
+Requested partition: <partno=3,start=6144,size=2048>
 Created a new <removed>.
+Requested partition: <partno=4,start=8192,size=2048>
 Created a new <removed>.
+Requested partition: <partno=6,start=10240,size=2048>
 Created a new <removed>.
+Requested partition: <partno=7,start=12288,size=2048>
 Created a new <removed>.
+Requested partition: <partno=8,start=14336,size=2048>
 Created a new <removed>.
 Disk <removed>: 15 MiB, 15728640 bytes, 30720 sectors
 Units: sectors of 1 * 512 = 512 bytes
diff --git a/tests/expected/libfdisk/mkpart-full-gpt-space-gap b/tests/expected/libfdisk/mkpart-full-gpt-space-gap
index c26f2896b..64b2da4ab 100644
--- a/tests/expected/libfdisk/mkpart-full-gpt-space-gap
+++ b/tests/expected/libfdisk/mkpart-full-gpt-space-gap
@@ -1,13 +1,13 @@
-Requested partition: <partno=0,start=2048,size=2048>
-Requested partition: <partno=1,start=6144,size=2048>
-Requested partition: <partno=2,start=8192,size=2048>
-Requested partition: <partno=3,start=12288,size=2048>
-Requested partition: <partno=4,start=14336,size=2048>
 Created a new <removed>.
+Requested partition: <partno=0,start=2048,size=2048>
 Created a new <removed>.
+Requested partition: <partno=1,start=6144,size=2048>
 Created a new <removed>.
+Requested partition: <partno=2,start=8192,size=2048>
 Created a new <removed>.
+Requested partition: <partno=3,start=12288,size=2048>
 Created a new <removed>.
+Requested partition: <partno=4,start=14336,size=2048>
 Created a new <removed>.
 Disk <removed>: 15 MiB, 15728640 bytes, 30720 sectors
 Units: sectors of 1 * 512 = 512 bytes
diff --git a/tests/expected/libfdisk/mkpart-full-mbr-err-logical b/tests/expected/libfdisk/mkpart-full-mbr-err-logical
index c2c0b0df6..6d48f487a 100644
--- a/tests/expected/libfdisk/mkpart-full-mbr-err-logical
+++ b/tests/expected/libfdisk/mkpart-full-mbr-err-logical
@@ -1,17 +1,17 @@
-Requested partition: <partno=0,start=2048,size=2048>
-Requested partition: <partno=1,start=4096,size=2048>
-Requested partition: <partno=2,start=6144,size=2048>
-Requested partition: <partno=3,start=8192,size=22528>
-Requested partition: <partno=4,start=10240,size=2048>
-Requested partition: <partno=5,start=4096,size=2048>
-sample-fdisk-mkpart-fullspec: failed to add #6 partition
 Created a new <removed>.
+Requested partition: <partno=0,start=2048,size=2048>
 Created a new <removed>.
+Requested partition: <partno=1,start=4096,size=2048>
 Created a new <removed>.
+Requested partition: <partno=2,start=6144,size=2048>
 Created a new <removed>.
+Requested partition: <partno=3,start=8192,size=22528>
 Created a new <removed>.
+Requested partition: <partno=4,start=10240,size=2048>
 Adding logical partition 5
 Created a new <removed>.
+Requested partition: <partno=5,start=4096,size=2048>
+sample-fdisk-mkpart-fullspec: failed to add #6 partition
 Disk <removed>: 15 MiB, 15728640 bytes, 30720 sectors
 Units: sectors of 1 * 512 = 512 bytes
 Sector size (logical/physical): 512 bytes / 512 bytes
diff --git a/tests/expected/libfdisk/mkpart-full-mbr-err-nospace b/tests/expected/libfdisk/mkpart-full-mbr-err-nospace
index d7a006569..a79c5800a 100644
--- a/tests/expected/libfdisk/mkpart-full-mbr-err-nospace
+++ b/tests/expected/libfdisk/mkpart-full-mbr-err-nospace
@@ -1,9 +1,9 @@
-Requested partition: <partno=0,start=2048,size=2048>
-Requested partition: <partno=1,start=4096,size=2048>
-Requested partition: <partno=2,start=4096,size=2048>
 Created a new <removed>.
+Requested partition: <partno=0,start=2048,size=2048>
 Created a new <removed>.
+Requested partition: <partno=1,start=4096,size=2048>
 Created a new <removed>.
+Requested partition: <partno=2,start=4096,size=2048>
 Start sector 4096 out of range.
 sample-fdisk-mkpart-fullspec: failed to add #3 partition
 Disk <removed>: 15 MiB, 15728640 bytes, 30720 sectors
diff --git a/tests/expected/libfdisk/mkpart-full-mbr-err-primary b/tests/expected/libfdisk/mkpart-full-mbr-err-primary
index 1142f6531..93edf2b07 100644
--- a/tests/expected/libfdisk/mkpart-full-mbr-err-primary
+++ b/tests/expected/libfdisk/mkpart-full-mbr-err-primary
@@ -1,9 +1,9 @@
-Requested partition: <partno=0,start=2048,size=2048>
-Requested partition: <partno=1,start=4096,size=2048>
-Requested partition: <partno=6,start=6144,size=2048>
 Created a new <removed>.
+Requested partition: <partno=0,start=2048,size=2048>
 Created a new <removed>.
+Requested partition: <partno=1,start=4096,size=2048>
 Created a new <removed>.
+Requested partition: <partno=6,start=6144,size=2048>
 Extended partition does not exists. Failed to add logical partition.
 sample-fdisk-mkpart-fullspec: failed to add #7 partition
 Disk <removed>: 15 MiB, 15728640 bytes, 30720 sectors
diff --git a/tests/expected/libfdisk/mkpart-full-mbr-logical b/tests/expected/libfdisk/mkpart-full-mbr-logical
index 97e7a4a54..ff2611cbb 100644
--- a/tests/expected/libfdisk/mkpart-full-mbr-logical
+++ b/tests/expected/libfdisk/mkpart-full-mbr-logical
@@ -1,19 +1,19 @@
-Requested partition: <partno=0,start=2048,size=2048>
-Requested partition: <partno=1,start=4096,size=2048>
-Requested partition: <partno=2,start=6144,size=2048>
-Requested partition: <partno=3,start=8192,size=22528>
-Requested partition: <partno=4,start=10240,size=2048>
-Requested partition: <partno=5,start=14336,size=2048>
-Requested partition: <partno=6,start=18432,size=12288>
 Created a new <removed>.
+Requested partition: <partno=0,start=2048,size=2048>
 Created a new <removed>.
+Requested partition: <partno=1,start=4096,size=2048>
 Created a new <removed>.
+Requested partition: <partno=2,start=6144,size=2048>
 Created a new <removed>.
+Requested partition: <partno=3,start=8192,size=22528>
 Created a new <removed>.
+Requested partition: <partno=4,start=10240,size=2048>
 Adding logical partition 5
 Created a new <removed>.
+Requested partition: <partno=5,start=14336,size=2048>
 Adding logical partition 6
 Created a new <removed>.
+Requested partition: <partno=6,start=18432,size=12288>
 Adding logical partition 7
 Created a new <removed>.
 Disk <removed>: 15 MiB, 15728640 bytes, 30720 sectors
diff --git a/tests/expected/libfdisk/mkpart-full-mbr-nopartno b/tests/expected/libfdisk/mkpart-full-mbr-nopartno
index 23f7ad5a7..c8c449cd1 100644
--- a/tests/expected/libfdisk/mkpart-full-mbr-nopartno
+++ b/tests/expected/libfdisk/mkpart-full-mbr-nopartno
@@ -1,19 +1,19 @@
-Requested partition: <partno=<default>,start=2048,size=2048>
-Requested partition: <partno=<default>,start=4096,size=2048>
-Requested partition: <partno=<default>,start=6144,size=2048>
-Requested partition: <partno=<default>,start=8192,size=22528>
-Requested partition: <partno=<default>,start=10240,size=2048>
-Requested partition: <partno=<default>,start=14336,size=2048>
-Requested partition: <partno=<default>,start=18432,size=12288>
 Created a new <removed>.
+Requested partition: <partno=<default>,start=2048,size=2048>
 Created a new <removed>.
+Requested partition: <partno=<default>,start=4096,size=2048>
 Created a new <removed>.
+Requested partition: <partno=<default>,start=6144,size=2048>
 Created a new <removed>.
+Requested partition: <partno=<default>,start=8192,size=22528>
 Created a new <removed>.
+Requested partition: <partno=<default>,start=10240,size=2048>
 Adding logical partition 5
 Created a new <removed>.
+Requested partition: <partno=<default>,start=14336,size=2048>
 Adding logical partition 6
 Created a new <removed>.
+Requested partition: <partno=<default>,start=18432,size=12288>
 Adding logical partition 7
 Created a new <removed>.
 Disk <removed>: 15 MiB, 15728640 bytes, 30720 sectors
diff --git a/tests/expected/libfdisk/mkpart-full-mbr-primary b/tests/expected/libfdisk/mkpart-full-mbr-primary
index 31e84344d..c71ec9e1f 100644
--- a/tests/expected/libfdisk/mkpart-full-mbr-primary
+++ b/tests/expected/libfdisk/mkpart-full-mbr-primary
@@ -1,11 +1,11 @@
-Requested partition: <partno=0,start=2048,size=2048>
-Requested partition: <partno=1,start=4096,size=2048>
-Requested partition: <partno=2,start=6144,size=2048>
-Requested partition: <partno=3,start=8192,size=22528>
 Created a new <removed>.
+Requested partition: <partno=0,start=2048,size=2048>
 Created a new <removed>.
+Requested partition: <partno=1,start=4096,size=2048>
 Created a new <removed>.
+Requested partition: <partno=2,start=6144,size=2048>
 Created a new <removed>.
+Requested partition: <partno=3,start=8192,size=22528>
 Created a new <removed>.
 Disk <removed>: 15 MiB, 15728640 bytes, 30720 sectors
 Units: sectors of 1 * 512 = 512 bytes
diff --git a/tests/expected/libfdisk/mkpart-full-mbr-primary-nopartno b/tests/expected/libfdisk/mkpart-full-mbr-primary-nopartno
index 90a71f3ab..33ba9ff88 100644
--- a/tests/expected/libfdisk/mkpart-full-mbr-primary-nopartno
+++ b/tests/expected/libfdisk/mkpart-full-mbr-primary-nopartno
@@ -1,11 +1,11 @@
-Requested partition: <partno=<default>,start=2048,size=2048>
-Requested partition: <partno=<default>,start=4096,size=2048>
-Requested partition: <partno=<default>,start=6144,size=2048>
-Requested partition: <partno=<default>,start=8192,size=22528>
 Created a new <removed>.
+Requested partition: <partno=<default>,start=2048,size=2048>
 Created a new <removed>.
+Requested partition: <partno=<default>,start=4096,size=2048>
 Created a new <removed>.
+Requested partition: <partno=<default>,start=6144,size=2048>
 Created a new <removed>.
+Requested partition: <partno=<default>,start=8192,size=22528>
 Created a new <removed>.
 Disk <removed>: 15 MiB, 15728640 bytes, 30720 sectors
 Units: sectors of 1 * 512 = 512 bytes
diff --git a/tests/expected/libfdisk/mkpart-full-mbr-space-gap b/tests/expected/libfdisk/mkpart-full-mbr-space-gap
index 45d45071f..881ea9ec7 100644
--- a/tests/expected/libfdisk/mkpart-full-mbr-space-gap
+++ b/tests/expected/libfdisk/mkpart-full-mbr-space-gap
@@ -1,9 +1,9 @@
-Requested partition: <partno=0,start=2048,size=2048>
-Requested partition: <partno=1,start=6144,size=2048>
-Requested partition: <partno=2,start=8192,size=2048>
 Created a new <removed>.
+Requested partition: <partno=0,start=2048,size=2048>
 Created a new <removed>.
+Requested partition: <partno=1,start=6144,size=2048>
 Created a new <removed>.
+Requested partition: <partno=2,start=8192,size=2048>
 Created a new <removed>.
 Disk <removed>: 15 MiB, 15728640 bytes, 30720 sectors
 Units: sectors of 1 * 512 = 512 bytes
diff --git a/tests/ts/libfdisk/mkpart-full b/tests/ts/libfdisk/mkpart-full
index eda506ef6..7f6413b09 100755
--- a/tests/ts/libfdisk/mkpart-full
+++ b/tests/ts/libfdisk/mkpart-full
@@ -31,7 +31,7 @@ ts_check_test_command "$TS_CMD_WIPEFS"
 TEST_IMAGE_NAME=$(ts_image_init 15)
 
 ts_init_subtest "mbr-primary"
-$TESTPROG --label mbr --device ${TEST_IMAGE_NAME} \
+ts_unbuffered $TESTPROG --label mbr --device ${TEST_IMAGE_NAME} \
 	1,2048,2048 \
 	2,4096,2048 \
 	3,6144,2048 \
@@ -45,7 +45,7 @@ $TS_CMD_WIPEFS --all --force ${TEST_IMAGE_NAME} &> /dev/null
 
 
 ts_init_subtest "mbr-primary-nopartno"
-$TESTPROG --label mbr --device ${TEST_IMAGE_NAME} -- \
+ts_unbuffered $TESTPROG --label mbr --device ${TEST_IMAGE_NAME} -- \
 	-,2048,2048 \
 	-,4096,2048 \
 	-,6144,2048 \
@@ -59,7 +59,7 @@ $TS_CMD_WIPEFS --all --force ${TEST_IMAGE_NAME} &> /dev/null
 
 ## no extended but partno > 4 requested
 ts_init_subtest "mbr-err-primary"
-$TESTPROG --label mbr --device ${TEST_IMAGE_NAME} \
+ts_unbuffered $TESTPROG --label mbr --device ${TEST_IMAGE_NAME} \
 	1,2048,2048 \
 	2,4096,2048 \
 	7,6144,2048 \
@@ -72,7 +72,7 @@ $TS_CMD_WIPEFS --all --force ${TEST_IMAGE_NAME} &> /dev/null
 
 ## no extended but partno > 4 requested
 ts_init_subtest "mbr-err-nospace"
-$TESTPROG --label mbr --device ${TEST_IMAGE_NAME} \
+ts_unbuffered $TESTPROG --label mbr --device ${TEST_IMAGE_NAME} \
 	1,2048,2048 \
 	2,4096,2048 \
 	3,4096,2048 \
@@ -85,7 +85,7 @@ $TS_CMD_WIPEFS --all --force ${TEST_IMAGE_NAME} &> /dev/null
 
 
 ts_init_subtest "mbr-logical"
-$TESTPROG --label mbr --device ${TEST_IMAGE_NAME} \
+ts_unbuffered $TESTPROG --label mbr --device ${TEST_IMAGE_NAME} \
 	1,2048,2048 \
 	2,4096,2048 \
 	3,6144,2048 \
@@ -101,7 +101,7 @@ ts_finalize_subtest
 $TS_CMD_WIPEFS --all --force ${TEST_IMAGE_NAME} &> /dev/null
 
 ts_init_subtest "mbr-nopartno"
-$TESTPROG --label mbr --device ${TEST_IMAGE_NAME} -- \
+ts_unbuffered $TESTPROG --label mbr --device ${TEST_IMAGE_NAME} -- \
 	-,2048,2048 \
 	-,4096,2048 \
 	-,6144,2048 \
@@ -118,7 +118,7 @@ $TS_CMD_WIPEFS --all --force ${TEST_IMAGE_NAME} &> /dev/null
 
 ### 6th partition (logical) out of extended
 ts_init_subtest "mbr-err-logical"
-$TESTPROG --label mbr --device ${TEST_IMAGE_NAME} \
+ts_unbuffered $TESTPROG --label mbr --device ${TEST_IMAGE_NAME} \
 	1,2048,2048 \
 	2,4096,2048 \
 	3,6144,2048 \
@@ -134,7 +134,7 @@ ts_finalize_subtest
 $TS_CMD_WIPEFS --all --force ${TEST_IMAGE_NAME} &> /dev/null
 
 ts_init_subtest "mbr-space-gap"
-$TESTPROG --label mbr --device ${TEST_IMAGE_NAME} \
+ts_unbuffered $TESTPROG --label mbr --device ${TEST_IMAGE_NAME} \
 	1,2048,2048 \
 	2,6144,2048 \
 	3,8192,2048 \
@@ -146,7 +146,7 @@ ts_finalize_subtest
 $TS_CMD_WIPEFS --all --force ${TEST_IMAGE_NAME} &> /dev/null
 
 ts_init_subtest "gpt"
-$TESTPROG --label gpt --device ${TEST_IMAGE_NAME} \
+ts_unbuffered $TESTPROG --label gpt --device ${TEST_IMAGE_NAME} \
 	1,2048,2048 \
 	2,4096,2048 \
 	3,6144,2048 \
@@ -162,7 +162,7 @@ ts_finalize_subtest
 $TS_CMD_WIPEFS --all --force ${TEST_IMAGE_NAME} &> /dev/null
 
 ts_init_subtest "gpt-nopartno"
-$TESTPROG --label gpt --device ${TEST_IMAGE_NAME} -- \
+ts_unbuffered $TESTPROG --label gpt --device ${TEST_IMAGE_NAME} -- \
 	-,2048,2048 \
 	-,4096,2048 \
 	-,6144,2048 \
@@ -179,7 +179,7 @@ $TS_CMD_WIPEFS --all --force ${TEST_IMAGE_NAME} &> /dev/null
 
 ### 4th partition overlap 4th and 5th
 ts_init_subtest "gpt-err-overlap"
-$TESTPROG --label gpt --device ${TEST_IMAGE_NAME} \
+ts_unbuffered $TESTPROG --label gpt --device ${TEST_IMAGE_NAME} \
 	1,2048,2048 \
 	2,4096,2048 \
 	3,6144,2048 \
@@ -195,7 +195,7 @@ ts_finalize_subtest
 $TS_CMD_WIPEFS --all --force ${TEST_IMAGE_NAME} &> /dev/null
 
 ts_init_subtest "gpt-partno-gap"
-$TESTPROG --label gpt --device ${TEST_IMAGE_NAME} \
+ts_unbuffered $TESTPROG --label gpt --device ${TEST_IMAGE_NAME} \
 	1,2048,2048 \
 	2,4096,2048 \
 	4,6144,2048 \
@@ -211,7 +211,7 @@ ts_finalize_subtest
 $TS_CMD_WIPEFS --all --force ${TEST_IMAGE_NAME} &> /dev/null
 
 ts_init_subtest "gpt-space-gap"
-$TESTPROG --label gpt --device ${TEST_IMAGE_NAME} \
+ts_unbuffered $TESTPROG --label gpt --device ${TEST_IMAGE_NAME} \
 	1,2048,2048 \
 	2,6144,2048 \
 	3,8192,2048 \
-- 
2.23.0


^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 6/6] tests: libfdisk: remove reliance on buffer behaviour of standard streams
  2019-08-23 10:17 ` [PATCH 6/6] tests: libfdisk: remove reliance on buffer behaviour of standard streams Patrick Steinhardt
@ 2019-08-23 12:15   ` Karel Zak
  0 siblings, 0 replies; 25+ messages in thread
From: Karel Zak @ 2019-08-23 12:15 UTC (permalink / raw)
  To: Patrick Steinhardt; +Cc: util-linux

On Fri, Aug 23, 2019 at 12:17:03PM +0200, Patrick Steinhardt wrote:
> The tests in libfdisk/mkpart-full all rely on the buffering behaviour of
> standard output and standard error streams, most importantly that stderr
> is non-buffering and stdout is buffering. This doesn't hold on all libc
> implementations when redirecting to a file, breaking the test suite on
> such platforms.
> 
> Use the ts_unbuffered function to stop buffering of the standard output
> stream to fix this.

We have function ts_run. For now it's used only for some library tests
where we want to detect leaks, etc. It seems that growing number of
situations when we need some extra setting before the exec.

May be we can make this function more generic, add buffering control 
and use in all tests.

Something like

 ts_run leak unbuf -- $TESTPROG       # ASAN & unbuffered exec
 ts_run unbuf -- $TESTPROG            # unbuffered exec
 ts_run -- $TESTPROG                  # just exec

... or so ;-)

    Karel


-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [PATCH v2 0/6] Test suite fixes for musl libc
  2019-08-23 10:16 [PATCH 0/6] Test suite fixes for musl libc Patrick Steinhardt
                   ` (5 preceding siblings ...)
  2019-08-23 10:17 ` [PATCH 6/6] tests: libfdisk: remove reliance on buffer behaviour of standard streams Patrick Steinhardt
@ 2019-08-23 13:32 ` Patrick Steinhardt
  2019-08-23 13:32   ` [PATCH v2 1/6] tests: remove reliance on buffer behaviour of stderr/stdout streams Patrick Steinhardt
                     ` (5 more replies)
  6 siblings, 6 replies; 25+ messages in thread
From: Patrick Steinhardt @ 2019-08-23 13:32 UTC (permalink / raw)
  To: util-linux; +Cc: Patrick Steinhardt, Karel Zak

Hi,

Changes in v2
=============

As proposed by Karel, this removes ts_unbuffered and instead
extends ts_run. Instead of accepting parameters like "leak" or
"unbuf" though, I opted to instead accept dashed longopts only as
that should allow us to keep all existing invocations of `ts_run`
the same. At least as far as I've seen, there is none that ever
starts with "-".

So one may now execute `ts_run --unbuffered $TESTPROG` to use
"stdbuf --output=0" and thus stop buffering. But the mechanism
is easily extensible, as proposed by Karel.

Old cover letter
================

on latest master of util-linux, there's currently 20 test- and
subtest failures on musl based systems. There's three different
categories of failures:

    - Reliance on buffering properties of stdout/stderr.

    - Expectance of non-standard error messages returned by
      strerror(3P).

    - Expectance of EILSEQ with POSIX locale.

This patch set fixes all of the above, bringing down the number
of failures from 20 to a single test failure. The remaining
failure is in getopt(1), which documents and implicitly relies on
the POSIXLY_CORRECT environment variable when calling getopt_long
from glibc. Adhering to this variable isn't implemented by musl
libc, so to get this working correctly one would have to modify
getopt(1) itself, e.g. by automatically prepending a '+' to the
optstr if the envvar is set. But I'll leave that to another patch
series.

Regards
Patrick

Patrick Steinhardt (6):
  tests: remove reliance on buffer behaviour of stderr/stdout streams
  tests: libfdisk: remove reliance on buffer behaviour of standard
    streams
  tests: colcrt: fix reliance on EILSEQ in POSIX locale
  tests: column: use actually invalid multibytes to test encoding
  tests: col: avoid hardcoding of errno string
  tests: fdisk: avoid hardcoding of errno string

 tests/commands.sh                             |  1 +
 tests/expected/col/multibyte                  |  2 +-
 tests/expected/column/invalid-multibyte       |  2 +-
 tests/expected/fdisk/oddinput                 |  4 +-
 tests/expected/libfdisk/mkpart-full-gpt       | 14 +++---
 .../libfdisk/mkpart-full-gpt-err-overlap      |  8 ++--
 .../libfdisk/mkpart-full-gpt-nopartno         | 14 +++---
 .../libfdisk/mkpart-full-gpt-partno-gap       | 14 +++---
 .../libfdisk/mkpart-full-gpt-space-gap        | 10 ++--
 .../libfdisk/mkpart-full-mbr-err-logical      | 14 +++---
 .../libfdisk/mkpart-full-mbr-err-nospace      |  6 +--
 .../libfdisk/mkpart-full-mbr-err-primary      |  6 +--
 .../expected/libfdisk/mkpart-full-mbr-logical | 14 +++---
 .../libfdisk/mkpart-full-mbr-nopartno         | 14 +++---
 .../expected/libfdisk/mkpart-full-mbr-primary |  8 ++--
 .../libfdisk/mkpart-full-mbr-primary-nopartno |  8 ++--
 .../libfdisk/mkpart-full-mbr-space-gap        |  6 +--
 tests/expected/misc/swaplabel                 |  2 +-
 tests/expected/rename/exit_codes              |  2 +-
 tests/functions.sh                            | 47 ++++++++++++++-----
 tests/helpers/Makemodule.am                   |  3 ++
 tests/helpers/test_strerror.c                 | 44 +++++++++++++++++
 tests/ts/col/multibyte                        |  5 +-
 tests/ts/colcrt/regressions                   |  2 +-
 tests/ts/column/invalid-multibyte             |  2 +-
 tests/ts/fdisk/oddinput                       |  6 ++-
 tests/ts/libfdisk/mkpart-full                 | 26 +++++-----
 tests/ts/misc/swaplabel                       |  4 +-
 tests/ts/rename/exit_codes                    |  2 +-
 29 files changed, 181 insertions(+), 109 deletions(-)
 create mode 100644 tests/helpers/test_strerror.c

-- 
2.23.0


^ permalink raw reply	[flat|nested] 25+ messages in thread

* [PATCH v2 1/6] tests: remove reliance on buffer behaviour of stderr/stdout streams
  2019-08-23 13:32 ` [PATCH v2 0/6] Test suite fixes for musl libc Patrick Steinhardt
@ 2019-08-23 13:32   ` Patrick Steinhardt
  2019-08-27 11:17     ` Karel Zak
  2019-08-23 13:32   ` [PATCH v2 2/6] tests: libfdisk: remove reliance on buffer behaviour of standard streams Patrick Steinhardt
                     ` (4 subsequent siblings)
  5 siblings, 1 reply; 25+ messages in thread
From: Patrick Steinhardt @ 2019-08-23 13:32 UTC (permalink / raw)
  To: util-linux; +Cc: Patrick Steinhardt, Karel Zak

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    |  2 +-
 tests/expected/rename/exit_codes |  2 +-
 tests/functions.sh               | 47 +++++++++++++++++++++++---------
 tests/ts/misc/swaplabel          |  4 +--
 tests/ts/rename/exit_codes       |  2 +-
 5 files changed, 39 insertions(+), 18 deletions(-)

diff --git a/tests/expected/misc/swaplabel b/tests/expected/misc/swaplabel
index 172f876af..790a28c6c 100644
--- a/tests/expected/misc/swaplabel
+++ b/tests/expected/misc/swaplabel
@@ -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
diff --git a/tests/expected/rename/exit_codes b/tests/expected/rename/exit_codes
index c57781788..3d53010b2 100644
--- a/tests/expected/rename/exit_codes
+++ b/tests/expected/rename/exit_codes
@@ -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
diff --git a/tests/functions.sh b/tests/functions.sh
index 0605a1320..3d7bb89bc 100644
--- a/tests/functions.sh
+++ b/tests/functions.sh
@@ -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
 }
-
diff --git a/tests/ts/misc/swaplabel b/tests/ts/misc/swaplabel
index 22858b0ac..106cb7d21 100755
--- a/tests/ts/misc/swaplabel
+++ b/tests/ts/misc/swaplabel
@@ -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 |\
diff --git a/tests/ts/rename/exit_codes b/tests/ts/rename/exit_codes
index 37028162b..d3012ae59 100755
--- a/tests/ts/rename/exit_codes
+++ b/tests/ts/rename/exit_codes
@@ -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
-- 
2.23.0


^ permalink raw reply	[flat|nested] 25+ messages in thread

* [PATCH v2 2/6] tests: libfdisk: remove reliance on buffer behaviour of standard streams
  2019-08-23 13:32 ` [PATCH v2 0/6] Test suite fixes for musl libc Patrick Steinhardt
  2019-08-23 13:32   ` [PATCH v2 1/6] tests: remove reliance on buffer behaviour of stderr/stdout streams Patrick Steinhardt
@ 2019-08-23 13:32   ` Patrick Steinhardt
  2019-08-23 13:32   ` [PATCH v2 3/6] tests: colcrt: fix reliance on EILSEQ in POSIX locale Patrick Steinhardt
                     ` (3 subsequent siblings)
  5 siblings, 0 replies; 25+ messages in thread
From: Patrick Steinhardt @ 2019-08-23 13:32 UTC (permalink / raw)
  To: util-linux; +Cc: Patrick Steinhardt, Karel Zak

The tests in libfdisk/mkpart-full all rely on the buffering behaviour of
standard output and standard error streams, most importantly that stderr
is non-buffering and stdout is buffering. This doesn't hold on all libc
implementations when redirecting to a file, breaking the test suite on
such platforms.

Use `ts_run --unbuffered` to stop buffering of the standard output
stream to fix this.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 tests/expected/libfdisk/mkpart-full-gpt       | 14 +++++-----
 .../libfdisk/mkpart-full-gpt-err-overlap      |  8 +++---
 .../libfdisk/mkpart-full-gpt-nopartno         | 14 +++++-----
 .../libfdisk/mkpart-full-gpt-partno-gap       | 14 +++++-----
 .../libfdisk/mkpart-full-gpt-space-gap        | 10 +++----
 .../libfdisk/mkpart-full-mbr-err-logical      | 14 +++++-----
 .../libfdisk/mkpart-full-mbr-err-nospace      |  6 ++---
 .../libfdisk/mkpart-full-mbr-err-primary      |  6 ++---
 .../expected/libfdisk/mkpart-full-mbr-logical | 14 +++++-----
 .../libfdisk/mkpart-full-mbr-nopartno         | 14 +++++-----
 .../expected/libfdisk/mkpart-full-mbr-primary |  8 +++---
 .../libfdisk/mkpart-full-mbr-primary-nopartno |  8 +++---
 .../libfdisk/mkpart-full-mbr-space-gap        |  6 ++---
 tests/ts/libfdisk/mkpart-full                 | 26 +++++++++----------
 14 files changed, 81 insertions(+), 81 deletions(-)

diff --git a/tests/expected/libfdisk/mkpart-full-gpt b/tests/expected/libfdisk/mkpart-full-gpt
index d33483ac6..7740454fd 100644
--- a/tests/expected/libfdisk/mkpart-full-gpt
+++ b/tests/expected/libfdisk/mkpart-full-gpt
@@ -1,17 +1,17 @@
-Requested partition: <partno=0,start=2048,size=2048>
-Requested partition: <partno=1,start=4096,size=2048>
-Requested partition: <partno=2,start=6144,size=2048>
-Requested partition: <partno=3,start=8192,size=2048>
-Requested partition: <partno=4,start=10240,size=2048>
-Requested partition: <partno=5,start=12288,size=2048>
-Requested partition: <partno=6,start=14336,size=2048>
 Created a new <removed>.
+Requested partition: <partno=0,start=2048,size=2048>
 Created a new <removed>.
+Requested partition: <partno=1,start=4096,size=2048>
 Created a new <removed>.
+Requested partition: <partno=2,start=6144,size=2048>
 Created a new <removed>.
+Requested partition: <partno=3,start=8192,size=2048>
 Created a new <removed>.
+Requested partition: <partno=4,start=10240,size=2048>
 Created a new <removed>.
+Requested partition: <partno=5,start=12288,size=2048>
 Created a new <removed>.
+Requested partition: <partno=6,start=14336,size=2048>
 Created a new <removed>.
 Disk <removed>: 15 MiB, 15728640 bytes, 30720 sectors
 Units: sectors of 1 * 512 = 512 bytes
diff --git a/tests/expected/libfdisk/mkpart-full-gpt-err-overlap b/tests/expected/libfdisk/mkpart-full-gpt-err-overlap
index 673339230..ebf078415 100644
--- a/tests/expected/libfdisk/mkpart-full-gpt-err-overlap
+++ b/tests/expected/libfdisk/mkpart-full-gpt-err-overlap
@@ -1,11 +1,11 @@
-Requested partition: <partno=0,start=2048,size=2048>
-Requested partition: <partno=1,start=4096,size=2048>
-Requested partition: <partno=2,start=6144,size=2048>
-Requested partition: <partno=3,start=5000,size=2048>
 Created a new <removed>.
+Requested partition: <partno=0,start=2048,size=2048>
 Created a new <removed>.
+Requested partition: <partno=1,start=4096,size=2048>
 Created a new <removed>.
+Requested partition: <partno=2,start=6144,size=2048>
 Created a new <removed>.
+Requested partition: <partno=3,start=5000,size=2048>
 Sector 5000 already used.
 sample-fdisk-mkpart-fullspec: failed to add #4 partition
 Disk <removed>: 15 MiB, 15728640 bytes, 30720 sectors
diff --git a/tests/expected/libfdisk/mkpart-full-gpt-nopartno b/tests/expected/libfdisk/mkpart-full-gpt-nopartno
index 2c1423b75..fc9fdf240 100644
--- a/tests/expected/libfdisk/mkpart-full-gpt-nopartno
+++ b/tests/expected/libfdisk/mkpart-full-gpt-nopartno
@@ -1,17 +1,17 @@
-Requested partition: <partno=<default>,start=2048,size=2048>
-Requested partition: <partno=<default>,start=4096,size=2048>
-Requested partition: <partno=<default>,start=6144,size=2048>
-Requested partition: <partno=<default>,start=8192,size=2048>
-Requested partition: <partno=<default>,start=10240,size=2048>
-Requested partition: <partno=<default>,start=12288,size=2048>
-Requested partition: <partno=<default>,start=14336,size=2048>
 Created a new <removed>.
+Requested partition: <partno=<default>,start=2048,size=2048>
 Created a new <removed>.
+Requested partition: <partno=<default>,start=4096,size=2048>
 Created a new <removed>.
+Requested partition: <partno=<default>,start=6144,size=2048>
 Created a new <removed>.
+Requested partition: <partno=<default>,start=8192,size=2048>
 Created a new <removed>.
+Requested partition: <partno=<default>,start=10240,size=2048>
 Created a new <removed>.
+Requested partition: <partno=<default>,start=12288,size=2048>
 Created a new <removed>.
+Requested partition: <partno=<default>,start=14336,size=2048>
 Created a new <removed>.
 Disk <removed>: 15 MiB, 15728640 bytes, 30720 sectors
 Units: sectors of 1 * 512 = 512 bytes
diff --git a/tests/expected/libfdisk/mkpart-full-gpt-partno-gap b/tests/expected/libfdisk/mkpart-full-gpt-partno-gap
index b142b5efe..3a65d37e4 100644
--- a/tests/expected/libfdisk/mkpart-full-gpt-partno-gap
+++ b/tests/expected/libfdisk/mkpart-full-gpt-partno-gap
@@ -1,17 +1,17 @@
-Requested partition: <partno=0,start=2048,size=2048>
-Requested partition: <partno=1,start=4096,size=2048>
-Requested partition: <partno=3,start=6144,size=2048>
-Requested partition: <partno=4,start=8192,size=2048>
-Requested partition: <partno=6,start=10240,size=2048>
-Requested partition: <partno=7,start=12288,size=2048>
-Requested partition: <partno=8,start=14336,size=2048>
 Created a new <removed>.
+Requested partition: <partno=0,start=2048,size=2048>
 Created a new <removed>.
+Requested partition: <partno=1,start=4096,size=2048>
 Created a new <removed>.
+Requested partition: <partno=3,start=6144,size=2048>
 Created a new <removed>.
+Requested partition: <partno=4,start=8192,size=2048>
 Created a new <removed>.
+Requested partition: <partno=6,start=10240,size=2048>
 Created a new <removed>.
+Requested partition: <partno=7,start=12288,size=2048>
 Created a new <removed>.
+Requested partition: <partno=8,start=14336,size=2048>
 Created a new <removed>.
 Disk <removed>: 15 MiB, 15728640 bytes, 30720 sectors
 Units: sectors of 1 * 512 = 512 bytes
diff --git a/tests/expected/libfdisk/mkpart-full-gpt-space-gap b/tests/expected/libfdisk/mkpart-full-gpt-space-gap
index c26f2896b..64b2da4ab 100644
--- a/tests/expected/libfdisk/mkpart-full-gpt-space-gap
+++ b/tests/expected/libfdisk/mkpart-full-gpt-space-gap
@@ -1,13 +1,13 @@
-Requested partition: <partno=0,start=2048,size=2048>
-Requested partition: <partno=1,start=6144,size=2048>
-Requested partition: <partno=2,start=8192,size=2048>
-Requested partition: <partno=3,start=12288,size=2048>
-Requested partition: <partno=4,start=14336,size=2048>
 Created a new <removed>.
+Requested partition: <partno=0,start=2048,size=2048>
 Created a new <removed>.
+Requested partition: <partno=1,start=6144,size=2048>
 Created a new <removed>.
+Requested partition: <partno=2,start=8192,size=2048>
 Created a new <removed>.
+Requested partition: <partno=3,start=12288,size=2048>
 Created a new <removed>.
+Requested partition: <partno=4,start=14336,size=2048>
 Created a new <removed>.
 Disk <removed>: 15 MiB, 15728640 bytes, 30720 sectors
 Units: sectors of 1 * 512 = 512 bytes
diff --git a/tests/expected/libfdisk/mkpart-full-mbr-err-logical b/tests/expected/libfdisk/mkpart-full-mbr-err-logical
index c2c0b0df6..6d48f487a 100644
--- a/tests/expected/libfdisk/mkpart-full-mbr-err-logical
+++ b/tests/expected/libfdisk/mkpart-full-mbr-err-logical
@@ -1,17 +1,17 @@
-Requested partition: <partno=0,start=2048,size=2048>
-Requested partition: <partno=1,start=4096,size=2048>
-Requested partition: <partno=2,start=6144,size=2048>
-Requested partition: <partno=3,start=8192,size=22528>
-Requested partition: <partno=4,start=10240,size=2048>
-Requested partition: <partno=5,start=4096,size=2048>
-sample-fdisk-mkpart-fullspec: failed to add #6 partition
 Created a new <removed>.
+Requested partition: <partno=0,start=2048,size=2048>
 Created a new <removed>.
+Requested partition: <partno=1,start=4096,size=2048>
 Created a new <removed>.
+Requested partition: <partno=2,start=6144,size=2048>
 Created a new <removed>.
+Requested partition: <partno=3,start=8192,size=22528>
 Created a new <removed>.
+Requested partition: <partno=4,start=10240,size=2048>
 Adding logical partition 5
 Created a new <removed>.
+Requested partition: <partno=5,start=4096,size=2048>
+sample-fdisk-mkpart-fullspec: failed to add #6 partition
 Disk <removed>: 15 MiB, 15728640 bytes, 30720 sectors
 Units: sectors of 1 * 512 = 512 bytes
 Sector size (logical/physical): 512 bytes / 512 bytes
diff --git a/tests/expected/libfdisk/mkpart-full-mbr-err-nospace b/tests/expected/libfdisk/mkpart-full-mbr-err-nospace
index d7a006569..a79c5800a 100644
--- a/tests/expected/libfdisk/mkpart-full-mbr-err-nospace
+++ b/tests/expected/libfdisk/mkpart-full-mbr-err-nospace
@@ -1,9 +1,9 @@
-Requested partition: <partno=0,start=2048,size=2048>
-Requested partition: <partno=1,start=4096,size=2048>
-Requested partition: <partno=2,start=4096,size=2048>
 Created a new <removed>.
+Requested partition: <partno=0,start=2048,size=2048>
 Created a new <removed>.
+Requested partition: <partno=1,start=4096,size=2048>
 Created a new <removed>.
+Requested partition: <partno=2,start=4096,size=2048>
 Start sector 4096 out of range.
 sample-fdisk-mkpart-fullspec: failed to add #3 partition
 Disk <removed>: 15 MiB, 15728640 bytes, 30720 sectors
diff --git a/tests/expected/libfdisk/mkpart-full-mbr-err-primary b/tests/expected/libfdisk/mkpart-full-mbr-err-primary
index 1142f6531..93edf2b07 100644
--- a/tests/expected/libfdisk/mkpart-full-mbr-err-primary
+++ b/tests/expected/libfdisk/mkpart-full-mbr-err-primary
@@ -1,9 +1,9 @@
-Requested partition: <partno=0,start=2048,size=2048>
-Requested partition: <partno=1,start=4096,size=2048>
-Requested partition: <partno=6,start=6144,size=2048>
 Created a new <removed>.
+Requested partition: <partno=0,start=2048,size=2048>
 Created a new <removed>.
+Requested partition: <partno=1,start=4096,size=2048>
 Created a new <removed>.
+Requested partition: <partno=6,start=6144,size=2048>
 Extended partition does not exists. Failed to add logical partition.
 sample-fdisk-mkpart-fullspec: failed to add #7 partition
 Disk <removed>: 15 MiB, 15728640 bytes, 30720 sectors
diff --git a/tests/expected/libfdisk/mkpart-full-mbr-logical b/tests/expected/libfdisk/mkpart-full-mbr-logical
index 97e7a4a54..ff2611cbb 100644
--- a/tests/expected/libfdisk/mkpart-full-mbr-logical
+++ b/tests/expected/libfdisk/mkpart-full-mbr-logical
@@ -1,19 +1,19 @@
-Requested partition: <partno=0,start=2048,size=2048>
-Requested partition: <partno=1,start=4096,size=2048>
-Requested partition: <partno=2,start=6144,size=2048>
-Requested partition: <partno=3,start=8192,size=22528>
-Requested partition: <partno=4,start=10240,size=2048>
-Requested partition: <partno=5,start=14336,size=2048>
-Requested partition: <partno=6,start=18432,size=12288>
 Created a new <removed>.
+Requested partition: <partno=0,start=2048,size=2048>
 Created a new <removed>.
+Requested partition: <partno=1,start=4096,size=2048>
 Created a new <removed>.
+Requested partition: <partno=2,start=6144,size=2048>
 Created a new <removed>.
+Requested partition: <partno=3,start=8192,size=22528>
 Created a new <removed>.
+Requested partition: <partno=4,start=10240,size=2048>
 Adding logical partition 5
 Created a new <removed>.
+Requested partition: <partno=5,start=14336,size=2048>
 Adding logical partition 6
 Created a new <removed>.
+Requested partition: <partno=6,start=18432,size=12288>
 Adding logical partition 7
 Created a new <removed>.
 Disk <removed>: 15 MiB, 15728640 bytes, 30720 sectors
diff --git a/tests/expected/libfdisk/mkpart-full-mbr-nopartno b/tests/expected/libfdisk/mkpart-full-mbr-nopartno
index 23f7ad5a7..c8c449cd1 100644
--- a/tests/expected/libfdisk/mkpart-full-mbr-nopartno
+++ b/tests/expected/libfdisk/mkpart-full-mbr-nopartno
@@ -1,19 +1,19 @@
-Requested partition: <partno=<default>,start=2048,size=2048>
-Requested partition: <partno=<default>,start=4096,size=2048>
-Requested partition: <partno=<default>,start=6144,size=2048>
-Requested partition: <partno=<default>,start=8192,size=22528>
-Requested partition: <partno=<default>,start=10240,size=2048>
-Requested partition: <partno=<default>,start=14336,size=2048>
-Requested partition: <partno=<default>,start=18432,size=12288>
 Created a new <removed>.
+Requested partition: <partno=<default>,start=2048,size=2048>
 Created a new <removed>.
+Requested partition: <partno=<default>,start=4096,size=2048>
 Created a new <removed>.
+Requested partition: <partno=<default>,start=6144,size=2048>
 Created a new <removed>.
+Requested partition: <partno=<default>,start=8192,size=22528>
 Created a new <removed>.
+Requested partition: <partno=<default>,start=10240,size=2048>
 Adding logical partition 5
 Created a new <removed>.
+Requested partition: <partno=<default>,start=14336,size=2048>
 Adding logical partition 6
 Created a new <removed>.
+Requested partition: <partno=<default>,start=18432,size=12288>
 Adding logical partition 7
 Created a new <removed>.
 Disk <removed>: 15 MiB, 15728640 bytes, 30720 sectors
diff --git a/tests/expected/libfdisk/mkpart-full-mbr-primary b/tests/expected/libfdisk/mkpart-full-mbr-primary
index 31e84344d..c71ec9e1f 100644
--- a/tests/expected/libfdisk/mkpart-full-mbr-primary
+++ b/tests/expected/libfdisk/mkpart-full-mbr-primary
@@ -1,11 +1,11 @@
-Requested partition: <partno=0,start=2048,size=2048>
-Requested partition: <partno=1,start=4096,size=2048>
-Requested partition: <partno=2,start=6144,size=2048>
-Requested partition: <partno=3,start=8192,size=22528>
 Created a new <removed>.
+Requested partition: <partno=0,start=2048,size=2048>
 Created a new <removed>.
+Requested partition: <partno=1,start=4096,size=2048>
 Created a new <removed>.
+Requested partition: <partno=2,start=6144,size=2048>
 Created a new <removed>.
+Requested partition: <partno=3,start=8192,size=22528>
 Created a new <removed>.
 Disk <removed>: 15 MiB, 15728640 bytes, 30720 sectors
 Units: sectors of 1 * 512 = 512 bytes
diff --git a/tests/expected/libfdisk/mkpart-full-mbr-primary-nopartno b/tests/expected/libfdisk/mkpart-full-mbr-primary-nopartno
index 90a71f3ab..33ba9ff88 100644
--- a/tests/expected/libfdisk/mkpart-full-mbr-primary-nopartno
+++ b/tests/expected/libfdisk/mkpart-full-mbr-primary-nopartno
@@ -1,11 +1,11 @@
-Requested partition: <partno=<default>,start=2048,size=2048>
-Requested partition: <partno=<default>,start=4096,size=2048>
-Requested partition: <partno=<default>,start=6144,size=2048>
-Requested partition: <partno=<default>,start=8192,size=22528>
 Created a new <removed>.
+Requested partition: <partno=<default>,start=2048,size=2048>
 Created a new <removed>.
+Requested partition: <partno=<default>,start=4096,size=2048>
 Created a new <removed>.
+Requested partition: <partno=<default>,start=6144,size=2048>
 Created a new <removed>.
+Requested partition: <partno=<default>,start=8192,size=22528>
 Created a new <removed>.
 Disk <removed>: 15 MiB, 15728640 bytes, 30720 sectors
 Units: sectors of 1 * 512 = 512 bytes
diff --git a/tests/expected/libfdisk/mkpart-full-mbr-space-gap b/tests/expected/libfdisk/mkpart-full-mbr-space-gap
index 45d45071f..881ea9ec7 100644
--- a/tests/expected/libfdisk/mkpart-full-mbr-space-gap
+++ b/tests/expected/libfdisk/mkpart-full-mbr-space-gap
@@ -1,9 +1,9 @@
-Requested partition: <partno=0,start=2048,size=2048>
-Requested partition: <partno=1,start=6144,size=2048>
-Requested partition: <partno=2,start=8192,size=2048>
 Created a new <removed>.
+Requested partition: <partno=0,start=2048,size=2048>
 Created a new <removed>.
+Requested partition: <partno=1,start=6144,size=2048>
 Created a new <removed>.
+Requested partition: <partno=2,start=8192,size=2048>
 Created a new <removed>.
 Disk <removed>: 15 MiB, 15728640 bytes, 30720 sectors
 Units: sectors of 1 * 512 = 512 bytes
diff --git a/tests/ts/libfdisk/mkpart-full b/tests/ts/libfdisk/mkpart-full
index eda506ef6..9fb46ef67 100755
--- a/tests/ts/libfdisk/mkpart-full
+++ b/tests/ts/libfdisk/mkpart-full
@@ -31,7 +31,7 @@ ts_check_test_command "$TS_CMD_WIPEFS"
 TEST_IMAGE_NAME=$(ts_image_init 15)
 
 ts_init_subtest "mbr-primary"
-$TESTPROG --label mbr --device ${TEST_IMAGE_NAME} \
+ts_run --unbuffered $TESTPROG --label mbr --device ${TEST_IMAGE_NAME} \
 	1,2048,2048 \
 	2,4096,2048 \
 	3,6144,2048 \
@@ -45,7 +45,7 @@ $TS_CMD_WIPEFS --all --force ${TEST_IMAGE_NAME} &> /dev/null
 
 
 ts_init_subtest "mbr-primary-nopartno"
-$TESTPROG --label mbr --device ${TEST_IMAGE_NAME} -- \
+ts_run --unbuffered $TESTPROG --label mbr --device ${TEST_IMAGE_NAME} -- \
 	-,2048,2048 \
 	-,4096,2048 \
 	-,6144,2048 \
@@ -59,7 +59,7 @@ $TS_CMD_WIPEFS --all --force ${TEST_IMAGE_NAME} &> /dev/null
 
 ## no extended but partno > 4 requested
 ts_init_subtest "mbr-err-primary"
-$TESTPROG --label mbr --device ${TEST_IMAGE_NAME} \
+ts_run --unbuffered $TESTPROG --label mbr --device ${TEST_IMAGE_NAME} \
 	1,2048,2048 \
 	2,4096,2048 \
 	7,6144,2048 \
@@ -72,7 +72,7 @@ $TS_CMD_WIPEFS --all --force ${TEST_IMAGE_NAME} &> /dev/null
 
 ## no extended but partno > 4 requested
 ts_init_subtest "mbr-err-nospace"
-$TESTPROG --label mbr --device ${TEST_IMAGE_NAME} \
+ts_run --unbuffered $TESTPROG --label mbr --device ${TEST_IMAGE_NAME} \
 	1,2048,2048 \
 	2,4096,2048 \
 	3,4096,2048 \
@@ -85,7 +85,7 @@ $TS_CMD_WIPEFS --all --force ${TEST_IMAGE_NAME} &> /dev/null
 
 
 ts_init_subtest "mbr-logical"
-$TESTPROG --label mbr --device ${TEST_IMAGE_NAME} \
+ts_run --unbuffered $TESTPROG --label mbr --device ${TEST_IMAGE_NAME} \
 	1,2048,2048 \
 	2,4096,2048 \
 	3,6144,2048 \
@@ -101,7 +101,7 @@ ts_finalize_subtest
 $TS_CMD_WIPEFS --all --force ${TEST_IMAGE_NAME} &> /dev/null
 
 ts_init_subtest "mbr-nopartno"
-$TESTPROG --label mbr --device ${TEST_IMAGE_NAME} -- \
+ts_run --unbuffered $TESTPROG --label mbr --device ${TEST_IMAGE_NAME} -- \
 	-,2048,2048 \
 	-,4096,2048 \
 	-,6144,2048 \
@@ -118,7 +118,7 @@ $TS_CMD_WIPEFS --all --force ${TEST_IMAGE_NAME} &> /dev/null
 
 ### 6th partition (logical) out of extended
 ts_init_subtest "mbr-err-logical"
-$TESTPROG --label mbr --device ${TEST_IMAGE_NAME} \
+ts_run --unbuffered $TESTPROG --label mbr --device ${TEST_IMAGE_NAME} \
 	1,2048,2048 \
 	2,4096,2048 \
 	3,6144,2048 \
@@ -134,7 +134,7 @@ ts_finalize_subtest
 $TS_CMD_WIPEFS --all --force ${TEST_IMAGE_NAME} &> /dev/null
 
 ts_init_subtest "mbr-space-gap"
-$TESTPROG --label mbr --device ${TEST_IMAGE_NAME} \
+ts_run --unbuffered $TESTPROG --label mbr --device ${TEST_IMAGE_NAME} \
 	1,2048,2048 \
 	2,6144,2048 \
 	3,8192,2048 \
@@ -146,7 +146,7 @@ ts_finalize_subtest
 $TS_CMD_WIPEFS --all --force ${TEST_IMAGE_NAME} &> /dev/null
 
 ts_init_subtest "gpt"
-$TESTPROG --label gpt --device ${TEST_IMAGE_NAME} \
+ts_run --unbuffered $TESTPROG --label gpt --device ${TEST_IMAGE_NAME} \
 	1,2048,2048 \
 	2,4096,2048 \
 	3,6144,2048 \
@@ -162,7 +162,7 @@ ts_finalize_subtest
 $TS_CMD_WIPEFS --all --force ${TEST_IMAGE_NAME} &> /dev/null
 
 ts_init_subtest "gpt-nopartno"
-$TESTPROG --label gpt --device ${TEST_IMAGE_NAME} -- \
+ts_run --unbuffered $TESTPROG --label gpt --device ${TEST_IMAGE_NAME} -- \
 	-,2048,2048 \
 	-,4096,2048 \
 	-,6144,2048 \
@@ -179,7 +179,7 @@ $TS_CMD_WIPEFS --all --force ${TEST_IMAGE_NAME} &> /dev/null
 
 ### 4th partition overlap 4th and 5th
 ts_init_subtest "gpt-err-overlap"
-$TESTPROG --label gpt --device ${TEST_IMAGE_NAME} \
+ts_run --unbuffered $TESTPROG --label gpt --device ${TEST_IMAGE_NAME} \
 	1,2048,2048 \
 	2,4096,2048 \
 	3,6144,2048 \
@@ -195,7 +195,7 @@ ts_finalize_subtest
 $TS_CMD_WIPEFS --all --force ${TEST_IMAGE_NAME} &> /dev/null
 
 ts_init_subtest "gpt-partno-gap"
-$TESTPROG --label gpt --device ${TEST_IMAGE_NAME} \
+ts_run --unbuffered $TESTPROG --label gpt --device ${TEST_IMAGE_NAME} \
 	1,2048,2048 \
 	2,4096,2048 \
 	4,6144,2048 \
@@ -211,7 +211,7 @@ ts_finalize_subtest
 $TS_CMD_WIPEFS --all --force ${TEST_IMAGE_NAME} &> /dev/null
 
 ts_init_subtest "gpt-space-gap"
-$TESTPROG --label gpt --device ${TEST_IMAGE_NAME} \
+ts_run --unbuffered $TESTPROG --label gpt --device ${TEST_IMAGE_NAME} \
 	1,2048,2048 \
 	2,6144,2048 \
 	3,8192,2048 \
-- 
2.23.0


^ permalink raw reply	[flat|nested] 25+ messages in thread

* [PATCH v2 3/6] tests: colcrt: fix reliance on EILSEQ in POSIX locale
  2019-08-23 13:32 ` [PATCH v2 0/6] Test suite fixes for musl libc Patrick Steinhardt
  2019-08-23 13:32   ` [PATCH v2 1/6] tests: remove reliance on buffer behaviour of stderr/stdout streams Patrick Steinhardt
  2019-08-23 13:32   ` [PATCH v2 2/6] tests: libfdisk: remove reliance on buffer behaviour of standard streams Patrick Steinhardt
@ 2019-08-23 13:32   ` Patrick Steinhardt
  2019-08-23 13:32   ` [PATCH v2 4/6] tests: column: use actually invalid multibytes to test encoding Patrick Steinhardt
                     ` (2 subsequent siblings)
  5 siblings, 0 replies; 25+ messages in thread
From: Patrick Steinhardt @ 2019-08-23 13:32 UTC (permalink / raw)
  To: util-linux; +Cc: Patrick Steinhardt, Karel Zak

The input file "crash1" in the colcrt/regressions test contains the
illegal byte sequence "\x94\x7e". While "\x7e" is '~', "\x94" is not a
valid character. Thus, the test assumes that getwc(3P) will return
`WEOF` and set `errno=EILSEQ`, causing colcrt(1) to abort reading the
stream and thus not print the trailing '~'.

This assumption holds just fine for glibc as it will dutifully report
EILSEQ, but musl libc will happily read the complete stream without
complaining about the illegal character. But in fact, as tests run with
LC_ALL=POSIX by default, glibc's behaviour is wrong while musl is right.
Quoting mbrtowc(3P) from POSIX.1-2017:

    [EILSEQ] An invalid character sequence is detected. In the POSIX locale an
             [EILSEQ] error cannot occur since all byte values are valid
             characters.

Fix the issue by running the colcrt tests with C.UTF8 locale.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 tests/ts/colcrt/regressions | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tests/ts/colcrt/regressions b/tests/ts/colcrt/regressions
index 394c4e823..2adeea3f3 100755
--- a/tests/ts/colcrt/regressions
+++ b/tests/ts/colcrt/regressions
@@ -24,7 +24,7 @@ ts_check_prog "timeout"
 
 check_input_file() {
 	ts_init_subtest ${1##*/}
-	timeout 2 $TS_CMD_COLCRT < $1 > $TS_OUTPUT 2>&1
+	LC_ALL=C.UTF-8 timeout 2 $TS_CMD_COLCRT < $1 > $TS_OUTPUT 2>&1
 	echo "return value: $?" >> $TS_OUTPUT
 	ts_finalize_subtest
 }
-- 
2.23.0


^ permalink raw reply	[flat|nested] 25+ messages in thread

* [PATCH v2 4/6] tests: column: use actually invalid multibytes to test encoding
  2019-08-23 13:32 ` [PATCH v2 0/6] Test suite fixes for musl libc Patrick Steinhardt
                     ` (2 preceding siblings ...)
  2019-08-23 13:32   ` [PATCH v2 3/6] tests: colcrt: fix reliance on EILSEQ in POSIX locale Patrick Steinhardt
@ 2019-08-23 13:32   ` Patrick Steinhardt
  2019-08-23 13:32   ` [PATCH v2 5/6] tests: col: avoid hardcoding of errno string Patrick Steinhardt
  2019-08-23 13:32   ` [PATCH v2 6/6] tests: fdisk: " Patrick Steinhardt
  5 siblings, 0 replies; 25+ messages in thread
From: Patrick Steinhardt @ 2019-08-23 13:32 UTC (permalink / raw)
  To: util-linux; +Cc: Patrick Steinhardt, Karel Zak

[-- Warning: decoded text below may be mangled --]
[-- Attachment #0: Type: text/plain; charset=UTF-8, Size: 1461 bytes --]

If reading an invalid multibyte sequence, column(1) will encode the byte
as "\x<hex>" instead. The tests try to verify that by piping "£" into
column(1). As the tests run with LC_ALL=POSIX by default, though, libc
implementations strictly adhering to the POSIX standard will treat all
characters as valid multibyte characters. As a consequence, no EILSEQ is
raised by mbtowc(3P) and the character is not encoded as hex, breaking
the test.

Fix this by setting LC_ALL=C.UTF-8. As "£" is a valid UTF-8 character,
we also change the test to use a proper illegal multibyte sequence.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 tests/expected/column/invalid-multibyte | 2 +-
 tests/ts/column/invalid-multibyte       | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/tests/expected/column/invalid-multibyte b/tests/expected/column/invalid-multibyte
index ea40a34e9..5b0c74503 100644
--- a/tests/expected/column/invalid-multibyte
+++ b/tests/expected/column/invalid-multibyte
@@ -1 +1 @@
-\xa3
+\x94~
diff --git a/tests/ts/column/invalid-multibyte b/tests/ts/column/invalid-multibyte
index a9e371003..4fcf44eb3 100755
--- a/tests/ts/column/invalid-multibyte
+++ b/tests/ts/column/invalid-multibyte
@@ -25,6 +25,6 @@ ts_check_test_command "$TS_CMD_COLUMN"
 
 ts_cd "$TS_OUTDIR"
 
-printf "£\n" | LC_ALL=C $TS_CMD_COLUMN >> $TS_OUTPUT 2>&1
+printf "\x94\x7e\n" | LC_ALL=C.UTF-8 $TS_CMD_COLUMN >> $TS_OUTPUT 2>&1
 
 ts_finalize
-- 
2.23.0


^ permalink raw reply	[flat|nested] 25+ messages in thread

* [PATCH v2 5/6] tests: col: avoid hardcoding of errno string
  2019-08-23 13:32 ` [PATCH v2 0/6] Test suite fixes for musl libc Patrick Steinhardt
                     ` (3 preceding siblings ...)
  2019-08-23 13:32   ` [PATCH v2 4/6] tests: column: use actually invalid multibytes to test encoding Patrick Steinhardt
@ 2019-08-23 13:32   ` Patrick Steinhardt
  2019-08-23 13:32   ` [PATCH v2 6/6] tests: fdisk: " Patrick Steinhardt
  5 siblings, 0 replies; 25+ messages in thread
From: Patrick Steinhardt @ 2019-08-23 13:32 UTC (permalink / raw)
  To: util-linux; +Cc: Patrick Steinhardt, Karel Zak

The col/multibyte test has a hardcoded error string as part of its
expected output that is returned by glibc's strerror(3P) function. Even
though many of these strings are the same across libc implementations,
they are not standardiced and some are certainly different. One example
is the string for EILSEQ on musl libc.

To fix this, we introduce a new test helper "test_strerror". The helper
can be invoked with an error code like "EILSEQ", which will cause it to
print out the the respective error message for that code. Note that
"test_strerror" cannot act on the error's value (e.g. 84 for EILSEQ), as
these aren't standardized either. Instead, we thus need to have an array
of the error's string representation ("EILSEQ") to its respective error
code (the define EILSEQ). The array can trivially be extended as
required, thus it is only sparsely populated with EILSEQ right now.

To fix the col/multibyte test, we introduce a call to sed(1) to replace
the strerror(3P) message from EILSEQ with "EILSEQ". Furthermore, as
we're running tests with the POSIX locale by default which treats all
bytes as valid multibyte sequences, we have to change to the C.UTF-8
locale instead to actually get an error.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 tests/commands.sh             |  1 +
 tests/expected/col/multibyte  |  2 +-
 tests/helpers/Makemodule.am   |  3 +++
 tests/helpers/test_strerror.c | 42 +++++++++++++++++++++++++++++++++++
 tests/ts/col/multibyte        |  5 +++--
 5 files changed, 50 insertions(+), 3 deletions(-)
 create mode 100644 tests/helpers/test_strerror.c

diff --git a/tests/commands.sh b/tests/commands.sh
index 5cc34f6b3..9fcd488ce 100644
--- a/tests/commands.sh
+++ b/tests/commands.sh
@@ -33,6 +33,7 @@ TS_HELPER_PARTITIONS="${ts_helpersdir}sample-partitions"
 TS_HELPER_PATHS="${ts_helpersdir}test_pathnames"
 TS_HELPER_SCRIPT="${ts_helpersdir}test_script"
 TS_HELPER_SIGRECEIVE="${ts_helpersdir}test_sigreceive"
+TS_HELPER_STRERROR="${ts_helpersdir}test_strerror"
 TS_HELPER_STRUTILS="${ts_helpersdir}test_strutils"
 TS_HELPER_SYSINFO="${ts_helpersdir}test_sysinfo"
 TS_HELPER_TIOCSTI="${ts_helpersdir}test_tiocsti"
diff --git a/tests/expected/col/multibyte b/tests/expected/col/multibyte
index 4e299adc1..abf607249 100644
--- a/tests/expected/col/multibyte
+++ b/tests/expected/col/multibyte
@@ -1 +1 @@
-col: failed on line 1: Invalid or incomplete multibyte or wide character
+col: failed on line 1: EILSEQ
diff --git a/tests/helpers/Makemodule.am b/tests/helpers/Makemodule.am
index ab0b3cea9..a34cd8d2a 100644
--- a/tests/helpers/Makemodule.am
+++ b/tests/helpers/Makemodule.am
@@ -14,6 +14,9 @@ test_sha1_SOURCES = tests/helpers/test_sha1.c lib/sha1.c
 check_PROGRAMS += test_pathnames
 test_pathnames_SOURCES = tests/helpers/test_pathnames.c
 
+check_PROGRAMS += test_strerror
+test_strerror_SOURCES = tests/helpers/test_strerror.c
+
 check_PROGRAMS += test_sysinfo
 test_sysinfo_SOURCES = tests/helpers/test_sysinfo.c
 
diff --git a/tests/helpers/test_strerror.c b/tests/helpers/test_strerror.c
new file mode 100644
index 000000000..1919698eb
--- /dev/null
+++ b/tests/helpers/test_strerror.c
@@ -0,0 +1,42 @@
+/*
+ * This test program prints errno messages to allow for portable
+ * verification of error messages.
+ *
+ * Copyright (C) 2019 Patrick Steinhardt <ps@pks.im
+ *
+ * This file may be redistributed under the terms of the GNU Public
+ * License.
+ */
+
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#define E(x) { #x, x }
+static struct {
+	const char *str;
+	int error;
+} errors[] = {
+	E(EILSEQ)
+};
+
+int main(int argc, const char *argv[])
+{
+	size_t i;
+
+	if (argc != 2) {
+		fprintf(stderr, "USAGE: %s <errno>\n", argv[0]);
+		return -1;
+	}
+
+	for (i = 0; i < sizeof(errors)/sizeof(*errors); i++) {
+		if (strcmp(errors[i].str, argv[1]))
+			continue;
+		puts(strerror(errors[i].error));
+		return 0;
+	}
+
+	fprintf(stderr, "Invalid errno: %s\n", argv[1]);
+	return -1;
+}
diff --git a/tests/ts/col/multibyte b/tests/ts/col/multibyte
index e9c02922e..1ed4b5ff8 100755
--- a/tests/ts/col/multibyte
+++ b/tests/ts/col/multibyte
@@ -22,8 +22,9 @@ TS_DESC="multibyte input"
 ts_init "$*"
 
 ts_check_test_command "$TS_CMD_COL"
+ts_check_test_command "$TS_HELPER_STRERROR"
 
-cat $TS_SELF/multibyte.data | $TS_CMD_COL > /dev/null  2> $TS_OUTPUT
+cat $TS_SELF/multibyte.data | LC_ALL=C.UTF-8 $TS_CMD_COL 2>&1 > /dev/null |
+    sed -e "s@$($TS_HELPER_STRERROR EILSEQ)@EILSEQ@" > $TS_OUTPUT
 
 ts_finalize
-
-- 
2.23.0


^ permalink raw reply	[flat|nested] 25+ messages in thread

* [PATCH v2 6/6] tests: fdisk: avoid hardcoding of errno string
  2019-08-23 13:32 ` [PATCH v2 0/6] Test suite fixes for musl libc Patrick Steinhardt
                     ` (4 preceding siblings ...)
  2019-08-23 13:32   ` [PATCH v2 5/6] tests: col: avoid hardcoding of errno string Patrick Steinhardt
@ 2019-08-23 13:32   ` " Patrick Steinhardt
  5 siblings, 0 replies; 25+ messages in thread
From: Patrick Steinhardt @ 2019-08-23 13:32 UTC (permalink / raw)
  To: util-linux; +Cc: Patrick Steinhardt, Karel Zak

The test fdisk/oddinput hardcodes strings returned by strerror(3P) for
both the errors ENOENT and ENOTTY. As these strings are unportable,
convert the tests to use the test_strerror helper instead to convert
them with sed(1).

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 tests/expected/fdisk/oddinput | 4 ++--
 tests/helpers/test_strerror.c | 2 ++
 tests/ts/fdisk/oddinput       | 6 ++++--
 3 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/tests/expected/fdisk/oddinput b/tests/expected/fdisk/oddinput
index 2fccc6cd5..219e98b67 100644
--- a/tests/expected/fdisk/oddinput
+++ b/tests/expected/fdisk/oddinput
@@ -6,6 +6,6 @@ Units: cylinders of 16065 * 512 = 8225280 bytes
 Sector size (logical/physical): 512 bytes / 512 bytes
 I/O size (minimum/optimal): 512 bytes / 512 bytes
 Nonexistent file
-fdisk: cannot open _a_file_that_does_not_exist_: No such file or directory
+fdisk: cannot open _a_file_that_does_not_exist_: ENOENT
 Too small file
-fdisk: cannot open oddinput.toosmall: Inappropriate ioctl for device
+fdisk: cannot open oddinput.toosmall: ENOTTY
diff --git a/tests/helpers/test_strerror.c b/tests/helpers/test_strerror.c
index 1919698eb..a063b1165 100644
--- a/tests/helpers/test_strerror.c
+++ b/tests/helpers/test_strerror.c
@@ -18,6 +18,8 @@ static struct {
 	const char *str;
 	int error;
 } errors[] = {
+	E(ENOENT),
+	E(ENOTTY),
 	E(EILSEQ)
 };
 
diff --git a/tests/ts/fdisk/oddinput b/tests/ts/fdisk/oddinput
index 067924264..7b0c8bfd4 100755
--- a/tests/ts/fdisk/oddinput
+++ b/tests/ts/fdisk/oddinput
@@ -38,10 +38,12 @@ ts_log "Empty image listing" # this should report empty partition table
 $TS_CMD_FDISK -c=dos -u=cylinders -l ${TEST_IMAGE_NAME} 2>&1 | sed -e "s/${TEST_IMAGE_NAME//\//\\/}/testimage/" >> $TS_OUTPUT
 
 ts_log "Nonexistent file" # this originally does absolutely nothing
-$TS_CMD_FDISK -c=dos -u=cylinders -l _a_file_that_does_not_exist_ >> $TS_OUTPUT 2>&1
+$TS_CMD_FDISK -c=dos -u=cylinders -l _a_file_that_does_not_exist_ 2>&1 |
+    sed -e "s@$($TS_HELPER_STRERROR ENOENT)@ENOENT@" >> $TS_OUTPUT
 
 ts_log "Too small file" # same here
 echo  "This file is too small" >> oddinput.toosmall
-$TS_CMD_FDISK -c=dos -u=cylinders -l oddinput.toosmall >> $TS_OUTPUT 2>&1
+$TS_CMD_FDISK -c=dos -u=cylinders -l oddinput.toosmall 2>&1 |
+    sed -e "s@$($TS_HELPER_STRERROR ENOTTY)@ENOTTY@" >> $TS_OUTPUT
 rm oddinput.toosmall
 ts_finalize
-- 
2.23.0


^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH v2 1/6] tests: remove reliance on buffer behaviour of stderr/stdout streams
  2019-08-23 13:32   ` [PATCH v2 1/6] tests: remove reliance on buffer behaviour of stderr/stdout streams Patrick Steinhardt
@ 2019-08-27 11:17     ` Karel Zak
  2019-08-27 11:49       ` Patrick Steinhardt
                         ` (2 more replies)
  0 siblings, 3 replies; 25+ messages in thread
From: Karel Zak @ 2019-08-27 11:17 UTC (permalink / raw)
  To: Patrick Steinhardt; +Cc: util-linux

On Fri, Aug 23, 2019 at 03:32:53PM +0200, Patrick Steinhardt wrote:
> +	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[@]}" "$@"
>  }

Unfortunately, it seems "${args[@]}" does not work when environment
variable used:

  ASAN_OPTIONS=detect_leaks=1 stdbuf --output=0 /home/projects/util-linux/util-linux/mkswap --label 1234567890abcdef --uuid 12345678-abcd-abcd-abcd-1234567890ab /dev/sdc

ends with

  ./tests/ts/misc/../../functions.sh: line 465: ASAN_OPTIONS=detect_leaks=1: command not found


And it's more tricky, it seems ASAN binary cannot be executed by stdbuf

  # stdbuf --output=0 /home/projects/util-linux/util-linux/mkswap --label 1234567890abcdef --uuid 12345678-abcd-abcd-abcd-1234567890ab /dev/sdc
  ==28469==ASan runtime does not come first in initial library list; you should either link runtime to your application or manually preload it with LD_PRELOAD.

it's because stdbuf is hack based on LD_PRELOAD which makes it
difficult to use with ASAN...

I have tried to fix it by
https://github.com/karelzak/util-linux/commit/f612c4c674e8e07fc40644432d8147a05c62058e

... but it's really not perfect. I have used "unbuffer" (from expect)
rather than stdbuf. The question is how usable it will be... (but all
tests passed).

Note that you can try to use ASAN by ./configure --enable-asan, the
script tests/run.sh should be smart enough to detect it and then
individual tests are executed with --memcheck-asan.

So, merged -- please, test it with musl libc. 

    Karel


-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH v2 1/6] tests: remove reliance on buffer behaviour of stderr/stdout streams
  2019-08-27 11:17     ` Karel Zak
@ 2019-08-27 11:49       ` Patrick Steinhardt
  2019-08-27 12:32         ` Karel Zak
  2019-08-27 11:55       ` Patrick Steinhardt
  2019-08-27 12:26       ` [PATCH] tests: use env and support both unbuffer/stdbuf Patrick Steinhardt
  2 siblings, 1 reply; 25+ messages in thread
From: Patrick Steinhardt @ 2019-08-27 11:49 UTC (permalink / raw)
  To: Karel Zak; +Cc: util-linux

[-- Attachment #1: Type: text/plain, Size: 2863 bytes --]

On Tue, Aug 27, 2019 at 01:17:48PM +0200, Karel Zak wrote:
> On Fri, Aug 23, 2019 at 03:32:53PM +0200, Patrick Steinhardt wrote:
> > +	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[@]}" "$@"
> >  }
> 
> Unfortunately, it seems "${args[@]}" does not work when environment
> variable used:

Huh. If I remember correctly then I did actually test that this
works, but oh, well...

>   ASAN_OPTIONS=detect_leaks=1 stdbuf --output=0 /home/projects/util-linux/util-linux/mkswap --label 1234567890abcdef --uuid 12345678-abcd-abcd-abcd-1234567890ab /dev/sdc
> 
> ends with
> 
>   ./tests/ts/misc/../../functions.sh: line 465: ASAN_OPTIONS=detect_leaks=1: command not found
> 
> And it's more tricky, it seems ASAN binary cannot be executed by stdbuf
> 
>   # stdbuf --output=0 /home/projects/util-linux/util-linux/mkswap --label 1234567890abcdef --uuid 12345678-abcd-abcd-abcd-1234567890ab /dev/sdc
>   ==28469==ASan runtime does not come first in initial library list; you should either link runtime to your application or manually preload it with LD_PRELOAD.
> 
> it's because stdbuf is hack based on LD_PRELOAD which makes it
> difficult to use with ASAN...
> 
> I have tried to fix it by
> https://github.com/karelzak/util-linux/commit/f612c4c674e8e07fc40644432d8147a05c62058e
> 
> ... but it's really not perfect. I have used "unbuffer" (from expect)
> rather than stdbuf. The question is how usable it will be... (but all
> tests passed).
> 
> Note that you can try to use ASAN by ./configure --enable-asan, the
> script tests/run.sh should be smart enough to detect it and then
> individual tests are executed with --memcheck-asan.

Thanks a lot for fixing this up for ASAN then. I've tried to get
ASAN running on musl libc multiple times, but didn't yet have any
luck in doing so as it will always crash immediately. I'll
probably have to invest some more time here at some point to get
this working.

> So, merged -- please, test it with musl libc. 

In fact there's one more test failure in fdisk/oddinput. Seems
like patch 6/6 (fdisk: avoid hardcoding of errno string,
2019-08-23) wasn't applied yet?

Patrick

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH v2 1/6] tests: remove reliance on buffer behaviour of stderr/stdout streams
  2019-08-27 11:17     ` Karel Zak
  2019-08-27 11:49       ` Patrick Steinhardt
@ 2019-08-27 11:55       ` Patrick Steinhardt
  2019-08-27 12:31         ` Karel Zak
  2019-08-27 12:26       ` [PATCH] tests: use env and support both unbuffer/stdbuf Patrick Steinhardt
  2 siblings, 1 reply; 25+ messages in thread
From: Patrick Steinhardt @ 2019-08-27 11:55 UTC (permalink / raw)
  To: Karel Zak; +Cc: util-linux

[-- Attachment #1: Type: text/plain, Size: 2110 bytes --]

On Tue, Aug 27, 2019 at 01:17:48PM +0200, Karel Zak wrote:
> On Fri, Aug 23, 2019 at 03:32:53PM +0200, Patrick Steinhardt wrote:
> > +	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[@]}" "$@"
> >  }
> 
> Unfortunately, it seems "${args[@]}" does not work when environment
> variable used:
> 
>   ASAN_OPTIONS=detect_leaks=1 stdbuf --output=0 /home/projects/util-linux/util-linux/mkswap --label 1234567890abcdef --uuid 12345678-abcd-abcd-abcd-1234567890ab /dev/sdc
> 
> ends with
> 
>   ./tests/ts/misc/../../functions.sh: line 465: ASAN_OPTIONS=detect_leaks=1: command not found
> 
> 
> And it's more tricky, it seems ASAN binary cannot be executed by stdbuf
> 
>   # stdbuf --output=0 /home/projects/util-linux/util-linux/mkswap --label 1234567890abcdef --uuid 12345678-abcd-abcd-abcd-1234567890ab /dev/sdc
>   ==28469==ASan runtime does not come first in initial library list; you should either link runtime to your application or manually preload it with LD_PRELOAD.
> 
> it's because stdbuf is hack based on LD_PRELOAD which makes it
> difficult to use with ASAN...
> 
> I have tried to fix it by
> https://github.com/karelzak/util-linux/commit/f612c4c674e8e07fc40644432d8147a05c62058e

Noticed one more thing. In the parameter parsing step, we check
`type stdbuf` while we actually use unbuffer later. I guess the
first check should now be `type unbuffer`, right?

Patrick

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [PATCH] tests: use env and support both unbuffer/stdbuf
  2019-08-27 11:17     ` Karel Zak
  2019-08-27 11:49       ` Patrick Steinhardt
  2019-08-27 11:55       ` Patrick Steinhardt
@ 2019-08-27 12:26       ` Patrick Steinhardt
  2019-08-27 12:46         ` Karel Zak
  2019-08-28 10:51         ` Karel Zak
  2 siblings, 2 replies; 25+ messages in thread
From: Patrick Steinhardt @ 2019-08-27 12:26 UTC (permalink / raw)
  To: util-linux; +Cc: Patrick Steinhardt, Karel Zak

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.

---

I wouldn't have minded, but as you state that your own patch
sucks I thought my initial approach might be preferable and thus
deemed it worthwhile to try and fix my original shortcomings.

 tests/functions.sh | 41 ++++++++++++++++++++---------------------
 1 file changed, 20 insertions(+), 21 deletions(-)


diff --git a/tests/functions.sh b/tests/functions.sh
index 67fab1d83..e71b0dfeb 100644
--- a/tests/functions.sh
+++ b/tests/functions.sh
@@ -425,9 +425,7 @@ function ts_run {
 	while true; do
 		case "$1" in
 			--unbuffered)
-				if type stdbuf >/dev/null 2>&1; then
-					UNBUFFERED=1
-				fi
+				UNBUFFERED=1
 				shift;;
 			--)
 				shift
@@ -437,34 +435,35 @@ function ts_run {
 		esac
 	done
 
+	declare -a args
+
 	#
 	# 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
+
+	"${args[@]}" "$@"
 }
 
 function ts_gen_diff {
-- 
2.23.0


^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH v2 1/6] tests: remove reliance on buffer behaviour of stderr/stdout streams
  2019-08-27 11:55       ` Patrick Steinhardt
@ 2019-08-27 12:31         ` Karel Zak
  0 siblings, 0 replies; 25+ messages in thread
From: Karel Zak @ 2019-08-27 12:31 UTC (permalink / raw)
  To: Patrick Steinhardt; +Cc: util-linux

On Tue, Aug 27, 2019 at 01:55:12PM +0200, Patrick Steinhardt wrote:
> Noticed one more thing. In the parameter parsing step, we check
> `type stdbuf` while we actually use unbuffer later. I guess the
> first check should now be `type unbuffer`, right?

Fixed. Thanks.

    Karel


-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH v2 1/6] tests: remove reliance on buffer behaviour of stderr/stdout streams
  2019-08-27 11:49       ` Patrick Steinhardt
@ 2019-08-27 12:32         ` Karel Zak
  0 siblings, 0 replies; 25+ messages in thread
From: Karel Zak @ 2019-08-27 12:32 UTC (permalink / raw)
  To: Patrick Steinhardt; +Cc: util-linux

On Tue, Aug 27, 2019 at 01:49:24PM +0200, Patrick Steinhardt wrote:
> > So, merged -- please, test it with musl libc. 
> 
> In fact there's one more test failure in fdisk/oddinput. Seems
> like patch 6/6 (fdisk: avoid hardcoding of errno string,
> 2019-08-23) wasn't applied yet?

Ah, sorry... Applied now. Thanks.

    Karel

-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH] tests: use env and support both unbuffer/stdbuf
  2019-08-27 12:26       ` [PATCH] tests: use env and support both unbuffer/stdbuf Patrick Steinhardt
@ 2019-08-27 12:46         ` Karel Zak
  2019-08-28 10:51         ` Karel Zak
  1 sibling, 0 replies; 25+ messages in thread
From: Karel Zak @ 2019-08-27 12:46 UTC (permalink / raw)
  To: Patrick Steinhardt; +Cc: util-linux

On Tue, Aug 27, 2019 at 02:26:08PM +0200, Patrick Steinhardt wrote:
> 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[@]}" "$@".

BTW, it's strange that ${args[@]} is interpreted in another way than
when we write "FOO=bar command" directly to the script. Sounds like
bash disadvantage.

> 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.
> 
> ---
> 
> I wouldn't have minded, but as you state that your own patch
> sucks I thought my initial approach might be preferable and thus
> deemed it worthwhile to try and fix my original shortcomings.

OK, I'll try to play with it tomorrow :-)  Thanks.

    Karel

-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH] tests: use env and support both unbuffer/stdbuf
  2019-08-27 12:26       ` [PATCH] tests: use env and support both unbuffer/stdbuf Patrick Steinhardt
  2019-08-27 12:46         ` Karel Zak
@ 2019-08-28 10:51         ` Karel Zak
  2019-08-30 19:08           ` Karel Zak
  2019-08-31  7:41           ` Patrick Steinhardt
  1 sibling, 2 replies; 25+ messages in thread
From: Karel Zak @ 2019-08-28 10:51 UTC (permalink / raw)
  To: Patrick Steinhardt; +Cc: util-linux

On Tue, Aug 27, 2019 at 02:26:08PM +0200, Patrick Steinhardt wrote:
> 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.

Applied, thanks.

Unfortunately, it seems result is fragile. It fails on travis
https://travis-ci.org/karelzak/util-linux/jobs/577767328

The problem is the order of some output lines, for example:
tests/output/rename/exit_codes

Maybe the best and most robust solution would be split stdout and
stderr into two files for each test. Now we have $TS_OUTPUT, what about
to replace it with $TS_STDOUT and $TS_STDERR? Something like:

 - $TS_CMD_MOUNT $DEVICE $TS_MOUNTPOINT >> $TS_OUTPUT 2>&1
 + $TS_CMD_MOUNT $DEVICE $TS_MOUNTPOINT >> $TS_STDOUT 2>> $TS_STDERR

And also create tests/expected/<foo>/<bar>{.err} for tests where any
output on stderr is expected, otherwise assume $TS_STDERR is empty.

This change will be pretty invasive, but than we can easily compare 
outputs and keep track about what is where printed. 

    Karel


-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH] tests: use env and support both unbuffer/stdbuf
  2019-08-28 10:51         ` Karel Zak
@ 2019-08-30 19:08           ` Karel Zak
  2019-08-31  7:41           ` Patrick Steinhardt
  1 sibling, 0 replies; 25+ messages in thread
From: Karel Zak @ 2019-08-30 19:08 UTC (permalink / raw)
  To: Patrick Steinhardt; +Cc: util-linux

On Wed, Aug 28, 2019 at 12:51:11PM +0200, Karel Zak wrote:
> Maybe the best and most robust solution would be split stdout and
> stderr into two files for each test. Now we have $TS_OUTPUT, what about
> to replace it with $TS_STDOUT and $TS_STDERR? Something like:
> 
>  - $TS_CMD_MOUNT $DEVICE $TS_MOUNTPOINT >> $TS_OUTPUT 2>&1
>  + $TS_CMD_MOUNT $DEVICE $TS_MOUNTPOINT >> $TS_STDOUT 2>> $TS_STDERR
> 
> And also create tests/expected/<foo>/<bar>{.err} for tests where any
> output on stderr is expected, otherwise assume $TS_STDERR is empty.
> 
> This change will be pretty invasive, but than we can easily compare 
> outputs and keep track about what is where printed. 

Implemented. So, the voodoo with (un)buffered output is no more
necessary.

The last remaining problem is colctl, see:

    https://travis-ci.org/karelzak/util-linux/jobs/578940843

diff-{{{
--- /home/travis/build/karelzak/util-linux/tests/expected/colcrt/regressions-hang1	2019-08-30 18:48:16.236479052 +0000
+++ /home/travis/build/karelzak/util-linux/tests/output/colcrt/regressions-hang1	2019-08-30 18:51:50.046236386 +0000
@@ -1,3 +1 @@
-789:;<=>=>?IABUVNXYZ[ `abcdefgg !"#$%&'()*+,-./01234)*:,-./0123456789:;[=>?1234)*:,-./0123456789:;[=>?4456789:;<=>?IABUVN`abcdefg !"
-                     -
-return value: 0
+return value: 124
}}}-diff

 ... for some reason it returns nothing, but $? is 124. The problem is
 elapsed timeout, but why?

        timeout 2 env LC_ALL=C.UTF-8 $TS_CMD_COLCRT < $1 >> $TS_OUTPUT 2>> $TS_ERRLOG
        echo "return value: $?" >> $TS_OUTPUT

 Karel

-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH] tests: use env and support both unbuffer/stdbuf
  2019-08-28 10:51         ` Karel Zak
  2019-08-30 19:08           ` Karel Zak
@ 2019-08-31  7:41           ` Patrick Steinhardt
  1 sibling, 0 replies; 25+ messages in thread
From: Patrick Steinhardt @ 2019-08-31  7:41 UTC (permalink / raw)
  To: Karel Zak; +Cc: util-linux

[-- Attachment #1: Type: text/plain, Size: 2314 bytes --]

On Wed, Aug 28, 2019 at 12:51:07PM +0200, Karel Zak wrote:
> On Tue, Aug 27, 2019 at 02:26:08PM +0200, Patrick Steinhardt wrote:
> > 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.
> 
> Applied, thanks.
> 
> Unfortunately, it seems result is fragile. It fails on travis
> https://travis-ci.org/karelzak/util-linux/jobs/577767328
> 
> The problem is the order of some output lines, for example:
> tests/output/rename/exit_codes
> 
> Maybe the best and most robust solution would be split stdout and
> stderr into two files for each test. Now we have $TS_OUTPUT, what about
> to replace it with $TS_STDOUT and $TS_STDERR? Something like:
> 
>  - $TS_CMD_MOUNT $DEVICE $TS_MOUNTPOINT >> $TS_OUTPUT 2>&1
>  + $TS_CMD_MOUNT $DEVICE $TS_MOUNTPOINT >> $TS_STDOUT 2>> $TS_STDERR
> 
> And also create tests/expected/<foo>/<bar>{.err} for tests where any
> output on stderr is expected, otherwise assume $TS_STDERR is empty.
> 
> This change will be pretty invasive, but than we can easily compare 
> outputs and keep track about what is where printed. 
> 
>     Karel

Sorry, I somehow didn't see this mail. I thought about splitting
it up too, but shied away as I expected it to be rather involved.
Anyway, I think in the long run it's definitely the best way to
tackle the issue at hand, so thanks for your effort!

I've just done a test run on musl libc, and everything except for
the known issue with POSIXLY_CORRECT getopt passes.

Patrick

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 25+ messages in thread

end of thread, back to index

Thread overview: 25+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-23 10:16 [PATCH 0/6] Test suite fixes for musl libc Patrick Steinhardt
2019-08-23 10:16 ` [PATCH 1/6] tests: remove reliance on buffer behaviour of stderr/stdout streams Patrick Steinhardt
2019-08-23 10:16 ` [PATCH 2/6] tests: colcrt: fix reliance on EILSEQ in POSIX locale Patrick Steinhardt
2019-08-23 10:17 ` [PATCH 3/6] tests: column: use actually invalid multibytes to test encoding Patrick Steinhardt
2019-08-23 10:17 ` [PATCH 4/6] tests: col: avoid hardcoding of errno string Patrick Steinhardt
2019-08-23 10:17 ` [PATCH 5/6] tests: fdisk: " Patrick Steinhardt
2019-08-23 10:17 ` [PATCH 6/6] tests: libfdisk: remove reliance on buffer behaviour of standard streams Patrick Steinhardt
2019-08-23 12:15   ` Karel Zak
2019-08-23 13:32 ` [PATCH v2 0/6] Test suite fixes for musl libc Patrick Steinhardt
2019-08-23 13:32   ` [PATCH v2 1/6] tests: remove reliance on buffer behaviour of stderr/stdout streams Patrick Steinhardt
2019-08-27 11:17     ` Karel Zak
2019-08-27 11:49       ` Patrick Steinhardt
2019-08-27 12:32         ` Karel Zak
2019-08-27 11:55       ` Patrick Steinhardt
2019-08-27 12:31         ` Karel Zak
2019-08-27 12:26       ` [PATCH] tests: use env and support both unbuffer/stdbuf Patrick Steinhardt
2019-08-27 12:46         ` Karel Zak
2019-08-28 10:51         ` Karel Zak
2019-08-30 19:08           ` Karel Zak
2019-08-31  7:41           ` Patrick Steinhardt
2019-08-23 13:32   ` [PATCH v2 2/6] tests: libfdisk: remove reliance on buffer behaviour of standard streams Patrick Steinhardt
2019-08-23 13:32   ` [PATCH v2 3/6] tests: colcrt: fix reliance on EILSEQ in POSIX locale Patrick Steinhardt
2019-08-23 13:32   ` [PATCH v2 4/6] tests: column: use actually invalid multibytes to test encoding Patrick Steinhardt
2019-08-23 13:32   ` [PATCH v2 5/6] tests: col: avoid hardcoding of errno string Patrick Steinhardt
2019-08-23 13:32   ` [PATCH v2 6/6] tests: fdisk: " Patrick Steinhardt

Util-Linux Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/util-linux/0 util-linux/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 util-linux util-linux/ https://lore.kernel.org/util-linux \
		util-linux@vger.kernel.org util-linux@archiver.kernel.org
	public-inbox-index util-linux


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.util-linux


AGPL code for this site: git clone https://public-inbox.org/ public-inbox