From mboxrd@z Thu Jan 1 00:00:00 1970 From: Andrew Jones Subject: Re: [PATCH kvm-unit-tests v2 03/12] scripts/mkstandalone: use common run function Date: Thu, 17 Dec 2015 13:09:42 -0600 Message-ID: <20151217190942.GC14168@hawk.localdomain> References: <1450374823-7648-1-git-send-email-rkrcmar@redhat.com> <1450374823-7648-4-git-send-email-rkrcmar@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: QUOTED-PRINTABLE Cc: kvm@vger.kernel.org, Paolo Bonzini To: Radim =?utf-8?B?S3LEjW3DocWZ?= Return-path: Received: from mx1.redhat.com ([209.132.183.28]:37590 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751797AbbLQTJs (ORCPT ); Thu, 17 Dec 2015 14:09:48 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (Postfix) with ESMTPS id 194C4694 for ; Thu, 17 Dec 2015 19:09:48 +0000 (UTC) Content-Disposition: inline In-Reply-To: <1450374823-7648-4-git-send-email-rkrcmar@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: On Thu, Dec 17, 2015 at 06:53:34PM +0100, Radim Kr=C4=8Dm=C3=A1=C5=99 w= rote: > 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= =2E Hmm... as hard as I worked to avoid the dependency on bash for the standalone tests, then I'm reluctant to give up on that. I do agree that having the dependency for the printf-%q trick helps a ton in making the code more maintainable though. > (We already depend on QEMU ...) Dependency on qemu doesn't imply a dependency on bash. The idea behind the standalone version of kvm-unit-tests tests is that you can receive one in your email and launch it. >=20 > Apart from that, there are changes in output and exit codes. > - summary doesn't go to stderr I wanted the summary on stderr so when you redirect the output of the test to a file the output would directly diff with the corresponding output in test.log from a system where run_tests.sh was used. > - PASS/FAIL is colourful > - FAILed scripts return 1 I'm not sure why I did exit 0 instead of exit $ret. I guess that was just a thinko on my part. exit $ret makes more sense. >=20 > 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(-) >=20 > 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; t= hen > + 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 >=20 > -- > To unsubscribe from this list: send the line "unsubscribe kvm" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html