From patchwork Thu Mar 9 17:27: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: 737080 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3vfHRH43Fzz9s7j for ; Fri, 10 Mar 2017 04:28:11 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932480AbdCIR2B (ORCPT ); Thu, 9 Mar 2017 12:28:01 -0500 Received: from mx1.redhat.com ([209.132.183.28]:48700 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754730AbdCIR1y (ORCPT ); Thu, 9 Mar 2017 12:27:54 -0500 Received: from smtp.corp.redhat.com (int-mx16.intmail.prod.int.phx2.redhat.com [10.5.11.28]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4730E64473; Thu, 9 Mar 2017 17:27:15 +0000 (UTC) Received: from thh440s.redhat.com (ovpn-116-46.ams2.redhat.com [10.36.116.46]) by smtp.corp.redhat.com (Postfix) with ESMTP id 39E592D653; Thu, 9 Mar 2017 17:27:11 +0000 (UTC) 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?= Subject: [kvm-unit-tests PATCH 1/2] Add the possibility to do simple migration tests Date: Thu, 9 Mar 2017 18:27:06 +0100 Message-Id: <1489080427-27103-2-git-send-email-thuth@redhat.com> In-Reply-To: <1489080427-27103-1-git-send-email-thuth@redhat.com> References: <1489080427-27103-1-git-send-email-thuth@redhat.com> X-Scanned-By: MIMEDefang 2.74 on 10.5.11.28 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Thu, 09 Mar 2017 17:27:15 +0000 (UTC) Sender: kvm-ppc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm-ppc@vger.kernel.org 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 | 5 ++++ scripts/qemu-migration-helper.sh | 51 ++++++++++++++++++++++++++++++++++++++++ scripts/runtime.bash | 3 +++ 3 files changed, 59 insertions(+) create mode 100755 scripts/qemu-migration-helper.sh diff --git a/powerpc/run b/powerpc/run index 6269abb..126fed5 100755 --- a/powerpc/run +++ b/powerpc/run @@ -41,6 +41,11 @@ if ! $qemu -machine '?' 2>&1 | grep 'pseries' > /dev/null; then exit 2 fi +if [ "$MIGRATION" = "1" ]; then + export QEMU_BIN="$qemu" + qemu=`dirname $0`/../scripts/qemu-migration-helper.sh +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..0cb7e4a --- /dev/null +++ b/scripts/qemu-migration-helper.sh @@ -0,0 +1,51 @@ +#!/bin/sh + +# 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 [ "x$QEMU_BIN" = "x" ]; then + echo "QEMU_BIN must be set to the QEMU binary" + exit 1 +fi + +if ! command -v nc >/dev/null 2>&1; then + echo "$0 needs nc (netcat)" + exit 1 +fi + +qmp_cmd() +{ + echo '{ "execute": "qmp_capabilities" }{ "execute":' "$2" '}' | nc -U $1 +} + +tempname=`mktemp` +qmp1=${tempname}.qmp1 +qmp2=${tempname}.qmp2 +qmpout1=${tempname}.qmpout1 +qmpout2=${tempname}.qmpout2 +stdout1=${tempname}.stdout1 +stdout2=${tempname}.stdout2 +migsock=${tempname}.mig + +$QEMU_BIN $* -chardev socket,id=mon1,path=${qmp1},server,nowait \ + -mon chardev=mon1,mode=control > ${stdout1} & + +$QEMU_BIN $* -chardev socket,id=mon2,path=${qmp2},server,nowait \ + -mon chardev=mon2,mode=control -incoming unix:${migsock} > ${stdout2} & + +sleep 1 + +qmp_cmd ${qmp1} '"migrate", "arguments": { "uri": "unix:'${migsock}'" }' > ${qmpout1} +while qmp_cmd ${qmp1} '"query-migrate"' | grep -q '"active"' ; do + sleep 1 +done +qmp_cmd ${qmp1} '"quit"'> ${qmpout1} 2>/dev/null + +qmp_cmd ${qmp2} '"inject-nmi"'> ${qmpout2} + +wait + +cat ${stdout1} ${stdout2} + +rm -f ${tempname} ${qmpout1} ${qmpout2} ${stdout1} ${stdout2} ${migsock} diff --git a/scripts/runtime.bash b/scripts/runtime.bash index 9c1bc3b..b383816 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=1 $cmdline" + fi if [ "$verbose" = "yes" ]; then echo $cmdline fi