From patchwork Tue Mar 14 10:23:29 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Huth X-Patchwork-Id: 9622925 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 D2DD260244 for ; Tue, 14 Mar 2017 10:23:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B9782283F3 for ; Tue, 14 Mar 2017 10:23:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AE21B2856F; Tue, 14 Mar 2017 10:23:44 +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 4F792283F3 for ; Tue, 14 Mar 2017 10:23:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750892AbdCNKXn (ORCPT ); Tue, 14 Mar 2017 06:23:43 -0400 Received: from mx1.redhat.com ([209.132.183.28]:46098 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750868AbdCNKXm (ORCPT ); Tue, 14 Mar 2017 06:23:42 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9E1E0C04B93D; Tue, 14 Mar 2017 10:23:42 +0000 (UTC) Received: from thh440s.redhat.com (ovpn-116-98.ams2.redhat.com [10.36.116.98]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v2EANVS6026645; Tue, 14 Mar 2017 06:23:38 -0400 From: Thomas Huth To: kvm@vger.kernel.org, Laurent Vivier , Drew Jones Cc: kvm-ppc@vger.kernel.org, Paolo Bonzini , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , David Matlack Subject: [kvm-unit-tests PATCH v2 1/2] Add the possibility to do simple migration tests Date: Tue, 14 Mar 2017 11:23:29 +0100 Message-Id: <1489487010-17051-2-git-send-email-thuth@redhat.com> In-Reply-To: <1489487010-17051-1-git-send-email-thuth@redhat.com> References: <1489487010-17051-1-git-send-email-thuth@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Tue, 14 Mar 2017 10:23:42 +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 --- powerpc/run | 4 +++ scripts/qemu-migration-helper.sh | 68 ++++++++++++++++++++++++++++++++++++++++ scripts/runtime.bash | 3 ++ 3 files changed, 75 insertions(+) create mode 100755 scripts/qemu-migration-helper.sh diff --git a/powerpc/run b/powerpc/run index 6269abb..f1528ed 100755 --- a/powerpc/run +++ b/powerpc/run @@ -41,6 +41,10 @@ if ! $qemu -machine '?' 2>&1 | grep 'pseries' > /dev/null; then exit 2 fi +if [ "$MIGRATION" = "yes" ]; then + qemu="scripts/qemu-migration-helper.sh $qemu" +fi + M='-machine pseries' M+=",accel=$ACCEL" command="$qemu -nodefaults $M -bios $FIRMWARE" diff --git a/scripts/qemu-migration-helper.sh b/scripts/qemu-migration-helper.sh new file mode 100755 index 0000000..5842026 --- /dev/null +++ b/scripts/qemu-migration-helper.sh @@ -0,0 +1,68 @@ +#!/bin/bash +# This script runs two instances of QEMU and then migrates the guest from one +# instance to the other. The end of the migration is signalled to the guest by +# injecting an NMI. + +if ! command -v nc >/dev/null 2>&1; then + echo "$0 needs nc (netcat)" + exit 1 +fi + +qemu=$1 +shift + +if ! command -v "$qemu" >/dev/null 2>&1; then + echo "The first parameter must be pointing to the QEMU executable" + exit 1 +fi + +migsock=`mktemp -u -t mig-helper-socket.XXXXXXXXXX` +stdout1=`mktemp -t mig-helper-stdout1.XXXXXXXXXX` +stdout2=`mktemp -t mig-helper-stdout2.XXXXXXXXXX` +qmpout1=`mktemp -t mig-helper-qmpout1.XXXXXXXXXX` +qmpout2=`mktemp -t mig-helper-qmpout2.XXXXXXXXXX` +qmp1=`mktemp -u -t mig-helper-qmp1.XXXXXXXXXX` +qmp2=`mktemp -u -t mig-helper-qmp2.XXXXXXXXXX` + +cleanup() +{ + rm -f ${stdout1} ${stdout2} ${migsock} + rm -f ${qmpout1} ${qmpout2} ${qmp1} ${qmp2} +} +trap cleanup EXIT + +qmp_cmd() +{ + echo '{ "execute": "qmp_capabilities" }{ "execute":' "$2" '}' | nc -U $1 +} + +$qemu $* -chardev socket,id=mon1,path=${qmp1},server,nowait \ + -mon chardev=mon1,mode=control > ${stdout1} & + +$qemu $* -chardev socket,id=mon2,path=${qmp2},server,nowait \ + -mon chardev=mon2,mode=control -incoming unix:${migsock} > ${stdout2} & + +# The test must prompt the user to migrate, so wait for the "migrate" keyword +while ! grep -q -i "migrate" < ${stdout1} ; do + sleep 1 +done + +qmp_cmd ${qmp1} '"migrate", "arguments": { "uri": "unix:'${migsock}'" }' > ${qmpout1} + +# Wait for the migration to complete +migstatus=`qmp_cmd ${qmp1} '"query-migrate"' | grep return` +while ! grep -q '"completed"' <<<"$migstatus" ; do + sleep 1 + migstatus=`qmp_cmd ${qmp1} '"query-migrate"' | grep return` + if grep -q '"failed"' <<<"$migstatus" ; then + echo "ERROR: Migration failed." + exit 1 + fi +done +qmp_cmd ${qmp1} '"quit"'> ${qmpout1} 2>/dev/null + +qmp_cmd ${qmp2} '"inject-nmi"'> ${qmpout2} + +wait + +cat ${stdout1} ${stdout2} diff --git a/scripts/runtime.bash b/scripts/runtime.bash index 9c1bc3b..f58eb4e 100644 --- a/scripts/runtime.bash +++ b/scripts/runtime.bash @@ -98,6 +98,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