diff options
author | Igor Mammedov <imammedo@redhat.com> | 2014-09-26 09:28:12 +0000 |
---|---|---|
committer | Andreas Färber <afaerber@suse.de> | 2014-10-15 05:03:12 +0200 |
commit | b0354ec59640a23c3be544d904400e38be8ff51d (patch) | |
tree | 0b5ac65ce77ae925410d1c67abc02916f27a6599 /tests/libqos | |
parent | aaf36070510cd95f8d77ec208fda8a555b507a1d (diff) |
tests: usb: Move uhci port test code to libqos/usb.c
Move code necessary for testing uhci port into library
so it could be used by other USB tests.
Signed-off-by: Igor Mammedov <imammedo@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Andreas Färber <afaerber@suse.de>
Diffstat (limited to 'tests/libqos')
-rw-r--r-- | tests/libqos/usb.c | 37 | ||||
-rw-r--r-- | tests/libqos/usb.h | 14 |
2 files changed, 51 insertions, 0 deletions
diff --git a/tests/libqos/usb.c b/tests/libqos/usb.c new file mode 100644 index 0000000000..54865b4759 --- /dev/null +++ b/tests/libqos/usb.c @@ -0,0 +1,37 @@ +/* + * common code shared by usb tests + * + * Copyright (c) 2014 Red Hat, Inc + * + * Authors: + * Gerd Hoffmann <kraxel@redhat.com> + * John Snow <jsnow@redhat.com> + * Igor Mammedov <imammedo@redhat.com> + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + */ +#include <glib.h> +#include <string.h> +#include "libqtest.h" +#include "qemu/osdep.h" +#include "hw/usb/uhci-regs.h" +#include "libqos/usb.h" + +void qusb_pci_init_one(QPCIBus *pcibus, struct qhc *hc, uint32_t devfn, int bar) +{ + hc->dev = qpci_device_find(pcibus, devfn); + g_assert(hc->dev != NULL); + qpci_device_enable(hc->dev); + hc->base = qpci_iomap(hc->dev, bar, NULL); + g_assert(hc->base != NULL); +} + +void uhci_port_test(struct qhc *hc, int port, uint16_t expect) +{ + void *addr = hc->base + 0x10 + 2 * port; + uint16_t value = qpci_io_readw(hc->dev, addr); + uint16_t mask = ~(UHCI_PORT_WRITE_CLEAR | UHCI_PORT_RSVD1); + + g_assert((value & mask) == (expect & mask)); +} diff --git a/tests/libqos/usb.h b/tests/libqos/usb.h new file mode 100644 index 0000000000..7fcd669ac4 --- /dev/null +++ b/tests/libqos/usb.h @@ -0,0 +1,14 @@ +#ifndef LIBQOS_USB_H +#define LIBQOS_USB_H + +#include "libqos/pci-pc.h" + +struct qhc { + QPCIDevice *dev; + void *base; +}; + +void qusb_pci_init_one(QPCIBus *pcibus, struct qhc *hc, + uint32_t devfn, int bar); +void uhci_port_test(struct qhc *hc, int port, uint16_t expect); +#endif |