From ad5c14dcadd4603363e68da960ed0101b61439bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A1draig=20Brady?= Date: Sat, 12 Aug 2017 23:53:33 -0700 Subject: [PATCH] tests: fix false failure with large printf formats * tests/misc/printf-surprise.sh: With musl libc the large printf format does succeed, outputting data. To avoid SIGPIPE being generated we ignore that signal and then handle the subsequent EPIPE error. Reported by A. Wilcox --- tests/misc/printf-surprise.sh | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/misc/printf-surprise.sh b/tests/misc/printf-surprise.sh index 2edd34c..46c0d8f 100755 --- a/tests/misc/printf-surprise.sh +++ b/tests/misc/printf-surprise.sh @@ -50,6 +50,9 @@ vm=$(get_min_ulimit_v_ env $prog %20f 0) \ mkfifo_or_skip_ fifo +(trap '' PIPE && yes | :) 2>&1 | grep -qF 'Broken pipe' || + skip_ 'trapping SIGPIPE is not supported' + # Disable MALLOC_PERTURB_, to avoid triggering this bug # https://bugs.debian.org/481543#77 export MALLOC_PERTURB_=0 @@ -60,11 +63,11 @@ cleanup_() { kill $pid 2>/dev/null && wait $pid; } head -c 10 fifo > out & pid=$! # Trigger large mem allocation failure -( ulimit -v $vm && env $prog %20000000f 0 2>err-msg > fifo ) +( trap '' PIPE && ulimit -v $vm && env $prog %20000000f 0 2>err-msg > fifo ) exit=$? # Map this longer, and rarer, diagnostic to the common one. -# printf: cannot perform formatted output: Cannot allocate memory" \ +# printf: cannot perform formatted output: Cannot allocate memory" sed 's/cannot perform .*/write error/' err-msg > k && mv k err-msg err_msg=$(tr '\n' : < err-msg) @@ -81,6 +84,7 @@ n_out=$(wc -c < out) case $n_out:$diagnostic:$exit in 10:n:0) ;; # ok, succeeds w/no diagnostic: FreeBSD 6.1 + 10:y:1) ;; # ok, fails with EPIPE diagnostic: musl libc 0:y:1) ;; # ok, glibc-2.8 and newer, when printf(3) fails with ENOMEM # With MALLOC_PERTURB_=0, this no longer happens. -- 2.9.3