]> git.proxmox.com Git - mirror_qemu.git/blame - tests/usb-hcd-uhci-test.c
Revert "vl: Fix to create migration object before block backends again"
[mirror_qemu.git] / tests / usb-hcd-uhci-test.c
CommitLineData
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 18static QOSState *qs;
44ced58e
GA
19
20static void test_uhci_init(void)
21{
fbd942c9 22}
44ced58e 23
b3937683 24static 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 30 uhci_port_test(&uhci, port - 1, UHCI_PORT_CCS);
62030ed1 31 uhci_deinit(&uhci);
b3937683
IM
32}
33
34static void test_port_1(void)
35{
36 test_port(1);
44ced58e
GA
37}
38
b3937683
IM
39static void test_port_2(void)
40{
41 test_port(2);
42}
43
44static void test_uhci_hotplug(void)
45{
82cab70b 46 usb_test_hotplug("uhci", "2", test_port_2);
b3937683 47}
44ced58e 48
b6ca82fe
IM
49static void test_usb_storage_hotplug(void)
50{
82cab70b 51 qtest_qmp_device_add("usb-storage", "usbdev0", "{'drive': 'drive0'}");
b6ca82fe 52
acd80015 53 qtest_qmp_device_del("usbdev0");
b6ca82fe
IM
54}
55
44ced58e
GA
56int main(int argc, char **argv)
57{
aa9026fd 58 const char *arch = qtest_get_arch();
44a3dd9b 59 const char *cmd = "-device piix3-usb-uhci,id=uhci,addr=1d.0"
2420d369 60 " -drive id=drive0,if=none,file=null-co://,format=raw"
44a3dd9b 61 " -device usb-tablet,bus=uhci.0,port=1";
44ced58e
GA
62 int ret;
63
64 g_test_init(&argc, &argv, NULL);
65
66 qtest_add_func("/uhci/pci/init", test_uhci_init);
fbd942c9 67 qtest_add_func("/uhci/pci/port1", test_port_1);
b3937683 68 qtest_add_func("/uhci/pci/hotplug", test_uhci_hotplug);
b6ca82fe 69 qtest_add_func("/uhci/pci/hotplug/usb-storage", test_usb_storage_hotplug);
44ced58e 70
aa9026fd 71 if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
44a3dd9b 72 qs = qtest_pc_boot(cmd);
aa9026fd 73 } else if (strcmp(arch, "ppc64") == 0) {
44a3dd9b
LV
74 qs = qtest_spapr_boot(cmd);
75 } else {
76 g_printerr("usb-hcd-uhci-test tests are only "
77 "available on x86 or ppc64\n");
78 exit(EXIT_FAILURE);
aa9026fd 79 }
3d95fb97 80 global_qtest = qs->qts;
44ced58e 81 ret = g_test_run();
aa9026fd 82 qtest_shutdown(qs);
44ced58e
GA
83
84 return ret;
85}