xref: /qemu/tests/qtest/usb-hcd-xhci-test.c (revision 1a3ff20e67330a15d62b00c2916e3541872103c0)
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"
11e532b2e0SPeter Maydell #include "libqtest.h"
12b3937683SIgor Mammedov #include "libqos/usb.h"
1325e89ec5SGonglei 
1425e89ec5SGonglei 
1525e89ec5SGonglei static void test_xhci_init(void)
1625e89ec5SGonglei {
1725e89ec5SGonglei }
1825e89ec5SGonglei 
19b3937683SIgor Mammedov static void test_xhci_hotplug(void)
20b3937683SIgor Mammedov {
21b3937683SIgor Mammedov     usb_test_hotplug("xhci", 1, NULL);
22b3937683SIgor Mammedov }
2325e89ec5SGonglei 
2449cec385SIgor Mammedov static void test_usb_uas_hotplug(void)
2549cec385SIgor Mammedov {
26acd80015SThomas Huth     qtest_qmp_device_add("usb-uas", "uas", NULL);
27acd80015SThomas Huth     qtest_qmp_device_add("scsi-hd", "scsihd", "'drive': 'drive0'");
2849cec385SIgor Mammedov 
2949cec385SIgor Mammedov     /* TODO:
3049cec385SIgor Mammedov         UAS HBA driver in libqos, to check that
3149cec385SIgor Mammedov         added disk is visible after BUS rescan
3249cec385SIgor Mammedov     */
3349cec385SIgor Mammedov 
34acd80015SThomas Huth     qtest_qmp_device_del("scsihd");
35acd80015SThomas Huth     qtest_qmp_device_del("uas");
3649cec385SIgor Mammedov }
3749cec385SIgor Mammedov 
38*1a3ff20eSMarc-André Lureau static void test_usb_ccid_hotplug(void)
39*1a3ff20eSMarc-André Lureau {
40*1a3ff20eSMarc-André Lureau     qtest_qmp_device_add("usb-ccid", "ccid", NULL);
41*1a3ff20eSMarc-André Lureau     qtest_qmp_device_del("ccid");
42*1a3ff20eSMarc-André Lureau     /* check the device can be added again */
43*1a3ff20eSMarc-André Lureau     qtest_qmp_device_add("usb-ccid", "ccid", NULL);
44*1a3ff20eSMarc-André Lureau     qtest_qmp_device_del("ccid");
45*1a3ff20eSMarc-André Lureau }
46*1a3ff20eSMarc-André Lureau 
4725e89ec5SGonglei int main(int argc, char **argv)
4825e89ec5SGonglei {
4925e89ec5SGonglei     int ret;
5025e89ec5SGonglei 
5125e89ec5SGonglei     g_test_init(&argc, &argv, NULL);
5225e89ec5SGonglei 
5325e89ec5SGonglei     qtest_add_func("/xhci/pci/init", test_xhci_init);
54b3937683SIgor Mammedov     qtest_add_func("/xhci/pci/hotplug", test_xhci_hotplug);
5549cec385SIgor Mammedov     qtest_add_func("/xhci/pci/hotplug/usb-uas", test_usb_uas_hotplug);
56*1a3ff20eSMarc-André Lureau     qtest_add_func("/xhci/pci/hotplug/usb-ccid", test_usb_ccid_hotplug);
5725e89ec5SGonglei 
5849cec385SIgor Mammedov     qtest_start("-device nec-usb-xhci,id=xhci"
592420d369SFam Zheng                 " -drive id=drive0,if=none,file=null-co://,format=raw");
6025e89ec5SGonglei     ret = g_test_run();
61b3937683SIgor Mammedov     qtest_end();
6225e89ec5SGonglei 
6325e89ec5SGonglei     return ret;
6425e89ec5SGonglei }
65