diff options
author | John Snow <jsnow@redhat.com> | 2015-04-28 15:27:51 -0400 |
---|---|---|
committer | John Snow <jsnow@redhat.com> | 2015-04-28 15:27:51 -0400 |
commit | 8fe941f749b2db3735abade1c298552de4eab496 (patch) | |
tree | b8542e58009e31de3534f84f347d56c21be5a469 | |
parent | debaaa114a8877a939533ba846e64168fb287b7b (diff) | |
download | hqemu-8fe941f749b2db3735abade1c298552de4eab496.zip hqemu-8fe941f749b2db3735abade1c298552de4eab496.tar.gz |
libqtest: add qmp_eventwait
Allow the user to poll until a desired interrupt occurs.
Signed-off-by: John Snow <jsnow@redhat.com>
Message-id: 1426018503-821-4-git-send-email-jsnow@redhat.com
-rw-r--r-- | tests/ide-test.c | 11 | ||||
-rw-r--r-- | tests/libqtest.c | 16 | ||||
-rw-r--r-- | 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 12d65bd..e2d01b4 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 03469b8..30009ca 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. @@ -429,6 +438,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. * |