]>
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" |
aa9026fd | 12 | #include "libqos/libqos.h" |
fbd942c9 | 13 | #include "libqos/usb.h" |
aa9026fd LV |
14 | #include "libqos/libqos-pc.h" |
15 | #include "libqos/libqos-spapr.h" | |
fbd942c9 | 16 | #include "hw/usb/uhci-regs.h" |
44ced58e | 17 | |
aa9026fd | 18 | static QOSState *qs; |
44ced58e GA |
19 | |
20 | static void test_uhci_init(void) | |
21 | { | |
fbd942c9 | 22 | } |
44ced58e | 23 | |
b3937683 | 24 | static void test_port(int port) |
fbd942c9 | 25 | { |
fbd942c9 IM |
26 | struct qhc uhci; |
27 | ||
b3937683 | 28 | g_assert(port > 0); |
aa9026fd | 29 | qusb_pci_init_one(qs->pcibus, &uhci, QPCI_DEVFN(0x1d, 0), 4); |
b3937683 IM |
30 | uhci_port_test(&uhci, port - 1, UHCI_PORT_CCS); |
31 | } | |
32 | ||
33 | static void test_port_1(void) | |
34 | { | |
35 | test_port(1); | |
44ced58e GA |
36 | } |
37 | ||
b3937683 IM |
38 | static void test_port_2(void) |
39 | { | |
40 | test_port(2); | |
41 | } | |
42 | ||
43 | static void test_uhci_hotplug(void) | |
44 | { | |
45 | usb_test_hotplug("uhci", 2, test_port_2); | |
46 | } | |
44ced58e | 47 | |
b6ca82fe IM |
48 | static void test_usb_storage_hotplug(void) |
49 | { | |
50 | QDict *response; | |
51 | ||
52 | response = qmp("{'execute': 'device_add'," | |
53 | " 'arguments': {" | |
54 | " 'driver': 'usb-storage'," | |
55 | " 'drive': 'drive0'," | |
56 | " 'id': 'usbdev0'" | |
57 | "}}"); | |
58 | g_assert(response); | |
59 | g_assert(!qdict_haskey(response, "error")); | |
60 | QDECREF(response); | |
61 | ||
62 | response = qmp("{'execute': 'device_del'," | |
63 | " 'arguments': {" | |
64 | " 'id': 'usbdev0'" | |
65 | "}}"); | |
66 | g_assert(response); | |
67 | g_assert(!qdict_haskey(response, "error")); | |
68 | QDECREF(response); | |
69 | ||
70 | response = qmp(""); | |
71 | g_assert(response); | |
72 | g_assert(qdict_haskey(response, "event")); | |
73 | g_assert(!strcmp(qdict_get_str(response, "event"), "DEVICE_DELETED")); | |
74 | QDECREF(response); | |
75 | } | |
76 | ||
44ced58e GA |
77 | int main(int argc, char **argv) |
78 | { | |
aa9026fd | 79 | const char *arch = qtest_get_arch(); |
44ced58e GA |
80 | int ret; |
81 | ||
82 | g_test_init(&argc, &argv, NULL); | |
83 | ||
84 | qtest_add_func("/uhci/pci/init", test_uhci_init); | |
fbd942c9 | 85 | qtest_add_func("/uhci/pci/port1", test_port_1); |
b3937683 | 86 | qtest_add_func("/uhci/pci/hotplug", test_uhci_hotplug); |
b6ca82fe | 87 | qtest_add_func("/uhci/pci/hotplug/usb-storage", test_usb_storage_hotplug); |
44ced58e | 88 | |
aa9026fd LV |
89 | if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) { |
90 | qs = qtest_pc_boot("-device piix3-usb-uhci,id=uhci,addr=1d.0" | |
91 | " -drive id=drive0,if=none,file=/dev/null,format=raw" | |
92 | " -device usb-tablet,bus=uhci.0,port=1"); | |
93 | } else if (strcmp(arch, "ppc64") == 0) { | |
94 | qs = qtest_spapr_boot("-device piix3-usb-uhci,id=uhci,addr=1d.0" | |
95 | " -drive id=drive0,if=none,file=/dev/null,format=raw" | |
96 | " -device usb-tablet,bus=uhci.0,port=1"); | |
97 | } | |
44ced58e | 98 | ret = g_test_run(); |
aa9026fd | 99 | qtest_shutdown(qs); |
44ced58e GA |
100 | |
101 | return ret; | |
102 | } |