From: Andrew Jones Subject: [kvm-unit-tests PATCH v2 6/6] run scripts: add timeout support Date: Wed, 27 Jan 2016 16:59:54 +0100 Message-ID: <1453910394-11766-7-git-send-email-drjones@redhat.com> References: <1453910394-11766-1-git-send-email-drjones@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: QUOTED-PRINTABLE Cc: pbonzini@redhat.com, rkrcmar@redhat.com To: kvm@vger.kernel.org Return-path: Received: from mx1.redhat.com ([209.132.183.28]:37073 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932858AbcA0QAJ (ORCPT ); Wed, 27 Jan 2016 11:00:09 -0500 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (Postfix) with ESMTPS id E1243B5B6F for ; Wed, 27 Jan 2016 16:00:08 +0000 (UTC) In-Reply-To: <1453910394-11766-1-git-send-email-drjones@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: Also remove useless qemu variable in scripts/runtime.bash. Signed-off-by: Andrew Jones Reviewed-by: Radim Kr=C4=8Dm=C3=A1=C5=99 --- arm/run | 1 + arm/unittests.cfg | 1 + scripts/arch-run.bash | 8 ++++++++ scripts/functions.bash | 8 ++++++-- scripts/runtime.bash | 10 ++++++---- x86/run | 1 + x86/unittests.cfg | 1 + 7 files changed, 24 insertions(+), 6 deletions(-) diff --git a/arm/run b/arm/run index c9463de6dd241..4b9aeb3665436 100755 --- a/arm/run +++ b/arm/run @@ -70,6 +70,7 @@ chr_testdev+=3D' -device virtconsole,chardev=3Dctd -c= hardev testdev,id=3Dctd' M+=3D",accel=3D$ACCEL" command=3D"$qemu $M -cpu $processor $chr_testdev" command+=3D" -display none -serial stdio -kernel" +command=3D"$(timeout_cmd) $command" echo $command "$@" =20 exit_fixup $command "$@" diff --git a/arm/unittests.cfg b/arm/unittests.cfg index 926bbb153728b..8c6c475f050fc 100644 --- a/arm/unittests.cfg +++ b/arm/unittests.cfg @@ -15,6 +15,7 @@ # accel =3D kvm|tcg # Optionally specify if test must run with # # kvm or tcg. If not specified, then kvm will # # be used when available. +# timeout =3D # Optionally specify a timeout. ######################################################################= ######## =20 # diff --git a/scripts/arch-run.bash b/scripts/arch-run.bash index 3a63ed179a7de..28a33f41b6ede 100644 --- a/scripts/arch-run.bash +++ b/scripts/arch-run.bash @@ -19,6 +19,7 @@ # 1 - most likely QEMU failed # 2 - most likely a run script failed # 3 - most likely the unittest failed +# 124 - most likely the unittest timed out # 127 - most likely the unittest called abort() # 1..127 - FAILURE (could be QEMU, a run script, or the unittest) # >=3D 128 - Signal (signum =3D status - 128) @@ -59,3 +60,10 @@ exit_fixup () =20 return $ret } + +timeout_cmd () +{ + if [ "$TIMEOUT" ] && [ "$TIMEOUT" !=3D "0" ]; then + echo "timeout -k 1s --foreground $TIMEOUT" + fi +} diff --git a/scripts/functions.bash b/scripts/functions.bash index f13fe6f88f23d..ee9143c5d630d 100644 --- a/scripts/functions.bash +++ b/scripts/functions.bash @@ -11,12 +11,13 @@ function for_each_unittest() local arch local check local accel + local timeout =20 exec {fd}<"$unittests" =20 while read -u $fd line; do if [[ "$line" =3D~ ^\[(.*)\]$ ]]; then - "$cmd" "$testname" "$groups" "$smp" "$kernel" "$opts" "$arch" "$che= ck" "$accel" + "$cmd" "$testname" "$groups" "$smp" "$kernel" "$opts" "$arch" "$che= ck" "$accel" "$timeout" testname=3D${BASH_REMATCH[1]} smp=3D1 kernel=3D"" @@ -25,6 +26,7 @@ function for_each_unittest() arch=3D"" check=3D"" accel=3D"" + timeout=3D"" elif [[ $line =3D~ ^file\ *=3D\ *(.*)$ ]]; then kernel=3D$TEST_DIR/${BASH_REMATCH[1]} elif [[ $line =3D~ ^smp\ *=3D\ *(.*)$ ]]; then @@ -39,8 +41,10 @@ function for_each_unittest() check=3D${BASH_REMATCH[1]} elif [[ $line =3D~ ^accel\ *=3D\ *(.*)$ ]]; then accel=3D${BASH_REMATCH[1]} + elif [[ $line =3D~ ^timeout\ *=3D\ *(.*)$ ]]; then + timeout=3D${BASH_REMATCH[1]} fi done - "$cmd" "$testname" "$groups" "$smp" "$kernel" "$opts" "$arch" "$check= " "$accel" + "$cmd" "$testname" "$groups" "$smp" "$kernel" "$opts" "$arch" "$check= " "$accel" "$timeout" exec {fd}<&- } diff --git a/scripts/runtime.bash b/scripts/runtime.bash index 1ac57ccdfc614..0e055f0dddc2c 100644 --- a/scripts/runtime.bash +++ b/scripts/runtime.bash @@ -1,6 +1,6 @@ : "${RUNTIME_arch_run?}" - -qemu=3D${QEMU:-qemu-system-$ARCH} +: ${MAX_SMP:=3D$(getconf _NPROCESSORS_CONF)} +: ${TIMEOUT:=3D90s} =20 function run() { @@ -12,6 +12,7 @@ function run() local arch=3D"$6" local check=3D"${CHECK:-$7}" local accel=3D"${ACCEL:-$8}" + local timeout=3D"${9:-$TIMEOUT}" # unittests.cfg overrides the def= ault =20 if [ -z "$testname" ]; then return @@ -38,7 +39,7 @@ function run() fi done =20 - cmdline=3D"TESTNAME=3D$testname ACCEL=3D$accel $RUNTIME_arch_run $= kernel -smp $smp $opts" + cmdline=3D"TESTNAME=3D$testname TIMEOUT=3D$timeout ACCEL=3D$accel = $RUNTIME_arch_run $kernel -smp $smp $opts" if [ "$verbose" =3D "yes" ]; then echo $cmdline fi @@ -50,6 +51,8 @@ function run() =20 if [ $ret -eq 0 ]; then echo -e "\e[32mPASS\e[0m $1" + elif [ $ret -eq 124 ]; then + echo -e "\e[31mFAIL\e[0m $1 (timeout; duration=3D$timeout)" else echo -e "\e[31mFAIL\e[0m $1" fi @@ -57,7 +60,6 @@ function run() return $ret } =20 -: ${MAX_SMP:=3D$(getconf _NPROCESSORS_CONF)} # # Probe for MAX_SMP, in case it's less than the number of host cpus. # diff --git a/x86/run b/x86/run index b07c815c5a6e1..3386524957a61 100755 --- a/x86/run +++ b/x86/run @@ -43,6 +43,7 @@ else fi =20 command=3D"${qemu} -enable-kvm $pc_testdev -vnc none -serial stdio $pc= i_testdev $hyperv_testdev -kernel" +command=3D"$(timeout_cmd) $command" echo ${command} "$@" =20 exit_fixup ${command} "$@" diff --git a/x86/unittests.cfg b/x86/unittests.cfg index 4a9564536e8ea..b6094a4477ad5 100644 --- a/x86/unittests.cfg +++ b/x86/unittests.cfg @@ -12,6 +12,7 @@ # # specific to only one. # groups =3D ... # Used to identify test c= ases # # with run_tests -g ... +# timeout =3D # Optionally specify a timeout. ######################################################################= ######## =20 [apic] --=20 2.4.3