From 8fe941f749b2db3735abade1c298552de4eab496 Mon Sep 17 00:00:00 2001 From: John Snow Date: Tue, 28 Apr 2015 15:27:51 -0400 Subject: libqtest: add qmp_eventwait Allow the user to poll until a desired interrupt occurs. Signed-off-by: John Snow Message-id: 1426018503-821-4-git-send-email-jsnow@redhat.com --- tests/libqtest.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'tests/libqtest.c') diff --git a/tests/libqtest.c b/tests/libqtest.c index 12d65bd1e6..e2d01b47a2 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"); -- cgit v1.2.3 From ba4ed39346c1bdbfefd1d781b39009f90822b956 Mon Sep 17 00:00:00 2001 From: John Snow Date: Tue, 28 Apr 2015 15:27:51 -0400 Subject: libqtest: add qmp_async Add qmp_async, which lets us send QMP commands asynchronously. This is useful when we want to send commands that will trigger event responses, but we don't know in what order to expect them. Sometimes the event responses may arrive even before the command confirmation will show up, so it is convenient to leave the responses in the stream. Signed-off-by: John Snow Message-id: 1426018503-821-5-git-send-email-jsnow@redhat.com --- tests/libqtest.c | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) (limited to 'tests/libqtest.c') diff --git a/tests/libqtest.c b/tests/libqtest.c index e2d01b47a2..659a3c7c63 100644 --- a/tests/libqtest.c +++ b/tests/libqtest.c @@ -388,7 +388,12 @@ QDict *qtest_qmp_receive(QTestState *s) return qmp.response; } -QDict *qtest_qmpv(QTestState *s, const char *fmt, va_list ap) +/** + * Allow users to send a message without waiting for the reply, + * in the case that they choose to discard all replies up until + * a particular EVENT is received. + */ +void qtest_async_qmpv(QTestState *s, const char *fmt, va_list ap) { va_list ap_copy; QObject *qobj; @@ -417,6 +422,11 @@ QDict *qtest_qmpv(QTestState *s, const char *fmt, va_list ap) QDECREF(qstr); qobject_decref(qobj); } +} + +QDict *qtest_qmpv(QTestState *s, const char *fmt, va_list ap) +{ + qtest_async_qmpv(s, fmt, ap); /* Receive reply */ return qtest_qmp_receive(s); @@ -433,6 +443,15 @@ QDict *qtest_qmp(QTestState *s, const char *fmt, ...) return response; } +void qtest_async_qmp(QTestState *s, const char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + qtest_async_qmpv(s, fmt, ap); + va_end(ap); +} + void qtest_qmpv_discard_response(QTestState *s, const char *fmt, va_list ap) { QDict *response = qtest_qmpv(s, fmt, ap); @@ -711,6 +730,15 @@ QDict *qmp(const char *fmt, ...) return response; } +void qmp_async(const char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + qtest_async_qmpv(global_qtest, fmt, ap); + va_end(ap); +} + void qmp_discard_response(const char *fmt, ...) { va_list ap; -- cgit v1.2.3 From c8368674980b299604e3cfe9215c4105acefa516 Mon Sep 17 00:00:00 2001 From: Ed Maste Date: Tue, 28 Apr 2015 15:27:51 -0400 Subject: qtest: Add assertion that required environment variable is set Signed-off-by: Ed Maste Reviewed-by: John Snow Message-id: 1427911244-22565-1-git-send-email-emaste@freebsd.org Signed-off-by: John Snow --- tests/libqtest.c | 1 + 1 file changed, 1 insertion(+) (limited to 'tests/libqtest.c') diff --git a/tests/libqtest.c b/tests/libqtest.c index 659a3c7c63..a525dc532c 100644 --- a/tests/libqtest.c +++ b/tests/libqtest.c @@ -488,6 +488,7 @@ void qtest_qmp_eventwait(QTestState *s, const char *event) const char *qtest_get_arch(void) { const char *qemu = getenv("QTEST_QEMU_BINARY"); + g_assert(qemu != NULL); const char *end = strrchr(qemu, '/'); return end + strlen("/qemu-system-"); -- cgit v1.2.3