xref: /qemu/tests/qtest/usb-hcd-xhci-test.c (revision 0084f6834a13aedaf4375fa34161c2f6ff0aeaa8)
125e89ec5SGonglei /*
225e89ec5SGonglei  * QTest testcase for USB xHCI controller
325e89ec5SGonglei  *
425e89ec5SGonglei  * Copyright (c) 2014 HUAWEI TECHNOLOGIES CO., LTD.
525e89ec5SGonglei  *
625e89ec5SGonglei  * This work is licensed under the terms of the GNU GPL, version 2 or later.
725e89ec5SGonglei  * See the COPYING file in the top-level directory.
825e89ec5SGonglei  */
925e89ec5SGonglei 
1025e89ec5SGonglei #include "qemu/osdep.h"
11dd210749SThomas Huth #include "libqtest-single.h"
12b3937683SIgor Mammedov #include "libqos/usb.h"
1325e89ec5SGonglei 
test_xhci_hotplug(void)14b3937683SIgor Mammedov static void test_xhci_hotplug(void)
15b3937683SIgor Mammedov {
16e5758de4SThomas Huth     usb_test_hotplug(global_qtest, "xhci", "1", NULL);
17b3937683SIgor Mammedov }
1825e89ec5SGonglei 
test_usb_uas_hotplug(void)1949cec385SIgor Mammedov static void test_usb_uas_hotplug(void)
2049cec385SIgor Mammedov {
21e5758de4SThomas Huth     QTestState *qts = global_qtest;
22e5758de4SThomas Huth 
23e5758de4SThomas Huth     qtest_qmp_device_add(qts, "usb-uas", "uas", "{}");
24e5758de4SThomas Huth     qtest_qmp_device_add(qts, "scsi-hd", "scsihd", "{'drive': 'drive0'}");
2549cec385SIgor Mammedov 
2649cec385SIgor Mammedov     /* TODO:
2749cec385SIgor Mammedov         UAS HBA driver in libqos, to check that
2849cec385SIgor Mammedov         added disk is visible after BUS rescan
2949cec385SIgor Mammedov     */
3049cec385SIgor Mammedov 
31e5758de4SThomas Huth     qtest_qmp_device_del(qts, "scsihd");
32e5758de4SThomas Huth     qtest_qmp_device_del(qts, "uas");
3349cec385SIgor Mammedov }
3449cec385SIgor Mammedov 
test_usb_ccid_hotplug(void)351a3ff20eSMarc-André Lureau static void test_usb_ccid_hotplug(void)
361a3ff20eSMarc-André Lureau {
37e5758de4SThomas Huth     QTestState *qts = global_qtest;
38e5758de4SThomas Huth 
39e5758de4SThomas Huth     qtest_qmp_device_add(qts, "usb-ccid", "ccid", "{}");
40e5758de4SThomas Huth     qtest_qmp_device_del(qts, "ccid");
411a3ff20eSMarc-André Lureau     /* check the device can be added again */
42e5758de4SThomas Huth     qtest_qmp_device_add(qts, "usb-ccid", "ccid", "{}");
43e5758de4SThomas Huth     qtest_qmp_device_del(qts, "ccid");
441a3ff20eSMarc-André Lureau }
451a3ff20eSMarc-André Lureau 
main(int argc,char ** argv)4625e89ec5SGonglei int main(int argc, char **argv)
4725e89ec5SGonglei {
4825e89ec5SGonglei     int ret;
4925e89ec5SGonglei 
5025e89ec5SGonglei     g_test_init(&argc, &argv, NULL);
5125e89ec5SGonglei 
52b3937683SIgor Mammedov     qtest_add_func("/xhci/pci/hotplug", test_xhci_hotplug);
53*0a1e462dSThomas Huth     if (qtest_has_device("usb-uas")) {
5449cec385SIgor Mammedov         qtest_add_func("/xhci/pci/hotplug/usb-uas", test_usb_uas_hotplug);
55*0a1e462dSThomas Huth     }
56*0a1e462dSThomas Huth     if (qtest_has_device("usb-ccid")) {
571a3ff20eSMarc-André Lureau         qtest_add_func("/xhci/pci/hotplug/usb-ccid", test_usb_ccid_hotplug);
58*0a1e462dSThomas Huth     }
5925e89ec5SGonglei 
6049cec385SIgor Mammedov     qtest_start("-device nec-usb-xhci,id=xhci"
61ca1ef1e6SAndrey Shinkevich                 " -drive id=drive0,if=none,file=null-co://,"
62ca1ef1e6SAndrey Shinkevich                 "file.read-zeroes=on,format=raw");
6325e89ec5SGonglei     ret = g_test_run();
64b3937683SIgor Mammedov     qtest_end();
6525e89ec5SGonglei 
6625e89ec5SGonglei     return ret;
6725e89ec5SGonglei }
68