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"
|
2014-06-23 15:53:52 +04:00
|
|
|
#include "libqtest.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)
|
|
|
|
{
|
|
|
|
usb_test_hotplug("uhci", 2, test_port_2);
|
|
|
|
}
|
2014-06-23 15:53:52 +04:00
|
|
|
|
2014-09-26 13:28:15 +04:00
|
|
|
static void test_usb_storage_hotplug(void)
|
|
|
|
{
|
|
|
|
QDict *response;
|
|
|
|
|
|
|
|
response = qmp("{'execute': 'device_add',"
|
|
|
|
" 'arguments': {"
|
|
|
|
" 'driver': 'usb-storage',"
|
|
|
|
" 'drive': 'drive0',"
|
|
|
|
" 'id': 'usbdev0'"
|
|
|
|
"}}");
|
|
|
|
g_assert(response);
|
|
|
|
g_assert(!qdict_haskey(response, "error"));
|
|
|
|
QDECREF(response);
|
|
|
|
|
|
|
|
response = qmp("{'execute': 'device_del',"
|
|
|
|
" 'arguments': {"
|
|
|
|
" 'id': 'usbdev0'"
|
|
|
|
"}}");
|
|
|
|
g_assert(response);
|
|
|
|
g_assert(!qdict_haskey(response, "error"));
|
|
|
|
QDECREF(response);
|
|
|
|
|
|
|
|
response = qmp("");
|
|
|
|
g_assert(response);
|
|
|
|
g_assert(qdict_haskey(response, "event"));
|
|
|
|
g_assert(!strcmp(qdict_get_str(response, "event"), "DEVICE_DELETED"));
|
|
|
|
QDECREF(response);
|
|
|
|
}
|
|
|
|
|
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"
|
2017-05-02 19:35:49 +03:00
|
|
|
" -drive id=drive0,if=none,file=null-co://,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);
|
|
|
|
|
|
|
|
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) {
|
2016-10-06 17:50:48 +03:00
|
|
|
qs = qtest_pc_boot(cmd);
|
2016-09-29 13:32:47 +03:00
|
|
|
} else if (strcmp(arch, "ppc64") == 0) {
|
2016-10-06 17:50:48 +03: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 13:32:47 +03:00
|
|
|
}
|
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;
|
|
|
|
}
|