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().
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.
*/
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.
* 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)
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);
}
}
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");
}
/*
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");
}
/*