]>
Commit | Line | Data |
---|---|---|
44ced58e GA |
1 | /* |
2 | * QTest testcase for USB UHCI controller | |
3 | * | |
fe75270c | 4 | * Copyright (c) 2014 HUAWEI TECHNOLOGIES CO., LTD. |
44ced58e GA |
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 | ||
e532b2e0 | 10 | #include "qemu/osdep.h" |
44ced58e | 11 | #include "libqtest.h" |
fbd942c9 IM |
12 | #include "libqos/usb.h" |
13 | #include "hw/usb/uhci-regs.h" | |
44ced58e GA |
14 | |
15 | ||
16 | static void test_uhci_init(void) | |
17 | { | |
fbd942c9 | 18 | } |
44ced58e | 19 | |
b3937683 | 20 | static void test_port(int port) |
fbd942c9 IM |
21 | { |
22 | QPCIBus *pcibus; | |
23 | struct qhc uhci; | |
24 | ||
b3937683 | 25 | g_assert(port > 0); |
fbd942c9 IM |
26 | pcibus = qpci_init_pc(); |
27 | g_assert(pcibus != NULL); | |
28 | qusb_pci_init_one(pcibus, &uhci, QPCI_DEVFN(0x1d, 0), 4); | |
b3937683 IM |
29 | uhci_port_test(&uhci, port - 1, UHCI_PORT_CCS); |
30 | } | |
31 | ||
32 | static void test_port_1(void) | |
33 | { | |
34 | test_port(1); | |
44ced58e GA |
35 | } |
36 | ||
b3937683 IM |
37 | static void test_port_2(void) |
38 | { | |
39 | test_port(2); | |
40 | } | |
41 | ||
42 | static void test_uhci_hotplug(void) | |
43 | { | |
44 | usb_test_hotplug("uhci", 2, test_port_2); | |
45 | } | |
44ced58e | 46 | |
b6ca82fe IM |
47 | static void test_usb_storage_hotplug(void) |
48 | { | |
49 | QDict *response; | |
50 | ||
51 | response = qmp("{'execute': 'device_add'," | |
52 | " 'arguments': {" | |
53 | " 'driver': 'usb-storage'," | |
54 | " 'drive': 'drive0'," | |
55 | " 'id': 'usbdev0'" | |
56 | "}}"); | |
57 | g_assert(response); | |
58 | g_assert(!qdict_haskey(response, "error")); | |
59 | QDECREF(response); | |
60 | ||
61 | response = qmp("{'execute': 'device_del'," | |
62 | " 'arguments': {" | |
63 | " 'id': 'usbdev0'" | |
64 | "}}"); | |
65 | g_assert(response); | |
66 | g_assert(!qdict_haskey(response, "error")); | |
67 | QDECREF(response); | |
68 | ||
69 | response = qmp(""); | |
70 | g_assert(response); | |
71 | g_assert(qdict_haskey(response, "event")); | |
72 | g_assert(!strcmp(qdict_get_str(response, "event"), "DEVICE_DELETED")); | |
73 | QDECREF(response); | |
74 | } | |
75 | ||
44ced58e GA |
76 | int main(int argc, char **argv) |
77 | { | |
78 | int ret; | |
79 | ||
80 | g_test_init(&argc, &argv, NULL); | |
81 | ||
82 | qtest_add_func("/uhci/pci/init", test_uhci_init); | |
fbd942c9 | 83 | qtest_add_func("/uhci/pci/port1", test_port_1); |
b3937683 | 84 | qtest_add_func("/uhci/pci/hotplug", test_uhci_hotplug); |
b6ca82fe | 85 | qtest_add_func("/uhci/pci/hotplug/usb-storage", test_usb_storage_hotplug); |
44ced58e | 86 | |
fbd942c9 | 87 | qtest_start("-device piix3-usb-uhci,id=uhci,addr=1d.0" |
b8e665e4 | 88 | " -drive id=drive0,if=none,file=/dev/null,format=raw" |
fbd942c9 | 89 | " -device usb-tablet,bus=uhci.0,port=1"); |
44ced58e | 90 | ret = g_test_run(); |
fbd942c9 | 91 | qtest_end(); |
44ced58e GA |
92 | |
93 | return ret; | |
94 | } |