On 09/13/2017 01:40 PM, Thomas Huth wrote: > A lot of tests provide code for adding and removing a device via the > device_add and device_del QMP commands. Maintaining this code in so many > places is cumbersome and error-prone (some of the code parts check the > responses for device deletion in an incorrect way, for example, we've got > to deal with both, error code and DEVICE_DEL event here). So let's provide > some proper generic functions for adding and removing a device instead. > > The code for correctly unplugging a device has been taken from a patch > from Peter Xu. > > Signed-off-by: Thomas Huth <[email protected]> > ---
> + */
> +void qtest_qmp_device_del(const char *id)
> +{
> + QDict *response1, *response2, *event = NULL;
> + char *cmd;
> +
> + cmd = g_strdup_printf("{'execute': 'device_del',"
> + " 'arguments': { 'id': '%s' }}", id);
> + response1 = qmp(cmd);
> + g_free(cmd);
> + g_assert(response1);
> + g_assert(!qdict_haskey(response1, "error"));
> +
> + response2 = qmp("");
Hmm, this new use of qmp("") means I get to rebase the efforts to remove
the empty qmp command usage from the testsuite efforts. We really want
to have two low-level functions (one to send, one to receive), and then
have qmp() be the combination of both in a row; we have qmp_async() for
the send, and only qtest_receive() for the receive, so I'll have to
revive my work on unifying things...
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3266
Virtualization: qemu.org | libvirt.org
signature.asc
Description: OpenPGP digital signature
