]> git.proxmox.com Git - mirror_qemu.git/blame - tests/usb-hcd-xhci-test.c
hw/net: Clean up includes
[mirror_qemu.git] / tests / usb-hcd-xhci-test.c
CommitLineData
25e89ec5
GA
1/*
2 * QTest testcase for USB xHCI controller
3 *
fe75270c 4 * Copyright (c) 2014 HUAWEI TECHNOLOGIES CO., LTD.
25e89ec5
GA
5 *
6 * This work is licensed under the terms of the GNU GPL, version 2 or later.
7 * See the COPYING file in the top-level directory.
8 */
9
10#include <glib.h>
11#include <string.h>
12#include "libqtest.h"
13#include "qemu/osdep.h"
b3937683 14#include "libqos/usb.h"
25e89ec5
GA
15
16
17static void test_xhci_init(void)
18{
25e89ec5
GA
19}
20
b3937683
IM
21static void test_xhci_hotplug(void)
22{
23 usb_test_hotplug("xhci", 1, NULL);
24}
25e89ec5 25
49cec385
IM
26static void test_usb_uas_hotplug(void)
27{
28 QDict *response;
29
30 response = qmp("{'execute': 'device_add',"
31 " 'arguments': {"
32 " 'driver': 'usb-uas',"
33 " 'id': 'uas'"
34 "}}");
35 g_assert(response);
36 g_assert(!qdict_haskey(response, "error"));
37 QDECREF(response);
38
39 response = qmp("{'execute': 'device_add',"
40 " 'arguments': {"
41 " 'driver': 'scsi-hd',"
42 " 'drive': 'drive0',"
43 " 'id': 'scsi-hd'"
44 "}}");
45 g_assert(response);
46 g_assert(!qdict_haskey(response, "error"));
47 QDECREF(response);
48
49 /* TODO:
50 UAS HBA driver in libqos, to check that
51 added disk is visible after BUS rescan
52 */
53
54 response = qmp("{'execute': 'device_del',"
55 " 'arguments': {"
56 " 'id': 'scsi-hd'"
57 "}}");
58 g_assert(response);
59 g_assert(!qdict_haskey(response, "error"));
60 QDECREF(response);
61
62 response = qmp("");
63 g_assert(qdict_haskey(response, "event"));
64 g_assert(!strcmp(qdict_get_str(response, "event"), "DEVICE_DELETED"));
65 QDECREF(response);
66
67
68 response = qmp("{'execute': 'device_del',"
69 " 'arguments': {"
70 " 'id': 'uas'"
71 "}}");
72 g_assert(response);
73 g_assert(!qdict_haskey(response, "error"));
74 QDECREF(response);
75
76 response = qmp("");
77 g_assert(response);
78 g_assert(qdict_haskey(response, "event"));
79 g_assert(!strcmp(qdict_get_str(response, "event"), "DEVICE_DELETED"));
80 QDECREF(response);
81}
82
25e89ec5
GA
83int main(int argc, char **argv)
84{
85 int ret;
86
87 g_test_init(&argc, &argv, NULL);
88
89 qtest_add_func("/xhci/pci/init", test_xhci_init);
b3937683 90 qtest_add_func("/xhci/pci/hotplug", test_xhci_hotplug);
49cec385 91 qtest_add_func("/xhci/pci/hotplug/usb-uas", test_usb_uas_hotplug);
25e89ec5 92
49cec385 93 qtest_start("-device nec-usb-xhci,id=xhci"
b8e665e4 94 " -drive id=drive0,if=none,file=/dev/null,format=raw");
25e89ec5 95 ret = g_test_run();
b3937683 96 qtest_end();
25e89ec5
GA
97
98 return ret;
99}