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