Gonglei | 44ced58 | 2014-06-23 19:53:52 +0800 | [diff] [blame] | 1 | /* |
| 2 | * QTest testcase for USB UHCI controller |
| 3 | * |
Gonglei | fe75270 | 2015-03-26 20:57:43 +0800 | [diff] [blame] | 4 | * Copyright (c) 2014 HUAWEI TECHNOLOGIES CO., LTD. |
Gonglei | 44ced58 | 2014-06-23 19:53:52 +0800 | [diff] [blame] | 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" |
Igor Mammedov | fbd942c | 2014-09-26 09:28:13 +0000 | [diff] [blame] | 14 | #include "libqos/usb.h" |
| 15 | #include "hw/usb/uhci-regs.h" |
Gonglei | 44ced58 | 2014-06-23 19:53:52 +0800 | [diff] [blame] | 16 | |
| 17 | |
| 18 | static void test_uhci_init(void) |
| 19 | { |
Igor Mammedov | fbd942c | 2014-09-26 09:28:13 +0000 | [diff] [blame] | 20 | } |
Gonglei | 44ced58 | 2014-06-23 19:53:52 +0800 | [diff] [blame] | 21 | |
Igor Mammedov | b393768 | 2014-09-26 09:28:14 +0000 | [diff] [blame] | 22 | static void test_port(int port) |
Igor Mammedov | fbd942c | 2014-09-26 09:28:13 +0000 | [diff] [blame] | 23 | { |
| 24 | QPCIBus *pcibus; |
| 25 | struct qhc uhci; |
| 26 | |
Igor Mammedov | b393768 | 2014-09-26 09:28:14 +0000 | [diff] [blame] | 27 | g_assert(port > 0); |
Igor Mammedov | fbd942c | 2014-09-26 09:28:13 +0000 | [diff] [blame] | 28 | pcibus = qpci_init_pc(); |
| 29 | g_assert(pcibus != NULL); |
| 30 | qusb_pci_init_one(pcibus, &uhci, QPCI_DEVFN(0x1d, 0), 4); |
Igor Mammedov | b393768 | 2014-09-26 09:28:14 +0000 | [diff] [blame] | 31 | uhci_port_test(&uhci, port - 1, UHCI_PORT_CCS); |
Gonglei | 44ced58 | 2014-06-23 19:53:52 +0800 | [diff] [blame] | 32 | } |
| 33 | |
Igor Mammedov | b393768 | 2014-09-26 09:28:14 +0000 | [diff] [blame] | 34 | static void test_port_1(void) |
| 35 | { |
| 36 | test_port(1); |
| 37 | } |
| 38 | |
| 39 | static void test_port_2(void) |
| 40 | { |
| 41 | test_port(2); |
| 42 | } |
| 43 | |
| 44 | static void test_uhci_hotplug(void) |
| 45 | { |
| 46 | usb_test_hotplug("uhci", 2, test_port_2); |
| 47 | } |
Gonglei | 44ced58 | 2014-06-23 19:53:52 +0800 | [diff] [blame] | 48 | |
Igor Mammedov | b6ca82f | 2014-09-26 09:28:15 +0000 | [diff] [blame] | 49 | static void test_usb_storage_hotplug(void) |
| 50 | { |
| 51 | QDict *response; |
| 52 | |
| 53 | response = qmp("{'execute': 'device_add'," |
| 54 | " 'arguments': {" |
| 55 | " 'driver': 'usb-storage'," |
| 56 | " 'drive': 'drive0'," |
| 57 | " 'id': 'usbdev0'" |
| 58 | "}}"); |
| 59 | g_assert(response); |
| 60 | g_assert(!qdict_haskey(response, "error")); |
| 61 | QDECREF(response); |
| 62 | |
| 63 | response = qmp("{'execute': 'device_del'," |
| 64 | " 'arguments': {" |
| 65 | " 'id': 'usbdev0'" |
| 66 | "}}"); |
| 67 | g_assert(response); |
| 68 | g_assert(!qdict_haskey(response, "error")); |
| 69 | QDECREF(response); |
| 70 | |
| 71 | response = qmp(""); |
| 72 | g_assert(response); |
| 73 | g_assert(qdict_haskey(response, "event")); |
| 74 | g_assert(!strcmp(qdict_get_str(response, "event"), "DEVICE_DELETED")); |
| 75 | QDECREF(response); |
| 76 | } |
| 77 | |
Gonglei | 44ced58 | 2014-06-23 19:53:52 +0800 | [diff] [blame] | 78 | int main(int argc, char **argv) |
| 79 | { |
| 80 | int ret; |
| 81 | |
| 82 | g_test_init(&argc, &argv, NULL); |
| 83 | |
| 84 | qtest_add_func("/uhci/pci/init", test_uhci_init); |
Igor Mammedov | fbd942c | 2014-09-26 09:28:13 +0000 | [diff] [blame] | 85 | qtest_add_func("/uhci/pci/port1", test_port_1); |
Igor Mammedov | b393768 | 2014-09-26 09:28:14 +0000 | [diff] [blame] | 86 | qtest_add_func("/uhci/pci/hotplug", test_uhci_hotplug); |
Igor Mammedov | b6ca82f | 2014-09-26 09:28:15 +0000 | [diff] [blame] | 87 | qtest_add_func("/uhci/pci/hotplug/usb-storage", test_usb_storage_hotplug); |
Gonglei | 44ced58 | 2014-06-23 19:53:52 +0800 | [diff] [blame] | 88 | |
Igor Mammedov | fbd942c | 2014-09-26 09:28:13 +0000 | [diff] [blame] | 89 | qtest_start("-device piix3-usb-uhci,id=uhci,addr=1d.0" |
Kevin Wolf | b8e665e | 2014-11-20 16:27:09 +0100 | [diff] [blame] | 90 | " -drive id=drive0,if=none,file=/dev/null,format=raw" |
Igor Mammedov | fbd942c | 2014-09-26 09:28:13 +0000 | [diff] [blame] | 91 | " -device usb-tablet,bus=uhci.0,port=1"); |
Gonglei | 44ced58 | 2014-06-23 19:53:52 +0800 | [diff] [blame] | 92 | ret = g_test_run(); |
Igor Mammedov | fbd942c | 2014-09-26 09:28:13 +0000 | [diff] [blame] | 93 | qtest_end(); |
Gonglei | 44ced58 | 2014-06-23 19:53:52 +0800 | [diff] [blame] | 94 | |
| 95 | return ret; |
| 96 | } |