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
This commit is contained in:
John Snow 2015-04-28 15:27:51 -04:00
parent debaaa114a
commit 8fe941f749
3 changed files with 37 additions and 10 deletions

View File

@ -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' }";

View File

@ -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");

View File

@ -91,6 +91,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.
@ -428,6 +437,17 @@ static inline QDict *qmp_receive(void)
return qtest_qmp_receive(global_qtest);
}
/**
* 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.