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