From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36861) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XeExv-0005xn-FL for qemu-devel@nongnu.org; Tue, 14 Oct 2014 23:09:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XeExp-0004gx-7V for qemu-devel@nongnu.org; Tue, 14 Oct 2014 23:09:31 -0400 Received: from cantor2.suse.de ([195.135.220.15]:49308 helo=mx2.suse.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XeExp-0004gV-0p for qemu-devel@nongnu.org; Tue, 14 Oct 2014 23:09:25 -0400 From: =?UTF-8?q?Andreas=20F=C3=A4rber?= Date: Wed, 15 Oct 2014 05:08:42 +0200 Message-Id: <1413342561-4754-9-git-send-email-afaerber@suse.de> In-Reply-To: <1413342561-4754-1-git-send-email-afaerber@suse.de> References: <1413342561-4754-1-git-send-email-afaerber@suse.de> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PULL 08/47] libqos: Add qpci_plug_device_test() and qpci_unplug_acpi_device_test() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Igor Mammedov , =?UTF-8?q?Andreas=20F=C3=A4rber?= From: Igor Mammedov Functions will be used for testing hot(un)plug of PCI devices. Signed-off-by: Igor Mammedov Reviewed-by: Paolo Bonzini Reviewed-by: Michael S. Tsirkin Signed-off-by: Andreas F=C3=A4rber --- tests/libqos/pci-pc.c | 49 +++++++++++++++++++++++++++++++++++++++++++++= ++++ tests/libqos/pci.h | 3 +++ 2 files changed, 52 insertions(+) diff --git a/tests/libqos/pci-pc.c b/tests/libqos/pci-pc.c index 0609294..6dba0db 100644 --- a/tests/libqos/pci-pc.c +++ b/tests/libqos/pci-pc.c @@ -20,6 +20,9 @@ =20 #include =20 +#define ACPI_PCIHP_ADDR 0xae00 +#define PCI_EJ_BASE 0x0008 + typedef struct QPCIBusPC { QPCIBus bus; @@ -247,3 +250,49 @@ void qpci_free_pc(QPCIBus *bus) =20 g_free(s); } + +void qpci_plug_device_test(const char *driver, const char *id, + uint8_t slot, const char *opts) +{ + QDict *response; + char *cmd; + + cmd =3D g_strdup_printf("{'execute': 'device_add'," + " 'arguments': {" + " 'driver': '%s'," + " 'addr': '%d'," + " %s%s" + " 'id': '%s'" + "}}", driver, slot, + opts ? opts : "", opts ? "," : "", + id); + response =3D qmp(cmd); + g_free(cmd); + g_assert(response); + g_assert(!qdict_haskey(response, "error")); + QDECREF(response); +} + +void qpci_unplug_acpi_device_test(const char *id, uint8_t slot) +{ + QDict *response; + char *cmd; + + cmd =3D g_strdup_printf("{'execute': 'device_del'," + " 'arguments': {" + " 'id': '%s'" + "}}", id); + response =3D qmp(cmd); + g_free(cmd); + g_assert(response); + g_assert(!qdict_haskey(response, "error")); + QDECREF(response); + + outb(ACPI_PCIHP_ADDR + PCI_EJ_BASE, 1 << slot); + + response =3D qmp(""); + g_assert(response); + g_assert(qdict_haskey(response, "event")); + g_assert(!strcmp(qdict_get_str(response, "event"), "DEVICE_DELETED")= ); + QDECREF(response); +} diff --git a/tests/libqos/pci.h b/tests/libqos/pci.h index d51eb9e..dfaee9e 100644 --- a/tests/libqos/pci.h +++ b/tests/libqos/pci.h @@ -87,4 +87,7 @@ void qpci_io_writel(QPCIDevice *dev, void *data, uint32= _t value); void *qpci_iomap(QPCIDevice *dev, int barno, uint64_t *sizeptr); void qpci_iounmap(QPCIDevice *dev, void *data); =20 +void qpci_plug_device_test(const char *driver, const char *id, + uint8_t slot, const char *opts); +void qpci_unplug_acpi_device_test(const char *id, uint8_t slot); #endif --=20 1.8.4.5