Add qemu 2.4.0
[kvmfornfv.git] / qemu / tests / usb-hcd-xhci-test.c
1 /*
2  * QTest testcase for USB xHCI controller
3  *
4  * Copyright (c) 2014 HUAWEI TECHNOLOGIES CO., LTD.
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"
14 #include "libqos/usb.h"
15
16
17 static void test_xhci_init(void)
18 {
19 }
20
21 static void test_xhci_hotplug(void)
22 {
23     usb_test_hotplug("xhci", 1, NULL);
24 }
25
26 static 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
83 int 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);
90     qtest_add_func("/xhci/pci/hotplug", test_xhci_hotplug);
91     qtest_add_func("/xhci/pci/hotplug/usb-uas", test_usb_uas_hotplug);
92
93     qtest_start("-device nec-usb-xhci,id=xhci"
94                 " -drive id=drive0,if=none,file=/dev/null,format=raw");
95     ret = g_test_run();
96     qtest_end();
97
98     return ret;
99 }