qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Dr. David Alan Gilbert (git)" <dgilbert@redhat.com>
To: qemu-devel@nongnu.org
Cc: pbonzini@redhat.com, thuth@redhat.com
Subject: [Qemu-devel] [PULL 2/4] libqtest: Ignore QMP events when parsing the response for HMP commands
Date: Mon, 24 Apr 2017 16:32:42 +0100	[thread overview]
Message-ID: <20170424153244.2600-3-dgilbert@redhat.com> (raw)
In-Reply-To: <20170424153244.2600-1-dgilbert@redhat.com>

From: Thomas Huth <thuth@redhat.com>

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 <thuth@redhat.com>
Message-Id: <1490860207-8302-2-git-send-email-thuth@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
  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.
  */
-- 
2.12.2

  parent reply	other threads:[~2017-04-24 15:32 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-24 15:32 [Qemu-devel] [PULL 0/4] hmp queue Dr. David Alan Gilbert (git)
2017-04-24 15:32 ` [Qemu-devel] [PULL 1/4] hmp: gpa2hva and gpa2hpa hostaddr command Dr. David Alan Gilbert (git)
2017-04-24 15:32 ` Dr. David Alan Gilbert (git) [this message]
2017-04-24 15:32 ` [Qemu-devel] [PULL 3/4] libqtest: Add a generic function to run a callback function for every machine Dr. David Alan Gilbert (git)
2017-04-24 15:32 ` [Qemu-devel] [PULL 4/4] tests: Add a tester for HMP commands Dr. David Alan Gilbert (git)
2017-04-24 16:50 ` [Qemu-devel] [PULL 0/4] hmp queue Peter Maydell
2017-04-24 16:57   ` Dr. David Alan Gilbert
2017-04-25  3:32     ` Thomas Huth
2017-04-25  5:16       ` [Qemu-devel] [PATCH v3 3/3] tests: Add a tester for HMP commands Thomas Huth
2017-04-25  9:28         ` Dr. David Alan Gilbert
2017-04-25 13:22         ` Eric Blake
2017-04-27  4:50           ` Thomas Huth
  -- strict thread matches above, loose matches on Subject: below --
2017-04-25 10:41 [Qemu-devel] [PULL 0/4] hmp queue Dr. David Alan Gilbert (git)
2017-04-25 10:41 ` [Qemu-devel] [PULL 2/4] libqtest: Ignore QMP events when parsing the response for HMP commands Dr. David Alan Gilbert (git)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170424153244.2600-3-dgilbert@redhat.com \
    --to=dgilbert@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=thuth@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).