2014-06-23 11:53:52 +00:00
|
|
|
/*
|
|
|
|
* QTest testcase for USB UHCI controller
|
|
|
|
*
|
2015-03-26 12:57:43 +00:00
|
|
|
* Copyright (c) 2014 HUAWEI TECHNOLOGIES CO., LTD.
|
2014-06-23 11:53:52 +00:00
|
|
|
*
|
|
|
|
* This work is licensed under the terms of the GNU GPL, version 2 or later.
|
|
|
|
* See the COPYING file in the top-level directory.
|
|
|
|
*/
|
|
|
|
|
2016-01-26 18:17:12 +00:00
|
|
|
#include "qemu/osdep.h"
|
2014-06-23 11:53:52 +00:00
|
|
|
#include "libqtest.h"
|
2016-09-29 10:32:47 +00:00
|
|
|
#include "libqos/libqos.h"
|
2014-09-26 09:28:13 +00:00
|
|
|
#include "libqos/usb.h"
|
2016-09-29 10:32:47 +00:00
|
|
|
#include "libqos/libqos-pc.h"
|
|
|
|
#include "libqos/libqos-spapr.h"
|
2014-09-26 09:28:13 +00:00
|
|
|
#include "hw/usb/uhci-regs.h"
|
2014-06-23 11:53:52 +00:00
|
|
|
|
2016-09-29 10:32:47 +00:00
|
|
|
static QOSState *qs;
|
2014-06-23 11:53:52 +00:00
|
|
|
|
|
|
|
static void test_uhci_init(void)
|
|
|
|
{
|
2014-09-26 09:28:13 +00:00
|
|
|
}
|
2014-06-23 11:53:52 +00:00
|
|
|
|
2014-09-26 09:28:14 +00:00
|
|
|
static void test_port(int port)
|
2014-09-26 09:28:13 +00:00
|
|
|
{
|
|
|
|
struct qhc uhci;
|
|
|
|
|
2014-09-26 09:28:14 +00:00
|
|
|
g_assert(port > 0);
|
2016-09-29 10:32:47 +00:00
|
|
|
qusb_pci_init_one(qs->pcibus, &uhci, QPCI_DEVFN(0x1d, 0), 4);
|
2014-09-26 09:28:14 +00:00
|
|
|
uhci_port_test(&uhci, port - 1, UHCI_PORT_CCS);
|
2017-02-07 11:47:39 +00:00
|
|
|
uhci_deinit(&uhci);
|
2014-09-26 09:28:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_port_1(void)
|
|
|
|
{
|
|
|
|
test_port(1);
|
2014-06-23 11:53:52 +00:00
|
|
|
}
|
|
|
|
|
2014-09-26 09:28:14 +00:00
|
|
|
static void test_port_2(void)
|
|
|
|
{
|
|
|
|
test_port(2);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_uhci_hotplug(void)
|
|
|
|
{
|
|
|
|
usb_test_hotplug("uhci", 2, test_port_2);
|
|
|
|
}
|
2014-06-23 11:53:52 +00:00
|
|
|
|
2014-09-26 09:28:15 +00:00
|
|
|
static void test_usb_storage_hotplug(void)
|
|
|
|
{
|
2017-08-15 06:58:54 +00:00
|
|
|
qtest_qmp_device_add("usb-storage", "usbdev0", "'drive': 'drive0'");
|
2014-09-26 09:28:15 +00:00
|
|
|
|
2017-08-15 06:58:54 +00:00
|
|
|
qtest_qmp_device_del("usbdev0");
|
2014-09-26 09:28:15 +00:00
|
|
|
}
|
|
|
|
|
2014-06-23 11:53:52 +00:00
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
2016-09-29 10:32:47 +00:00
|
|
|
const char *arch = qtest_get_arch();
|
2016-10-06 14:50:48 +00:00
|
|
|
const char *cmd = "-device piix3-usb-uhci,id=uhci,addr=1d.0"
|
2017-05-02 16:35:49 +00:00
|
|
|
" -drive id=drive0,if=none,file=null-co://,format=raw"
|
2016-10-06 14:50:48 +00:00
|
|
|
" -device usb-tablet,bus=uhci.0,port=1";
|
2014-06-23 11:53:52 +00:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
g_test_init(&argc, &argv, NULL);
|
|
|
|
|
|
|
|
qtest_add_func("/uhci/pci/init", test_uhci_init);
|
2014-09-26 09:28:13 +00:00
|
|
|
qtest_add_func("/uhci/pci/port1", test_port_1);
|
2014-09-26 09:28:14 +00:00
|
|
|
qtest_add_func("/uhci/pci/hotplug", test_uhci_hotplug);
|
2014-09-26 09:28:15 +00:00
|
|
|
qtest_add_func("/uhci/pci/hotplug/usb-storage", test_usb_storage_hotplug);
|
2014-06-23 11:53:52 +00:00
|
|
|
|
2016-09-29 10:32:47 +00:00
|
|
|
if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
|
2016-10-06 14:50:48 +00:00
|
|
|
qs = qtest_pc_boot(cmd);
|
2016-09-29 10:32:47 +00:00
|
|
|
} else if (strcmp(arch, "ppc64") == 0) {
|
2016-10-06 14:50:48 +00:00
|
|
|
qs = qtest_spapr_boot(cmd);
|
|
|
|
} else {
|
|
|
|
g_printerr("usb-hcd-uhci-test tests are only "
|
|
|
|
"available on x86 or ppc64\n");
|
|
|
|
exit(EXIT_FAILURE);
|
2016-09-29 10:32:47 +00:00
|
|
|
}
|
2017-09-11 17:20:01 +00:00
|
|
|
global_qtest = qs->qts;
|
2014-06-23 11:53:52 +00:00
|
|
|
ret = g_test_run();
|
2016-09-29 10:32:47 +00:00
|
|
|
qtest_shutdown(qs);
|
2014-06-23 11:53:52 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|