2 * QTest testcase for USB UHCI controller
4 * Copyright (c) 2014 HUAWEI TECHNOLOGIES CO., LTD.
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.
10 #include "qemu/osdep.h"
12 #include "libqos/usb.h"
13 #include "hw/usb/uhci-regs.h"
16 static void test_uhci_init(void)
20 static void test_port(int port)
26 pcibus = qpci_init_pc();
27 g_assert(pcibus != NULL);
28 qusb_pci_init_one(pcibus, &uhci, QPCI_DEVFN(0x1d, 0), 4);
29 uhci_port_test(&uhci, port - 1, UHCI_PORT_CCS);
32 static void test_port_1(void)
37 static void test_port_2(void)
42 static void test_uhci_hotplug(void)
44 usb_test_hotplug("uhci", 2, test_port_2);
47 static void test_usb_storage_hotplug(void)
51 response = qmp("{'execute': 'device_add',"
53 " 'driver': 'usb-storage',"
58 g_assert(!qdict_haskey(response, "error"));
61 response = qmp("{'execute': 'device_del',"
66 g_assert(!qdict_haskey(response, "error"));
71 g_assert(qdict_haskey(response, "event"));
72 g_assert(!strcmp(qdict_get_str(response, "event"), "DEVICE_DELETED"));
76 int main(int argc, char **argv)
80 g_test_init(&argc, &argv, NULL);
82 qtest_add_func("/uhci/pci/init", test_uhci_init);
83 qtest_add_func("/uhci/pci/port1", test_port_1);
84 qtest_add_func("/uhci/pci/hotplug", test_uhci_hotplug);
85 qtest_add_func("/uhci/pci/hotplug/usb-storage", test_usb_storage_hotplug);
87 qtest_start("-device piix3-usb-uhci,id=uhci,addr=1d.0"
88 " -drive id=drive0,if=none,file=/dev/null,format=raw"
89 " -device usb-tablet,bus=uhci.0,port=1");