mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-02 07:13:54 -06:00
tests: Introduce generic device hot-plug/hot-unplug functions
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. Reviewed-by: Peter Xu <peterx@redhat.com> Tested-by: Peter Xu <peterx@redhat.com> Signed-off-by: Thomas Huth <thuth@redhat.com>
This commit is contained in:
parent
3dabde1128
commit
acd80015fb
8 changed files with 112 additions and 155 deletions
|
@ -394,21 +394,6 @@ QPCIBar qpci_legacy_iomap(QPCIDevice *dev, uint16_t addr)
|
|||
void qpci_plug_device_test(const char *driver, const char *id,
|
||||
uint8_t slot, const char *opts)
|
||||
{
|
||||
QDict *response;
|
||||
char *cmd;
|
||||
|
||||
cmd = g_strdup_printf("{'execute': 'device_add',"
|
||||
" 'arguments': {"
|
||||
" 'driver': '%s',"
|
||||
" 'addr': '%d',"
|
||||
" %s%s"
|
||||
" 'id': '%s'"
|
||||
"}}", driver, slot,
|
||||
opts ? opts : "", opts ? "," : "",
|
||||
id);
|
||||
response = qmp(cmd);
|
||||
g_free(cmd);
|
||||
g_assert(response);
|
||||
g_assert(!qdict_haskey(response, "error"));
|
||||
QDECREF(response);
|
||||
qtest_qmp_device_add(driver, id, "'addr': '%d'%s%s", slot,
|
||||
opts ? ", " : "", opts ? opts : "");
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue