2014-06-23 19:53:52 +08:00
|
|
|
/*
|
|
|
|
* QTest testcase for USB UHCI controller
|
|
|
|
*
|
2015-03-26 20:57:43 +08:00
|
|
|
* Copyright (c) 2014 HUAWEI TECHNOLOGIES CO., LTD.
|
2014-06-23 19:53:52 +08: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-27 02:17:12 +08:00
|
|
|
#include "qemu/osdep.h"
|
2014-06-23 19:53:52 +08:00
|
|
|
#include "libqtest.h"
|
2016-09-29 18:32:47 +08:00
|
|
|
#include "libqos/libqos.h"
|
2014-09-26 17:28:13 +08:00
|
|
|
#include "libqos/usb.h"
|
2016-09-29 18:32:47 +08:00
|
|
|
#include "libqos/libqos-pc.h"
|
|
|
|
#include "libqos/libqos-spapr.h"
|
2014-09-26 17:28:13 +08:00
|
|
|
#include "hw/usb/uhci-regs.h"
|
2014-06-23 19:53:52 +08:00
|
|
|
|
2016-09-29 18:32:47 +08:00
|
|
|
static QOSState *qs;
|
2014-06-23 19:53:52 +08:00
|
|
|
|
|
|
|
static void test_uhci_init(void)
|
|
|
|
{
|
2014-09-26 17:28:13 +08:00
|
|
|
}
|
2014-06-23 19:53:52 +08:00
|
|
|
|
2014-09-26 17:28:14 +08:00
|
|
|
static void test_port(int port)
|
2014-09-26 17:28:13 +08:00
|
|
|
{
|
|
|
|
struct qhc uhci;
|
|
|
|
|
2014-09-26 17:28:14 +08:00
|
|
|
g_assert(port > 0);
|
2016-09-29 18:32:47 +08:00
|
|
|
qusb_pci_init_one(qs->pcibus, &uhci, QPCI_DEVFN(0x1d, 0), 4);
|
2014-09-26 17:28:14 +08:00
|
|
|
uhci_port_test(&uhci, port - 1, UHCI_PORT_CCS);
|
2017-02-07 19:47:39 +08:00
|
|
|
uhci_deinit(&uhci);
|
2014-09-26 17:28:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_port_1(void)
|
|
|
|
{
|
|
|
|
test_port(1);
|
2014-06-23 19:53:52 +08:00
|
|
|
}
|
|
|
|
|
2014-09-26 17:28:14 +08:00
|
|
|
static void test_port_2(void)
|
|
|
|
{
|
|
|
|
test_port(2);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_uhci_hotplug(void)
|
|
|
|
{
|
2019-07-22 23:10:55 +08:00
|
|
|
usb_test_hotplug(global_qtest, "uhci", "2", test_port_2);
|
2014-09-26 17:28:14 +08:00
|
|
|
}
|
2014-06-23 19:53:52 +08:00
|
|
|
|
2014-09-26 17:28:15 +08:00
|
|
|
static void test_usb_storage_hotplug(void)
|
|
|
|
{
|
2019-07-22 23:10:55 +08:00
|
|
|
QTestState *qts = global_qtest;
|
2014-09-26 17:28:15 +08:00
|
|
|
|
2019-07-22 23:10:55 +08:00
|
|
|
qtest_qmp_device_add(qts, "usb-storage", "usbdev0", "{'drive': 'drive0'}");
|
|
|
|
|
|
|
|
qtest_qmp_device_del(qts, "usbdev0");
|
2014-09-26 17:28:15 +08:00
|
|
|
}
|
|
|
|
|
2014-06-23 19:53:52 +08:00
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
2016-09-29 18:32:47 +08:00
|
|
|
const char *arch = qtest_get_arch();
|
2016-10-06 22:50:48 +08:00
|
|
|
const char *cmd = "-device piix3-usb-uhci,id=uhci,addr=1d.0"
|
2019-07-29 20:46:00 +08:00
|
|
|
" -drive id=drive0,if=none,file=null-co://,"
|
|
|
|
"file.read-zeroes=on,format=raw"
|
2016-10-06 22:50:48 +08:00
|
|
|
" -device usb-tablet,bus=uhci.0,port=1";
|
2014-06-23 19:53:52 +08:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
g_test_init(&argc, &argv, NULL);
|
|
|
|
|
|
|
|
qtest_add_func("/uhci/pci/init", test_uhci_init);
|
2014-09-26 17:28:13 +08:00
|
|
|
qtest_add_func("/uhci/pci/port1", test_port_1);
|
2014-09-26 17:28:14 +08:00
|
|
|
qtest_add_func("/uhci/pci/hotplug", test_uhci_hotplug);
|
2014-09-26 17:28:15 +08:00
|
|
|
qtest_add_func("/uhci/pci/hotplug/usb-storage", test_usb_storage_hotplug);
|
2014-06-23 19:53:52 +08:00
|
|
|
|
2016-09-29 18:32:47 +08:00
|
|
|
if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
|
2016-10-06 22:50:48 +08:00
|
|
|
qs = qtest_pc_boot(cmd);
|
2016-09-29 18:32:47 +08:00
|
|
|
} else if (strcmp(arch, "ppc64") == 0) {
|
2016-10-06 22:50:48 +08: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 18:32:47 +08:00
|
|
|
}
|
2017-09-12 01:20:01 +08:00
|
|
|
global_qtest = qs->qts;
|
2014-06-23 19:53:52 +08:00
|
|
|
ret = g_test_run();
|
2016-09-29 18:32:47 +08:00
|
|
|
qtest_shutdown(qs);
|
2014-06-23 19:53:52 +08:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|