From mboxrd@z Thu Jan 1 00:00:00 1970 From: Andrew Jones Subject: [PATCH kvm-unit-tests 2/8] scripts/arch-run: run_migration improvements Date: Wed, 7 Feb 2018 20:03:28 +0100 Message-ID: <20180207190334.16516-3-drjones@redhat.com> References: <20180207190334.16516-1-drjones@redhat.com> Cc: pbonzini@redhat.com, rkrcmar@redhat.com To: kvm@vger.kernel.org Return-path: Received: from mx3-rdu2.redhat.com ([66.187.233.73]:38980 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754348AbeBGTDi (ORCPT ); Wed, 7 Feb 2018 14:03:38 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5F96040363AD for ; Wed, 7 Feb 2018 19:03:38 +0000 (UTC) In-Reply-To: <20180207190334.16516-1-drjones@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: - Don't assume the first argument is QEMU, it's actually most likely 'timeout'. - Don't assume run_migration is called from a subshell (even though it is) and use return and a RETURN trap handler instead (and make this change in env_generate_errata() as well). - Cleanup all child processes on termination - Make sure the exit code of the unit test is propagated. Signed-off-by: Andrew Jones --- scripts/arch-run.bash | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/scripts/arch-run.bash b/scripts/arch-run.bash index 1e41eb7bd4ab..565e299295db 100644 --- a/scripts/arch-run.bash +++ b/scripts/arch-run.bash @@ -108,12 +108,9 @@ run_migration () { if ! command -v nc >/dev/null 2>&1; then echo "${FUNCNAME[0]} needs nc (netcat)" >&2 - exit 2 + return 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` @@ -121,13 +118,15 @@ run_migration () qmpout1=/dev/null qmpout2=/dev/null - trap 'rm -f ${migout1} ${migsock} ${qmp1} ${qmp2}' EXIT + trap 'kill 0; exit 2' INT TERM + trap 'rm -f ${migout1} ${migsock} ${qmp1} ${qmp2}' RETURN EXIT - $qemu "$@" -chardev socket,id=mon1,path=${qmp1},server,nowait \ - -mon chardev=mon1,mode=control | tee ${migout1} & + eval "$@" -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} & + eval "$@" -chardev socket,id=mon2,path=${qmp2},server,nowait \ + -mon chardev=mon2,mode=control -incoming unix:${migsock} & + incoming_pid=`jobs -l %+ | awk '{print$2}'` # The test must prompt the user to migrate, so wait for the "migrate" keyword while ! grep -q -i "migrate" < ${migout1} ; do @@ -145,14 +144,17 @@ run_migration () echo "ERROR: Migration failed." >&2 qmp ${qmp1} '"quit"'> ${qmpout1} 2>/dev/null qmp ${qmp2} '"quit"'> ${qmpout2} 2>/dev/null - exit 2 + return 2 fi done qmp ${qmp1} '"quit"'> ${qmpout1} 2>/dev/null qmp ${qmp2} '"inject-nmi"'> ${qmpout2} + wait $incoming_pid + ret=$? wait + return $ret } migration_cmd () @@ -254,7 +256,7 @@ env_generate_errata () if ! [[ $v =~ ^[0-9]+$ ]] || ! [[ $p =~ ^[0-9]+$ ]]; then echo "Bad minimum kernel version in $ERRATATXT, $minver" - exit 2 + return 2 fi ! [[ $s =~ ^[0-9]+$ ]] && unset $s ! [[ $x =~ ^[0-9]+$ ]] && unset $x -- 2.13.6