tests: usb: Generic usb device hotplug
[qemu.git] / tests / usb-hcd-uhci-test.c
blobda96f98de6de30457babc81f6537f27bbff6fde0
1 /*
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.
8 */
10 #include <glib.h>
11 #include <string.h>
12 #include "libqtest.h"
13 #include "qemu/osdep.h"
14 #include "libqos/usb.h"
15 #include "hw/usb/uhci-regs.h"
18 static void test_uhci_init(void)
22 static void test_port(int port)
24 QPCIBus *pcibus;
25 struct qhc uhci;
27 g_assert(port > 0);
28 pcibus = qpci_init_pc();
29 g_assert(pcibus != NULL);
30 qusb_pci_init_one(pcibus, &uhci, QPCI_DEVFN(0x1d, 0), 4);
31 uhci_port_test(&uhci, port - 1, UHCI_PORT_CCS);
34 static void test_port_1(void)
36 test_port(1);
39 static void test_port_2(void)
41 test_port(2);
44 static void test_uhci_hotplug(void)
46 usb_test_hotplug("uhci", 2, test_port_2);
49 int main(int argc, char **argv)
51 int ret;
53 g_test_init(&argc, &argv, NULL);
55 qtest_add_func("/uhci/pci/init", test_uhci_init);
56 qtest_add_func("/uhci/pci/port1", test_port_1);
57 qtest_add_func("/uhci/pci/hotplug", test_uhci_hotplug);
59 qtest_start("-device piix3-usb-uhci,id=uhci,addr=1d.0"
60 " -device usb-tablet,bus=uhci.0,port=1");
61 ret = g_test_run();
62 qtest_end();
64 return ret;