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 <pbonzini@redhat.com> Signed-off-by: Maxim Levitsky <mlevitsk@redhat.com>
This commit is contained in:
parent
c22045bfe6
commit
5e34005571
@ -240,23 +240,6 @@ QDict *qtest_qmp_eventwait_ref(QTestState *s, const char *event);
|
|||||||
*/
|
*/
|
||||||
QDict *qtest_qmp_event_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:
|
* qtest_hmp:
|
||||||
* @s: #QTestState instance to operate on.
|
* @s: #QTestState instance to operate on.
|
||||||
|
@ -1291,35 +1291,6 @@ void qtest_cb_for_every_machine(void (*cb)(const char *machine),
|
|||||||
qobject_unref(response);
|
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.
|
* 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);
|
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.
|
* 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:
|
* and this one:
|
||||||
*
|
*
|
||||||
* {"return": {}}
|
* {"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)
|
void qtest_qmp_device_del(QTestState *qts, const char *id)
|
||||||
{
|
{
|
||||||
bool got_event = false;
|
|
||||||
QDict *rsp;
|
QDict *rsp;
|
||||||
|
|
||||||
qtest_qmp_send(qts, "{'execute': 'device_del', 'arguments': {'id': %s}}",
|
rsp = qtest_qmp(qts, "{'execute': 'device_del', 'arguments': {'id': %s}}",
|
||||||
id);
|
id);
|
||||||
rsp = qtest_qmp_receive_success(qts, device_deleted_cb, &got_event);
|
|
||||||
|
g_assert(qdict_haskey(rsp, "return"));
|
||||||
qobject_unref(rsp);
|
qobject_unref(rsp);
|
||||||
if (!got_event) {
|
qtest_qmp_eventwait(qts, "DEVICE_DELETED");
|
||||||
rsp = qtest_qmp_receive_dict(qts);
|
|
||||||
g_assert_cmpstr(qdict_get_try_str(rsp, "event"),
|
|
||||||
==, "DEVICE_DELETED");
|
|
||||||
qobject_unref(rsp);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool qmp_rsp_is_err(QDict *rsp)
|
bool qmp_rsp_is_err(QDict *rsp)
|
||||||
|
@ -17,10 +17,12 @@
|
|||||||
|
|
||||||
bool got_stop;
|
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;
|
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, ...)
|
QDict *wait_command_fd(QTestState *who, int fd, const char *command, ...)
|
||||||
{
|
{
|
||||||
va_list ap;
|
va_list ap;
|
||||||
|
QDict *resp;
|
||||||
|
|
||||||
va_start(ap, command);
|
va_start(ap, command);
|
||||||
qtest_qmp_vsend_fds(who, &fd, 1, command, ap);
|
qtest_qmp_vsend_fds(who, &fd, 1, command, ap);
|
||||||
va_end(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, ...)
|
QDict *wait_command(QTestState *who, const char *command, ...)
|
||||||
{
|
{
|
||||||
va_list ap;
|
va_list ap;
|
||||||
|
QDict *resp;
|
||||||
|
|
||||||
va_start(ap, command);
|
va_start(ap, command);
|
||||||
qtest_qmp_vsend(who, command, ap);
|
resp = qtest_vqmp(who, command, ap);
|
||||||
va_end(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");
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Loading…
Reference in New Issue
Block a user