From patchwork Fri Nov 6 00:24:34 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 7564941 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 33EE9C05C6 for ; Fri, 6 Nov 2015 00:25:27 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 1FE9D207A4 for ; Fri, 6 Nov 2015 00:25:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E0A8F20784 for ; Fri, 6 Nov 2015 00:25:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S966043AbbKFAZV (ORCPT ); Thu, 5 Nov 2015 19:25:21 -0500 Received: from mx1.redhat.com ([209.132.183.28]:60913 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S966018AbbKFAZP (ORCPT ); Thu, 5 Nov 2015 19:25:15 -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 1256D8E718; Fri, 6 Nov 2015 00:25:15 +0000 (UTC) Received: from hawk.localdomain.com (ovpn-116-20.ams2.redhat.com [10.36.116.20]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id tA60Olmn016750; Thu, 5 Nov 2015 19:25:12 -0500 From: Andrew Jones To: pbonzini@redhat.com, kvm@vger.kernel.org Cc: alex.bennee@linaro.org, cov@codeaurora.org Subject: [kvm-unit-tests PATCH 09/18] arm/run: use ACCEL to choose between kvm and tcg Date: Thu, 5 Nov 2015 18:24:34 -0600 Message-Id: <1446769483-21586-10-git-send-email-drjones@redhat.com> In-Reply-To: <1446769483-21586-1-git-send-email-drjones@redhat.com> References: <1446769483-21586-1-git-send-email-drjones@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Inspired by a patch by Alex Bennée. This version uses a new unittests.cfg variable and includes support for DRYRUN. Signed-off-by: Andrew Jones --- arm/run | 43 +++++++++++++++++++++++++++++++++++++------ arm/unittests.cfg | 4 +++- run_tests.sh | 3 ++- scripts/functions.bash | 8 ++++++-- scripts/mkstandalone.sh | 15 +++++++++++---- 5 files changed, 59 insertions(+), 14 deletions(-) diff --git a/arm/run b/arm/run index 8cc2fa2571967..4a648697d7fb5 100755 --- a/arm/run +++ b/arm/run @@ -7,6 +7,42 @@ fi source config.mak processor="$PROCESSOR" +if [ -c /dev/kvm ]; then + if [ "$HOST" = "arm" ] && [ "$ARCH" = "arm" ]; then + kvm_available=yes + elif [ "$HOST" = "aarch64" ]; then + kvm_available=yes + fi +fi + +if [ "$ACCEL" = "kvm" ] && [ "$kvm_available" != "yes" ] && + [ "$DRYRUN" != "yes" ]; then + printf "skip $TESTNAME (kvm only)\n\n" + exit 2 +fi + +if [ -z "$ACCEL" ]; then + if [ "$DRYRUN" = "yes" ]; then + # Output kvm with tcg fallback for dryrun (when both are + # allowed), since the command line we output may get used + # elsewhere. + ACCEL="kvm:tcg" + elif [ "$kvm_available" = "yes" ]; then + ACCEL="kvm" + else + ACCEL="tcg" + fi +fi + +if [ "$ARCH" = "arm64" ]; then + if [[ $ACCEL =~ kvm ]]; then + # arm64 must use '-cpu host' with kvm, and we can't use + # '-cpu host' with tcg, so we force kvm-only (no fallback) + ACCEL="kvm" + processor="host" + fi +fi + qemu="${QEMU:-qemu-system-$ARCH_NAME}" qpath=$(which $qemu 2>/dev/null) @@ -33,15 +69,10 @@ if $qemu $M -chardev testdev,id=id -initrd . 2>&1 \ exit 2 fi -M='-machine virt,accel=kvm:tcg' chr_testdev='-device virtio-serial-device' chr_testdev+=' -device virtconsole,chardev=ctd -chardev testdev,id=ctd' -# arm64 must use '-cpu host' with kvm -if [ "$(arch)" = "aarch64" ] && [ "$ARCH" = "arm64" ] && [ -c /dev/kvm ]; then - processor="host" -fi - +M+=",accel=$ACCEL" command="$qemu $M -cpu $processor $chr_testdev" command+=" -display none -serial stdio -kernel" echo $command "$@" diff --git a/arm/unittests.cfg b/arm/unittests.cfg index e068a0cdd9c1f..243c13301811b 100644 --- a/arm/unittests.cfg +++ b/arm/unittests.cfg @@ -3,8 +3,10 @@ # file = foo.flat # Name of the flat file to be used # smp = 2 # Number of processors the VM will use during this test # extra_params = -append # Additional parameters used -# arch = arm/arm64 # Only if test case is specific to one +# arch = arm|arm64 # Only if test case is specific to one # groups = group1 group2 # Used to identify test cases with run_tests -g ... +# accel = kvm|tcg # Optionally specify if test must run with kvm or tcg. +# # If not specified, then kvm will be used when available. # # Test that the configured number of processors (smp = ), and diff --git a/run_tests.sh b/run_tests.sh index 80b87823c3358..b1b4c541ecaea 100755 --- a/run_tests.sh +++ b/run_tests.sh @@ -20,6 +20,7 @@ function run() local opts="$5" local arch="$6" local check="$7" + local accel="$8" if [ -z "$testname" ]; then return @@ -46,7 +47,7 @@ function run() fi done - cmdline="TESTNAME=$testname ./$TEST_DIR-run $kernel -smp $smp $opts" + cmdline="TESTNAME=$testname ACCEL=$accel ./$TEST_DIR-run $kernel -smp $smp $opts" if [ $verbose != 0 ]; then echo $cmdline fi diff --git a/scripts/functions.bash b/scripts/functions.bash index 7ed5a517250bc..f13fe6f88f23d 100644 --- a/scripts/functions.bash +++ b/scripts/functions.bash @@ -10,12 +10,13 @@ function for_each_unittest() local groups local arch local check + local accel exec {fd}<"$unittests" while read -u $fd line; do if [[ "$line" =~ ^\[(.*)\]$ ]]; then - "$cmd" "$testname" "$groups" "$smp" "$kernel" "$opts" "$arch" "$check" + "$cmd" "$testname" "$groups" "$smp" "$kernel" "$opts" "$arch" "$check" "$accel" testname=${BASH_REMATCH[1]} smp=1 kernel="" @@ -23,6 +24,7 @@ function for_each_unittest() groups="" arch="" check="" + accel="" elif [[ $line =~ ^file\ *=\ *(.*)$ ]]; then kernel=$TEST_DIR/${BASH_REMATCH[1]} elif [[ $line =~ ^smp\ *=\ *(.*)$ ]]; then @@ -35,8 +37,10 @@ function for_each_unittest() arch=${BASH_REMATCH[1]} elif [[ $line =~ ^check\ *=\ *(.*)$ ]]; then check=${BASH_REMATCH[1]} + elif [[ $line =~ ^accel\ *=\ *(.*)$ ]]; then + accel=${BASH_REMATCH[1]} fi done - "$cmd" "$testname" "$groups" "$smp" "$kernel" "$opts" "$arch" "$check" + "$cmd" "$testname" "$groups" "$smp" "$kernel" "$opts" "$arch" "$check" "$accel" exec {fd}<&- } diff --git a/scripts/mkstandalone.sh b/scripts/mkstandalone.sh index 4cf346ab87d24..0c39451e538c9 100755 --- a/scripts/mkstandalone.sh +++ b/scripts/mkstandalone.sh @@ -29,6 +29,7 @@ function mkstandalone() local opts="$5" local arch="$6" local check="$7" + local accel="$8" if [ -z "$testname" ]; then return 1 @@ -39,7 +40,7 @@ function mkstandalone() fi standalone=tests/$testname - cmdline=$(DRYRUN=yes ./$TEST_DIR-run $kernel) + cmdline=$(DRYRUN=yes ACCEL=$accel ./$TEST_DIR-run $kernel) if [ $? -ne 0 ]; then echo $cmdline exit 1 @@ -94,10 +95,16 @@ qemu="$qemu" if [ "\$QEMU" ]; then qemu="\$QEMU" fi -cmdline="\`echo '$cmdline' | sed s%$kernel%\$bin%\`" echo \$qemu $cmdline -smp $smp $opts -\$qemu \$cmdline -smp $smp $opts -ret=\$? + +cmdline="\`echo '$cmdline' | sed s%$kernel%_NO_FILE_4Uhere_%\`" +if \$qemu \$cmdline 2>&1 | grep 'No accelerator found'; then + ret=2 +else + cmdline="\`echo '$cmdline' | sed s%$kernel%\$bin%\`" + \$qemu \$cmdline -smp $smp $opts + ret=\$? +fi echo Return value from qemu: \$ret if [ \$ret -le 1 ]; then echo PASS $testname 1>&2