From patchwork Wed Mar 22 08:28:06 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Huth X-Patchwork-Id: 9638225 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id F3F7D6032A for ; Wed, 22 Mar 2017 08:28:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DFD3B2768C for ; Wed, 22 Mar 2017 08:28:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D4C0527B2F; Wed, 22 Mar 2017 08:28:26 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 687AB281F9 for ; Wed, 22 Mar 2017 08:28:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933563AbdCVI2Y (ORCPT ); Wed, 22 Mar 2017 04:28:24 -0400 Received: from mx1.redhat.com ([209.132.183.28]:48518 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932323AbdCVI2U (ORCPT ); Wed, 22 Mar 2017 04:28:20 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1272481253; Wed, 22 Mar 2017 08:28:20 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 1272481253 Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=thuth@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 1272481253 Received: from thh440s.redhat.com (ovpn-116-231.ams2.redhat.com [10.36.116.231]) by smtp.corp.redhat.com (Postfix) with ESMTP id EA2BD83E82; Wed, 22 Mar 2017 08:28:12 +0000 (UTC) From: Thomas Huth To: kvm@vger.kernel.org, Laurent Vivier , Drew Jones , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= Cc: kvm-ppc@vger.kernel.org, Paolo Bonzini , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , David Matlack Subject: [kvm-unit-tests PATCH v4 1/2] Add the possibility to do simple migration tests Date: Wed, 22 Mar 2017 09:28:06 +0100 Message-Id: <1490171287-30893-2-git-send-email-thuth@redhat.com> In-Reply-To: <1490171287-30893-1-git-send-email-thuth@redhat.com> References: <1490171287-30893-1-git-send-email-thuth@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Wed, 22 Mar 2017 08:28:20 +0000 (UTC) Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP To be able to do simple migration tests with kvm-unit-tests, too, add a helper script that does all the necessary work: Start two instances of QEMU (source and destination) with QMP sockets for sending commands to them, then trigger the migration from one instance to the other and finally signal the end of the migration to the guest by injecting an NMI. This helper script is now used automatically for powerpc tests if the test is put into the "migration" group in the unittests.cfg file. Signed-off-by: Thomas Huth Reviewed-by: Andrew Jones --- powerpc/run | 2 +- scripts/arch-run.bash | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++ scripts/runtime.bash | 3 +++ 3 files changed, 67 insertions(+), 1 deletion(-) diff --git a/powerpc/run b/powerpc/run index 6269abb..d92608e 100755 --- a/powerpc/run +++ b/powerpc/run @@ -46,7 +46,7 @@ M+=",accel=$ACCEL" command="$qemu -nodefaults $M -bios $FIRMWARE" [ -f "$ENV" ] && command+=" -initrd $ENV" command+=" -display none -serial stdio -kernel" -command="$(timeout_cmd) $command" +command="$(migration_cmd) $(timeout_cmd) $command" echo $command "$@" # powerpc tests currently exit with rtas-poweroff, which exits with 0. diff --git a/scripts/arch-run.bash b/scripts/arch-run.bash index 1610f3b..96bd5c4 100644 --- a/scripts/arch-run.bash +++ b/scripts/arch-run.bash @@ -70,3 +70,66 @@ timeout_cmd () echo "timeout -k 1s --foreground $TIMEOUT" fi } + +qmp () +{ + echo '{ "execute": "qmp_capabilities" }{ "execute":' "$2" '}' | nc -U $1 +} + +run_migration () +{ + if ! command -v nc >/dev/null 2>&1; then + echo "$0 needs nc (netcat)" >&2 + exit 2 + fi + + qemu=$1 + shift + + migsock=`mktemp -u -t mig-helper-socket.XXXXXXXXXX` + migout1=`mktemp -t mig-helper-stdout1.XXXXXXXXXX` + qmp1=`mktemp -u -t mig-helper-qmp1.XXXXXXXXXX` + qmp2=`mktemp -u -t mig-helper-qmp2.XXXXXXXXXX` + qmpout1=/dev/null + qmpout2=/dev/null + + trap 'rm -f ${migout1} ${migsock} ${qmp1} ${qmp2}' EXIT + + $qemu "$@" -chardev socket,id=mon1,path=${qmp1},server,nowait \ + -mon chardev=mon1,mode=control | tee ${migout1} & + + $qemu "$@" -chardev socket,id=mon2,path=${qmp2},server,nowait \ + -mon chardev=mon2,mode=control -incoming unix:${migsock} & + + # The test must prompt the user to migrate, so wait for the "migrate" keyword + while ! grep -q -i "migrate" < ${migout1} ; do + sleep 1 + done + + qmp ${qmp1} '"migrate", "arguments": { "uri": "unix:'${migsock}'" }' > ${qmpout1} + + # Wait for the migration to complete + migstatus=`qmp ${qmp1} '"query-migrate"' | grep return` + while ! grep -q '"completed"' <<<"$migstatus" ; do + sleep 1 + migstatus=`qmp ${qmp1} '"query-migrate"' | grep return` + if grep -q '"failed"' <<<"$migstatus" ; then + echo "ERROR: Migration failed." >&2 + qmp ${qmp1} '"quit"'> ${qmpout1} 2>/dev/null + qmp ${qmp2} '"quit"'> ${qmpout2} 2>/dev/null + exit 2 + fi + done + qmp ${qmp1} '"quit"'> ${qmpout1} 2>/dev/null + + qmp ${qmp2} '"inject-nmi"'> ${qmpout2} + + wait +} + +migration_cmd () +{ + if [ "$MIGRATION" = "yes" ]; then + echo "run_migration" + fi +} diff --git a/scripts/runtime.bash b/scripts/runtime.bash index 98f1835..e630279 100644 --- a/scripts/runtime.bash +++ b/scripts/runtime.bash @@ -99,6 +99,9 @@ function run() } cmdline=$(get_cmdline $kernel) + if grep -qw "migration" <<<$groups ; then + cmdline="MIGRATION=yes $cmdline" + fi if [ "$verbose" = "yes" ]; then echo $cmdline fi