diff options
author | Igor Mammedov <imammedo@redhat.com> | 2014-09-26 09:28:14 +0000 |
---|---|---|
committer | Andreas Färber <afaerber@suse.de> | 2014-10-15 05:03:13 +0200 |
commit | b3937683147481fba3406a01da4ce15f0b2deb21 (patch) | |
tree | 6b03dc1a4e4d72397e4f8757a813a5459beabecd /tests/libqos | |
parent | fbd942c993001f5276fcd1f25a56405fdd968472 (diff) | |
download | qemu-b3937683147481fba3406a01da4ce15f0b2deb21.zip |
tests: usb: Generic usb device hotplug
use usb-tablet as a hotplugged usb device.
Signed-off-by: Igor Mammedov <imammedo@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Andreas Färber <afaerber@suse.de>
Diffstat (limited to 'tests/libqos')
-rw-r--r-- | tests/libqos/usb.c | 34 | ||||
-rw-r--r-- | tests/libqos/usb.h | 3 |
2 files changed, 37 insertions, 0 deletions
diff --git a/tests/libqos/usb.c b/tests/libqos/usb.c index 54865b4759..41d89b8487 100644 --- a/tests/libqos/usb.c +++ b/tests/libqos/usb.c @@ -35,3 +35,37 @@ void uhci_port_test(struct qhc *hc, int port, uint16_t expect) g_assert((value & mask) == (expect & mask)); } + +void usb_test_hotplug(const char *hcd_id, const int port, + void (*port_check)(void)) +{ + QDict *response; + char *cmd; + + cmd = g_strdup_printf("{'execute': 'device_add'," + " 'arguments': {" + " 'driver': 'usb-tablet'," + " 'port': '%d'," + " 'bus': '%s.0'," + " 'id': 'usbdev%d'" + "}}", port, hcd_id, port); + response = qmp(cmd); + g_free(cmd); + g_assert(response); + g_assert(!qdict_haskey(response, "error")); + QDECREF(response); + + if (port_check) { + port_check(); + } + + cmd = g_strdup_printf("{'execute': 'device_del'," + " 'arguments': {" + " 'id': 'usbdev%d'" + "}}", port); + response = qmp(cmd); + g_free(cmd); + g_assert(response); + g_assert(qdict_haskey(response, "event")); + g_assert(!strcmp(qdict_get_str(response, "event"), "DEVICE_DELETED")); +} diff --git a/tests/libqos/usb.h b/tests/libqos/usb.h index 7fcd669ac4..8fe56872b7 100644 --- a/tests/libqos/usb.h +++ b/tests/libqos/usb.h @@ -11,4 +11,7 @@ struct qhc { void qusb_pci_init_one(QPCIBus *pcibus, struct qhc *hc, uint32_t devfn, int bar); void uhci_port_test(struct qhc *hc, int port, uint16_t expect); + +void usb_test_hotplug(const char *bus_name, const int port, + void (*port_check)(void)); #endif |