From mboxrd@z Thu Jan 1 00:00:00 1970 From: =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= Subject: [kvm-unit-tests PATCH 3/5] s390+powerpc/run: improve output handling Date: Wed, 28 Jun 2017 22:08:55 +0200 Message-ID: <20170628200857.1718-4-rkrcmar@redhat.com> References: <20170628200857.1718-1-rkrcmar@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Paolo Bonzini , Drew Jones , Laurent Vivier , Thomas Huth , David Hildenbrand To: kvm@vger.kernel.org Return-path: Received: from mx1.redhat.com ([209.132.183.28]:55868 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751787AbdF1UJU (ORCPT ); Wed, 28 Jun 2017 16:09:20 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 124E8FD09 for ; Wed, 28 Jun 2017 20:09:20 +0000 (UTC) In-Reply-To: <20170628200857.1718-1-rkrcmar@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: 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ář --- powerpc/run | 15 +-------------- s390x/run | 15 +-------------- scripts/arch-run.bash | 23 +++++++++++++++++++++++ 3 files changed, 25 insertions(+), 28 deletions(-) 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 -- 2.13.2