ui/gtk: Fix build with older versions of gtk
[qemu/ar7.git] / tests / usb-hcd-uhci-test.c
blobe956b9ccb7a6a2155d3a4badcb07828237a85f36
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 "qemu/osdep.h"
11 #include "libqtest.h"
12 #include "libqos/libqos.h"
13 #include "libqos/usb.h"
14 #include "libqos/libqos-pc.h"
15 #include "libqos/libqos-spapr.h"
16 #include "hw/usb/uhci-regs.h"
18 static QOSState *qs;
20 static void test_uhci_init(void)
24 static void test_port(int port)
26 struct qhc uhci;
28 g_assert(port > 0);
29 qusb_pci_init_one(qs->pcibus, &uhci, QPCI_DEVFN(0x1d, 0), 4);
30 uhci_port_test(&uhci, port - 1, UHCI_PORT_CCS);
33 static void test_port_1(void)
35 test_port(1);
38 static void test_port_2(void)
40 test_port(2);
43 static void test_uhci_hotplug(void)
45 usb_test_hotplug("uhci", 2, test_port_2);
48 static void test_usb_storage_hotplug(void)
50 QDict *response;
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);
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);
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);
77 int main(int argc, char **argv)
79 const char *arch = qtest_get_arch();
80 const char *cmd = "-device piix3-usb-uhci,id=uhci,addr=1d.0"
81 " -drive id=drive0,if=none,file=/dev/null,format=raw"
82 " -device usb-tablet,bus=uhci.0,port=1";
83 int ret;
85 g_test_init(&argc, &argv, NULL);
87 qtest_add_func("/uhci/pci/init", test_uhci_init);
88 qtest_add_func("/uhci/pci/port1", test_port_1);
89 qtest_add_func("/uhci/pci/hotplug", test_uhci_hotplug);
90 qtest_add_func("/uhci/pci/hotplug/usb-storage", test_usb_storage_hotplug);
92 if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
93 qs = qtest_pc_boot(cmd);
94 } else if (strcmp(arch, "ppc64") == 0) {
95 qs = qtest_spapr_boot(cmd);
96 } else {
97 g_printerr("usb-hcd-uhci-test tests are only "
98 "available on x86 or ppc64\n");
99 exit(EXIT_FAILURE);
101 ret = g_test_run();
102 qtest_shutdown(qs);
104 return ret;