From 5e34005571af53b73e4a10cb2c6e0712cf6b8d2c Mon Sep 17 00:00:00 2001 From: Maxim Levitsky Date: Tue, 6 Oct 2020 08:59:32 -0400 Subject: [PATCH] qtest: remove qtest_qmp_receive_success The purpose of qtest_qmp_receive_success was mostly to process events that arrived between the issueing of a command and the "return" line from QMP. This is now handled by the buffering of events that libqtest performs automatically. Signed-off-by: Paolo Bonzini Signed-off-by: Maxim Levitsky --- tests/qtest/libqos/libqtest.h | 17 ------------- tests/qtest/libqtest.c | 53 ++++------------------------------------- tests/qtest/migration-helpers.c | 25 +++++++++++++++---- 3 files changed, 25 insertions(+), 70 deletions(-) diff --git a/tests/qtest/libqos/libqtest.h b/tests/qtest/libqos/libqtest.h index b7a776068c..5c959f1853 100644 --- a/tests/qtest/libqos/libqtest.h +++ b/tests/qtest/libqos/libqtest.h @@ -241,23 +241,6 @@ QDict *qtest_qmp_eventwait_ref(QTestState *s, const char *event); QDict *qtest_qmp_event_ref(QTestState *s, const char *event); /** - * qtest_qmp_receive_success: - * @s: #QTestState instance to operate on - * @event_cb: Event callback - * @opaque: Argument for @event_cb - * - * Poll QMP messages until a command success response is received. - * If @event_cb, call it for each event received, passing @opaque, - * the event's name and data. - * Return the success response's "return" member. - */ -QDict *qtest_qmp_receive_success(QTestState *s, - void (*event_cb)(void *opaque, - const char *name, - QDict *data), - void *opaque); - -/** * qtest_hmp: * @s: #QTestState instance to operate on. * @fmt: HMP command to send to QEMU, formats arguments like sprintf(). diff --git a/tests/qtest/libqtest.c b/tests/qtest/libqtest.c index d4c49a52ff..baac667b8d 100644 --- a/tests/qtest/libqtest.c +++ b/tests/qtest/libqtest.c @@ -1291,35 +1291,6 @@ void qtest_cb_for_every_machine(void (*cb)(const char *machine), qobject_unref(response); } -QDict *qtest_qmp_receive_success(QTestState *s, - void (*event_cb)(void *opaque, - const char *event, - QDict *data), - void *opaque) -{ - QDict *response, *ret, *data; - const char *event; - - for (;;) { - response = qtest_qmp_receive_dict(s); - g_assert(!qdict_haskey(response, "error")); - ret = qdict_get_qdict(response, "return"); - if (ret) { - break; - } - event = qdict_get_str(response, "event"); - data = qdict_get_qdict(response, "data"); - if (event_cb) { - event_cb(opaque, event, data); - } - qobject_unref(response); - } - - qobject_ref(ret); - qobject_unref(response); - return ret; -} - /* * Generic hot-plugging test via the device_add QMP commands. */ @@ -1355,13 +1326,6 @@ void qtest_qmp_device_add(QTestState *qts, const char *driver, const char *id, qobject_unref(args); } -static void device_deleted_cb(void *opaque, const char *name, QDict *data) -{ - bool *got_event = opaque; - - g_assert_cmpstr(name, ==, "DEVICE_DELETED"); - *got_event = true; -} /* * Generic hot-unplugging test via the device_del QMP command. @@ -1378,24 +1342,17 @@ static void device_deleted_cb(void *opaque, const char *name, QDict *data) * and this one: * * {"return": {}} - * - * But the order of arrival may vary - so we've got to detect both. */ void qtest_qmp_device_del(QTestState *qts, const char *id) { - bool got_event = false; QDict *rsp; - qtest_qmp_send(qts, "{'execute': 'device_del', 'arguments': {'id': %s}}", - id); - rsp = qtest_qmp_receive_success(qts, device_deleted_cb, &got_event); + rsp = qtest_qmp(qts, "{'execute': 'device_del', 'arguments': {'id': %s}}", + id); + + g_assert(qdict_haskey(rsp, "return")); qobject_unref(rsp); - if (!got_event) { - rsp = qtest_qmp_receive_dict(qts); - g_assert_cmpstr(qdict_get_try_str(rsp, "event"), - ==, "DEVICE_DELETED"); - qobject_unref(rsp); - } + qtest_qmp_eventwait(qts, "DEVICE_DELETED"); } bool qmp_rsp_is_err(QDict *rsp) diff --git a/tests/qtest/migration-helpers.c b/tests/qtest/migration-helpers.c index 516093b39a..b799dbafb7 100644 --- a/tests/qtest/migration-helpers.c +++ b/tests/qtest/migration-helpers.c @@ -17,10 +17,12 @@ bool got_stop; -static void stop_cb(void *opaque, const char *name, QDict *data) +static void check_stop_event(QTestState *who) { - if (!strcmp(name, "STOP")) { + QDict *event = qtest_qmp_event_ref(who, "STOP"); + if (event) { got_stop = true; + qobject_unref(event); } } @@ -30,12 +32,19 @@ static void stop_cb(void *opaque, const char *name, QDict *data) QDict *wait_command_fd(QTestState *who, int fd, const char *command, ...) { va_list ap; + QDict *resp; va_start(ap, command); qtest_qmp_vsend_fds(who, &fd, 1, command, ap); va_end(ap); - return qtest_qmp_receive_success(who, stop_cb, NULL); + resp = qtest_qmp_receive(who); + check_stop_event(who); + + g_assert(!qdict_haskey(resp, "error")); + g_assert(qdict_haskey(resp, "return")); + + return qdict_get_qdict(resp, "return"); } /* @@ -44,12 +53,18 @@ QDict *wait_command_fd(QTestState *who, int fd, const char *command, ...) QDict *wait_command(QTestState *who, const char *command, ...) { va_list ap; + QDict *resp; va_start(ap, command); - qtest_qmp_vsend(who, command, ap); + resp = qtest_vqmp(who, command, ap); va_end(ap); - return qtest_qmp_receive_success(who, stop_cb, NULL); + check_stop_event(who); + + g_assert(!qdict_haskey(resp, "error")); + g_assert(qdict_haskey(resp, "return")); + + return qdict_get_qdict(resp, "return"); } /* -- 2.11.4.GIT