From: John Snow <jsnow@redhat.com>
To: qemu-block@nongnu.org
Cc: kwolf@redhat.com, marc.mari.barcelo@gmail.com,
qemu-devel@nongnu.org, stefanha@redhat.com, pbonzini@redhat.com,
John Snow <jsnow@redhat.com>
Subject: [Qemu-devel] [PATCH v2 3/6] libqtest: add qmp_eventwait
Date: Tue, 10 Mar 2015 16:15:00 -0400 [thread overview]
Message-ID: <1426018503-821-4-git-send-email-jsnow@redhat.com> (raw)
In-Reply-To: <1426018503-821-1-git-send-email-jsnow@redhat.com>
Allow the user to poll until a desired interrupt occurs.
Signed-off-by: John Snow <jsnow@redhat.com>
---
tests/ide-test.c | 11 +----------
tests/libqtest.c | 16 ++++++++++++++++
tests/libqtest.h | 20 ++++++++++++++++++++
3 files changed, 37 insertions(+), 10 deletions(-)
diff --git a/tests/ide-test.c b/tests/ide-test.c
index b28a302..1dae84f 100644
--- a/tests/ide-test.c
+++ b/tests/ide-test.c
@@ -520,7 +520,6 @@ static void test_retry_flush(const char *machine)
{
uint8_t data;
const char *s;
- QDict *response;
prepare_blkdebug_script(debug_path, "flush_to_disk");
@@ -539,15 +538,7 @@ static void test_retry_flush(const char *machine)
assert_bit_set(data, BSY | DRDY);
assert_bit_clear(data, DF | ERR | DRQ);
- for (;; response = NULL) {
- response = qmp_receive();
- if ((qdict_haskey(response, "event")) &&
- (strcmp(qdict_get_str(response, "event"), "STOP") == 0)) {
- QDECREF(response);
- break;
- }
- QDECREF(response);
- }
+ qmp_eventwait("STOP");
/* Complete the command */
s = "{'execute':'cont' }";
diff --git a/tests/libqtest.c b/tests/libqtest.c
index 9a92aa7..a3ee8ae 100644
--- a/tests/libqtest.c
+++ b/tests/libqtest.c
@@ -450,6 +450,22 @@ void qtest_qmp_discard_response(QTestState *s, const char *fmt, ...)
QDECREF(response);
}
+void qtest_qmp_eventwait(QTestState *s, const char *event)
+{
+ QDict *response;
+
+ for (;;) {
+ response = qtest_qmp_receive(s);
+ if ((qdict_haskey(response, "event")) &&
+ (strcmp(qdict_get_str(response, "event"), event) == 0)) {
+ QDECREF(response);
+ break;
+ }
+ QDECREF(response);
+ }
+}
+
+
const char *qtest_get_arch(void)
{
const char *qemu = getenv("QTEST_QEMU_BINARY");
diff --git a/tests/libqtest.h b/tests/libqtest.h
index e7413d5..2aa2e6f 100644
--- a/tests/libqtest.h
+++ b/tests/libqtest.h
@@ -92,6 +92,15 @@ QDict *qtest_qmpv(QTestState *s, const char *fmt, va_list ap);
QDict *qtest_qmp_receive(QTestState *s);
/**
+ * qtest_qmp_eventwait:
+ * @s: #QTestState instance to operate on.
+ * @s: #event event to wait for.
+ *
+ * Continuosly polls for QMP responses until it receives the desired event.
+ */
+void qtest_qmp_eventwait(QTestState *s, const char *event);
+
+/**
* qtest_get_irq:
* @s: #QTestState instance to operate on.
* @num: Interrupt to observe.
@@ -397,6 +406,17 @@ static inline QDict *qmp_receive(void)
}
/**
+ * qmp_eventwait:
+ * @s: #event event to wait for.
+ *
+ * Continuosly polls for QMP responses until it receives the desired event.
+ */
+static inline void qmp_eventwait(const char *event)
+{
+ return qtest_qmp_eventwait(global_qtest, event);
+}
+
+/**
* get_irq:
* @num: Interrupt to observe.
*
--
1.9.3
next prev parent reply other threads:[~2015-03-10 20:15 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-03-10 20:14 [Qemu-devel] [PATCH v2 0/6] ahci: rerror/werror=stop resume tests John Snow
2015-03-10 20:14 ` [Qemu-devel] [PATCH v2 1/6] qtest/ahci: Add simple flush test John Snow
2015-03-10 20:14 ` [Qemu-devel] [PATCH v2 2/6] qtest/ahci: Allow override of default CLI options John Snow
2015-03-10 20:15 ` John Snow [this message]
2015-03-10 20:15 ` [Qemu-devel] [PATCH v2 4/6] libqtest: add qmp_async John Snow
2015-03-10 20:15 ` [Qemu-devel] [PATCH v2 5/6] libqos: add blkdebug_prepare_script John Snow
2015-03-10 20:15 ` [Qemu-devel] [PATCH v2 6/6] qtest/ahci: add flush retry test John Snow
2015-03-13 19:35 ` [Qemu-devel] [PATCH v2 0/6] ahci: rerror/werror=stop resume tests John Snow
2015-03-25 22:29 ` John Snow
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=1426018503-821-4-git-send-email-jsnow@redhat.com \
--to=jsnow@redhat.com \
--cc=kwolf@redhat.com \
--cc=marc.mari.barcelo@gmail.com \
--cc=pbonzini@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@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).