aboutsummaryrefslogtreecommitdiff
path: root/tests/libqos
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
parentfbd942c993001f5276fcd1f25a56405fdd968472 (diff)
downloadqemu-b3937683147481fba3406a01da4ce15f0b2deb21.zip
qemu-b3937683147481fba3406a01da4ce15f0b2deb21.tar.gz
qemu-b3937683147481fba3406a01da4ce15f0b2deb21.tar.bz2
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.c34
-rw-r--r--tests/libqos/usb.h3
2 files changed, 37 insertions, 0 deletions
diff --git a/tests/libqos/usb.c b/tests/libqos/usb.c
index 54865b4..41d89b8 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 7fcd669..8fe5687 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