Merge remote-tracking branch 'remotes/pmaydell/tags/pull-target-arm-20210330' into...
[qemu/ar7.git] / tests / qtest / usb-hcd-uhci-test.c
blob7a117b64d90c802ffeecd5cd092a196eac725a43
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-single.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);
31 uhci_deinit(&uhci);
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(global_qtest, "uhci", "2", test_port_2);
49 static void test_usb_storage_hotplug(void)
51 QTestState *qts = global_qtest;
53 qtest_qmp_device_add(qts, "usb-storage", "usbdev0", "{'drive': 'drive0'}");
55 qtest_qmp_device_del(qts, "usbdev0");
58 int main(int argc, char **argv)
60 const char *arch = qtest_get_arch();
61 const char *cmd = "-device piix3-usb-uhci,id=uhci,addr=1d.0"
62 " -drive id=drive0,if=none,file=null-co://,"
63 "file.read-zeroes=on,format=raw"
64 " -device usb-tablet,bus=uhci.0,port=1";
65 int ret;
67 g_test_init(&argc, &argv, NULL);
69 qtest_add_func("/uhci/pci/init", test_uhci_init);
70 qtest_add_func("/uhci/pci/port1", test_port_1);
71 qtest_add_func("/uhci/pci/hotplug", test_uhci_hotplug);
72 qtest_add_func("/uhci/pci/hotplug/usb-storage", test_usb_storage_hotplug);
74 if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
75 qs = qtest_pc_boot(cmd);
76 } else if (strcmp(arch, "ppc64") == 0) {
77 qs = qtest_spapr_boot(cmd);
78 } else {
79 g_printerr("usb-hcd-uhci-test tests are only "
80 "available on x86 or ppc64\n");
81 exit(EXIT_FAILURE);
83 global_qtest = qs->qts;
84 ret = g_test_run();
85 qtest_shutdown(qs);
87 return ret;