Test suite fixes for musl libc
cover Test suite fixes for musl libc
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
Signature · 1 line
2.23.0
PATCH 1/6 tests: remove reliance on buffer behaviour of stderr/stdout streams
In the test cases "rename::exit_codes" and "rename::exit_codes", we rely on the flushing behaviour of stderr and stdout streams relative to each other. Streams in glibc will not flush on newlines if stdout is pointing to a non-TTY file descriptor, but relying on this is fragile and may break on systems with a different behaviour like musl libc.
Fix this by introducing a new 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.
--- 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(-)
tests/expected/misc/swaplabel +1 -1
@@ -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
tests/expected/rename/exit_codes +1 -1
@@ -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
tests/functions.sh +7 -0
@@ -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 +}
tests/ts/misc/swaplabel +2 -2
@@ -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 |\
tests/ts/rename/exit_codes +1 -1
@@ -32,7 +32,7 @@ $TS_CMD_RENAME -v codes values rename_exit_codes.? >> $TS_OUTPUT 2>&1 echo "EXIT_SUCCESS: $?" >> $TS_OUTPUT mkdir rename_exit_codes.2 -$TS_CMD_RENAME -v values codes rename_exit_values.? >> $TS_OUTPUT 2>&1 +ts_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
Signature · 1 line
2.23.0
PATCH 2/6 tests: colcrt: fix reliance on EILSEQ in POSIX locale
In reply to Patrick SteinhardtThe 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.
--- tests/ts/colcrt/regressions | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tests/ts/colcrt/regressions +1 -1
@@ -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 }
Signature · 1 line
2.23.0
PATCH 3/6 tests: column: use actually invalid multibytes to test encoding
In reply to Patrick SteinhardtIf 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.
--- tests/expected/column/invalid-multibyte | 2 +- tests/ts/column/invalid-multibyte | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
tests/expected/column/invalid-multibyte +1 -1
@@ -1 +1 @@ -\xa3 +\x94~
tests/ts/column/invalid-multibyte +1 -1
@@ -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
Signature · 1 line
2.23.0
PATCH 4/6 tests: col: avoid hardcoding of errno string
In reply to Patrick SteinhardtThe 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.
--- 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
tests/commands.sh +1 -0
@@ -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"
tests/expected/col/multibyte +1 -1
@@ -1 +1 @@ -col: failed on line 1: Invalid or incomplete multibyte or wide character +col: failed on line 1: EILSEQ
tests/helpers/Makemodule.am +3 -0
@@ -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
tests/helpers/test_strerror.c new file +42 -0
42 lines not on this page · raw message
tests/ts/col/multibyte +3 -2
@@ -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 -
Signature · 1 line
2.23.0
PATCH 5/6 tests: fdisk: avoid hardcoding of errno string
In reply to Patrick SteinhardtThe 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).
--- tests/expected/fdisk/oddinput | 4 ++-- tests/helpers/test_strerror.c | 2 ++ tests/ts/fdisk/oddinput | 6 ++++-- 3 files changed, 8 insertions(+), 4 deletions(-)
tests/expected/fdisk/oddinput +2 -2
@@ -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
tests/helpers/test_strerror.c +2 -0
@@ -18,6 +18,8 @@ static struct {const char *str;int error; } errors[] = { +E (ENOENT ), +E (ENOTTY ),E (EILSEQ ) };
tests/ts/fdisk/oddinput +4 -2
@@ -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
Signature · 1 line
2.23.0
PATCH 6/6 tests: libfdisk: remove reliance on buffer behaviour of standard streams
In reply to Patrick SteinhardtThe 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.
--- 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(-)
tests/expected/libfdisk/mkpart-full-gpt +7 -7
@@ -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
tests/expected/libfdisk/mkpart-full-gpt-err-overlap +4 -4
@@ -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
tests/expected/libfdisk/mkpart-full-gpt-nopartno +7 -7
@@ -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
tests/expected/libfdisk/mkpart-full-gpt-partno-gap +7 -7
@@ -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
tests/expected/libfdisk/mkpart-full-gpt-space-gap +5 -5
@@ -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
tests/expected/libfdisk/mkpart-full-mbr-err-logical +7 -7
@@ -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
tests/expected/libfdisk/mkpart-full-mbr-err-nospace +3 -3
@@ -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
tests/expected/libfdisk/mkpart-full-mbr-err-primary +3 -3
@@ -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
tests/expected/libfdisk/mkpart-full-mbr-logical +7 -7
@@ -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
tests/expected/libfdisk/mkpart-full-mbr-nopartno +7 -7
@@ -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
tests/expected/libfdisk/mkpart-full-mbr-primary +4 -4
@@ -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
tests/expected/libfdisk/mkpart-full-mbr-primary-nopartno +4 -4
@@ -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
tests/expected/libfdisk/mkpart-full-mbr-space-gap +3 -3
@@ -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
tests/ts/libfdisk/mkpart-full +13 -13
@@ -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 \
Signature · 1 line
2.23.0
Karel Zak
maintainerRe: [PATCH 6/6] tests: libfdisk: remove reliance on buffer behaviour of standard streams
Quoted 8 lines · 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_unbufferedfunction 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
Signature · 2 lines
Karel Zak <[email protected]> http://karelzak.blogspot.com
v2 cover Test suite fixes for musl libc
In reply to Patrick SteinhardtHi,
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
Signature · 1 line
2.23.0
PATCH v2 1/6 tests: remove reliance on buffer behaviour of stderr/stdout streams
In the test cases "rename::exit_codes" and "rename::exit_codes", we rely on the flushing behaviour of stderr and stdout streams relative to each other. Streams in glibc will not flush on newlines if stdout is pointing to a non-TTY file descriptor, but relying on this is fragile and may break on systems with a different behaviour like musl libc.
Fix this by introducing a new parameter "--unbuffered" to ts_run. If this parameter is passed and stdbuf(1) from coreutils is available, then it will use it to disable buffering of standard output completely. Like this, we can selectively run tests with this if ordering of messages from stdout and stderr is being checked.
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(-)
tests/expected/misc/swaplabel +1 -1
@@ -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
tests/expected/rename/exit_codes +1 -1
@@ -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
tests/functions.sh +34 -13
64 lines not on this page · raw message
tests/ts/misc/swaplabel +2 -2
@@ -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 |\
tests/ts/rename/exit_codes +1 -1
@@ -32,7 +32,7 @@ $TS_CMD_RENAME -v codes values rename_exit_codes.? >> $TS_OUTPUT 2>&1 echo "EXIT_SUCCESS: $?" >> $TS_OUTPUT mkdir rename_exit_codes.2 -$TS_CMD_RENAME -v values codes rename_exit_values.? >> $TS_OUTPUT 2>&1 +ts_run --unbuffered $TS_CMD_RENAME -v values codes rename_exit_values.? >> $TS_OUTPUT 2>&1 echo "RENAME_EXIT_SOMEOK: $?" >> $TS_OUTPUT rmdir rename_exit_codes.2
Signature · 1 line
2.23.0
Karel Zak
maintainerRe: [PATCH v2 1/6] tests: remove reliance on buffer behaviour of stderr/stdout streams
Quoted 19 lines · Patrick Steinhardt
tests/functions.sh +11
-4+ 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
tests/functions.sh function ts_init_py { · line 465
Quoted 10 lines
tests/functions.sh +5
-2# - 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
Signature · 2 lines
Karel Zak <[email protected]> http://karelzak.blogspot.com
Re: [PATCH v2 1/6] tests: remove reliance on buffer behaviour of stderr/stdout streams
Quoted 17 lines · Karel Zak
Quoted 16 lines · Patrick Steinhardt
tests/functions.sh +10
-3+ 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
Quoted 16 lines
tests/functions.sh function ts_init_py { · line 465
Quoted 13 lines
tests/functions.sh +6
-3# - # 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...
Quoted 17 lines
ASAN_OPTIONS=detect_leaks=1 stdbuf --output=0 /home/projects/util-linux/util-linux/mkswap --label 1234567890abcdef --uuid 12345678-abcd-abcd-abcd-1234567890ab /dev/sdcends with
./tests/ts/misc/../../functions.sh: line 465: ASAN_OPTIONS=detect_leaks=1: command not foundAnd 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_PRELOADwhich makes it difficult to use with ASAN...I have tried to fix it by
https://github.com/karelzak/util-linux/commit/f612c4c674e8e07fc40644432d8147a05c62058e
Quoted 7 lines
... 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.shshould 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.
Quoted 1 line
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
Karel Zak
maintainerRe: [PATCH v2 1/6] tests: remove reliance on buffer behaviour of stderr/stdout streams
Quoted 5 lines · Patrick Steinhardt
Quoted 1 line
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
Signature · 2 lines
Karel Zak <[email protected]> http://karelzak.blogspot.com
Re: [PATCH v2 1/6] tests: remove reliance on buffer behaviour of stderr/stdout streams
In reply to Karel ZakQuoted 43 lines · Karel Zak
Quoted 19 lines · Patrick Steinhardt
tests/functions.sh +11
-4+ 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 modetests/functions.sh function ts_init_py { · line 465
Quoted 10 lines
tests/functions.sh +5
-2# - 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/sdcends with
./tests/ts/misc/../../functions.sh: line 465: ASAN_OPTIONS=detect_leaks=1: command not foundAnd it's more tricky, it seems ASAN binary cannot be executed by stdbuf
Quoted 8 lines
# 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_PRELOADwhich 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
Karel Zak
maintainerRe: [PATCH v2 1/6] tests: remove reliance on buffer behaviour of stderr/stdout streams
Quoted 3 lines · Patrick Steinhardt
Noticed one more thing. In the parameter parsing step, we check
type stdbufwhile we actually use unbuffer later. I guess the first check should now betype unbuffer, right?
Fixed. Thanks.
Karel
Signature · 2 lines
Karel Zak <[email protected]> http://karelzak.blogspot.com
PATCH 1/1 tests: use env and support both unbuffer/stdbuf
In reply to Karel ZakTriggered 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(-)
tests/functions.sh +20 -21
@@ -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 {
Signature · 1 line
2.23.0
Karel Zak
maintainerRe: [PATCH] tests: use env and support both unbuffer/stdbuf
Quoted 11 lines · Patrick Steinhardt
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_OPTIONSinstead 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.
Quoted 7 lines
Second, it now supports both unbuffer(1) and stdbuf(1). The latter uses
LD_PRELOADtricks, 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.
Quoted 5 lines
---
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
Signature · 2 lines
Karel Zak <[email protected]> http://karelzak.blogspot.com
Re: [PATCH] tests: use env and support both unbuffer/stdbuf
In reply to Patrick SteinhardtQuoted 12 lines · Patrick Steinhardt
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_OPTIONSinstead of directly adding it to the args array to fix execution of "${args[@]}" "$@".
Quoted 6 lines
Second, it now supports both unbuffer(1) and stdbuf(1). The latter uses
LD_PRELOADtricks, 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
Signature · 2 lines
Karel Zak <[email protected]> http://karelzak.blogspot.com
Karel Zak
maintainerRe: [PATCH] tests: use env and support both unbuffer/stdbuf
Quoted 4 lines · Karel Zak
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:
Quoted 8 lines
- $TS_CMD_MOUNT $DEVICE $TS_MOUNTPOINT >> $TS_OUTPUT 2>&1
+ $TS_CMD_MOUNT $DEVICE $TS_MOUNTPOINT >> $TS_STDOUT 2>> $TS_STDERRAnd 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/output/colcrt/regressions-hang1 renamed from home/travis/build/karelzak/util-linux/tests/expected/colcrt/regressions-hang1 +1 -3
@@ -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
Signature · 2 lines
Karel Zak <[email protected]> http://karelzak.blogspot.com
Re: [PATCH] tests: use env and support both unbuffer/stdbuf
In reply to Karel ZakQuoted 35 lines · Karel Zak
Quoted 12 lines · Patrick Steinhardt
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_OPTIONSinstead of directly adding it to the args array to fix execution of "${args[@]}" "$@".Quoted 6 lines
Second, it now supports both unbuffer(1) and stdbuf(1). The latter uses
LD_PRELOADtricks, 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/577767328The problem is the order of some output lines, for example:
tests/output/rename/exit_codesMaybe 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
Quoted 7 lines
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
PATCH v2 2/6 tests: libfdisk: remove reliance on buffer behaviour of standard streams
In reply to Patrick SteinhardtThe 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.
--- 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(-)
tests/expected/libfdisk/mkpart-full-gpt +7 -7
@@ -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
tests/expected/libfdisk/mkpart-full-gpt-err-overlap +4 -4
@@ -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
tests/expected/libfdisk/mkpart-full-gpt-nopartno +7 -7
@@ -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
tests/expected/libfdisk/mkpart-full-gpt-partno-gap +7 -7
@@ -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
tests/expected/libfdisk/mkpart-full-gpt-space-gap +5 -5
@@ -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
tests/expected/libfdisk/mkpart-full-mbr-err-logical +7 -7
@@ -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
tests/expected/libfdisk/mkpart-full-mbr-err-nospace +3 -3
@@ -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
tests/expected/libfdisk/mkpart-full-mbr-err-primary +3 -3
@@ -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
tests/expected/libfdisk/mkpart-full-mbr-logical +7 -7
@@ -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
tests/expected/libfdisk/mkpart-full-mbr-nopartno +7 -7
@@ -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
tests/expected/libfdisk/mkpart-full-mbr-primary +4 -4
@@ -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
tests/expected/libfdisk/mkpart-full-mbr-primary-nopartno +4 -4
@@ -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
tests/expected/libfdisk/mkpart-full-mbr-space-gap +3 -3
@@ -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
tests/ts/libfdisk/mkpart-full +13 -13
@@ -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 \
Signature · 1 line
2.23.0
PATCH v2 3/6 tests: colcrt: fix reliance on EILSEQ in POSIX locale
In reply to Patrick SteinhardtThe 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.
--- tests/ts/colcrt/regressions | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tests/ts/colcrt/regressions +1 -1
@@ -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 }
Signature · 1 line
2.23.0
PATCH v2 4/6 tests: column: use actually invalid multibytes to test encoding
In reply to Patrick SteinhardtIf 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.
--- tests/expected/column/invalid-multibyte | 2 +- tests/ts/column/invalid-multibyte | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
tests/expected/column/invalid-multibyte +1 -1
@@ -1 +1 @@ -\xa3 +\x94~
tests/ts/column/invalid-multibyte +1 -1
@@ -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
Signature · 1 line
2.23.0
PATCH v2 5/6 tests: col: avoid hardcoding of errno string
In reply to Patrick SteinhardtThe 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.
--- 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
tests/commands.sh +1 -0
@@ -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"
tests/expected/col/multibyte +1 -1
@@ -1 +1 @@ -col: failed on line 1: Invalid or incomplete multibyte or wide character +col: failed on line 1: EILSEQ
tests/helpers/Makemodule.am +3 -0
@@ -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
tests/helpers/test_strerror.c new file +42 -0
42 lines not on this page · raw message
tests/ts/col/multibyte +3 -2
@@ -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 -
Signature · 1 line
2.23.0
PATCH v2 6/6 tests: fdisk: avoid hardcoding of errno string
In reply to Patrick SteinhardtThe 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).
--- tests/expected/fdisk/oddinput | 4 ++-- tests/helpers/test_strerror.c | 2 ++ tests/ts/fdisk/oddinput | 6 ++++-- 3 files changed, 8 insertions(+), 4 deletions(-)
tests/expected/fdisk/oddinput +2 -2
@@ -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
tests/helpers/test_strerror.c +2 -0
@@ -18,6 +18,8 @@ static struct {const char *str;int error; } errors[] = { +E (ENOENT ), +E (ENOTTY ),E (EILSEQ ) };
tests/ts/fdisk/oddinput +4 -2
@@ -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
Signature · 1 line
2.23.0