Skip to content

Commit

Permalink
libqtest: add qmp_eventwait
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jnsnow committed Apr 28, 2015
1 parent debaaa1 commit 8fe941f
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 10 deletions.
11 changes: 1 addition & 10 deletions tests/ide-test.c
Expand Up @@ -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");

Expand All @@ -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' }";
Expand Down
16 changes: 16 additions & 0 deletions tests/libqtest.c
Expand Up @@ -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");
Expand Down
20 changes: 20 additions & 0 deletions tests/libqtest.h
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 8fe941f

Please sign in to comment.