1 /*
2  * QTest testcase for USB xHCI controller
3  *
4  * Copyright (c) 2014 HUAWEI TECHNOLOGIES CO., LTD.
5  *
6  * This work is licensed under the terms of the GNU GPL, version 2 or later.
7  * See the COPYING file in the top-level directory.
8  */
9 
10 #include "qemu/osdep.h"
11 #include "libqtest-single.h"
12 #include "libqos/usb.h"
13 
test_xhci_hotplug(void)14 static void test_xhci_hotplug(void)
15 {
16     usb_test_hotplug(global_qtest, "xhci", "1", NULL);
17 }
18 
test_usb_uas_hotplug(void)19 static void test_usb_uas_hotplug(void)
20 {
21     QTestState *qts = global_qtest;
22 
23     qtest_qmp_device_add(qts, "usb-uas", "uas", "{}");
24     qtest_qmp_device_add(qts, "scsi-hd", "scsihd", "{'drive': 'drive0'}");
25 
26     /* TODO:
27         UAS HBA driver in libqos, to check that
28         added disk is visible after BUS rescan
29     */
30 
31     qtest_qmp_device_del(qts, "scsihd");
32     qtest_qmp_device_del(qts, "uas");
33 }
34 
test_usb_ccid_hotplug(void)35 static void test_usb_ccid_hotplug(void)
36 {
37     QTestState *qts = global_qtest;
38 
39     qtest_qmp_device_add(qts, "usb-ccid", "ccid", "{}");
40     qtest_qmp_device_del(qts, "ccid");
41     /* check the device can be added again */
42     qtest_qmp_device_add(qts, "usb-ccid", "ccid", "{}");
43     qtest_qmp_device_del(qts, "ccid");
44 }
45 
main(int argc,char ** argv)46 int main(int argc, char **argv)
47 {
48     int ret;
49 
50     g_test_init(&argc, &argv, NULL);
51 
52     qtest_add_func("/xhci/pci/hotplug", test_xhci_hotplug);
53     if (qtest_has_device("usb-uas")) {
54         qtest_add_func("/xhci/pci/hotplug/usb-uas", test_usb_uas_hotplug);
55     }
56     if (qtest_has_device("usb-ccid")) {
57         qtest_add_func("/xhci/pci/hotplug/usb-ccid", test_usb_ccid_hotplug);
58     }
59 
60     qtest_start("-device nec-usb-xhci,id=xhci"
61                 " -drive id=drive0,if=none,file=null-co://,"
62                 "file.read-zeroes=on,format=raw");
63     ret = g_test_run();
64     qtest_end();
65 
66     return ret;
67 }
68