summaryrefslogtreecommitdiff
path: root/tests/libqos/usb.c
diff options
context:
space:
mode:
authorIgor Mammedov <imammedo@redhat.com>2014-09-26 09:28:14 +0000
committerAndreas Färber <afaerber@suse.de>2014-10-15 05:03:13 +0200
commitb3937683147481fba3406a01da4ce15f0b2deb21 (patch)
tree6b03dc1a4e4d72397e4f8757a813a5459beabecd /tests/libqos/usb.c
parentfbd942c993001f5276fcd1f25a56405fdd968472 (diff)
downloadqemu-b3937683147481fba3406a01da4ce15f0b2deb21.tar.gz
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/usb.c')
-rw-r--r--tests/libqos/usb.c34
1 files changed, 34 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"));
+}