diff options
author | Maxim Levitsky <mlevitsk@redhat.com> | 2020-10-06 08:59:32 -0400 |
---|---|---|
committer | wanchao-xu <wanchao.xu@samsung.com> | 2024-01-09 19:53:24 +0800 |
commit | d231a08b3bf680b7dd1a9f278765c83a95ede02e (patch) | |
tree | 21da3577539a15ed05e32d13cc30b2dd2e0df3ec | |
parent | 62682ae2e4d7b47b3eaf53c70fb81cca14affe62 (diff) | |
download | qemu-arm-static-d231a08b3bf680b7dd1a9f278765c83a95ede02e.tar.gz qemu-arm-static-d231a08b3bf680b7dd1a9f278765c83a95ede02e.tar.bz2 qemu-arm-static-d231a08b3bf680b7dd1a9f278765c83a95ede02e.zip |
qtest: remove qtest_qmp_receive_success
Git-commit: 5e34005571af53b73e4a10cb2c6e0712cf6b8d2c
References: bsc#1184574
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 <pbonzini@redhat.com>
Signed-off-by: Maxim Levitsky <mlevitsk@redhat.com>
Signed-off-by: Lin Ma <lma@suse.com>
-rw-r--r-- | tests/libqtest.c | 53 | ||||
-rw-r--r-- | tests/libqtest.h | 17 | ||||
-rw-r--r-- | tests/migration-helpers.c | 25 |
3 files changed, 25 insertions, 70 deletions
diff --git a/tests/libqtest.c b/tests/libqtest.c index 80476fef3..e9bca67b5 100644 --- a/tests/libqtest.c +++ b/tests/libqtest.c @@ -1259,35 +1259,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. */ @@ -1323,13 +1294,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. @@ -1346,24 +1310,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/libqtest.h b/tests/libqtest.h index a8d0aea4d..2ac3c107c 100644 --- a/tests/libqtest.h +++ b/tests/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/migration-helpers.c b/tests/migration-helpers.c index 516093b39..b799dbafb 100644 --- a/tests/migration-helpers.c +++ b/tests/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"); } /* |