From mboxrd@z Thu Jan 1 00:00:00 1970 From: =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= Subject: [PATCH kvm-unit-tests v2 03/12] scripts/mkstandalone: use common run function Date: Thu, 17 Dec 2015 18:53:34 +0100 Message-ID: <1450374823-7648-4-git-send-email-rkrcmar@redhat.com> References: <1450374823-7648-1-git-send-email-rkrcmar@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: QUOTED-PRINTABLE Cc: Paolo Bonzini , Andrew Jones To: kvm@vger.kernel.org Return-path: Received: from mx1.redhat.com ([209.132.183.28]:53075 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751956AbbLQRyE (ORCPT ); Thu, 17 Dec 2015 12:54:04 -0500 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (Postfix) with ESMTPS id 33D488F242 for ; Thu, 17 Dec 2015 17:54:04 +0000 (UTC) In-Reply-To: <1450374823-7648-1-git-send-email-rkrcmar@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: The biggest change is dependency on bash. An alternative would be to rewrite `run` in POSIX shell, but I think it's ok to presume that KVM unit tests will run on a system where installing bash isn't a problem. (We already depend on QEMU ...) Apart from that, there are changes in output and exit codes. - summary doesn't go to stderr - PASS/FAIL is colourful - FAILed scripts return 1 Signed-off-by: Radim Kr=C4=8Dm=C3=A1=C5=99 --- v2: new (I can fix the stderr in v3) =20 scripts/mkstandalone.sh | 59 +++++++++++++++++++++--------------------= -------- 1 file changed, 25 insertions(+), 34 deletions(-) diff --git a/scripts/mkstandalone.sh b/scripts/mkstandalone.sh index 3ce244aff67b..cf2182dbd936 100755 --- a/scripts/mkstandalone.sh +++ b/scripts/mkstandalone.sh @@ -20,6 +20,13 @@ fi unittests=3D$TEST_DIR/unittests.cfg mkdir -p tests =20 +escape () +{ + for arg in "${@}"; do + printf "%q " "$arg"; # XXX: trailing whitespace + done +} + function mkstandalone() { local testname=3D"$1" @@ -49,33 +56,14 @@ function mkstandalone() cmdline=3D$(cut -d' ' -f2- <<< "$cmdline") =20 cat < $standalone -#!/bin/sh +#!/bin/bash =20 -EOF -if [ "$arch" ]; then - cat <> $standalone ARCH=3D\`uname -m | sed -e s/i.86/i386/ | sed -e 's/arm.*/arm/'\` -[ "\$ARCH" =3D "aarch64" ] && ARCH=3D"arm64" -if [ "\$ARCH" !=3D "$arch" ]; then - echo "skip $testname ($arch only)" 1>&2 - exit 1 -fi =20 EOF -fi -if [ "$check" ]; then - cat <> $standalone -for param in $check; do - path=3D\`echo \$param | cut -d=3D -f1\` - value=3D\`echo \$param | cut -d=3D -f2\` - if [ -f "\$path" ] && [ "\`cat \$path\`" !=3D "\$value" ]; then - echo "skip $testname (\$path not equal to \$value)" 1>&2 - exit 1 - fi -done =20 -EOF -fi +cat scripts/run.bash >> $standalone + if [ ! -f $kernel ]; then cat <> $standalone echo "skip $testname (test kernel not present)" 1>&2 @@ -100,9 +88,13 @@ MAX_SMP=3D"MAX_SMP" echo \$qemu $cmdline -smp $smp $opts =20 cmdline=3D"\`echo '$cmdline' | sed s%$kernel%_NO_FILE_4Uhere_%\`" -if \$qemu \$cmdline 2>&1 | grep 'No accelerator found'; then - ret=3D2 -else +if \$qemu \$cmdline 2>&1 | grep 'No accelerator found' >/dev/null; the= n + echo "skip $testname (QEMU doesn't support KVM)" + exit 1 +fi + +__run() +{ MAX_SMP=3D\`getconf _NPROCESSORS_CONF\` while \$qemu \$cmdline -smp \$MAX_SMP 2>&1 | grep 'exceeds max cpus' = > /dev/null; do MAX_SMP=3D\`expr \$MAX_SMP - 1\` @@ -110,16 +102,15 @@ else =20 cmdline=3D"\`echo '$cmdline' | sed s%$kernel%\$bin%\`" \$qemu \$cmdline -smp $smp $opts - ret=3D\$? -fi -echo Return value from qemu: \$ret -if [ \$ret -le 1 ]; then - echo PASS $testname 1>&2 -else - echo FAIL $testname 1>&2 -fi +} + +__eval_log() { eval "\${@}"; } + +run `escape "${@}"` +ret=3D$? + rm -f \$bin -exit 0 +exit \$ret EOF fi chmod +x $standalone --=20 2.6.4