tests: qpci_unplug_acpi_device_test() should not rely on global_qtest
authorThomas Huth <thuth@redhat.com>
Tue, 9 Apr 2019 12:25:57 +0000 (14:25 +0200)
committerThomas Huth <thuth@redhat.com>
Wed, 8 May 2019 15:45:54 +0000 (17:45 +0200)
libqos functions should not use functions that require global_qtest to
be set, since such library functions could also be used by tests that
deal with multiple test states. Add a parameter to this function to
explicitly specify the test state.

Reviewed-by: Eric Blake <eblake@redhat.com>
Message-Id: <20190508143209.24350-1-thuth@redhat.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
tests/e1000e-test.c
tests/ivshmem-test.c
tests/libqos/pci-pc.c
tests/libqos/pci.h
tests/virtio-blk-test.c
tests/virtio-net-test.c
tests/virtio-rng-test.c

index 77ba8095bbfc0036729611195c7e0552dd90073c..6a946c048462ace81c283859da8a0d89737062ae 100644 (file)
@@ -231,8 +231,10 @@ static void test_e1000e_multiple_transfers(void *obj, void *data,
 
 static void test_e1000e_hotplug(void *obj, void *data, QGuestAllocator * alloc)
 {
+    QTestState *qts = global_qtest;  /* TODO: get rid of global_qtest here */
+
     qtest_qmp_device_add("e1000e", "e1000e_net", "{'addr': '0x06'}");
-    qpci_unplug_acpi_device_test("e1000e_net", 0x06);
+    qpci_unplug_acpi_device_test(qts, "e1000e_net", 0x06);
 }
 
 static void data_test_clear(void *sockets)
index 227561fbca3f7bc2def6e04e991d0b847eccef13..a467b8c03d0b69c3abee6b86dbe6c1200970e618 100644 (file)
@@ -383,18 +383,21 @@ static void test_ivshmem_server(void)
 
 static void test_ivshmem_hotplug(void)
 {
+    QTestState *qts;
     const char *arch = qtest_get_arch();
 
-    qtest_start("-object memory-backend-ram,size=1M,id=mb1");
+    qts = qtest_init("-object memory-backend-ram,size=1M,id=mb1");
 
+    global_qtest = qts;  /* TODO: Get rid of global_qtest here */
     qtest_qmp_device_add("ivshmem-plain", "iv1",
                          "{'addr': %s, 'memdev': 'mb1'}",
                          stringify(PCI_SLOT_HP));
     if (strcmp(arch, "ppc64") != 0) {
-        qpci_unplug_acpi_device_test("iv1", PCI_SLOT_HP);
+        qpci_unplug_acpi_device_test(qts, "iv1", PCI_SLOT_HP);
     }
 
-    qtest_end();
+    qtest_quit(qts);
+    global_qtest = NULL;
 }
 
 static void test_ivshmem_memdev(void)
index 407d8aff784d67343f07ab3032c025147904c180..634fedd0490542a4a6962d53e81fe8003a8e7f1e 100644 (file)
@@ -176,19 +176,19 @@ void qpci_free_pc(QPCIBus *bus)
     g_free(s);
 }
 
-void qpci_unplug_acpi_device_test(const char *id, uint8_t slot)
+void qpci_unplug_acpi_device_test(QTestState *qts, const char *id, uint8_t slot)
 {
     QDict *response;
 
-    response = qmp("{'execute': 'device_del', 'arguments': {'id': %s}}",
-                   id);
+    response = qtest_qmp(qts, "{'execute': 'device_del',"
+                              " 'arguments': {'id': %s}}", id);
     g_assert(response);
     g_assert(!qdict_haskey(response, "error"));
     qobject_unref(response);
 
-    outb(ACPI_PCIHP_ADDR + PCI_EJ_BASE, 1 << slot);
+    qtest_outb(qts, ACPI_PCIHP_ADDR + PCI_EJ_BASE, 1 << slot);
 
-    qmp_eventwait("DEVICE_DELETED");
+    qtest_qmp_eventwait(qts, "DEVICE_DELETED");
 }
 
 static void qpci_pc_register_nodes(void)
index 8e1d292a7da94659ce3907a2a7da8e6c9ba2fa88..a5389a58450763ac37466376f894563fd0902ce8 100644 (file)
@@ -123,7 +123,7 @@ QPCIBar qpci_iomap(QPCIDevice *dev, int barno, uint64_t *sizeptr);
 void qpci_iounmap(QPCIDevice *dev, QPCIBar addr);
 QPCIBar qpci_legacy_iomap(QPCIDevice *dev, uint16_t addr);
 
-void qpci_unplug_acpi_device_test(const char *id, uint8_t slot);
+void qpci_unplug_acpi_device_test(QTestState *qs, const char *id, uint8_t slot);
 
 void add_qpci_address(QOSGraphEdgeOptions *opts, QPCIAddress *addr);
 #endif
index b65365934b5eb67575703cd64ee2192ea4eeb38a..fe1168a90ad0359ac2af4a3efaeefd94e18ba3f1 100644 (file)
@@ -679,6 +679,7 @@ static void pci_hotplug(void *obj, void *data, QGuestAllocator *t_alloc)
 {
     QVirtioPCIDevice *dev1 = obj;
     QVirtioPCIDevice *dev;
+    QTestState *qts = dev1->pdev->bus->qts;
 
     /* plug secondary disk */
     qtest_qmp_device_add("virtio-blk-pci", "drv1",
@@ -693,7 +694,7 @@ static void pci_hotplug(void *obj, void *data, QGuestAllocator *t_alloc)
     qos_object_destroy((QOSGraphObject *)dev);
 
     /* unplug secondary disk */
-    qpci_unplug_acpi_device_test("drv1", PCI_SLOT_HP);
+    qpci_unplug_acpi_device_test(qts, "drv1", PCI_SLOT_HP);
 }
 
 /*
index 0d956f36fef9fd383651216f2580a58c90f8dfbd..163126cf07e1aa401d7d91f3bff91a889cec1cf5 100644 (file)
@@ -162,13 +162,15 @@ static void stop_cont_test(void *obj, void *data, QGuestAllocator *t_alloc)
 
 static void hotplug(void *obj, void *data, QGuestAllocator *t_alloc)
 {
+    QVirtioPCIDevice *dev = obj;
+    QTestState *qts = dev->pdev->bus->qts;
     const char *arch = qtest_get_arch();
 
     qtest_qmp_device_add("virtio-net-pci", "net1",
                          "{'addr': %s}", stringify(PCI_SLOT_HP));
 
     if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
-        qpci_unplug_acpi_device_test("net1", PCI_SLOT_HP);
+        qpci_unplug_acpi_device_test(qts, "net1", PCI_SLOT_HP);
     }
 }
 
index 5309c7c8ab6fae332bf5b21869fe12a538d6ee44..fcb22481bd385e7820e9079553137d8598bdc49e 100644 (file)
 
 static void rng_hotplug(void *obj, void *data, QGuestAllocator *alloc)
 {
+    QVirtioPCIDevice *dev = obj;
+    QTestState *qts = dev->pdev->bus->qts;
+
     const char *arch = qtest_get_arch();
 
     qtest_qmp_device_add("virtio-rng-pci", "rng1",
                          "{'addr': %s}", stringify(PCI_SLOT_HP));
 
     if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
-        qpci_unplug_acpi_device_test("rng1", PCI_SLOT_HP);
+        qpci_unplug_acpi_device_test(qts, "rng1", PCI_SLOT_HP);
     }
 }