diff options
author | Thomas Huth <thuth@redhat.com> | 2017-08-15 08:58:54 +0200 |
---|---|---|
committer | Thomas Huth <thuth@redhat.com> | 2017-09-15 09:05:18 +0200 |
commit | acd80015fbe28f4f513e036ad1db2a76738d1f53 (patch) | |
tree | eb1db46ee8961cffdda43c21958bb4540a65c2d8 /tests/virtio-scsi-test.c | |
parent | 3dabde1128b671f36ac6cb36b97b273139964420 (diff) |
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>
Diffstat (limited to 'tests/virtio-scsi-test.c')
-rw-r--r-- | tests/virtio-scsi-test.c | 24 |
1 files changed, 2 insertions, 22 deletions
diff --git a/tests/virtio-scsi-test.c b/tests/virtio-scsi-test.c index 87a3b6e81a..d1485128bd 100644 --- a/tests/virtio-scsi-test.c +++ b/tests/virtio-scsi-test.c @@ -192,32 +192,12 @@ static void pci_nop(void) static void hotplug(void) { - QDict *response; QOSState *qs; qs = qvirtio_scsi_start( "-drive id=drv1,if=none,file=null-co://,format=raw"); - response = qmp("{\"execute\": \"device_add\"," - " \"arguments\": {" - " \"driver\": \"scsi-hd\"," - " \"id\": \"scsi-hd\"," - " \"drive\": \"drv1\"" - "}}"); - - g_assert(response); - g_assert(!qdict_haskey(response, "error")); - QDECREF(response); - - response = qmp("{\"execute\": \"device_del\"," - " \"arguments\": {" - " \"id\": \"scsi-hd\"" - "}}"); - - g_assert(response); - g_assert(!qdict_haskey(response, "error")); - g_assert(qdict_haskey(response, "event")); - g_assert(!strcmp(qdict_get_str(response, "event"), "DEVICE_DELETED")); - QDECREF(response); + qtest_qmp_device_add("scsi-hd", "scsihd", "'drive': 'drv1'"); + qtest_qmp_device_del("scsihd"); qvirtio_scsi_stop(qs); } |