diff mbox

[kvm-unit-tests,3/5] s390+powerpc/run: improve output handling

Message ID 20170628200857.1718-4-rkrcmar@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Radim Krčmář June 28, 2017, 8:08 p.m. UTC
If the test is hanging, then using arch/run would produce no output,
because of caching in a temporary variable.
Use the `tee` trick to save the output while passing it through.

They were also using the very same code.

Signed-off-by: Radim Krčmář <rkrcmar@redhat.com>
---
 powerpc/run           | 15 +--------------
 s390x/run             | 15 +--------------
 scripts/arch-run.bash | 23 +++++++++++++++++++++++
 3 files changed, 25 insertions(+), 28 deletions(-)
diff mbox

Patch

diff --git a/powerpc/run b/powerpc/run
index 3fd5a91aeffb..3f69386c642a 100755
--- a/powerpc/run
+++ b/powerpc/run
@@ -46,17 +46,4 @@  command="$(migration_cmd) $(timeout_cmd) $command"
 # to fixup the fixup below by parsing the true exit code from the output.
 # The second fixup is also a FIXME, because once we add chr-testdev
 # support for powerpc, we won't need the second fixup.
-lines=$(run_qemu $command "$@")
-ret=$?
-echo "$lines"
-if [ $ret -eq 1 ]; then
-	testret=$(grep '^EXIT: ' <<<"$lines" | sed 's/.*STATUS=\([0-9][0-9]*\).*/\1/')
-	if [ "$testret" ]; then
-		if [ $testret -eq 1 ]; then
-			ret=0
-		else
-			ret=$testret
-		fi
-	fi
-fi
-exit $ret
+run_qemu_status $command "$@"
diff --git a/s390x/run b/s390x/run
index 89210f4fb6b6..6df348a93783 100755
--- a/s390x/run
+++ b/s390x/run
@@ -38,17 +38,4 @@  command+=" -kernel"
 command="$(timeout_cmd) $command"
 
 # We return the exit code via stdout, not via the QEMU return code
-lines=$(run_qemu $command "$@")
-ret=$?
-echo "$lines"
-if [ $ret -eq 1 ]; then
-	testret=$(grep '^EXIT: ' <<<"$lines" | sed 's/.*STATUS=\([0-9][0-9]*\).*/\1/')
-	if [ "$testret" ]; then
-		if [ $testret -eq 1 ]; then
-			ret=0
-		else
-			ret=$testret
-		fi
-	fi
-fi
-exit $ret
+run_qemu_status $command "$@"
diff --git a/scripts/arch-run.bash b/scripts/arch-run.bash
index 8ad37e4ebf97..6e429a8748f4 100644
--- a/scripts/arch-run.bash
+++ b/scripts/arch-run.bash
@@ -69,6 +69,29 @@  run_qemu ()
 	return $ret
 }
 
+run_qemu_status ()
+{
+	local stdout ret
+
+	exec {stdout}>&1
+	lines=$(run_qemu "$@" > >(tee /dev/fd/$stdout))
+	ret=$?
+	exec {stdout}>&-
+
+	if [ $ret -eq 1 ]; then
+		testret=$(grep '^EXIT: ' <<<"$lines" | sed 's/.*STATUS=\([0-9][0-9]*\).*/\1/')
+		if [ "$testret" ]; then
+			if [ $testret -eq 1 ]; then
+				ret=0
+			else
+				ret=$testret
+			fi
+		fi
+	fi
+
+	return $ret
+}
+
 timeout_cmd ()
 {
 	if [ "$TIMEOUT" ] && [ "$TIMEOUT" != "0" ]; then