]> Git Repo - qemu.git/blame - tests/libqos/usb.c
tests: Don't assume structure of PCI IO base in ahci-test
[qemu.git] / tests / libqos / usb.c
CommitLineData
b0354ec5
IM
1/*
2 * common code shared by usb tests
3 *
4 * Copyright (c) 2014 Red Hat, Inc
5 *
6 * Authors:
7 * Gerd Hoffmann <[email protected]>
8 * John Snow <[email protected]>
9 * Igor Mammedov <[email protected]>
10 *
11 * This work is licensed under the terms of the GNU GPL, version 2 or later.
12 * See the COPYING file in the top-level directory.
13 */
681c28a3 14#include "qemu/osdep.h"
b0354ec5 15#include "libqtest.h"
b0354ec5
IM
16#include "hw/usb/uhci-regs.h"
17#include "libqos/usb.h"
18
19void qusb_pci_init_one(QPCIBus *pcibus, struct qhc *hc, uint32_t devfn, int bar)
20{
21 hc->dev = qpci_device_find(pcibus, devfn);
22 g_assert(hc->dev != NULL);
23 qpci_device_enable(hc->dev);
24 hc->base = qpci_iomap(hc->dev, bar, NULL);
25 g_assert(hc->base != NULL);
26}
27
28void uhci_port_test(struct qhc *hc, int port, uint16_t expect)
29{
30 void *addr = hc->base + 0x10 + 2 * port;
31 uint16_t value = qpci_io_readw(hc->dev, addr);
32 uint16_t mask = ~(UHCI_PORT_WRITE_CLEAR | UHCI_PORT_RSVD1);
33
34 g_assert((value & mask) == (expect & mask));
35}
b3937683
IM
36
37void usb_test_hotplug(const char *hcd_id, const int port,
38 void (*port_check)(void))
39{
40 QDict *response;
41 char *cmd;
42
43 cmd = g_strdup_printf("{'execute': 'device_add',"
44 " 'arguments': {"
45 " 'driver': 'usb-tablet',"
46 " 'port': '%d',"
47 " 'bus': '%s.0',"
48 " 'id': 'usbdev%d'"
49 "}}", port, hcd_id, port);
50 response = qmp(cmd);
51 g_free(cmd);
52 g_assert(response);
53 g_assert(!qdict_haskey(response, "error"));
54 QDECREF(response);
55
56 if (port_check) {
57 port_check();
58 }
59
60 cmd = g_strdup_printf("{'execute': 'device_del',"
61 " 'arguments': {"
62 " 'id': 'usbdev%d'"
63 "}}", port);
64 response = qmp(cmd);
65 g_free(cmd);
66 g_assert(response);
67 g_assert(qdict_haskey(response, "event"));
68 g_assert(!strcmp(qdict_get_str(response, "event"), "DEVICE_DELETED"));
69}
This page took 0.162249 seconds and 4 git commands to generate.