[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 24/39] qtest: remove qtest_qmp_receive_success
From: |
Paolo Bonzini |
Subject: |
[PULL 24/39] qtest: remove qtest_qmp_receive_success |
Date: |
Sat, 10 Oct 2020 03:57:24 -0400 |
From: Maxim Levitsky <mlevitsk@redhat.com>
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>
---
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 a2e3961792..64bb1cd9eb 100644
--- a/tests/qtest/libqos/libqtest.h
+++ b/tests/qtest/libqos/libqtest.h
@@ -240,23 +240,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.
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.26.2
- [PULL 13/39] qom: fix objects with improper parent type, (continued)
- [PULL 13/39] qom: fix objects with improper parent type, Paolo Bonzini, 2020/10/10
- [PULL 19/39] docs/devel: update instruction on how to add new unit tests, Paolo Bonzini, 2020/10/10
- [PULL 14/39] configure: fix performance regression due to PIC objects, Paolo Bonzini, 2020/10/10
- [PULL 17/39] docs/devel/qtest: Include libqtest API reference, Paolo Bonzini, 2020/10/10
- [PULL 12/39] exec: split out non-softmmu-specific parts, Paolo Bonzini, 2020/10/10
- [PULL 25/39] device-plug-test: use qtest_qmp to send the device_del command, Paolo Bonzini, 2020/10/10
- [PULL 22/39] qtest: rename qtest_qmp_receive to qtest_qmp_receive_dict, Paolo Bonzini, 2020/10/10
- [PULL 20/39] build-sys: fix git version from -version, Paolo Bonzini, 2020/10/10
- [PULL 18/39] qtest: unify extra_qtest_srcs and extra_qtest_deps, Paolo Bonzini, 2020/10/10
- [PULL 26/39] qtest: switch users back to qtest_qmp_receive, Paolo Bonzini, 2020/10/10
- [PULL 24/39] qtest: remove qtest_qmp_receive_success,
Paolo Bonzini <=
- [PULL 29/39] qdev: add "check if address free" callback for buses, Paolo Bonzini, 2020/10/10
- [PULL 23/39] qtest: Reintroduce qtest_qmp_receive, Paolo Bonzini, 2020/10/10
- [PULL 21/39] meson.build: Re-enable KVM support for MIPS, Paolo Bonzini, 2020/10/10
- [PULL 30/39] scsi/scsi_bus: switch search direction in scsi_device_find, Paolo Bonzini, 2020/10/10
- [PULL 27/39] qtest: check that drives are really appearing and disappearing, Paolo Bonzini, 2020/10/10
- [PULL 28/39] qemu-iotests, qtest: rewrite test 067 as a qtest, Paolo Bonzini, 2020/10/10
- [PULL 36/39] scsi/scsi_bus: Add scsi_device_get, Paolo Bonzini, 2020/10/10
- [PULL 35/39] scsi/scsi-bus: scsi_device_find: don't return unrealized devices, Paolo Bonzini, 2020/10/10
- [PULL 37/39] virtio-scsi: use scsi_device_get, Paolo Bonzini, 2020/10/10
- [PULL 32/39] device-core: use RCU for list of children of a bus, Paolo Bonzini, 2020/10/10