diff mbox

[04/30] test: virtio-net: check if hot-plug/unplug works

Message ID 1411559299-19042-5-git-send-email-imammedo@redhat.com
State New
Headers show

Commit Message

Igor Mammedov Sept. 24, 2014, 11:47 a.m. UTC
Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
 tests/virtio-net-test.c | 39 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)

Comments

Paolo Bonzini Sept. 24, 2014, 12:35 p.m. UTC | #1
Il 24/09/2014 13:47, Igor Mammedov ha scritto:
> Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> ---
>  tests/virtio-net-test.c | 39 +++++++++++++++++++++++++++++++++++++++
>  1 file changed, 39 insertions(+)
> 
> diff --git a/tests/virtio-net-test.c b/tests/virtio-net-test.c
> index df99343..b80a72f 100644
> --- a/tests/virtio-net-test.c
> +++ b/tests/virtio-net-test.c
> @@ -12,17 +12,56 @@
>  #include "libqtest.h"
>  #include "qemu/osdep.h"
>  
> +#define PCI_SLOT_HP             0x06
> +#define ACPI_PCIHP_ADDR         0xae00
> +#define PCI_EJ_BASE             0x0008
> +
>  /* Tests only initialization so far. TODO: Replace with functional tests */
>  static void pci_nop(void)
>  {
>  }
>  
> +static void hotplug(void)
> +{
> +    QDict *response;
> +
> +    response = qmp("{\"execute\": \"device_add\","
> +                   " \"arguments\": {"
> +                   "   \"driver\": \"virtio-net-pci\","
> +                   "   \"addr\": \"" stringify(PCI_SLOT_HP) "\","
> +                   "   \"id\": \"net1\""
> +                   "}}");
> +
> +    g_assert(response);
> +    g_assert(!qdict_haskey(response, "error"));
> +    QDECREF(response);
> +
> +    response = qmp("{\"execute\": \"device_del\","
> +                   " \"arguments\": {"
> +                   "   \"id\": \"net1\""
> +                   "}}");
> +
> +    g_assert(response);
> +    g_assert(!qdict_haskey(response, "error"));
> +    QDECREF(response);
> +
> +    outb(ACPI_PCIHP_ADDR + PCI_EJ_BASE, 1 << PCI_SLOT_HP);

Code duplication alarm! :)

Paolo

> +    response = qmp("");
> +    g_assert(response);
> +    g_assert(qdict_haskey(response, "event"));
> +    g_assert(!strcmp(qdict_get_str(response, "event"), "DEVICE_DELETED"));
> +    QDECREF(response);
> +}
> +
> +
>  int main(int argc, char **argv)
>  {
>      int ret;
>  
>      g_test_init(&argc, &argv, NULL);
>      qtest_add_func("/virtio/net/pci/nop", pci_nop);
> +    qtest_add_func("/virtio/net/pci/hotplug", hotplug);
>  
>      qtest_start("-device virtio-net-pci");
>      ret = g_test_run();
>
diff mbox

Patch

diff --git a/tests/virtio-net-test.c b/tests/virtio-net-test.c
index df99343..b80a72f 100644
--- a/tests/virtio-net-test.c
+++ b/tests/virtio-net-test.c
@@ -12,17 +12,56 @@ 
 #include "libqtest.h"
 #include "qemu/osdep.h"
 
+#define PCI_SLOT_HP             0x06
+#define ACPI_PCIHP_ADDR         0xae00
+#define PCI_EJ_BASE             0x0008
+
 /* Tests only initialization so far. TODO: Replace with functional tests */
 static void pci_nop(void)
 {
 }
 
+static void hotplug(void)
+{
+    QDict *response;
+
+    response = qmp("{\"execute\": \"device_add\","
+                   " \"arguments\": {"
+                   "   \"driver\": \"virtio-net-pci\","
+                   "   \"addr\": \"" stringify(PCI_SLOT_HP) "\","
+                   "   \"id\": \"net1\""
+                   "}}");
+
+    g_assert(response);
+    g_assert(!qdict_haskey(response, "error"));
+    QDECREF(response);
+
+    response = qmp("{\"execute\": \"device_del\","
+                   " \"arguments\": {"
+                   "   \"id\": \"net1\""
+                   "}}");
+
+    g_assert(response);
+    g_assert(!qdict_haskey(response, "error"));
+    QDECREF(response);
+
+    outb(ACPI_PCIHP_ADDR + PCI_EJ_BASE, 1 << PCI_SLOT_HP);
+
+    response = qmp("");
+    g_assert(response);
+    g_assert(qdict_haskey(response, "event"));
+    g_assert(!strcmp(qdict_get_str(response, "event"), "DEVICE_DELETED"));
+    QDECREF(response);
+}
+
+
 int main(int argc, char **argv)
 {
     int ret;
 
     g_test_init(&argc, &argv, NULL);
     qtest_add_func("/virtio/net/pci/nop", pci_nop);
+    qtest_add_func("/virtio/net/pci/hotplug", hotplug);
 
     qtest_start("-device virtio-net-pci");
     ret = g_test_run();