提交 8fe941f7 编写于 作者: J John Snow

libqtest: add qmp_eventwait

Allow the user to poll until a desired interrupt occurs.
Signed-off-by: NJohn Snow <jsnow@redhat.com>
Message-id: 1426018503-821-4-git-send-email-jsnow@redhat.com
上级 debaaa11
......@@ -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' }";
......
......@@ -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");
......
......@@ -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.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册