Util-Linux Archive on lore.kernel.org
 help / color / Atom feed
From: Patrick Steinhardt <ps@pks.im>
To: util-linux@vger.kernel.org
Cc: Patrick Steinhardt <ps@pks.im>, Karel Zak <kzak@redhat.com>
Subject: [PATCH] tests: use env and support both unbuffer/stdbuf
Date: Tue, 27 Aug 2019 14:26:08 +0200
Message-ID: <219cbcaeb173a07e97dbac8e1b653904369d91e0.1566907983.git.ps@pks.im> (raw)
In-Reply-To: <20190827111748.g4o375ya2shfrivs@10.255.255.10>

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


  parent reply index

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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       ` Patrick Steinhardt [this message]
2019-08-27 12:46         ` [PATCH] tests: use env and support both unbuffer/stdbuf 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

Reply instructions:

You may reply publically to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=219cbcaeb173a07e97dbac8e1b653904369d91e0.1566907983.git.ps@pks.im \
    --to=ps@pks.im \
    --cc=kzak@redhat.com \
    --cc=util-linux@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

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