From patchwork Mon Apr 24 15:32:42 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Dr. David Alan Gilbert" X-Patchwork-Id: 754300 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3wBVjm3XGrz9s8Q for ; Tue, 25 Apr 2017 01:33:31 +1000 (AEST) Received: from localhost ([::1]:44674 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d2fzT-0007Fz-O4 for incoming@patchwork.ozlabs.org; Mon, 24 Apr 2017 11:33:27 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39363) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d2fys-0007EJ-PS for qemu-devel@nongnu.org; Mon, 24 Apr 2017 11:32:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d2fyr-00082m-So for qemu-devel@nongnu.org; Mon, 24 Apr 2017 11:32:50 -0400 Received: from mx1.redhat.com ([209.132.183.28]:50130) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d2fyr-00082V-Mq for qemu-devel@nongnu.org; Mon, 24 Apr 2017 11:32:49 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A8239C05975B for ; Mon, 24 Apr 2017 15:32:48 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com A8239C05975B Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=dgilbert@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com A8239C05975B Received: from dgilbert-t530.redhat.com (ovpn-117-235.ams2.redhat.com [10.36.117.235]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9D166179DA; Mon, 24 Apr 2017 15:32:47 +0000 (UTC) From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org Date: Mon, 24 Apr 2017 16:32:42 +0100 Message-Id: <20170424153244.2600-3-dgilbert@redhat.com> In-Reply-To: <20170424153244.2600-1-dgilbert@redhat.com> References: <20170424153244.2600-1-dgilbert@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Mon, 24 Apr 2017 15:32:48 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 2/4] libqtest: Ignore QMP events when parsing the response for HMP commands X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: pbonzini@redhat.com, thuth@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Thomas Huth When running certain HMP commands (like "device_del") via QMP, we can sometimes get a QMP event in the response first, so that the "g_assert(ret)" statement in qtest_hmp() triggers and the test fails. Fix this by ignoring such QMP events while looking for the real return value from QMP. Signed-off-by: Thomas Huth Message-Id: <1490860207-8302-2-git-send-email-thuth@redhat.com> Reviewed-by: Markus Armbruster Signed-off-by: Dr. David Alan Gilbert Added note to qtest_hmp/qtest_hmpv's header description to say it discards events --- tests/libqtest.c | 6 ++++++ tests/libqtest.h | 4 +++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/tests/libqtest.c b/tests/libqtest.c index 99b1195355..0b0bf1d460 100644 --- a/tests/libqtest.c +++ b/tests/libqtest.c @@ -588,6 +588,12 @@ char *qtest_hmpv(QTestState *s, const char *fmt, va_list ap) " 'arguments': {'command-line': %s}}", cmd); ret = g_strdup(qdict_get_try_str(resp, "return")); + while (ret == NULL && qdict_get_try_str(resp, "event")) { + /* Ignore asynchronous QMP events */ + QDECREF(resp); + resp = qtest_qmp_receive(s); + ret = g_strdup(qdict_get_try_str(resp, "return")); + } g_assert(ret); QDECREF(resp); g_free(cmd); diff --git a/tests/libqtest.h b/tests/libqtest.h index 2c9962d94f..ee237448da 100644 --- a/tests/libqtest.h +++ b/tests/libqtest.h @@ -132,11 +132,12 @@ void qtest_qmp_eventwait(QTestState *s, const char *event); QDict *qtest_qmp_eventwait_ref(QTestState *s, const char *event); /** - * qtest_hmpv: + * qtest_hmp: * @s: #QTestState instance to operate on. * @fmt...: HMP command to send to QEMU * * Send HMP command to QEMU via QMP's human-monitor-command. + * QMP events are discarded. * * Returns: the command's output. The caller should g_free() it. */ @@ -149,6 +150,7 @@ char *qtest_hmp(QTestState *s, const char *fmt, ...); * @ap: HMP command arguments * * Send HMP command to QEMU via QMP's human-monitor-command. + * QMP events are discarded. * * Returns: the command's output. The caller should g_free() it. */