QEMU-Devel Archive on lore.kernel.org
 help / color / Atom feed
* [Qemu-devel] [PATCH 0/6] First batch of global_qtest-removement patches for QEMU 4.2
@ 2019-08-13  9:30 Thomas Huth
  2019-08-13  9:30 ` [Qemu-devel] [PATCH 1/6] tests/libqos: Make generic virtio code independent from global_qtest Thomas Huth
                   ` (6 more replies)
  0 siblings, 7 replies; 16+ messages in thread
From: Thomas Huth @ 2019-08-13  9:30 UTC (permalink / raw)
  To: qemu-devel
  Cc: Fam Zheng, Laurent Vivier, Thomas Huth, qemu-block, Amit Shah,
	John Snow, Jason Wang, Dr. David Alan Gilbert, Markus Armbruster,
	Greg Kurz, Gerd Hoffmann, Stefan Hajnoczi, Paolo Bonzini

While global_qtest and its wrapper functions work fine for tests that only
run one instance of QEMU, using the global_qtest variable in our qtests is
very problematic for tests that use multiple test states (e.g. migration
tests). Thus the core libqtest and libqos library functions should not
depend on global_qtest or functions that rely on this variable.

This patch series gets rid of these dependencies in most of the libqtest
and libqos code.

Thomas Huth (6):
  tests/libqos: Make generic virtio code independent from global_qtest
  tests/libqos: Make virtio-pci code independent from global_qtest
  tests/libqtest: Remove unused function hmp()
  tests/libqtest: Clean up qtest_cb_for_every_machine() wrt global_qtest
  tests/libqtest: Make qtest_qmp_device_add/del independent from
    global_qtest
  tests/libqtest: Make qmp_assert_success() independent from
    global_qtest

 tests/cpu-plug-test.c      |  15 ++--
 tests/e1000e-test.c        |   2 +-
 tests/ivshmem-test.c       |   2 +-
 tests/libqos/usb.c         |   6 +-
 tests/libqos/usb.h         |   2 +-
 tests/libqos/virtio-pci.c  |   8 +-
 tests/libqos/virtio.c      |  74 +++++++++---------
 tests/libqos/virtio.h      |  27 ++++---
 tests/libqtest.c           |  37 ++++-----
 tests/libqtest.h           |  24 +++---
 tests/usb-hcd-ohci-test.c  |   2 +-
 tests/usb-hcd-uhci-test.c  |   8 +-
 tests/usb-hcd-xhci-test.c  |  22 +++---
 tests/virtio-9p-test.c     |  16 ++--
 tests/virtio-blk-test.c    | 153 +++++++++++++++++++------------------
 tests/virtio-ccw-test.c    |  18 +++--
 tests/virtio-net-test.c    |  35 +++++----
 tests/virtio-rng-test.c    |   2 +-
 tests/virtio-scsi-test.c   |  22 +++---
 tests/virtio-serial-test.c |   4 +-
 20 files changed, 251 insertions(+), 228 deletions(-)

-- 
2.18.1



^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Qemu-devel] [PATCH 1/6] tests/libqos: Make generic virtio code independent from global_qtest
  2019-08-13  9:30 [Qemu-devel] [PATCH 0/6] First batch of global_qtest-removement patches for QEMU 4.2 Thomas Huth
@ 2019-08-13  9:30 ` Thomas Huth
  2019-08-13 15:18   ` Eric Blake
  2019-08-13  9:30 ` [Qemu-devel] [PATCH 2/6] tests/libqos: Make virtio-pci " Thomas Huth
                   ` (5 subsequent siblings)
  6 siblings, 1 reply; 16+ messages in thread
From: Thomas Huth @ 2019-08-13  9:30 UTC (permalink / raw)
  To: qemu-devel
  Cc: Fam Zheng, Laurent Vivier, Thomas Huth, qemu-block, Amit Shah,
	John Snow, Jason Wang, Dr. David Alan Gilbert, Markus Armbruster,
	Greg Kurz, Gerd Hoffmann, Stefan Hajnoczi, Paolo Bonzini

The libqos library functions should never depend on global_qtest,
since these functions might be used in tests that track multiple
test states. Pass around a pointer to the QTestState instead.

Signed-off-by: Thomas Huth <thuth@redhat.com>
---
 tests/libqos/virtio.c    |  74 ++++++++++---------
 tests/libqos/virtio.h    |  27 +++----
 tests/virtio-9p-test.c   |  16 +++--
 tests/virtio-blk-test.c  | 151 ++++++++++++++++++++-------------------
 tests/virtio-net-test.c  |  33 +++++----
 tests/virtio-scsi-test.c |  13 ++--
 6 files changed, 170 insertions(+), 144 deletions(-)

diff --git a/tests/libqos/virtio.c b/tests/libqos/virtio.c
index b4c01dc0c1..191e2f97f9 100644
--- a/tests/libqos/virtio.c
+++ b/tests/libqos/virtio.c
@@ -101,7 +101,7 @@ void qvirtio_wait_queue_isr(QVirtioDevice *d,
  * The virtqueue interrupt must not be raised, making this useful for testing
  * event_index functionality.
  */
-uint8_t qvirtio_wait_status_byte_no_isr(QVirtioDevice *d,
+uint8_t qvirtio_wait_status_byte_no_isr(QTestState *qts, QVirtioDevice *d,
                                         QVirtQueue *vq,
                                         uint64_t addr,
                                         gint64 timeout_us)
@@ -126,7 +126,7 @@ uint8_t qvirtio_wait_status_byte_no_isr(QVirtioDevice *d,
  *
  * This function waits for the next completed request on the used ring.
  */
-void qvirtio_wait_used_elem(QVirtioDevice *d,
+void qvirtio_wait_used_elem(QTestState *qts, QVirtioDevice *d,
                             QVirtQueue *vq,
                             uint32_t desc_idx,
                             uint32_t *len,
@@ -140,7 +140,7 @@ void qvirtio_wait_used_elem(QVirtioDevice *d,
         clock_step(100);
 
         if (d->bus->get_queue_isr_status(d, vq) &&
-            qvirtqueue_get_buf(vq, &got_desc_idx, len)) {
+            qvirtqueue_get_buf(qts, vq, &got_desc_idx, len)) {
             g_assert_cmpint(got_desc_idx, ==, desc_idx);
             return;
         }
@@ -193,7 +193,7 @@ void qvring_init(QTestState *qts, const QGuestAllocator *alloc, QVirtQueue *vq,
                  0);
 }
 
-QVRingIndirectDesc *qvring_indirect_desc_setup(QVirtioDevice *d,
+QVRingIndirectDesc *qvring_indirect_desc_setup(QTestState *qs, QVirtioDevice *d,
                                         QGuestAllocator *alloc, uint16_t elem)
 {
     int i;
@@ -205,41 +205,41 @@ QVRingIndirectDesc *qvring_indirect_desc_setup(QVirtioDevice *d,
 
     for (i = 0; i < elem - 1; ++i) {
         /* indirect->desc[i].addr */
-        writeq(indirect->desc + (16 * i), 0);
+        qtest_writeq(qs, indirect->desc + (16 * i), 0);
         /* indirect->desc[i].flags */
-        writew(indirect->desc + (16 * i) + 12, VRING_DESC_F_NEXT);
+        qtest_writew(qs, indirect->desc + (16 * i) + 12, VRING_DESC_F_NEXT);
         /* indirect->desc[i].next */
-        writew(indirect->desc + (16 * i) + 14, i + 1);
+        qtest_writew(qs, indirect->desc + (16 * i) + 14, i + 1);
     }
 
     return indirect;
 }
 
-void qvring_indirect_desc_add(QVRingIndirectDesc *indirect, uint64_t data,
-                                                    uint32_t len, bool write)
+void qvring_indirect_desc_add(QTestState *qts, QVRingIndirectDesc *indirect,
+                              uint64_t data, uint32_t len, bool write)
 {
     uint16_t flags;
 
     g_assert_cmpint(indirect->index, <, indirect->elem);
 
-    flags = readw(indirect->desc + (16 * indirect->index) + 12);
+    flags = qtest_readw(qts, indirect->desc + (16 * indirect->index) + 12);
 
     if (write) {
         flags |= VRING_DESC_F_WRITE;
     }
 
     /* indirect->desc[indirect->index].addr */
-    writeq(indirect->desc + (16 * indirect->index), data);
+    qtest_writeq(qts, indirect->desc + (16 * indirect->index), data);
     /* indirect->desc[indirect->index].len */
-    writel(indirect->desc + (16 * indirect->index) + 8, len);
+    qtest_writel(qts, indirect->desc + (16 * indirect->index) + 8, len);
     /* indirect->desc[indirect->index].flags */
-    writew(indirect->desc + (16 * indirect->index) + 12, flags);
+    qtest_writew(qts, indirect->desc + (16 * indirect->index) + 12, flags);
 
     indirect->index++;
 }
 
-uint32_t qvirtqueue_add(QVirtQueue *vq, uint64_t data, uint32_t len, bool write,
-                                                                    bool next)
+uint32_t qvirtqueue_add(QTestState *qts, QVirtQueue *vq, uint64_t data,
+                        uint32_t len, bool write, bool next)
 {
     uint16_t flags = 0;
     vq->num_free--;
@@ -253,16 +253,17 @@ uint32_t qvirtqueue_add(QVirtQueue *vq, uint64_t data, uint32_t len, bool write,
     }
 
     /* vq->desc[vq->free_head].addr */
-    writeq(vq->desc + (16 * vq->free_head), data);
+    qtest_writeq(qts, vq->desc + (16 * vq->free_head), data);
     /* vq->desc[vq->free_head].len */
-    writel(vq->desc + (16 * vq->free_head) + 8, len);
+    qtest_writel(qts, vq->desc + (16 * vq->free_head) + 8, len);
     /* vq->desc[vq->free_head].flags */
-    writew(vq->desc + (16 * vq->free_head) + 12, flags);
+    qtest_writew(qts, vq->desc + (16 * vq->free_head) + 12, flags);
 
     return vq->free_head++; /* Return and increase, in this order */
 }
 
-uint32_t qvirtqueue_add_indirect(QVirtQueue *vq, QVRingIndirectDesc *indirect)
+uint32_t qvirtqueue_add_indirect(QTestState *qts, QVirtQueue *vq,
+                                 QVRingIndirectDesc *indirect)
 {
     g_assert(vq->indirect);
     g_assert_cmpint(vq->size, >=, indirect->elem);
@@ -271,33 +272,35 @@ uint32_t qvirtqueue_add_indirect(QVirtQueue *vq, QVRingIndirectDesc *indirect)
     vq->num_free--;
 
     /* vq->desc[vq->free_head].addr */
-    writeq(vq->desc + (16 * vq->free_head), indirect->desc);
+    qtest_writeq(qts, vq->desc + (16 * vq->free_head), indirect->desc);
     /* vq->desc[vq->free_head].len */
-    writel(vq->desc + (16 * vq->free_head) + 8,
+    qtest_writel(qts, vq->desc + (16 * vq->free_head) + 8,
            sizeof(struct vring_desc) * indirect->elem);
     /* vq->desc[vq->free_head].flags */
-    writew(vq->desc + (16 * vq->free_head) + 12, VRING_DESC_F_INDIRECT);
+    qtest_writew(qts, vq->desc + (16 * vq->free_head) + 12,
+                 VRING_DESC_F_INDIRECT);
 
     return vq->free_head++; /* Return and increase, in this order */
 }
 
-void qvirtqueue_kick(QVirtioDevice *d, QVirtQueue *vq, uint32_t free_head)
+void qvirtqueue_kick(QTestState *qts, QVirtioDevice *d, QVirtQueue *vq,
+                     uint32_t free_head)
 {
     /* vq->avail->idx */
-    uint16_t idx = readw(vq->avail + 2);
+    uint16_t idx = qtest_readw(qts, vq->avail + 2);
     /* vq->used->flags */
     uint16_t flags;
     /* vq->used->avail_event */
     uint16_t avail_event;
 
     /* vq->avail->ring[idx % vq->size] */
-    writew(vq->avail + 4 + (2 * (idx % vq->size)), free_head);
+    qtest_writew(qts, vq->avail + 4 + (2 * (idx % vq->size)), free_head);
     /* vq->avail->idx */
-    writew(vq->avail + 2, idx + 1);
+    qtest_writew(qts, vq->avail + 2, idx + 1);
 
     /* Must read after idx is updated */
-    flags = readw(vq->avail);
-    avail_event = readw(vq->used + 4 +
+    flags = qtest_readw(qts, vq->avail);
+    avail_event = qtest_readw(qts, vq->used + 4 +
                                 sizeof(struct vring_used_elem) * vq->size);
 
     /* < 1 because we add elements to avail queue one by one */
@@ -317,12 +320,13 @@ void qvirtqueue_kick(QVirtioDevice *d, QVirtQueue *vq, uint32_t free_head)
  *
  * Returns: true if an element was ready, false otherwise
  */
-bool qvirtqueue_get_buf(QVirtQueue *vq, uint32_t *desc_idx, uint32_t *len)
+bool qvirtqueue_get_buf(QTestState *qts, QVirtQueue *vq, uint32_t *desc_idx,
+                        uint32_t *len)
 {
     uint16_t idx;
     uint64_t elem_addr;
 
-    idx = readw(vq->used + offsetof(struct vring_used, idx));
+    idx = qtest_readw(qts, vq->used + offsetof(struct vring_used, idx));
     if (idx == vq->last_used_idx) {
         return false;
     }
@@ -333,23 +337,25 @@ bool qvirtqueue_get_buf(QVirtQueue *vq, uint32_t *desc_idx, uint32_t *len)
         sizeof(struct vring_used_elem);
 
     if (desc_idx) {
-        *desc_idx = readl(elem_addr + offsetof(struct vring_used_elem, id));
+        *desc_idx = qtest_readl(qts, elem_addr +
+                                     offsetof(struct vring_used_elem, id));
     }
 
     if (len) {
-        *len = readw(elem_addr + offsetof(struct vring_used_elem, len));
+        *len = qtest_readw(qts, elem_addr +
+                                offsetof(struct vring_used_elem, len));
     }
 
     vq->last_used_idx++;
     return true;
 }
 
-void qvirtqueue_set_used_event(QVirtQueue *vq, uint16_t idx)
+void qvirtqueue_set_used_event(QTestState *qts, QVirtQueue *vq, uint16_t idx)
 {
     g_assert(vq->event);
 
     /* vq->avail->used_event */
-    writew(vq->avail + 4 + (2 * vq->size), idx);
+    qtest_writew(qts, vq->avail + 4 + (2 * vq->size), idx);
 }
 
 void qvirtio_start_device(QVirtioDevice *vdev)
diff --git a/tests/libqos/virtio.h b/tests/libqos/virtio.h
index 7b97f5e567..b6e21110b8 100644
--- a/tests/libqos/virtio.h
+++ b/tests/libqos/virtio.h
@@ -114,11 +114,11 @@ void qvirtio_set_driver_ok(QVirtioDevice *d);
 
 void qvirtio_wait_queue_isr(QVirtioDevice *d,
                             QVirtQueue *vq, gint64 timeout_us);
-uint8_t qvirtio_wait_status_byte_no_isr(QVirtioDevice *d,
+uint8_t qvirtio_wait_status_byte_no_isr(QTestState *qts, QVirtioDevice *d,
                                         QVirtQueue *vq,
                                         uint64_t addr,
                                         gint64 timeout_us);
-void qvirtio_wait_used_elem(QVirtioDevice *d,
+void qvirtio_wait_used_elem(QTestState *qts, QVirtioDevice *d,
                             QVirtQueue *vq,
                             uint32_t desc_idx,
                             uint32_t *len,
@@ -131,17 +131,20 @@ void qvirtqueue_cleanup(const QVirtioBus *bus, QVirtQueue *vq,
 
 void qvring_init(QTestState *qts, const QGuestAllocator *alloc, QVirtQueue *vq,
                  uint64_t addr);
-QVRingIndirectDesc *qvring_indirect_desc_setup(QVirtioDevice *d,
+QVRingIndirectDesc *qvring_indirect_desc_setup(QTestState *qs, QVirtioDevice *d,
                                         QGuestAllocator *alloc, uint16_t elem);
-void qvring_indirect_desc_add(QVRingIndirectDesc *indirect, uint64_t data,
-                                                    uint32_t len, bool write);
-uint32_t qvirtqueue_add(QVirtQueue *vq, uint64_t data, uint32_t len, bool write,
-                                                                    bool next);
-uint32_t qvirtqueue_add_indirect(QVirtQueue *vq, QVRingIndirectDesc *indirect);
-void qvirtqueue_kick(QVirtioDevice *d, QVirtQueue *vq, uint32_t free_head);
-bool qvirtqueue_get_buf(QVirtQueue *vq, uint32_t *desc_idx, uint32_t *len);
-
-void qvirtqueue_set_used_event(QVirtQueue *vq, uint16_t idx);
+void qvring_indirect_desc_add(QTestState *qts, QVRingIndirectDesc *indirect,
+                              uint64_t data, uint32_t len, bool write);
+uint32_t qvirtqueue_add(QTestState *qts, QVirtQueue *vq, uint64_t data,
+                        uint32_t len, bool write, bool next);
+uint32_t qvirtqueue_add_indirect(QTestState *qts, QVirtQueue *vq,
+                                 QVRingIndirectDesc *indirect);
+void qvirtqueue_kick(QTestState *qts, QVirtioDevice *d, QVirtQueue *vq,
+                     uint32_t free_head);
+bool qvirtqueue_get_buf(QTestState *qts, QVirtQueue *vq, uint32_t *desc_idx,
+                        uint32_t *len);
+
+void qvirtqueue_set_used_event(QTestState *qts, QVirtQueue *vq, uint16_t idx);
 
 void qvirtio_start_device(QVirtioDevice *vdev);
 
diff --git a/tests/virtio-9p-test.c b/tests/virtio-9p-test.c
index ac49bca991..30e6cf3e63 100644
--- a/tests/virtio-9p-test.c
+++ b/tests/virtio-9p-test.c
@@ -39,6 +39,7 @@ static void pci_config(void *obj, void *data, QGuestAllocator *t_alloc)
 #define P9_MAX_SIZE 4096 /* Max size of a T-message or R-message */
 
 typedef struct {
+    QTestState *qts;
     QVirtio9P *v9p;
     uint16_t tag;
     uint64_t t_msg;
@@ -52,7 +53,7 @@ typedef struct {
 
 static void v9fs_memwrite(P9Req *req, const void *addr, size_t len)
 {
-    memwrite(req->t_msg + req->t_off, addr, len);
+    qtest_memwrite(req->qts, req->t_msg + req->t_off, addr, len);
     req->t_off += len;
 }
 
@@ -63,7 +64,7 @@ static void v9fs_memskip(P9Req *req, size_t len)
 
 static void v9fs_memread(P9Req *req, void *addr, size_t len)
 {
-    memread(req->r_msg + req->r_off, addr, len);
+    qtest_memread(req->qts, req->r_msg + req->r_off, addr, len);
     req->r_off += len;
 }
 
@@ -158,6 +159,7 @@ static P9Req *v9fs_req_init(QVirtio9P *v9p, uint32_t size, uint8_t id,
 
     g_assert_cmpint(total_size, <=, P9_MAX_SIZE);
 
+    req->qts = global_qtest;
     req->v9p = v9p;
     req->t_size = total_size;
     req->t_msg = guest_alloc(alloc, req->t_size);
@@ -171,10 +173,10 @@ static void v9fs_req_send(P9Req *req)
     QVirtio9P *v9p = req->v9p;
 
     req->r_msg = guest_alloc(alloc, P9_MAX_SIZE);
-    req->free_head = qvirtqueue_add(v9p->vq, req->t_msg, req->t_size, false,
-                                    true);
-    qvirtqueue_add(v9p->vq, req->r_msg, P9_MAX_SIZE, true, false);
-    qvirtqueue_kick(v9p->vdev, v9p->vq, req->free_head);
+    req->free_head = qvirtqueue_add(req->qts, v9p->vq, req->t_msg, req->t_size,
+                                    false, true);
+    qvirtqueue_add(req->qts, v9p->vq, req->r_msg, P9_MAX_SIZE, true, false);
+    qvirtqueue_kick(req->qts, v9p->vdev, v9p->vq, req->free_head);
     req->t_off = 0;
 }
 
@@ -195,7 +197,7 @@ static void v9fs_req_wait_for_reply(P9Req *req, uint32_t *len)
 {
     QVirtio9P *v9p = req->v9p;
 
-    qvirtio_wait_used_elem(v9p->vdev, v9p->vq, req->free_head, len,
+    qvirtio_wait_used_elem(req->qts, v9p->vdev, v9p->vq, req->free_head, len,
                            QVIRTIO_9P_TIMEOUT_US);
 }
 
diff --git a/tests/virtio-blk-test.c b/tests/virtio-blk-test.c
index 1b02714bc7..ff365c8035 100644
--- a/tests/virtio-blk-test.c
+++ b/tests/virtio-blk-test.c
@@ -123,6 +123,7 @@ static void test_basic(QVirtioDevice *dev, QGuestAllocator *alloc,
     uint32_t free_head;
     uint8_t status;
     char *data;
+    QTestState *qts = global_qtest;
 
     capacity = qvirtio_config_readq(dev, 0);
 
@@ -149,13 +150,14 @@ static void test_basic(QVirtioDevice *dev, QGuestAllocator *alloc,
 
     g_free(req.data);
 
-    free_head = qvirtqueue_add(vq, req_addr, 16, false, true);
-    qvirtqueue_add(vq, req_addr + 16, 512, false, true);
-    qvirtqueue_add(vq, req_addr + 528, 1, true, false);
+    free_head = qvirtqueue_add(qts, vq, req_addr, 16, false, true);
+    qvirtqueue_add(qts, vq, req_addr + 16, 512, false, true);
+    qvirtqueue_add(qts, vq, req_addr + 528, 1, true, false);
 
-    qvirtqueue_kick(dev, vq, free_head);
+    qvirtqueue_kick(qts, dev, vq, free_head);
 
-    qvirtio_wait_used_elem(dev, vq, free_head, NULL, QVIRTIO_BLK_TIMEOUT_US);
+    qvirtio_wait_used_elem(qts, dev, vq, free_head, NULL,
+                           QVIRTIO_BLK_TIMEOUT_US);
     status = readb(req_addr + 528);
     g_assert_cmpint(status, ==, 0);
 
@@ -171,13 +173,14 @@ static void test_basic(QVirtioDevice *dev, QGuestAllocator *alloc,
 
     g_free(req.data);
 
-    free_head = qvirtqueue_add(vq, req_addr, 16, false, true);
-    qvirtqueue_add(vq, req_addr + 16, 512, true, true);
-    qvirtqueue_add(vq, req_addr + 528, 1, true, false);
+    free_head = qvirtqueue_add(qts, vq, req_addr, 16, false, true);
+    qvirtqueue_add(qts, vq, req_addr + 16, 512, true, true);
+    qvirtqueue_add(qts, vq, req_addr + 528, 1, true, false);
 
-    qvirtqueue_kick(dev, vq, free_head);
+    qvirtqueue_kick(qts, dev, vq, free_head);
 
-    qvirtio_wait_used_elem(dev, vq, free_head, NULL, QVIRTIO_BLK_TIMEOUT_US);
+    qvirtio_wait_used_elem(qts, dev, vq, free_head, NULL,
+                           QVIRTIO_BLK_TIMEOUT_US);
     status = readb(req_addr + 528);
     g_assert_cmpint(status, ==, 0);
 
@@ -206,13 +209,14 @@ static void test_basic(QVirtioDevice *dev, QGuestAllocator *alloc,
 
         req_addr = virtio_blk_request(alloc, dev, &req, sizeof(dwz_hdr));
 
-        free_head = qvirtqueue_add(vq, req_addr, 16, false, true);
-        qvirtqueue_add(vq, req_addr + 16, sizeof(dwz_hdr), false, true);
-        qvirtqueue_add(vq, req_addr + 16 + sizeof(dwz_hdr), 1, true, false);
+        free_head = qvirtqueue_add(qts, vq, req_addr, 16, false, true);
+        qvirtqueue_add(qts, vq, req_addr + 16, sizeof(dwz_hdr), false, true);
+        qvirtqueue_add(qts, vq, req_addr + 16 + sizeof(dwz_hdr), 1, true,
+                       false);
 
-        qvirtqueue_kick(dev, vq, free_head);
+        qvirtqueue_kick(qts, dev, vq, free_head);
 
-        qvirtio_wait_used_elem(dev, vq, free_head, NULL,
+        qvirtio_wait_used_elem(qts, dev, vq, free_head, NULL,
                                QVIRTIO_BLK_TIMEOUT_US);
         status = readb(req_addr + 16 + sizeof(dwz_hdr));
         g_assert_cmpint(status, ==, 0);
@@ -229,13 +233,13 @@ static void test_basic(QVirtioDevice *dev, QGuestAllocator *alloc,
 
         g_free(req.data);
 
-        free_head = qvirtqueue_add(vq, req_addr, 16, false, true);
-        qvirtqueue_add(vq, req_addr + 16, 512, true, true);
-        qvirtqueue_add(vq, req_addr + 528, 1, true, false);
+        free_head = qvirtqueue_add(qts, vq, req_addr, 16, false, true);
+        qvirtqueue_add(qts, vq, req_addr + 16, 512, true, true);
+        qvirtqueue_add(qts, vq, req_addr + 528, 1, true, false);
 
-        qvirtqueue_kick(dev, vq, free_head);
+        qvirtqueue_kick(qts, dev, vq, free_head);
 
-        qvirtio_wait_used_elem(dev, vq, free_head, NULL,
+        qvirtio_wait_used_elem(qts, dev, vq, free_head, NULL,
                                QVIRTIO_BLK_TIMEOUT_US);
         status = readb(req_addr + 528);
         g_assert_cmpint(status, ==, 0);
@@ -263,13 +267,13 @@ static void test_basic(QVirtioDevice *dev, QGuestAllocator *alloc,
 
         req_addr = virtio_blk_request(alloc, dev, &req, sizeof(dwz_hdr));
 
-        free_head = qvirtqueue_add(vq, req_addr, 16, false, true);
-        qvirtqueue_add(vq, req_addr + 16, sizeof(dwz_hdr), false, true);
-        qvirtqueue_add(vq, req_addr + 16 + sizeof(dwz_hdr), 1, true, false);
+        free_head = qvirtqueue_add(qts, vq, req_addr, 16, false, true);
+        qvirtqueue_add(qts, vq, req_addr + 16, sizeof(dwz_hdr), false, true);
+        qvirtqueue_add(qts, vq, req_addr + 16 + sizeof(dwz_hdr), 1, true, false);
 
-        qvirtqueue_kick(dev, vq, free_head);
+        qvirtqueue_kick(qts, dev, vq, free_head);
 
-        qvirtio_wait_used_elem(dev, vq, free_head, NULL,
+        qvirtio_wait_used_elem(qts, dev, vq, free_head, NULL,
                                QVIRTIO_BLK_TIMEOUT_US);
         status = readb(req_addr + 16 + sizeof(dwz_hdr));
         g_assert_cmpint(status, ==, 0);
@@ -290,11 +294,11 @@ static void test_basic(QVirtioDevice *dev, QGuestAllocator *alloc,
 
         g_free(req.data);
 
-        free_head = qvirtqueue_add(vq, req_addr, 528, false, true);
-        qvirtqueue_add(vq, req_addr + 528, 1, true, false);
-        qvirtqueue_kick(dev, vq, free_head);
+        free_head = qvirtqueue_add(qts, vq, req_addr, 528, false, true);
+        qvirtqueue_add(qts, vq, req_addr + 528, 1, true, false);
+        qvirtqueue_kick(qts, dev, vq, free_head);
 
-        qvirtio_wait_used_elem(dev, vq, free_head, NULL,
+        qvirtio_wait_used_elem(qts, dev, vq, free_head, NULL,
                                QVIRTIO_BLK_TIMEOUT_US);
         status = readb(req_addr + 528);
         g_assert_cmpint(status, ==, 0);
@@ -311,12 +315,12 @@ static void test_basic(QVirtioDevice *dev, QGuestAllocator *alloc,
 
         g_free(req.data);
 
-        free_head = qvirtqueue_add(vq, req_addr, 16, false, true);
-        qvirtqueue_add(vq, req_addr + 16, 513, true, false);
+        free_head = qvirtqueue_add(qts, vq, req_addr, 16, false, true);
+        qvirtqueue_add(qts, vq, req_addr + 16, 513, true, false);
 
-        qvirtqueue_kick(dev, vq, free_head);
+        qvirtqueue_kick(qts, dev, vq, free_head);
 
-        qvirtio_wait_used_elem(dev, vq, free_head, NULL,
+        qvirtio_wait_used_elem(qts, dev, vq, free_head, NULL,
                                QVIRTIO_BLK_TIMEOUT_US);
         status = readb(req_addr + 528);
         g_assert_cmpint(status, ==, 0);
@@ -353,6 +357,7 @@ static void indirect(void *obj, void *u_data, QGuestAllocator *t_alloc)
     uint32_t free_head;
     uint8_t status;
     char *data;
+    QTestState *qts = global_qtest;
 
     capacity = qvirtio_config_readq(dev, 0);
     g_assert_cmpint(capacity, ==, TEST_IMAGE_SIZE / 512);
@@ -378,13 +383,13 @@ static void indirect(void *obj, void *u_data, QGuestAllocator *t_alloc)
 
     g_free(req.data);
 
-    indirect = qvring_indirect_desc_setup(dev, t_alloc, 2);
-    qvring_indirect_desc_add(indirect, req_addr, 528, false);
-    qvring_indirect_desc_add(indirect, req_addr + 528, 1, true);
-    free_head = qvirtqueue_add_indirect(vq, indirect);
-    qvirtqueue_kick(dev, vq, free_head);
+    indirect = qvring_indirect_desc_setup(qts, dev, t_alloc, 2);
+    qvring_indirect_desc_add(qts, indirect, req_addr, 528, false);
+    qvring_indirect_desc_add(qts, indirect, req_addr + 528, 1, true);
+    free_head = qvirtqueue_add_indirect(qts, vq, indirect);
+    qvirtqueue_kick(qts, dev, vq, free_head);
 
-    qvirtio_wait_used_elem(dev, vq, free_head, NULL,
+    qvirtio_wait_used_elem(qts, dev, vq, free_head, NULL,
                            QVIRTIO_BLK_TIMEOUT_US);
     status = readb(req_addr + 528);
     g_assert_cmpint(status, ==, 0);
@@ -403,13 +408,13 @@ static void indirect(void *obj, void *u_data, QGuestAllocator *t_alloc)
 
     g_free(req.data);
 
-    indirect = qvring_indirect_desc_setup(dev, t_alloc, 2);
-    qvring_indirect_desc_add(indirect, req_addr, 16, false);
-    qvring_indirect_desc_add(indirect, req_addr + 16, 513, true);
-    free_head = qvirtqueue_add_indirect(vq, indirect);
-    qvirtqueue_kick(dev, vq, free_head);
+    indirect = qvring_indirect_desc_setup(qts, dev, t_alloc, 2);
+    qvring_indirect_desc_add(qts, indirect, req_addr, 16, false);
+    qvring_indirect_desc_add(qts, indirect, req_addr + 16, 513, true);
+    free_head = qvirtqueue_add_indirect(qts, vq, indirect);
+    qvirtqueue_kick(qts, dev, vq, free_head);
 
-    qvirtio_wait_used_elem(dev, vq, free_head, NULL,
+    qvirtio_wait_used_elem(qts, dev, vq, free_head, NULL,
                            QVIRTIO_BLK_TIMEOUT_US);
     status = readb(req_addr + 528);
     g_assert_cmpint(status, ==, 0);
@@ -461,6 +466,7 @@ static void msix(void *obj, void *u_data, QGuestAllocator *t_alloc)
     char *data;
     QOSGraphObject *blk_object = obj;
     QPCIDevice *pci_dev = blk_object->get_driver(blk_object, "pci-device");
+    QTestState *qts = global_qtest;
 
     if (qpci_check_buggy_msi(pci_dev)) {
         return;
@@ -504,12 +510,12 @@ static void msix(void *obj, void *u_data, QGuestAllocator *t_alloc)
 
     g_free(req.data);
 
-    free_head = qvirtqueue_add(vq, req_addr, 16, false, true);
-    qvirtqueue_add(vq, req_addr + 16, 512, false, true);
-    qvirtqueue_add(vq, req_addr + 528, 1, true, false);
-    qvirtqueue_kick(dev, vq, free_head);
+    free_head = qvirtqueue_add(qts, vq, req_addr, 16, false, true);
+    qvirtqueue_add(qts, vq, req_addr + 16, 512, false, true);
+    qvirtqueue_add(qts, vq, req_addr + 528, 1, true, false);
+    qvirtqueue_kick(qts, dev, vq, free_head);
 
-    qvirtio_wait_used_elem(dev, vq, free_head, NULL,
+    qvirtio_wait_used_elem(qts, dev, vq, free_head, NULL,
                            QVIRTIO_BLK_TIMEOUT_US);
 
     status = readb(req_addr + 528);
@@ -527,14 +533,14 @@ static void msix(void *obj, void *u_data, QGuestAllocator *t_alloc)
 
     g_free(req.data);
 
-    free_head = qvirtqueue_add(vq, req_addr, 16, false, true);
-    qvirtqueue_add(vq, req_addr + 16, 512, true, true);
-    qvirtqueue_add(vq, req_addr + 528, 1, true, false);
+    free_head = qvirtqueue_add(qts, vq, req_addr, 16, false, true);
+    qvirtqueue_add(qts, vq, req_addr + 16, 512, true, true);
+    qvirtqueue_add(qts, vq, req_addr + 528, 1, true, false);
 
-    qvirtqueue_kick(dev, vq, free_head);
+    qvirtqueue_kick(qts, dev, vq, free_head);
 
 
-    qvirtio_wait_used_elem(dev, vq, free_head, NULL,
+    qvirtio_wait_used_elem(qts, dev, vq, free_head, NULL,
                            QVIRTIO_BLK_TIMEOUT_US);
 
     status = readb(req_addr + 528);
@@ -569,6 +575,7 @@ static void idx(void *obj, void *u_data, QGuestAllocator *t_alloc)
     char *data;
     QOSGraphObject *blk_object = obj;
     QPCIDevice *pci_dev = blk_object->get_driver(blk_object, "pci-device");
+    QTestState *qts = global_qtest;
 
     if (qpci_check_buggy_msi(pci_dev)) {
         return;
@@ -603,12 +610,12 @@ static void idx(void *obj, void *u_data, QGuestAllocator *t_alloc)
 
     g_free(req.data);
 
-    free_head = qvirtqueue_add(vq, req_addr, 16, false, true);
-    qvirtqueue_add(vq, req_addr + 16, 512, false, true);
-    qvirtqueue_add(vq, req_addr + 528, 1, true, false);
-    qvirtqueue_kick(dev, vq, free_head);
+    free_head = qvirtqueue_add(qts, vq, req_addr, 16, false, true);
+    qvirtqueue_add(qts, vq, req_addr + 16, 512, false, true);
+    qvirtqueue_add(qts, vq, req_addr + 528, 1, true, false);
+    qvirtqueue_kick(qts, dev, vq, free_head);
 
-    qvirtio_wait_used_elem(dev, vq, free_head, NULL,
+    qvirtio_wait_used_elem(qts, dev, vq, free_head, NULL,
                            QVIRTIO_BLK_TIMEOUT_US);
 
     /* Write request */
@@ -623,15 +630,15 @@ static void idx(void *obj, void *u_data, QGuestAllocator *t_alloc)
     g_free(req.data);
 
     /* Notify after processing the third request */
-    qvirtqueue_set_used_event(vq, 2);
-    free_head = qvirtqueue_add(vq, req_addr, 16, false, true);
-    qvirtqueue_add(vq, req_addr + 16, 512, false, true);
-    qvirtqueue_add(vq, req_addr + 528, 1, true, false);
-    qvirtqueue_kick(dev, vq, free_head);
+    qvirtqueue_set_used_event(qts, vq, 2);
+    free_head = qvirtqueue_add(qts, vq, req_addr, 16, false, true);
+    qvirtqueue_add(qts, vq, req_addr + 16, 512, false, true);
+    qvirtqueue_add(qts, vq, req_addr + 528, 1, true, false);
+    qvirtqueue_kick(qts, dev, vq, free_head);
     write_head = free_head;
 
     /* No notification expected */
-    status = qvirtio_wait_status_byte_no_isr(dev,
+    status = qvirtio_wait_status_byte_no_isr(qts, dev,
                                              vq, req_addr + 528,
                                              QVIRTIO_BLK_TIMEOUT_US);
     g_assert_cmpint(status, ==, 0);
@@ -648,16 +655,16 @@ static void idx(void *obj, void *u_data, QGuestAllocator *t_alloc)
 
     g_free(req.data);
 
-    free_head = qvirtqueue_add(vq, req_addr, 16, false, true);
-    qvirtqueue_add(vq, req_addr + 16, 512, true, true);
-    qvirtqueue_add(vq, req_addr + 528, 1, true, false);
+    free_head = qvirtqueue_add(qts, vq, req_addr, 16, false, true);
+    qvirtqueue_add(qts, vq, req_addr + 16, 512, true, true);
+    qvirtqueue_add(qts, vq, req_addr + 528, 1, true, false);
 
-    qvirtqueue_kick(dev, vq, free_head);
+    qvirtqueue_kick(qts, dev, vq, free_head);
 
     /* We get just one notification for both requests */
-    qvirtio_wait_used_elem(dev, vq, write_head, NULL,
+    qvirtio_wait_used_elem(qts, dev, vq, write_head, NULL,
                            QVIRTIO_BLK_TIMEOUT_US);
-    g_assert(qvirtqueue_get_buf(vq, &desc_idx, NULL));
+    g_assert(qvirtqueue_get_buf(qts, vq, &desc_idx, NULL));
     g_assert_cmpint(desc_idx, ==, free_head);
 
     status = readb(req_addr + 528);
diff --git a/tests/virtio-net-test.c b/tests/virtio-net-test.c
index 7aa9622f30..1071dd82c9 100644
--- a/tests/virtio-net-test.c
+++ b/tests/virtio-net-test.c
@@ -33,6 +33,7 @@ static void rx_test(QVirtioDevice *dev,
                     QGuestAllocator *alloc, QVirtQueue *vq,
                     int socket)
 {
+    QTestState *qts = global_qtest;
     uint64_t req_addr;
     uint32_t free_head;
     char test[] = "TEST";
@@ -51,13 +52,14 @@ static void rx_test(QVirtioDevice *dev,
 
     req_addr = guest_alloc(alloc, 64);
 
-    free_head = qvirtqueue_add(vq, req_addr, 64, true, false);
-    qvirtqueue_kick(dev, vq, free_head);
+    free_head = qvirtqueue_add(qts, vq, req_addr, 64, true, false);
+    qvirtqueue_kick(qts, dev, vq, free_head);
 
     ret = iov_send(socket, iov, 2, 0, sizeof(len) + sizeof(test));
     g_assert_cmpint(ret, ==, sizeof(test) + sizeof(len));
 
-    qvirtio_wait_used_elem(dev, vq, free_head, NULL, QVIRTIO_NET_TIMEOUT_US);
+    qvirtio_wait_used_elem(qts, dev, vq, free_head, NULL,
+                           QVIRTIO_NET_TIMEOUT_US);
     memread(req_addr + VNET_HDR_SIZE, buffer, sizeof(test));
     g_assert_cmpstr(buffer, ==, "TEST");
 
@@ -68,6 +70,7 @@ static void tx_test(QVirtioDevice *dev,
                     QGuestAllocator *alloc, QVirtQueue *vq,
                     int socket)
 {
+    QTestState *qts = global_qtest;
     uint64_t req_addr;
     uint32_t free_head;
     uint32_t len;
@@ -77,10 +80,11 @@ static void tx_test(QVirtioDevice *dev,
     req_addr = guest_alloc(alloc, 64);
     memwrite(req_addr + VNET_HDR_SIZE, "TEST", 4);
 
-    free_head = qvirtqueue_add(vq, req_addr, 64, false, false);
-    qvirtqueue_kick(dev, vq, free_head);
+    free_head = qvirtqueue_add(qts, vq, req_addr, 64, false, false);
+    qvirtqueue_kick(qts, dev, vq, free_head);
 
-    qvirtio_wait_used_elem(dev, vq, free_head, NULL, QVIRTIO_NET_TIMEOUT_US);
+    qvirtio_wait_used_elem(qts, dev, vq, free_head, NULL,
+                           QVIRTIO_NET_TIMEOUT_US);
     guest_free(alloc, req_addr);
 
     ret = qemu_recv(socket, &len, sizeof(len), 0);
@@ -95,6 +99,7 @@ static void rx_stop_cont_test(QVirtioDevice *dev,
                               QGuestAllocator *alloc, QVirtQueue *vq,
                               int socket)
 {
+    QTestState *qts = global_qtest;
     uint64_t req_addr;
     uint32_t free_head;
     char test[] = "TEST";
@@ -114,8 +119,8 @@ static void rx_stop_cont_test(QVirtioDevice *dev,
 
     req_addr = guest_alloc(alloc, 64);
 
-    free_head = qvirtqueue_add(vq, req_addr, 64, true, false);
-    qvirtqueue_kick(dev, vq, free_head);
+    free_head = qvirtqueue_add(qts, vq, req_addr, 64, true, false);
+    qvirtqueue_kick(qts, dev, vq, free_head);
 
     rsp = qmp("{ 'execute' : 'stop'}");
     qobject_unref(rsp);
@@ -131,7 +136,8 @@ static void rx_stop_cont_test(QVirtioDevice *dev,
     rsp = qmp("{ 'execute' : 'cont'}");
     qobject_unref(rsp);
 
-    qvirtio_wait_used_elem(dev, vq, free_head, NULL, QVIRTIO_NET_TIMEOUT_US);
+    qvirtio_wait_used_elem(qts, dev, vq, free_head, NULL,
+                           QVIRTIO_NET_TIMEOUT_US);
     memread(req_addr + VNET_HDR_SIZE, buffer, sizeof(test));
     g_assert_cmpstr(buffer, ==, "TEST");
 
@@ -283,19 +289,20 @@ static void large_tx(void *obj, void *data, QGuestAllocator *t_alloc)
     uint64_t req_addr;
     uint32_t free_head;
     size_t alloc_size = (size_t)data / 64;
+    QTestState *qts = global_qtest;
     int i;
 
     /* Bypass the limitation by pointing several descriptors to a single
      * smaller area */
     req_addr = guest_alloc(t_alloc, alloc_size);
-    free_head = qvirtqueue_add(vq, req_addr, alloc_size, false, true);
+    free_head = qvirtqueue_add(qts, vq, req_addr, alloc_size, false, true);
 
     for (i = 0; i < 64; i++) {
-        qvirtqueue_add(vq, req_addr, alloc_size, false, i != 63);
+        qvirtqueue_add(qts, vq, req_addr, alloc_size, false, i != 63);
     }
-    qvirtqueue_kick(dev->vdev, vq, free_head);
+    qvirtqueue_kick(qts, dev->vdev, vq, free_head);
 
-    qvirtio_wait_used_elem(dev->vdev, vq, free_head, NULL,
+    qvirtio_wait_used_elem(qts, dev->vdev, vq, free_head, NULL,
                            QVIRTIO_NET_TIMEOUT_US);
     guest_free(t_alloc, req_addr);
 }
diff --git a/tests/virtio-scsi-test.c b/tests/virtio-scsi-test.c
index 1ad9f75d74..6f8b310cf8 100644
--- a/tests/virtio-scsi-test.c
+++ b/tests/virtio-scsi-test.c
@@ -72,6 +72,7 @@ static uint8_t virtio_scsi_do_command(QVirtioSCSIQueues *vs,
     uint64_t req_addr, resp_addr, data_in_addr = 0, data_out_addr = 0;
     uint8_t response;
     uint32_t free_head;
+    QTestState *qts = global_qtest;
 
     vq = vs->vq[2];
 
@@ -83,24 +84,24 @@ static uint8_t virtio_scsi_do_command(QVirtioSCSIQueues *vs,
 
     /* Add request header */
     req_addr = qvirtio_scsi_alloc(vs, sizeof(req), &req);
-    free_head = qvirtqueue_add(vq, req_addr, sizeof(req), false, true);
+    free_head = qvirtqueue_add(qts, vq, req_addr, sizeof(req), false, true);
 
     if (data_out_len) {
         data_out_addr = qvirtio_scsi_alloc(vs, data_out_len, data_out);
-        qvirtqueue_add(vq, data_out_addr, data_out_len, false, true);
+        qvirtqueue_add(qts, vq, data_out_addr, data_out_len, false, true);
     }
 
     /* Add response header */
     resp_addr = qvirtio_scsi_alloc(vs, sizeof(resp), &resp);
-    qvirtqueue_add(vq, resp_addr, sizeof(resp), true, !!data_in_len);
+    qvirtqueue_add(qts, vq, resp_addr, sizeof(resp), true, !!data_in_len);
 
     if (data_in_len) {
         data_in_addr = qvirtio_scsi_alloc(vs, data_in_len, data_in);
-        qvirtqueue_add(vq, data_in_addr, data_in_len, true, false);
+        qvirtqueue_add(qts, vq, data_in_addr, data_in_len, true, false);
     }
 
-    qvirtqueue_kick(vs->dev, vq, free_head);
-    qvirtio_wait_used_elem(vs->dev, vq, free_head, NULL,
+    qvirtqueue_kick(qts, vs->dev, vq, free_head);
+    qvirtio_wait_used_elem(qts, vs->dev, vq, free_head, NULL,
                            QVIRTIO_SCSI_TIMEOUT_US);
 
     response = readb(resp_addr +
-- 
2.18.1



^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Qemu-devel] [PATCH 2/6] tests/libqos: Make virtio-pci code independent from global_qtest
  2019-08-13  9:30 [Qemu-devel] [PATCH 0/6] First batch of global_qtest-removement patches for QEMU 4.2 Thomas Huth
  2019-08-13  9:30 ` [Qemu-devel] [PATCH 1/6] tests/libqos: Make generic virtio code independent from global_qtest Thomas Huth
@ 2019-08-13  9:30 ` " Thomas Huth
  2019-08-13 15:19   ` Eric Blake
  2019-08-13  9:30 ` [Qemu-devel] [PATCH 3/6] tests/libqtest: Remove unused function hmp() Thomas Huth
                   ` (4 subsequent siblings)
  6 siblings, 1 reply; 16+ messages in thread
From: Thomas Huth @ 2019-08-13  9:30 UTC (permalink / raw)
  To: qemu-devel
  Cc: Fam Zheng, Laurent Vivier, Thomas Huth, qemu-block, Amit Shah,
	John Snow, Jason Wang, Dr. David Alan Gilbert, Markus Armbruster,
	Greg Kurz, Gerd Hoffmann, Stefan Hajnoczi, Paolo Bonzini

The libqos library functions should never depend on global_qtest,
since these functions might be used in tests that track multiple
test states. So let's use the test state of the QPCIDevice instead.

Signed-off-by: Thomas Huth <thuth@redhat.com>
---
 tests/libqos/virtio-pci.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/tests/libqos/virtio-pci.c b/tests/libqos/virtio-pci.c
index a622ca26ca..3f55c047a0 100644
--- a/tests/libqos/virtio-pci.c
+++ b/tests/libqos/virtio-pci.c
@@ -138,9 +138,9 @@ static bool qvirtio_pci_get_queue_isr_status(QVirtioDevice *d, QVirtQueue *vq)
             /* No ISR checking should be done if masked, but read anyway */
             return qpci_msix_pending(dev->pdev, vqpci->msix_entry);
         } else {
-            data = readl(vqpci->msix_addr);
+            data = qtest_readl(dev->pdev->bus->qts, vqpci->msix_addr);
             if (data == vqpci->msix_data) {
-                writel(vqpci->msix_addr, 0);
+                qtest_writel(dev->pdev->bus->qts, vqpci->msix_addr, 0);
                 return true;
             } else {
                 return false;
@@ -162,9 +162,9 @@ static bool qvirtio_pci_get_config_isr_status(QVirtioDevice *d)
             /* No ISR checking should be done if masked, but read anyway */
             return qpci_msix_pending(dev->pdev, dev->config_msix_entry);
         } else {
-            data = readl(dev->config_msix_addr);
+            data = qtest_readl(dev->pdev->bus->qts, dev->config_msix_addr);
             if (data == dev->config_msix_data) {
-                writel(dev->config_msix_addr, 0);
+                qtest_writel(dev->pdev->bus->qts, dev->config_msix_addr, 0);
                 return true;
             } else {
                 return false;
-- 
2.18.1



^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Qemu-devel] [PATCH 3/6] tests/libqtest: Remove unused function hmp()
  2019-08-13  9:30 [Qemu-devel] [PATCH 0/6] First batch of global_qtest-removement patches for QEMU 4.2 Thomas Huth
  2019-08-13  9:30 ` [Qemu-devel] [PATCH 1/6] tests/libqos: Make generic virtio code independent from global_qtest Thomas Huth
  2019-08-13  9:30 ` [Qemu-devel] [PATCH 2/6] tests/libqos: Make virtio-pci " Thomas Huth
@ 2019-08-13  9:30 ` Thomas Huth
  2019-08-13 15:20   ` Eric Blake
  2019-08-13  9:30 ` [Qemu-devel] [PATCH 4/6] tests/libqtest: Clean up qtest_cb_for_every_machine() wrt global_qtest Thomas Huth
                   ` (3 subsequent siblings)
  6 siblings, 1 reply; 16+ messages in thread
From: Thomas Huth @ 2019-08-13  9:30 UTC (permalink / raw)
  To: qemu-devel
  Cc: Fam Zheng, Laurent Vivier, Thomas Huth, qemu-block, Amit Shah,
	John Snow, Jason Wang, Dr. David Alan Gilbert, Markus Armbruster,
	Greg Kurz, Gerd Hoffmann, Stefan Hajnoczi, Paolo Bonzini

No test is using hmp() anymore, and since this function uses the disliked
global_qtest variable, we should also make sure that nobody adds new code
with this function again. qtest_hmp() should be used instead.

Signed-off-by: Thomas Huth <thuth@redhat.com>
---
 tests/libqtest.c | 11 -----------
 tests/libqtest.h | 10 ----------
 2 files changed, 21 deletions(-)

diff --git a/tests/libqtest.c b/tests/libqtest.c
index 3c5c3f49d8..3e9245d4c9 100644
--- a/tests/libqtest.c
+++ b/tests/libqtest.c
@@ -1130,17 +1130,6 @@ void qmp_assert_success(const char *fmt, ...)
     qobject_unref(response);
 }
 
-char *hmp(const char *fmt, ...)
-{
-    va_list ap;
-    char *ret;
-
-    va_start(ap, fmt);
-    ret = qtest_vhmp(global_qtest, fmt, ap);
-    va_end(ap);
-    return ret;
-}
-
 bool qtest_big_endian(QTestState *s)
 {
     return s->big_endian;
diff --git a/tests/libqtest.h b/tests/libqtest.h
index cadf1d4a03..0009b65791 100644
--- a/tests/libqtest.h
+++ b/tests/libqtest.h
@@ -687,16 +687,6 @@ static inline void qmp_eventwait(const char *event)
     return qtest_qmp_eventwait(global_qtest, event);
 }
 
-/**
- * hmp:
- * @fmt...: HMP command to send to QEMU, formats arguments like sprintf().
- *
- * Send HMP command to QEMU via QMP's human-monitor-command.
- *
- * Returns: the command's output.  The caller should g_free() it.
- */
-char *hmp(const char *fmt, ...) GCC_FMT_ATTR(1, 2);
-
 /**
  * get_irq:
  * @num: Interrupt to observe.
-- 
2.18.1



^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Qemu-devel] [PATCH 4/6] tests/libqtest: Clean up qtest_cb_for_every_machine() wrt global_qtest
  2019-08-13  9:30 [Qemu-devel] [PATCH 0/6] First batch of global_qtest-removement patches for QEMU 4.2 Thomas Huth
                   ` (2 preceding siblings ...)
  2019-08-13  9:30 ` [Qemu-devel] [PATCH 3/6] tests/libqtest: Remove unused function hmp() Thomas Huth
@ 2019-08-13  9:30 ` Thomas Huth
  2019-08-13 15:21   ` Eric Blake
  2019-08-13  9:30 ` [Qemu-devel] [PATCH 5/6] tests/libqtest: Make qtest_qmp_device_add/del independent from global_qtest Thomas Huth
                   ` (2 subsequent siblings)
  6 siblings, 1 reply; 16+ messages in thread
From: Thomas Huth @ 2019-08-13  9:30 UTC (permalink / raw)
  To: qemu-devel
  Cc: Fam Zheng, Laurent Vivier, Thomas Huth, qemu-block, Amit Shah,
	John Snow, Jason Wang, Dr. David Alan Gilbert, Markus Armbruster,
	Greg Kurz, Gerd Hoffmann, Stefan Hajnoczi, Paolo Bonzini

The generic libqtest library functions should not use functions that
require the global_qtest variable.

Signed-off-by: Thomas Huth <thuth@redhat.com>
---
 tests/libqtest.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/tests/libqtest.c b/tests/libqtest.c
index 3e9245d4c9..d1aead30ed 100644
--- a/tests/libqtest.c
+++ b/tests/libqtest.c
@@ -1189,9 +1189,10 @@ void qtest_cb_for_every_machine(void (*cb)(const char *machine),
     QObject *qobj;
     QString *qstr;
     const char *mname;
+    QTestState *qts;
 
-    qtest_start("-machine none");
-    response = qmp("{ 'execute': 'query-machines' }");
+    qts = qtest_init("-machine none");
+    response = qtest_qmp(qts, "{ 'execute': 'query-machines' }");
     g_assert(response);
     list = qdict_get_qlist(response, "return");
     g_assert(list);
@@ -1209,7 +1210,7 @@ void qtest_cb_for_every_machine(void (*cb)(const char *machine),
         }
     }
 
-    qtest_end();
+    qtest_quit(qts);
     qobject_unref(response);
 }
 
-- 
2.18.1



^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Qemu-devel] [PATCH 5/6] tests/libqtest: Make qtest_qmp_device_add/del independent from global_qtest
  2019-08-13  9:30 [Qemu-devel] [PATCH 0/6] First batch of global_qtest-removement patches for QEMU 4.2 Thomas Huth
                   ` (3 preceding siblings ...)
  2019-08-13  9:30 ` [Qemu-devel] [PATCH 4/6] tests/libqtest: Clean up qtest_cb_for_every_machine() wrt global_qtest Thomas Huth
@ 2019-08-13  9:30 ` Thomas Huth
  2019-08-13 15:22   ` Eric Blake
  2019-08-13  9:30 ` [Qemu-devel] [PATCH 6/6] tests/libqtest: Make qmp_assert_success() " Thomas Huth
  2019-08-13 15:00 ` [Qemu-devel] [PATCH 0/6] First batch of global_qtest-removement patches for QEMU 4.2 Stefan Hajnoczi
  6 siblings, 1 reply; 16+ messages in thread
From: Thomas Huth @ 2019-08-13  9:30 UTC (permalink / raw)
  To: qemu-devel
  Cc: Fam Zheng, Laurent Vivier, Thomas Huth, qemu-block, Amit Shah,
	John Snow, Jason Wang, Dr. David Alan Gilbert, Markus Armbruster,
	Greg Kurz, Gerd Hoffmann, Stefan Hajnoczi, Paolo Bonzini

Generic library functions like qtest_qmp_device_add() and _del()
should not depend on the global_qtest variable. Pass the test
state via parameter instead.

Signed-off-by: Thomas Huth <thuth@redhat.com>
---
 tests/cpu-plug-test.c      | 15 +++++++++------
 tests/e1000e-test.c        |  2 +-
 tests/ivshmem-test.c       |  2 +-
 tests/libqos/usb.c         |  6 +++---
 tests/libqos/usb.h         |  2 +-
 tests/libqtest.c           | 15 +++++++--------
 tests/libqtest.h           |  8 +++++---
 tests/usb-hcd-ohci-test.c  |  2 +-
 tests/usb-hcd-uhci-test.c  |  8 +++++---
 tests/usb-hcd-xhci-test.c  | 22 +++++++++++++---------
 tests/virtio-blk-test.c    |  2 +-
 tests/virtio-ccw-test.c    | 18 ++++++++++--------
 tests/virtio-net-test.c    |  2 +-
 tests/virtio-rng-test.c    |  2 +-
 tests/virtio-scsi-test.c   |  6 ++++--
 tests/virtio-serial-test.c |  4 ++--
 16 files changed, 65 insertions(+), 51 deletions(-)

diff --git a/tests/cpu-plug-test.c b/tests/cpu-plug-test.c
index 668f00144e..3049620854 100644
--- a/tests/cpu-plug-test.c
+++ b/tests/cpu-plug-test.c
@@ -77,18 +77,19 @@ static void test_plug_with_device_add_x86(gconstpointer data)
     const PlugTestData *td = data;
     char *args;
     unsigned int s, c, t;
+    QTestState *qts;
 
     args = g_strdup_printf("-machine %s -cpu %s "
                            "-smp 1,sockets=%u,cores=%u,threads=%u,maxcpus=%u",
                            td->machine, td->cpu_model,
                            td->sockets, td->cores, td->threads, td->maxcpus);
-    qtest_start(args);
+    qts = qtest_init(args);
 
     for (s = 1; s < td->sockets; s++) {
         for (c = 0; c < td->cores; c++) {
             for (t = 0; t < td->threads; t++) {
                 char *id = g_strdup_printf("id-%i-%i-%i", s, c, t);
-                qtest_qmp_device_add(td->device_model, id,
+                qtest_qmp_device_add(qts, td->device_model, id,
                                      "{'socket-id':%u, 'core-id':%u,"
                                      " 'thread-id':%u}",
                                      s, c, t);
@@ -97,7 +98,7 @@ static void test_plug_with_device_add_x86(gconstpointer data)
         }
     }
 
-    qtest_end();
+    qtest_quit(qts);
     g_free(args);
 }
 
@@ -106,20 +107,22 @@ static void test_plug_with_device_add_coreid(gconstpointer data)
     const PlugTestData *td = data;
     char *args;
     unsigned int c;
+    QTestState *qts;
 
     args = g_strdup_printf("-machine %s -cpu %s "
                            "-smp 1,sockets=%u,cores=%u,threads=%u,maxcpus=%u",
                            td->machine, td->cpu_model,
                            td->sockets, td->cores, td->threads, td->maxcpus);
-    qtest_start(args);
+    qts = qtest_init(args);
 
     for (c = 1; c < td->cores; c++) {
         char *id = g_strdup_printf("id-%i", c);
-        qtest_qmp_device_add(td->device_model, id, "{'core-id':%u}", c);
+        qtest_qmp_device_add(qts, td->device_model, id,
+                             "{'core-id':%u}", c);
         g_free(id);
     }
 
-    qtest_end();
+    qtest_quit(qts);
     g_free(args);
 }
 
diff --git a/tests/e1000e-test.c b/tests/e1000e-test.c
index 445787a7e4..93628c588d 100644
--- a/tests/e1000e-test.c
+++ b/tests/e1000e-test.c
@@ -235,7 +235,7 @@ 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'}");
+    qtest_qmp_device_add(qts, "e1000e", "e1000e_net", "{'addr': '0x06'}");
     qpci_unplug_acpi_device_test(qts, "e1000e_net", 0x06);
 }
 
diff --git a/tests/ivshmem-test.c b/tests/ivshmem-test.c
index a467b8c03d..b76457948b 100644
--- a/tests/ivshmem-test.c
+++ b/tests/ivshmem-test.c
@@ -389,7 +389,7 @@ static void test_ivshmem_hotplug(void)
     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",
+    qtest_qmp_device_add(qts, "ivshmem-plain", "iv1",
                          "{'addr': %s, 'memdev': 'mb1'}",
                          stringify(PCI_SLOT_HP));
     if (strcmp(arch, "ppc64") != 0) {
diff --git a/tests/libqos/usb.c b/tests/libqos/usb.c
index 49e2f4bc0a..d7a9cb3c72 100644
--- a/tests/libqos/usb.c
+++ b/tests/libqos/usb.c
@@ -37,20 +37,20 @@ void uhci_port_test(struct qhc *hc, int port, uint16_t expect)
     g_assert((value & mask) == (expect & mask));
 }
 
-void usb_test_hotplug(const char *hcd_id, const char *port,
+void usb_test_hotplug(QTestState *qts, const char *hcd_id, const char *port,
                       void (*port_check)(void))
 {
     char *id = g_strdup_printf("usbdev%s", port);
     char *bus = g_strdup_printf("%s.0", hcd_id);
 
-    qtest_qmp_device_add("usb-tablet", id, "{'port': %s, 'bus': %s}",
+    qtest_qmp_device_add(qts, "usb-tablet", id, "{'port': %s, 'bus': %s}",
                          port, bus);
 
     if (port_check) {
         port_check();
     }
 
-    qtest_qmp_device_del(id);
+    qtest_qmp_device_del(qts, id);
 
     g_free(bus);
     g_free(id);
diff --git a/tests/libqos/usb.h b/tests/libqos/usb.h
index c506418a13..eeced39a2f 100644
--- a/tests/libqos/usb.h
+++ b/tests/libqos/usb.h
@@ -13,6 +13,6 @@ void qusb_pci_init_one(QPCIBus *pcibus, struct qhc *hc,
 void uhci_port_test(struct qhc *hc, int port, uint16_t expect);
 void uhci_deinit(struct qhc *hc);
 
-void usb_test_hotplug(const char *bus_name, const char *port,
+void usb_test_hotplug(QTestState *qts, const char *bus_name, const char *port,
                       void (*port_check)(void));
 #endif
diff --git a/tests/libqtest.c b/tests/libqtest.c
index d1aead30ed..19c1fc2e97 100644
--- a/tests/libqtest.c
+++ b/tests/libqtest.c
@@ -1246,7 +1246,7 @@ QDict *qtest_qmp_receive_success(QTestState *s,
 /*
  * Generic hot-plugging test via the device_add QMP command.
  */
-void qtest_qmp_device_add(const char *driver, const char *id,
+void qtest_qmp_device_add(QTestState *qts, const char *driver, const char *id,
                           const char *fmt, ...)
 {
     QDict *args, *response;
@@ -1260,7 +1260,8 @@ void qtest_qmp_device_add(const char *driver, const char *id,
     qdict_put_str(args, "driver", driver);
     qdict_put_str(args, "id", id);
 
-    response = qmp("{'execute': 'device_add', 'arguments': %p}", args);
+    response = qtest_qmp(qts, "{'execute': 'device_add', 'arguments': %p}",
+                         args);
     g_assert(response);
     g_assert(!qdict_haskey(response, "event")); /* We don't expect any events */
     g_assert(!qdict_haskey(response, "error"));
@@ -1293,19 +1294,17 @@ static void device_deleted_cb(void *opaque, const char *name, QDict *data)
  *
  * But the order of arrival may vary - so we've got to detect both.
  */
-void qtest_qmp_device_del(const char *id)
+void qtest_qmp_device_del(QTestState *qts, const char *id)
 {
     bool got_event = false;
     QDict *rsp;
 
-    qtest_qmp_send(global_qtest,
-                   "{'execute': 'device_del', 'arguments': {'id': %s}}",
+    qtest_qmp_send(qts, "{'execute': 'device_del', 'arguments': {'id': %s}}",
                    id);
-    rsp = qtest_qmp_receive_success(global_qtest, device_deleted_cb,
-                                    &got_event);
+    rsp = qtest_qmp_receive_success(qts, device_deleted_cb, &got_event);
     qobject_unref(rsp);
     if (!got_event) {
-        rsp = qtest_qmp_receive(global_qtest);
+        rsp = qtest_qmp_receive(qts);
         g_assert_cmpstr(qdict_get_try_str(rsp, "event"),
                         ==, "DEVICE_DELETED");
         qobject_unref(rsp);
diff --git a/tests/libqtest.h b/tests/libqtest.h
index 0009b65791..d93144fb74 100644
--- a/tests/libqtest.h
+++ b/tests/libqtest.h
@@ -946,6 +946,7 @@ void qtest_cb_for_every_machine(void (*cb)(const char *machine),
 
 /**
  * qtest_qmp_device_add:
+ * @qts: QTestState instance to operate on
  * @driver: Name of the device that should be added
  * @id: Identification string
  * @fmt...: QMP message to send to qemu, formatted like
@@ -954,16 +955,17 @@ void qtest_cb_for_every_machine(void (*cb)(const char *machine),
  *
  * Generic hot-plugging test via the device_add QMP command.
  */
-void qtest_qmp_device_add(const char *driver, const char *id, const char *fmt,
-                          ...) GCC_FMT_ATTR(3, 4);
+void qtest_qmp_device_add(QTestState *qts, const char *driver, const char *id,
+                          const char *fmt, ...) GCC_FMT_ATTR(4, 5);
 
 /**
  * qtest_qmp_device_del:
+ * @qts: QTestState instance to operate on
  * @id: Identification string
  *
  * Generic hot-unplugging test via the device_del QMP command.
  */
-void qtest_qmp_device_del(const char *id);
+void qtest_qmp_device_del(QTestState *qts, const char *id);
 
 /**
  * qmp_rsp_is_err:
diff --git a/tests/usb-hcd-ohci-test.c b/tests/usb-hcd-ohci-test.c
index c12b892085..0cd73b7363 100644
--- a/tests/usb-hcd-ohci-test.c
+++ b/tests/usb-hcd-ohci-test.c
@@ -23,7 +23,7 @@ struct QOHCI_PCI {
 
 static void test_ohci_hotplug(void *obj, void *data, QGuestAllocator *alloc)
 {
-    usb_test_hotplug("ohci", "1", NULL);
+    usb_test_hotplug(global_qtest, "ohci", "1", NULL);
 }
 
 static void *ohci_pci_get_driver(void *obj, const char *interface)
diff --git a/tests/usb-hcd-uhci-test.c b/tests/usb-hcd-uhci-test.c
index a119d6d5c8..bdfa006cf5 100644
--- a/tests/usb-hcd-uhci-test.c
+++ b/tests/usb-hcd-uhci-test.c
@@ -43,14 +43,16 @@ static void test_port_2(void)
 
 static void test_uhci_hotplug(void)
 {
-    usb_test_hotplug("uhci", "2", test_port_2);
+    usb_test_hotplug(global_qtest, "uhci", "2", test_port_2);
 }
 
 static void test_usb_storage_hotplug(void)
 {
-    qtest_qmp_device_add("usb-storage", "usbdev0", "{'drive': 'drive0'}");
+    QTestState *qts = global_qtest;
 
-    qtest_qmp_device_del("usbdev0");
+    qtest_qmp_device_add(qts, "usb-storage", "usbdev0", "{'drive': 'drive0'}");
+
+    qtest_qmp_device_del(qts, "usbdev0");
 }
 
 int main(int argc, char **argv)
diff --git a/tests/usb-hcd-xhci-test.c b/tests/usb-hcd-xhci-test.c
index 9eb24b00e4..0e51efe59a 100644
--- a/tests/usb-hcd-xhci-test.c
+++ b/tests/usb-hcd-xhci-test.c
@@ -18,30 +18,34 @@ static void test_xhci_init(void)
 
 static void test_xhci_hotplug(void)
 {
-    usb_test_hotplug("xhci", "1", NULL);
+    usb_test_hotplug(global_qtest, "xhci", "1", NULL);
 }
 
 static void test_usb_uas_hotplug(void)
 {
-    qtest_qmp_device_add("usb-uas", "uas", "{}");
-    qtest_qmp_device_add("scsi-hd", "scsihd", "{'drive': 'drive0'}");
+    QTestState *qts = global_qtest;
+
+    qtest_qmp_device_add(qts, "usb-uas", "uas", "{}");
+    qtest_qmp_device_add(qts, "scsi-hd", "scsihd", "{'drive': 'drive0'}");
 
     /* TODO:
         UAS HBA driver in libqos, to check that
         added disk is visible after BUS rescan
     */
 
-    qtest_qmp_device_del("scsihd");
-    qtest_qmp_device_del("uas");
+    qtest_qmp_device_del(qts, "scsihd");
+    qtest_qmp_device_del(qts, "uas");
 }
 
 static void test_usb_ccid_hotplug(void)
 {
-    qtest_qmp_device_add("usb-ccid", "ccid", "{}");
-    qtest_qmp_device_del("ccid");
+    QTestState *qts = global_qtest;
+
+    qtest_qmp_device_add(qts, "usb-ccid", "ccid", "{}");
+    qtest_qmp_device_del(qts, "ccid");
     /* check the device can be added again */
-    qtest_qmp_device_add("usb-ccid", "ccid", "{}");
-    qtest_qmp_device_del("ccid");
+    qtest_qmp_device_add(qts, "usb-ccid", "ccid", "{}");
+    qtest_qmp_device_del(qts, "ccid");
 }
 
 int main(int argc, char **argv)
diff --git a/tests/virtio-blk-test.c b/tests/virtio-blk-test.c
index ff365c8035..6a364390db 100644
--- a/tests/virtio-blk-test.c
+++ b/tests/virtio-blk-test.c
@@ -690,7 +690,7 @@ static void pci_hotplug(void *obj, void *data, QGuestAllocator *t_alloc)
     QTestState *qts = dev1->pdev->bus->qts;
 
     /* plug secondary disk */
-    qtest_qmp_device_add("virtio-blk-pci", "drv1",
+    qtest_qmp_device_add(qts, "virtio-blk-pci", "drv1",
                          "{'addr': %s, 'drive': 'drive1'}",
                          stringify(PCI_SLOT_HP) ".0");
 
diff --git a/tests/virtio-ccw-test.c b/tests/virtio-ccw-test.c
index 48c714d84c..83957b265e 100644
--- a/tests/virtio-ccw-test.c
+++ b/tests/virtio-ccw-test.c
@@ -45,10 +45,12 @@ static void virtio_serial_nop(void)
 
 static void virtio_serial_hotplug(void)
 {
-    global_qtest = qtest_initf("-device virtio-serial-ccw");
-    qtest_qmp_device_add("virtserialport", "hp-port", "{}");
-    qtest_qmp_device_del("hp-port");
-    qtest_end();
+    QTestState *qts = qtest_initf("-device virtio-serial-ccw");
+
+    qtest_qmp_device_add(qts, "virtserialport", "hp-port", "{}");
+    qtest_qmp_device_del(qts, "hp-port");
+
+    qtest_quit(qts);
 }
 
 static void virtio_blk_nop(void)
@@ -78,14 +80,14 @@ static void virtio_scsi_nop(void)
 
 static void virtio_scsi_hotplug(void)
 {
-    global_qtest = qtest_initf("-drive if=none,id=drv0,file=null-co://,format=raw "
+    QTestState *s = qtest_initf("-drive if=none,id=drv0,file=null-co://,format=raw "
                                 "-drive if=none,id=drv1,file=null-co://,format=raw "
                                 "-device virtio-scsi-ccw "
                                 "-device scsi-hd,drive=drv0");
-    qtest_qmp_device_add("scsi-hd", "scsihd", "{'drive': 'drv1'}");
-    qtest_qmp_device_del("scsihd");
+    qtest_qmp_device_add(s, "scsi-hd", "scsihd", "{'drive': 'drv1'}");
+    qtest_qmp_device_del(s, "scsihd");
 
-    qtest_end();
+    qtest_quit(s);
 }
 
 int main(int argc, char **argv)
diff --git a/tests/virtio-net-test.c b/tests/virtio-net-test.c
index 1071dd82c9..840875aaae 100644
--- a/tests/virtio-net-test.c
+++ b/tests/virtio-net-test.c
@@ -174,7 +174,7 @@ static void hotplug(void *obj, void *data, QGuestAllocator *t_alloc)
     QTestState *qts = dev->pdev->bus->qts;
     const char *arch = qtest_get_arch();
 
-    qtest_qmp_device_add("virtio-net-pci", "net1",
+    qtest_qmp_device_add(qts, "virtio-net-pci", "net1",
                          "{'addr': %s}", stringify(PCI_SLOT_HP));
 
     if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
diff --git a/tests/virtio-rng-test.c b/tests/virtio-rng-test.c
index a38a0d175b..092ba13068 100644
--- a/tests/virtio-rng-test.c
+++ b/tests/virtio-rng-test.c
@@ -22,7 +22,7 @@ static void rng_hotplug(void *obj, void *data, QGuestAllocator *alloc)
 
     const char *arch = qtest_get_arch();
 
-    qtest_qmp_device_add("virtio-rng-pci", "rng1",
+    qtest_qmp_device_add(qts, "virtio-rng-pci", "rng1",
                          "{'addr': %s}", stringify(PCI_SLOT_HP));
 
     if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
diff --git a/tests/virtio-scsi-test.c b/tests/virtio-scsi-test.c
index 6f8b310cf8..928b400341 100644
--- a/tests/virtio-scsi-test.c
+++ b/tests/virtio-scsi-test.c
@@ -150,8 +150,10 @@ static QVirtioSCSIQueues *qvirtio_scsi_init(QVirtioDevice *dev)
 
 static void hotplug(void *obj, void *data, QGuestAllocator *alloc)
 {
-    qtest_qmp_device_add("scsi-hd", "scsihd", "{'drive': 'drv1'}");
-    qtest_qmp_device_del("scsihd");
+    QTestState *qts = global_qtest;
+
+    qtest_qmp_device_add(qts, "scsi-hd", "scsihd", "{'drive': 'drv1'}");
+    qtest_qmp_device_del(qts, "scsihd");
 }
 
 /* Test WRITE SAME with the lba not aligned */
diff --git a/tests/virtio-serial-test.c b/tests/virtio-serial-test.c
index 066ca61280..e584ad76e8 100644
--- a/tests/virtio-serial-test.c
+++ b/tests/virtio-serial-test.c
@@ -20,8 +20,8 @@ static void virtio_serial_nop(void *obj, void *data, QGuestAllocator *alloc)
 
 static void serial_hotplug(void *obj, void *data, QGuestAllocator *alloc)
 {
-    qtest_qmp_device_add("virtserialport", "hp-port", "{}");
-    qtest_qmp_device_del("hp-port");
+    qtest_qmp_device_add(global_qtest, "virtserialport", "hp-port", "{}");
+    qtest_qmp_device_del(global_qtest, "hp-port");
 }
 
 static void register_virtio_serial_test(void)
-- 
2.18.1



^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Qemu-devel] [PATCH 6/6] tests/libqtest: Make qmp_assert_success() independent from global_qtest
  2019-08-13  9:30 [Qemu-devel] [PATCH 0/6] First batch of global_qtest-removement patches for QEMU 4.2 Thomas Huth
                   ` (4 preceding siblings ...)
  2019-08-13  9:30 ` [Qemu-devel] [PATCH 5/6] tests/libqtest: Make qtest_qmp_device_add/del independent from global_qtest Thomas Huth
@ 2019-08-13  9:30 ` " Thomas Huth
  2019-08-13 15:24   ` Eric Blake
  2019-08-13 15:00 ` [Qemu-devel] [PATCH 0/6] First batch of global_qtest-removement patches for QEMU 4.2 Stefan Hajnoczi
  6 siblings, 1 reply; 16+ messages in thread
From: Thomas Huth @ 2019-08-13  9:30 UTC (permalink / raw)
  To: qemu-devel
  Cc: Fam Zheng, Laurent Vivier, Thomas Huth, qemu-block, Amit Shah,
	John Snow, Jason Wang, Dr. David Alan Gilbert, Markus Armbruster,
	Greg Kurz, Gerd Hoffmann, Stefan Hajnoczi, Paolo Bonzini

The normal libqtest library functions should never depend on global_qtest.
Pass in the test state via parameter instead. And while we're at it,
also rename this function to qtest_qmp_assert_success() to make it clear
that it is part of libqtest.

Signed-off-by: Thomas Huth <thuth@redhat.com>
---
 tests/libqtest.c         | 4 ++--
 tests/libqtest.h         | 6 ++++--
 tests/virtio-scsi-test.c | 3 ++-
 3 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/tests/libqtest.c b/tests/libqtest.c
index 19c1fc2e97..eb971d0d11 100644
--- a/tests/libqtest.c
+++ b/tests/libqtest.c
@@ -1111,13 +1111,13 @@ QDict *qmp(const char *fmt, ...)
     return response;
 }
 
-void qmp_assert_success(const char *fmt, ...)
+void qtest_qmp_assert_success(QTestState *qts, const char *fmt, ...)
 {
     va_list ap;
     QDict *response;
 
     va_start(ap, fmt);
-    response = qtest_vqmp(global_qtest, fmt, ap);
+    response = qtest_vqmp(qts, fmt, ap);
     va_end(ap);
 
     g_assert(response);
diff --git a/tests/libqtest.h b/tests/libqtest.h
index d93144fb74..7833148358 100644
--- a/tests/libqtest.h
+++ b/tests/libqtest.h
@@ -666,7 +666,8 @@ static inline void qtest_end(void)
 QDict *qmp(const char *fmt, ...) GCC_FMT_ATTR(1, 2);
 
 /**
- * qmp_assert_success:
+ * qtest_qmp_assert_success:
+ * @qts: QTestState instance to operate on
  * @fmt...: QMP message to send to qemu, formatted like
  * qobject_from_jsonf_nofail().  See parse_escape() for what's
  * supported after '%'.
@@ -674,7 +675,8 @@ QDict *qmp(const char *fmt, ...) GCC_FMT_ATTR(1, 2);
  * Sends a QMP message to QEMU and asserts that a 'return' key is present in
  * the response.
  */
-void qmp_assert_success(const char *fmt, ...) GCC_FMT_ATTR(1, 2);
+void qtest_qmp_assert_success(QTestState *qts, const char *fmt, ...)
+    GCC_FMT_ATTR(2, 3);
 
 /*
  * qmp_eventwait:
diff --git a/tests/virtio-scsi-test.c b/tests/virtio-scsi-test.c
index 928b400341..6068b22986 100644
--- a/tests/virtio-scsi-test.c
+++ b/tests/virtio-scsi-test.c
@@ -225,7 +225,8 @@ static void test_iothread_attach_node(void *obj, void *data,
     mkqcow2(tmp_path, 64);
 
     /* Attach the overlay to the null0 node */
-    qmp_assert_success("{'execute': 'blockdev-add', 'arguments': {"
+    qtest_qmp_assert_success(scsi_pci->pci_vdev.pdev->bus->qts,
+                       "{'execute': 'blockdev-add', 'arguments': {"
                        "   'driver': 'qcow2', 'node-name': 'overlay',"
                        "   'backing': 'null0', 'file': {"
                        "     'driver': 'file', 'filename': %s}}}", tmp_path);
-- 
2.18.1



^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [Qemu-devel] [PATCH 0/6] First batch of global_qtest-removement patches for QEMU 4.2
  2019-08-13  9:30 [Qemu-devel] [PATCH 0/6] First batch of global_qtest-removement patches for QEMU 4.2 Thomas Huth
                   ` (5 preceding siblings ...)
  2019-08-13  9:30 ` [Qemu-devel] [PATCH 6/6] tests/libqtest: Make qmp_assert_success() " Thomas Huth
@ 2019-08-13 15:00 ` Stefan Hajnoczi
  6 siblings, 0 replies; 16+ messages in thread
From: Stefan Hajnoczi @ 2019-08-13 15:00 UTC (permalink / raw)
  To: Thomas Huth
  Cc: Fam Zheng, Laurent Vivier, qemu-block, Amit Shah, John Snow,
	Jason Wang, qemu-devel, Dr. David Alan Gilbert, Greg Kurz,
	Gerd Hoffmann, Paolo Bonzini, Markus Armbruster

[-- Attachment #1: Type: text/plain, Size: 2006 bytes --]

On Tue, Aug 13, 2019 at 11:30:41AM +0200, Thomas Huth wrote:
> While global_qtest and its wrapper functions work fine for tests that only
> run one instance of QEMU, using the global_qtest variable in our qtests is
> very problematic for tests that use multiple test states (e.g. migration
> tests). Thus the core libqtest and libqos library functions should not
> depend on global_qtest or functions that rely on this variable.
> 
> This patch series gets rid of these dependencies in most of the libqtest
> and libqos code.
> 
> Thomas Huth (6):
>   tests/libqos: Make generic virtio code independent from global_qtest
>   tests/libqos: Make virtio-pci code independent from global_qtest
>   tests/libqtest: Remove unused function hmp()
>   tests/libqtest: Clean up qtest_cb_for_every_machine() wrt global_qtest
>   tests/libqtest: Make qtest_qmp_device_add/del independent from
>     global_qtest
>   tests/libqtest: Make qmp_assert_success() independent from
>     global_qtest
> 
>  tests/cpu-plug-test.c      |  15 ++--
>  tests/e1000e-test.c        |   2 +-
>  tests/ivshmem-test.c       |   2 +-
>  tests/libqos/usb.c         |   6 +-
>  tests/libqos/usb.h         |   2 +-
>  tests/libqos/virtio-pci.c  |   8 +-
>  tests/libqos/virtio.c      |  74 +++++++++---------
>  tests/libqos/virtio.h      |  27 ++++---
>  tests/libqtest.c           |  37 ++++-----
>  tests/libqtest.h           |  24 +++---
>  tests/usb-hcd-ohci-test.c  |   2 +-
>  tests/usb-hcd-uhci-test.c  |   8 +-
>  tests/usb-hcd-xhci-test.c  |  22 +++---
>  tests/virtio-9p-test.c     |  16 ++--
>  tests/virtio-blk-test.c    | 153 +++++++++++++++++++------------------
>  tests/virtio-ccw-test.c    |  18 +++--
>  tests/virtio-net-test.c    |  35 +++++----
>  tests/virtio-rng-test.c    |   2 +-
>  tests/virtio-scsi-test.c   |  22 +++---
>  tests/virtio-serial-test.c |   4 +-
>  20 files changed, 251 insertions(+), 228 deletions(-)

Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [Qemu-devel] [PATCH 1/6] tests/libqos: Make generic virtio code independent from global_qtest
  2019-08-13  9:30 ` [Qemu-devel] [PATCH 1/6] tests/libqos: Make generic virtio code independent from global_qtest Thomas Huth
@ 2019-08-13 15:18   ` Eric Blake
  2019-08-14 19:59     ` [Qemu-devel] [PATCH v2] " Thomas Huth
  0 siblings, 1 reply; 16+ messages in thread
From: Eric Blake @ 2019-08-13 15:18 UTC (permalink / raw)
  To: Thomas Huth, qemu-devel
  Cc: Fam Zheng, Laurent Vivier, qemu-block, Amit Shah, Jason Wang,
	Dr. David Alan Gilbert, Markus Armbruster, Greg Kurz,
	Gerd Hoffmann, Stefan Hajnoczi, Paolo Bonzini, John Snow

[-- Attachment #1.1: Type: text/plain, Size: 3652 bytes --]

On 8/13/19 4:30 AM, Thomas Huth wrote:
> The libqos library functions should never depend on global_qtest,
> since these functions might be used in tests that track multiple
> test states. Pass around a pointer to the QTestState instead.

Thanks for picking up on my initial RFC along these lines a couple years
ago now; it's taking us a while, but these cleanups are worthwhile.

> 
> Signed-off-by: Thomas Huth <thuth@redhat.com>
> ---

> @@ -193,7 +193,7 @@ void qvring_init(QTestState *qts, const QGuestAllocator *alloc, QVirtQueue *vq,
>                   0);
>  }
>  
> -QVRingIndirectDesc *qvring_indirect_desc_setup(QVirtioDevice *d,
> +QVRingIndirectDesc *qvring_indirect_desc_setup(QTestState *qs, QVirtioDevice *d,
>                                          QGuestAllocator *alloc, uint16_t elem)
>  {

Pre-existing, but indentation is off; maybe you want to fix that while here.


> -void qvirtqueue_kick(QVirtioDevice *d, QVirtQueue *vq, uint32_t free_head)
> +void qvirtqueue_kick(QTestState *qts, QVirtioDevice *d, QVirtQueue *vq,
> +                     uint32_t free_head)
>  {
>      /* vq->avail->idx */
> -    uint16_t idx = readw(vq->avail + 2);
> +    uint16_t idx = qtest_readw(qts, vq->avail + 2);
>      /* vq->used->flags */
>      uint16_t flags;
>      /* vq->used->avail_event */
>      uint16_t avail_event;
>  
>      /* vq->avail->ring[idx % vq->size] */
> -    writew(vq->avail + 4 + (2 * (idx % vq->size)), free_head);
> +    qtest_writew(qts, vq->avail + 4 + (2 * (idx % vq->size)), free_head);
>      /* vq->avail->idx */
> -    writew(vq->avail + 2, idx + 1);
> +    qtest_writew(qts, vq->avail + 2, idx + 1);
>  
>      /* Must read after idx is updated */
> -    flags = readw(vq->avail);
> -    avail_event = readw(vq->used + 4 +
> +    flags = qtest_readw(qts, vq->avail);
> +    avail_event = qtest_readw(qts, vq->used + 4 +
>                                  sizeof(struct vring_used_elem) * vq->size);

Here as well.

> @@ -333,23 +337,25 @@ bool qvirtqueue_get_buf(QVirtQueue *vq, uint32_t *desc_idx, uint32_t *len)
>          sizeof(struct vring_used_elem);
>  
>      if (desc_idx) {
> -        *desc_idx = readl(elem_addr + offsetof(struct vring_used_elem, id));
> +        *desc_idx = qtest_readl(qts, elem_addr +
> +                                     offsetof(struct vring_used_elem, id));

This one works as-is, although it gives me a double-take when the
indentation is not right after a ( in the line above.  I probably would
have written either:

        *desc_idx = qtest_readl(qts,
                                elem_addr + offsetof(struct
vring_used_elem, id));

or

        *desc_idx = qtest_readl(qts, (elem_addr +
                                      offsetof(struct vring_used_elem,
id)));

or even introduce a temp variable to bring down the line length.


> @@ -131,17 +131,20 @@ void qvirtqueue_cleanup(const QVirtioBus *bus, QVirtQueue *vq,
>  
>  void qvring_init(QTestState *qts, const QGuestAllocator *alloc, QVirtQueue *vq,
>                   uint64_t addr);
> -QVRingIndirectDesc *qvring_indirect_desc_setup(QVirtioDevice *d,
> +QVRingIndirectDesc *qvring_indirect_desc_setup(QTestState *qs, QVirtioDevice *d,
>                                          QGuestAllocator *alloc, uint16_t elem);

Another pre-existing odd indentation (here, it looks like line length
was the reason).

Indentation is minor, so:

Reviewed-by: Eric Blake <eblake@redhat.com>

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [Qemu-devel] [PATCH 2/6] tests/libqos: Make virtio-pci code independent from global_qtest
  2019-08-13  9:30 ` [Qemu-devel] [PATCH 2/6] tests/libqos: Make virtio-pci " Thomas Huth
@ 2019-08-13 15:19   ` Eric Blake
  0 siblings, 0 replies; 16+ messages in thread
From: Eric Blake @ 2019-08-13 15:19 UTC (permalink / raw)
  To: Thomas Huth, qemu-devel
  Cc: Fam Zheng, Laurent Vivier, qemu-block, Amit Shah, Jason Wang,
	Dr. David Alan Gilbert, Markus Armbruster, Greg Kurz,
	Gerd Hoffmann, Stefan Hajnoczi, Paolo Bonzini, John Snow

[-- Attachment #1.1: Type: text/plain, Size: 582 bytes --]

On 8/13/19 4:30 AM, Thomas Huth wrote:
> The libqos library functions should never depend on global_qtest,
> since these functions might be used in tests that track multiple
> test states. So let's use the test state of the QPCIDevice instead.
> 
> Signed-off-by: Thomas Huth <thuth@redhat.com>
> ---
>  tests/libqos/virtio-pci.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)

Reviewed-by: Eric Blake <eblake@redhat.com>

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [Qemu-devel] [PATCH 3/6] tests/libqtest: Remove unused function hmp()
  2019-08-13  9:30 ` [Qemu-devel] [PATCH 3/6] tests/libqtest: Remove unused function hmp() Thomas Huth
@ 2019-08-13 15:20   ` Eric Blake
  2019-08-13 17:38     ` Thomas Huth
  0 siblings, 1 reply; 16+ messages in thread
From: Eric Blake @ 2019-08-13 15:20 UTC (permalink / raw)
  To: Thomas Huth, qemu-devel
  Cc: Fam Zheng, Laurent Vivier, qemu-block, Amit Shah, Jason Wang,
	Dr. David Alan Gilbert, Markus Armbruster, Greg Kurz,
	Gerd Hoffmann, Stefan Hajnoczi, Paolo Bonzini, John Snow

[-- Attachment #1.1: Type: text/plain, Size: 758 bytes --]

On 8/13/19 4:30 AM, Thomas Huth wrote:
> No test is using hmp() anymore, and since this function uses the disliked
> global_qtest variable, we should also make sure that nobody adds new code
> with this function again. qtest_hmp() should be used instead.
> 
> Signed-off-by: Thomas Huth <thuth@redhat.com>
> ---
>  tests/libqtest.c | 11 -----------
>  tests/libqtest.h | 10 ----------
>  2 files changed, 21 deletions(-)

Yay.

We could, at a later time, introduce a patch to do s/qtest_hmp/hmp/ if
it was deemed worthwhile, but I'm not sure it's worth the churn.

Reviewed-by: Eric Blake <eblake@redhat.com>

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [Qemu-devel] [PATCH 4/6] tests/libqtest: Clean up qtest_cb_for_every_machine() wrt global_qtest
  2019-08-13  9:30 ` [Qemu-devel] [PATCH 4/6] tests/libqtest: Clean up qtest_cb_for_every_machine() wrt global_qtest Thomas Huth
@ 2019-08-13 15:21   ` Eric Blake
  0 siblings, 0 replies; 16+ messages in thread
From: Eric Blake @ 2019-08-13 15:21 UTC (permalink / raw)
  To: Thomas Huth, qemu-devel
  Cc: Fam Zheng, Laurent Vivier, qemu-block, Amit Shah, Jason Wang,
	Dr. David Alan Gilbert, Markus Armbruster, Greg Kurz,
	Gerd Hoffmann, Stefan Hajnoczi, Paolo Bonzini, John Snow

[-- Attachment #1.1: Type: text/plain, Size: 476 bytes --]

On 8/13/19 4:30 AM, Thomas Huth wrote:
> The generic libqtest library functions should not use functions that
> require the global_qtest variable.
> 
> Signed-off-by: Thomas Huth <thuth@redhat.com>
> ---
>  tests/libqtest.c | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
> 
Reviewed-by: Eric Blake <eblake@redhat.com>

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [Qemu-devel] [PATCH 5/6] tests/libqtest: Make qtest_qmp_device_add/del independent from global_qtest
  2019-08-13  9:30 ` [Qemu-devel] [PATCH 5/6] tests/libqtest: Make qtest_qmp_device_add/del independent from global_qtest Thomas Huth
@ 2019-08-13 15:22   ` Eric Blake
  0 siblings, 0 replies; 16+ messages in thread
From: Eric Blake @ 2019-08-13 15:22 UTC (permalink / raw)
  To: Thomas Huth, qemu-devel
  Cc: Fam Zheng, Laurent Vivier, qemu-block, Amit Shah, Jason Wang,
	Dr. David Alan Gilbert, Markus Armbruster, Greg Kurz,
	Gerd Hoffmann, Stefan Hajnoczi, Paolo Bonzini, John Snow

[-- Attachment #1.1: Type: text/plain, Size: 444 bytes --]

On 8/13/19 4:30 AM, Thomas Huth wrote:
> Generic library functions like qtest_qmp_device_add() and _del()
> should not depend on the global_qtest variable. Pass the test
> state via parameter instead.
> 
> Signed-off-by: Thomas Huth <thuth@redhat.com>
> ---

Reviewed-by: Eric Blake <eblake@redhat.com>

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [Qemu-devel] [PATCH 6/6] tests/libqtest: Make qmp_assert_success() independent from global_qtest
  2019-08-13  9:30 ` [Qemu-devel] [PATCH 6/6] tests/libqtest: Make qmp_assert_success() " Thomas Huth
@ 2019-08-13 15:24   ` Eric Blake
  0 siblings, 0 replies; 16+ messages in thread
From: Eric Blake @ 2019-08-13 15:24 UTC (permalink / raw)
  To: Thomas Huth, qemu-devel
  Cc: Fam Zheng, Laurent Vivier, qemu-block, Amit Shah, Jason Wang,
	Dr. David Alan Gilbert, Markus Armbruster, Greg Kurz,
	Gerd Hoffmann, Stefan Hajnoczi, Paolo Bonzini, John Snow

[-- Attachment #1.1: Type: text/plain, Size: 1390 bytes --]

On 8/13/19 4:30 AM, Thomas Huth wrote:
> The normal libqtest library functions should never depend on global_qtest.
> Pass in the test state via parameter instead. And while we're at it,
> also rename this function to qtest_qmp_assert_success() to make it clear
> that it is part of libqtest.
> 
> Signed-off-by: Thomas Huth <thuth@redhat.com>
> ---
>  tests/libqtest.c         | 4 ++--
>  tests/libqtest.h         | 6 ++++--
>  tests/virtio-scsi-test.c | 3 ++-
>  3 files changed, 8 insertions(+), 5 deletions(-)
> 

> +++ b/tests/virtio-scsi-test.c
> @@ -225,7 +225,8 @@ static void test_iothread_attach_node(void *obj, void *data,
>      mkqcow2(tmp_path, 64);
>  
>      /* Attach the overlay to the null0 node */
> -    qmp_assert_success("{'execute': 'blockdev-add', 'arguments': {"
> +    qtest_qmp_assert_success(scsi_pci->pci_vdev.pdev->bus->qts,
> +                       "{'execute': 'blockdev-add', 'arguments': {"
>                         "   'driver': 'qcow2', 'node-name': 'overlay',"
>                         "   'backing': 'null0', 'file': {"
>                         "     'driver': 'file', 'filename': %s}}}", tmp_path);
> 

Indentation is now off.  Minor, so:

Reviewed-by: Eric Blake <eblake@redhat.com>

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [Qemu-devel] [PATCH 3/6] tests/libqtest: Remove unused function hmp()
  2019-08-13 15:20   ` Eric Blake
@ 2019-08-13 17:38     ` Thomas Huth
  0 siblings, 0 replies; 16+ messages in thread
From: Thomas Huth @ 2019-08-13 17:38 UTC (permalink / raw)
  To: Eric Blake, qemu-devel
  Cc: Fam Zheng, Laurent Vivier, qemu-block, Amit Shah, Jason Wang,
	Dr. David Alan Gilbert, Markus Armbruster, Greg Kurz,
	Gerd Hoffmann, Stefan Hajnoczi, Paolo Bonzini, John Snow

[-- Attachment #1.1: Type: text/plain, Size: 888 bytes --]

On 8/13/19 5:20 PM, Eric Blake wrote:
> On 8/13/19 4:30 AM, Thomas Huth wrote:
>> No test is using hmp() anymore, and since this function uses the disliked
>> global_qtest variable, we should also make sure that nobody adds new code
>> with this function again. qtest_hmp() should be used instead.
>>
>> Signed-off-by: Thomas Huth <thuth@redhat.com>
>> ---
>>  tests/libqtest.c | 11 -----------
>>  tests/libqtest.h | 10 ----------
>>  2 files changed, 21 deletions(-)
> 
> Yay.
> 
> We could, at a later time, introduce a patch to do s/qtest_hmp/hmp/ if
> it was deemed worthwhile, but I'm not sure it's worth the churn.

Actually, I like the qtest_* prefix for the libqtest functions - so it
is clear at the first sight that a function is part of libqtest or
rather the test itself.

> Reviewed-by: Eric Blake <eblake@redhat.com>

Thanks a lot!

 Thomas




[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Qemu-devel] [PATCH v2] tests/libqos: Make generic virtio code independent from global_qtest
  2019-08-13 15:18   ` Eric Blake
@ 2019-08-14 19:59     ` " Thomas Huth
  0 siblings, 0 replies; 16+ messages in thread
From: Thomas Huth @ 2019-08-14 19:59 UTC (permalink / raw)
  To: qemu-devel; +Cc: Laurent Vivier, Paolo Bonzini, Stefan Hajnoczi

The libqos library functions should never depend on global_qtest,
since these functions might be used in tests that track multiple
test states. Pass around a pointer to the QTestState instead.

Signed-off-by: Thomas Huth <thuth@redhat.com>
---
 v2: Adjust indentations as suggested by Eric

 tests/libqos/virtio.c    |  81 +++++++++++----------
 tests/libqos/virtio.h    |  30 ++++----
 tests/virtio-9p-test.c   |  16 +++--
 tests/virtio-blk-test.c  | 151 ++++++++++++++++++++-------------------
 tests/virtio-net-test.c  |  33 +++++----
 tests/virtio-scsi-test.c |  13 ++--
 6 files changed, 176 insertions(+), 148 deletions(-)

diff --git a/tests/libqos/virtio.c b/tests/libqos/virtio.c
index b4c01dc0c1..91ce06954b 100644
--- a/tests/libqos/virtio.c
+++ b/tests/libqos/virtio.c
@@ -101,7 +101,7 @@ void qvirtio_wait_queue_isr(QVirtioDevice *d,
  * The virtqueue interrupt must not be raised, making this useful for testing
  * event_index functionality.
  */
-uint8_t qvirtio_wait_status_byte_no_isr(QVirtioDevice *d,
+uint8_t qvirtio_wait_status_byte_no_isr(QTestState *qts, QVirtioDevice *d,
                                         QVirtQueue *vq,
                                         uint64_t addr,
                                         gint64 timeout_us)
@@ -126,7 +126,7 @@ uint8_t qvirtio_wait_status_byte_no_isr(QVirtioDevice *d,
  *
  * This function waits for the next completed request on the used ring.
  */
-void qvirtio_wait_used_elem(QVirtioDevice *d,
+void qvirtio_wait_used_elem(QTestState *qts, QVirtioDevice *d,
                             QVirtQueue *vq,
                             uint32_t desc_idx,
                             uint32_t *len,
@@ -140,7 +140,7 @@ void qvirtio_wait_used_elem(QVirtioDevice *d,
         clock_step(100);
 
         if (d->bus->get_queue_isr_status(d, vq) &&
-            qvirtqueue_get_buf(vq, &got_desc_idx, len)) {
+            qvirtqueue_get_buf(qts, vq, &got_desc_idx, len)) {
             g_assert_cmpint(got_desc_idx, ==, desc_idx);
             return;
         }
@@ -193,8 +193,9 @@ void qvring_init(QTestState *qts, const QGuestAllocator *alloc, QVirtQueue *vq,
                  0);
 }
 
-QVRingIndirectDesc *qvring_indirect_desc_setup(QVirtioDevice *d,
-                                        QGuestAllocator *alloc, uint16_t elem)
+QVRingIndirectDesc *qvring_indirect_desc_setup(QTestState *qs, QVirtioDevice *d,
+                                               QGuestAllocator *alloc,
+                                               uint16_t elem)
 {
     int i;
     QVRingIndirectDesc *indirect = g_malloc(sizeof(*indirect));
@@ -205,41 +206,41 @@ QVRingIndirectDesc *qvring_indirect_desc_setup(QVirtioDevice *d,
 
     for (i = 0; i < elem - 1; ++i) {
         /* indirect->desc[i].addr */
-        writeq(indirect->desc + (16 * i), 0);
+        qtest_writeq(qs, indirect->desc + (16 * i), 0);
         /* indirect->desc[i].flags */
-        writew(indirect->desc + (16 * i) + 12, VRING_DESC_F_NEXT);
+        qtest_writew(qs, indirect->desc + (16 * i) + 12, VRING_DESC_F_NEXT);
         /* indirect->desc[i].next */
-        writew(indirect->desc + (16 * i) + 14, i + 1);
+        qtest_writew(qs, indirect->desc + (16 * i) + 14, i + 1);
     }
 
     return indirect;
 }
 
-void qvring_indirect_desc_add(QVRingIndirectDesc *indirect, uint64_t data,
-                                                    uint32_t len, bool write)
+void qvring_indirect_desc_add(QTestState *qts, QVRingIndirectDesc *indirect,
+                              uint64_t data, uint32_t len, bool write)
 {
     uint16_t flags;
 
     g_assert_cmpint(indirect->index, <, indirect->elem);
 
-    flags = readw(indirect->desc + (16 * indirect->index) + 12);
+    flags = qtest_readw(qts, indirect->desc + (16 * indirect->index) + 12);
 
     if (write) {
         flags |= VRING_DESC_F_WRITE;
     }
 
     /* indirect->desc[indirect->index].addr */
-    writeq(indirect->desc + (16 * indirect->index), data);
+    qtest_writeq(qts, indirect->desc + (16 * indirect->index), data);
     /* indirect->desc[indirect->index].len */
-    writel(indirect->desc + (16 * indirect->index) + 8, len);
+    qtest_writel(qts, indirect->desc + (16 * indirect->index) + 8, len);
     /* indirect->desc[indirect->index].flags */
-    writew(indirect->desc + (16 * indirect->index) + 12, flags);
+    qtest_writew(qts, indirect->desc + (16 * indirect->index) + 12, flags);
 
     indirect->index++;
 }
 
-uint32_t qvirtqueue_add(QVirtQueue *vq, uint64_t data, uint32_t len, bool write,
-                                                                    bool next)
+uint32_t qvirtqueue_add(QTestState *qts, QVirtQueue *vq, uint64_t data,
+                        uint32_t len, bool write, bool next)
 {
     uint16_t flags = 0;
     vq->num_free--;
@@ -253,16 +254,17 @@ uint32_t qvirtqueue_add(QVirtQueue *vq, uint64_t data, uint32_t len, bool write,
     }
 
     /* vq->desc[vq->free_head].addr */
-    writeq(vq->desc + (16 * vq->free_head), data);
+    qtest_writeq(qts, vq->desc + (16 * vq->free_head), data);
     /* vq->desc[vq->free_head].len */
-    writel(vq->desc + (16 * vq->free_head) + 8, len);
+    qtest_writel(qts, vq->desc + (16 * vq->free_head) + 8, len);
     /* vq->desc[vq->free_head].flags */
-    writew(vq->desc + (16 * vq->free_head) + 12, flags);
+    qtest_writew(qts, vq->desc + (16 * vq->free_head) + 12, flags);
 
     return vq->free_head++; /* Return and increase, in this order */
 }
 
-uint32_t qvirtqueue_add_indirect(QVirtQueue *vq, QVRingIndirectDesc *indirect)
+uint32_t qvirtqueue_add_indirect(QTestState *qts, QVirtQueue *vq,
+                                 QVRingIndirectDesc *indirect)
 {
     g_assert(vq->indirect);
     g_assert_cmpint(vq->size, >=, indirect->elem);
@@ -271,34 +273,36 @@ uint32_t qvirtqueue_add_indirect(QVirtQueue *vq, QVRingIndirectDesc *indirect)
     vq->num_free--;
 
     /* vq->desc[vq->free_head].addr */
-    writeq(vq->desc + (16 * vq->free_head), indirect->desc);
+    qtest_writeq(qts, vq->desc + (16 * vq->free_head), indirect->desc);
     /* vq->desc[vq->free_head].len */
-    writel(vq->desc + (16 * vq->free_head) + 8,
+    qtest_writel(qts, vq->desc + (16 * vq->free_head) + 8,
            sizeof(struct vring_desc) * indirect->elem);
     /* vq->desc[vq->free_head].flags */
-    writew(vq->desc + (16 * vq->free_head) + 12, VRING_DESC_F_INDIRECT);
+    qtest_writew(qts, vq->desc + (16 * vq->free_head) + 12,
+                 VRING_DESC_F_INDIRECT);
 
     return vq->free_head++; /* Return and increase, in this order */
 }
 
-void qvirtqueue_kick(QVirtioDevice *d, QVirtQueue *vq, uint32_t free_head)
+void qvirtqueue_kick(QTestState *qts, QVirtioDevice *d, QVirtQueue *vq,
+                     uint32_t free_head)
 {
     /* vq->avail->idx */
-    uint16_t idx = readw(vq->avail + 2);
+    uint16_t idx = qtest_readw(qts, vq->avail + 2);
     /* vq->used->flags */
     uint16_t flags;
     /* vq->used->avail_event */
     uint16_t avail_event;
 
     /* vq->avail->ring[idx % vq->size] */
-    writew(vq->avail + 4 + (2 * (idx % vq->size)), free_head);
+    qtest_writew(qts, vq->avail + 4 + (2 * (idx % vq->size)), free_head);
     /* vq->avail->idx */
-    writew(vq->avail + 2, idx + 1);
+    qtest_writew(qts, vq->avail + 2, idx + 1);
 
     /* Must read after idx is updated */
-    flags = readw(vq->avail);
-    avail_event = readw(vq->used + 4 +
-                                sizeof(struct vring_used_elem) * vq->size);
+    flags = qtest_readw(qts, vq->avail);
+    avail_event = qtest_readw(qts, vq->used + 4 +
+                                   sizeof(struct vring_used_elem) * vq->size);
 
     /* < 1 because we add elements to avail queue one by one */
     if ((flags & VRING_USED_F_NO_NOTIFY) == 0 &&
@@ -317,12 +321,13 @@ void qvirtqueue_kick(QVirtioDevice *d, QVirtQueue *vq, uint32_t free_head)
  *
  * Returns: true if an element was ready, false otherwise
  */
-bool qvirtqueue_get_buf(QVirtQueue *vq, uint32_t *desc_idx, uint32_t *len)
+bool qvirtqueue_get_buf(QTestState *qts, QVirtQueue *vq, uint32_t *desc_idx,
+                        uint32_t *len)
 {
     uint16_t idx;
-    uint64_t elem_addr;
+    uint64_t elem_addr, addr;
 
-    idx = readw(vq->used + offsetof(struct vring_used, idx));
+    idx = qtest_readw(qts, vq->used + offsetof(struct vring_used, idx));
     if (idx == vq->last_used_idx) {
         return false;
     }
@@ -333,23 +338,25 @@ bool qvirtqueue_get_buf(QVirtQueue *vq, uint32_t *desc_idx, uint32_t *len)
         sizeof(struct vring_used_elem);
 
     if (desc_idx) {
-        *desc_idx = readl(elem_addr + offsetof(struct vring_used_elem, id));
+        addr = elem_addr + offsetof(struct vring_used_elem, id);
+        *desc_idx = qtest_readl(qts, addr);
     }
 
     if (len) {
-        *len = readw(elem_addr + offsetof(struct vring_used_elem, len));
+        addr = elem_addr + offsetof(struct vring_used_elem, len);
+        *len = qtest_readw(qts, addr);
     }
 
     vq->last_used_idx++;
     return true;
 }
 
-void qvirtqueue_set_used_event(QVirtQueue *vq, uint16_t idx)
+void qvirtqueue_set_used_event(QTestState *qts, QVirtQueue *vq, uint16_t idx)
 {
     g_assert(vq->event);
 
     /* vq->avail->used_event */
-    writew(vq->avail + 4 + (2 * vq->size), idx);
+    qtest_writew(qts, vq->avail + 4 + (2 * vq->size), idx);
 }
 
 void qvirtio_start_device(QVirtioDevice *vdev)
diff --git a/tests/libqos/virtio.h b/tests/libqos/virtio.h
index 7b97f5e567..037176dbd8 100644
--- a/tests/libqos/virtio.h
+++ b/tests/libqos/virtio.h
@@ -114,11 +114,11 @@ void qvirtio_set_driver_ok(QVirtioDevice *d);
 
 void qvirtio_wait_queue_isr(QVirtioDevice *d,
                             QVirtQueue *vq, gint64 timeout_us);
-uint8_t qvirtio_wait_status_byte_no_isr(QVirtioDevice *d,
+uint8_t qvirtio_wait_status_byte_no_isr(QTestState *qts, QVirtioDevice *d,
                                         QVirtQueue *vq,
                                         uint64_t addr,
                                         gint64 timeout_us);
-void qvirtio_wait_used_elem(QVirtioDevice *d,
+void qvirtio_wait_used_elem(QTestState *qts, QVirtioDevice *d,
                             QVirtQueue *vq,
                             uint32_t desc_idx,
                             uint32_t *len,
@@ -131,17 +131,21 @@ void qvirtqueue_cleanup(const QVirtioBus *bus, QVirtQueue *vq,
 
 void qvring_init(QTestState *qts, const QGuestAllocator *alloc, QVirtQueue *vq,
                  uint64_t addr);
-QVRingIndirectDesc *qvring_indirect_desc_setup(QVirtioDevice *d,
-                                        QGuestAllocator *alloc, uint16_t elem);
-void qvring_indirect_desc_add(QVRingIndirectDesc *indirect, uint64_t data,
-                                                    uint32_t len, bool write);
-uint32_t qvirtqueue_add(QVirtQueue *vq, uint64_t data, uint32_t len, bool write,
-                                                                    bool next);
-uint32_t qvirtqueue_add_indirect(QVirtQueue *vq, QVRingIndirectDesc *indirect);
-void qvirtqueue_kick(QVirtioDevice *d, QVirtQueue *vq, uint32_t free_head);
-bool qvirtqueue_get_buf(QVirtQueue *vq, uint32_t *desc_idx, uint32_t *len);
-
-void qvirtqueue_set_used_event(QVirtQueue *vq, uint16_t idx);
+QVRingIndirectDesc *qvring_indirect_desc_setup(QTestState *qs, QVirtioDevice *d,
+                                               QGuestAllocator *alloc,
+                                               uint16_t elem);
+void qvring_indirect_desc_add(QTestState *qts, QVRingIndirectDesc *indirect,
+                              uint64_t data, uint32_t len, bool write);
+uint32_t qvirtqueue_add(QTestState *qts, QVirtQueue *vq, uint64_t data,
+                        uint32_t len, bool write, bool next);
+uint32_t qvirtqueue_add_indirect(QTestState *qts, QVirtQueue *vq,
+                                 QVRingIndirectDesc *indirect);
+void qvirtqueue_kick(QTestState *qts, QVirtioDevice *d, QVirtQueue *vq,
+                     uint32_t free_head);
+bool qvirtqueue_get_buf(QTestState *qts, QVirtQueue *vq, uint32_t *desc_idx,
+                        uint32_t *len);
+
+void qvirtqueue_set_used_event(QTestState *qts, QVirtQueue *vq, uint16_t idx);
 
 void qvirtio_start_device(QVirtioDevice *vdev);
 
diff --git a/tests/virtio-9p-test.c b/tests/virtio-9p-test.c
index ac49bca991..30e6cf3e63 100644
--- a/tests/virtio-9p-test.c
+++ b/tests/virtio-9p-test.c
@@ -39,6 +39,7 @@ static void pci_config(void *obj, void *data, QGuestAllocator *t_alloc)
 #define P9_MAX_SIZE 4096 /* Max size of a T-message or R-message */
 
 typedef struct {
+    QTestState *qts;
     QVirtio9P *v9p;
     uint16_t tag;
     uint64_t t_msg;
@@ -52,7 +53,7 @@ typedef struct {
 
 static void v9fs_memwrite(P9Req *req, const void *addr, size_t len)
 {
-    memwrite(req->t_msg + req->t_off, addr, len);
+    qtest_memwrite(req->qts, req->t_msg + req->t_off, addr, len);
     req->t_off += len;
 }
 
@@ -63,7 +64,7 @@ static void v9fs_memskip(P9Req *req, size_t len)
 
 static void v9fs_memread(P9Req *req, void *addr, size_t len)
 {
-    memread(req->r_msg + req->r_off, addr, len);
+    qtest_memread(req->qts, req->r_msg + req->r_off, addr, len);
     req->r_off += len;
 }
 
@@ -158,6 +159,7 @@ static P9Req *v9fs_req_init(QVirtio9P *v9p, uint32_t size, uint8_t id,
 
     g_assert_cmpint(total_size, <=, P9_MAX_SIZE);
 
+    req->qts = global_qtest;
     req->v9p = v9p;
     req->t_size = total_size;
     req->t_msg = guest_alloc(alloc, req->t_size);
@@ -171,10 +173,10 @@ static void v9fs_req_send(P9Req *req)
     QVirtio9P *v9p = req->v9p;
 
     req->r_msg = guest_alloc(alloc, P9_MAX_SIZE);
-    req->free_head = qvirtqueue_add(v9p->vq, req->t_msg, req->t_size, false,
-                                    true);
-    qvirtqueue_add(v9p->vq, req->r_msg, P9_MAX_SIZE, true, false);
-    qvirtqueue_kick(v9p->vdev, v9p->vq, req->free_head);
+    req->free_head = qvirtqueue_add(req->qts, v9p->vq, req->t_msg, req->t_size,
+                                    false, true);
+    qvirtqueue_add(req->qts, v9p->vq, req->r_msg, P9_MAX_SIZE, true, false);
+    qvirtqueue_kick(req->qts, v9p->vdev, v9p->vq, req->free_head);
     req->t_off = 0;
 }
 
@@ -195,7 +197,7 @@ static void v9fs_req_wait_for_reply(P9Req *req, uint32_t *len)
 {
     QVirtio9P *v9p = req->v9p;
 
-    qvirtio_wait_used_elem(v9p->vdev, v9p->vq, req->free_head, len,
+    qvirtio_wait_used_elem(req->qts, v9p->vdev, v9p->vq, req->free_head, len,
                            QVIRTIO_9P_TIMEOUT_US);
 }
 
diff --git a/tests/virtio-blk-test.c b/tests/virtio-blk-test.c
index 1b02714bc7..ff365c8035 100644
--- a/tests/virtio-blk-test.c
+++ b/tests/virtio-blk-test.c
@@ -123,6 +123,7 @@ static void test_basic(QVirtioDevice *dev, QGuestAllocator *alloc,
     uint32_t free_head;
     uint8_t status;
     char *data;
+    QTestState *qts = global_qtest;
 
     capacity = qvirtio_config_readq(dev, 0);
 
@@ -149,13 +150,14 @@ static void test_basic(QVirtioDevice *dev, QGuestAllocator *alloc,
 
     g_free(req.data);
 
-    free_head = qvirtqueue_add(vq, req_addr, 16, false, true);
-    qvirtqueue_add(vq, req_addr + 16, 512, false, true);
-    qvirtqueue_add(vq, req_addr + 528, 1, true, false);
+    free_head = qvirtqueue_add(qts, vq, req_addr, 16, false, true);
+    qvirtqueue_add(qts, vq, req_addr + 16, 512, false, true);
+    qvirtqueue_add(qts, vq, req_addr + 528, 1, true, false);
 
-    qvirtqueue_kick(dev, vq, free_head);
+    qvirtqueue_kick(qts, dev, vq, free_head);
 
-    qvirtio_wait_used_elem(dev, vq, free_head, NULL, QVIRTIO_BLK_TIMEOUT_US);
+    qvirtio_wait_used_elem(qts, dev, vq, free_head, NULL,
+                           QVIRTIO_BLK_TIMEOUT_US);
     status = readb(req_addr + 528);
     g_assert_cmpint(status, ==, 0);
 
@@ -171,13 +173,14 @@ static void test_basic(QVirtioDevice *dev, QGuestAllocator *alloc,
 
     g_free(req.data);
 
-    free_head = qvirtqueue_add(vq, req_addr, 16, false, true);
-    qvirtqueue_add(vq, req_addr + 16, 512, true, true);
-    qvirtqueue_add(vq, req_addr + 528, 1, true, false);
+    free_head = qvirtqueue_add(qts, vq, req_addr, 16, false, true);
+    qvirtqueue_add(qts, vq, req_addr + 16, 512, true, true);
+    qvirtqueue_add(qts, vq, req_addr + 528, 1, true, false);
 
-    qvirtqueue_kick(dev, vq, free_head);
+    qvirtqueue_kick(qts, dev, vq, free_head);
 
-    qvirtio_wait_used_elem(dev, vq, free_head, NULL, QVIRTIO_BLK_TIMEOUT_US);
+    qvirtio_wait_used_elem(qts, dev, vq, free_head, NULL,
+                           QVIRTIO_BLK_TIMEOUT_US);
     status = readb(req_addr + 528);
     g_assert_cmpint(status, ==, 0);
 
@@ -206,13 +209,14 @@ static void test_basic(QVirtioDevice *dev, QGuestAllocator *alloc,
 
         req_addr = virtio_blk_request(alloc, dev, &req, sizeof(dwz_hdr));
 
-        free_head = qvirtqueue_add(vq, req_addr, 16, false, true);
-        qvirtqueue_add(vq, req_addr + 16, sizeof(dwz_hdr), false, true);
-        qvirtqueue_add(vq, req_addr + 16 + sizeof(dwz_hdr), 1, true, false);
+        free_head = qvirtqueue_add(qts, vq, req_addr, 16, false, true);
+        qvirtqueue_add(qts, vq, req_addr + 16, sizeof(dwz_hdr), false, true);
+        qvirtqueue_add(qts, vq, req_addr + 16 + sizeof(dwz_hdr), 1, true,
+                       false);
 
-        qvirtqueue_kick(dev, vq, free_head);
+        qvirtqueue_kick(qts, dev, vq, free_head);
 
-        qvirtio_wait_used_elem(dev, vq, free_head, NULL,
+        qvirtio_wait_used_elem(qts, dev, vq, free_head, NULL,
                                QVIRTIO_BLK_TIMEOUT_US);
         status = readb(req_addr + 16 + sizeof(dwz_hdr));
         g_assert_cmpint(status, ==, 0);
@@ -229,13 +233,13 @@ static void test_basic(QVirtioDevice *dev, QGuestAllocator *alloc,
 
         g_free(req.data);
 
-        free_head = qvirtqueue_add(vq, req_addr, 16, false, true);
-        qvirtqueue_add(vq, req_addr + 16, 512, true, true);
-        qvirtqueue_add(vq, req_addr + 528, 1, true, false);
+        free_head = qvirtqueue_add(qts, vq, req_addr, 16, false, true);
+        qvirtqueue_add(qts, vq, req_addr + 16, 512, true, true);
+        qvirtqueue_add(qts, vq, req_addr + 528, 1, true, false);
 
-        qvirtqueue_kick(dev, vq, free_head);
+        qvirtqueue_kick(qts, dev, vq, free_head);
 
-        qvirtio_wait_used_elem(dev, vq, free_head, NULL,
+        qvirtio_wait_used_elem(qts, dev, vq, free_head, NULL,
                                QVIRTIO_BLK_TIMEOUT_US);
         status = readb(req_addr + 528);
         g_assert_cmpint(status, ==, 0);
@@ -263,13 +267,13 @@ static void test_basic(QVirtioDevice *dev, QGuestAllocator *alloc,
 
         req_addr = virtio_blk_request(alloc, dev, &req, sizeof(dwz_hdr));
 
-        free_head = qvirtqueue_add(vq, req_addr, 16, false, true);
-        qvirtqueue_add(vq, req_addr + 16, sizeof(dwz_hdr), false, true);
-        qvirtqueue_add(vq, req_addr + 16 + sizeof(dwz_hdr), 1, true, false);
+        free_head = qvirtqueue_add(qts, vq, req_addr, 16, false, true);
+        qvirtqueue_add(qts, vq, req_addr + 16, sizeof(dwz_hdr), false, true);
+        qvirtqueue_add(qts, vq, req_addr + 16 + sizeof(dwz_hdr), 1, true, false);
 
-        qvirtqueue_kick(dev, vq, free_head);
+        qvirtqueue_kick(qts, dev, vq, free_head);
 
-        qvirtio_wait_used_elem(dev, vq, free_head, NULL,
+        qvirtio_wait_used_elem(qts, dev, vq, free_head, NULL,
                                QVIRTIO_BLK_TIMEOUT_US);
         status = readb(req_addr + 16 + sizeof(dwz_hdr));
         g_assert_cmpint(status, ==, 0);
@@ -290,11 +294,11 @@ static void test_basic(QVirtioDevice *dev, QGuestAllocator *alloc,
 
         g_free(req.data);
 
-        free_head = qvirtqueue_add(vq, req_addr, 528, false, true);
-        qvirtqueue_add(vq, req_addr + 528, 1, true, false);
-        qvirtqueue_kick(dev, vq, free_head);
+        free_head = qvirtqueue_add(qts, vq, req_addr, 528, false, true);
+        qvirtqueue_add(qts, vq, req_addr + 528, 1, true, false);
+        qvirtqueue_kick(qts, dev, vq, free_head);
 
-        qvirtio_wait_used_elem(dev, vq, free_head, NULL,
+        qvirtio_wait_used_elem(qts, dev, vq, free_head, NULL,
                                QVIRTIO_BLK_TIMEOUT_US);
         status = readb(req_addr + 528);
         g_assert_cmpint(status, ==, 0);
@@ -311,12 +315,12 @@ static void test_basic(QVirtioDevice *dev, QGuestAllocator *alloc,
 
         g_free(req.data);
 
-        free_head = qvirtqueue_add(vq, req_addr, 16, false, true);
-        qvirtqueue_add(vq, req_addr + 16, 513, true, false);
+        free_head = qvirtqueue_add(qts, vq, req_addr, 16, false, true);
+        qvirtqueue_add(qts, vq, req_addr + 16, 513, true, false);
 
-        qvirtqueue_kick(dev, vq, free_head);
+        qvirtqueue_kick(qts, dev, vq, free_head);
 
-        qvirtio_wait_used_elem(dev, vq, free_head, NULL,
+        qvirtio_wait_used_elem(qts, dev, vq, free_head, NULL,
                                QVIRTIO_BLK_TIMEOUT_US);
         status = readb(req_addr + 528);
         g_assert_cmpint(status, ==, 0);
@@ -353,6 +357,7 @@ static void indirect(void *obj, void *u_data, QGuestAllocator *t_alloc)
     uint32_t free_head;
     uint8_t status;
     char *data;
+    QTestState *qts = global_qtest;
 
     capacity = qvirtio_config_readq(dev, 0);
     g_assert_cmpint(capacity, ==, TEST_IMAGE_SIZE / 512);
@@ -378,13 +383,13 @@ static void indirect(void *obj, void *u_data, QGuestAllocator *t_alloc)
 
     g_free(req.data);
 
-    indirect = qvring_indirect_desc_setup(dev, t_alloc, 2);
-    qvring_indirect_desc_add(indirect, req_addr, 528, false);
-    qvring_indirect_desc_add(indirect, req_addr + 528, 1, true);
-    free_head = qvirtqueue_add_indirect(vq, indirect);
-    qvirtqueue_kick(dev, vq, free_head);
+    indirect = qvring_indirect_desc_setup(qts, dev, t_alloc, 2);
+    qvring_indirect_desc_add(qts, indirect, req_addr, 528, false);
+    qvring_indirect_desc_add(qts, indirect, req_addr + 528, 1, true);
+    free_head = qvirtqueue_add_indirect(qts, vq, indirect);
+    qvirtqueue_kick(qts, dev, vq, free_head);
 
-    qvirtio_wait_used_elem(dev, vq, free_head, NULL,
+    qvirtio_wait_used_elem(qts, dev, vq, free_head, NULL,
                            QVIRTIO_BLK_TIMEOUT_US);
     status = readb(req_addr + 528);
     g_assert_cmpint(status, ==, 0);
@@ -403,13 +408,13 @@ static void indirect(void *obj, void *u_data, QGuestAllocator *t_alloc)
 
     g_free(req.data);
 
-    indirect = qvring_indirect_desc_setup(dev, t_alloc, 2);
-    qvring_indirect_desc_add(indirect, req_addr, 16, false);
-    qvring_indirect_desc_add(indirect, req_addr + 16, 513, true);
-    free_head = qvirtqueue_add_indirect(vq, indirect);
-    qvirtqueue_kick(dev, vq, free_head);
+    indirect = qvring_indirect_desc_setup(qts, dev, t_alloc, 2);
+    qvring_indirect_desc_add(qts, indirect, req_addr, 16, false);
+    qvring_indirect_desc_add(qts, indirect, req_addr + 16, 513, true);
+    free_head = qvirtqueue_add_indirect(qts, vq, indirect);
+    qvirtqueue_kick(qts, dev, vq, free_head);
 
-    qvirtio_wait_used_elem(dev, vq, free_head, NULL,
+    qvirtio_wait_used_elem(qts, dev, vq, free_head, NULL,
                            QVIRTIO_BLK_TIMEOUT_US);
     status = readb(req_addr + 528);
     g_assert_cmpint(status, ==, 0);
@@ -461,6 +466,7 @@ static void msix(void *obj, void *u_data, QGuestAllocator *t_alloc)
     char *data;
     QOSGraphObject *blk_object = obj;
     QPCIDevice *pci_dev = blk_object->get_driver(blk_object, "pci-device");
+    QTestState *qts = global_qtest;
 
     if (qpci_check_buggy_msi(pci_dev)) {
         return;
@@ -504,12 +510,12 @@ static void msix(void *obj, void *u_data, QGuestAllocator *t_alloc)
 
     g_free(req.data);
 
-    free_head = qvirtqueue_add(vq, req_addr, 16, false, true);
-    qvirtqueue_add(vq, req_addr + 16, 512, false, true);
-    qvirtqueue_add(vq, req_addr + 528, 1, true, false);
-    qvirtqueue_kick(dev, vq, free_head);
+    free_head = qvirtqueue_add(qts, vq, req_addr, 16, false, true);
+    qvirtqueue_add(qts, vq, req_addr + 16, 512, false, true);
+    qvirtqueue_add(qts, vq, req_addr + 528, 1, true, false);
+    qvirtqueue_kick(qts, dev, vq, free_head);
 
-    qvirtio_wait_used_elem(dev, vq, free_head, NULL,
+    qvirtio_wait_used_elem(qts, dev, vq, free_head, NULL,
                            QVIRTIO_BLK_TIMEOUT_US);
 
     status = readb(req_addr + 528);
@@ -527,14 +533,14 @@ static void msix(void *obj, void *u_data, QGuestAllocator *t_alloc)
 
     g_free(req.data);
 
-    free_head = qvirtqueue_add(vq, req_addr, 16, false, true);
-    qvirtqueue_add(vq, req_addr + 16, 512, true, true);
-    qvirtqueue_add(vq, req_addr + 528, 1, true, false);
+    free_head = qvirtqueue_add(qts, vq, req_addr, 16, false, true);
+    qvirtqueue_add(qts, vq, req_addr + 16, 512, true, true);
+    qvirtqueue_add(qts, vq, req_addr + 528, 1, true, false);
 
-    qvirtqueue_kick(dev, vq, free_head);
+    qvirtqueue_kick(qts, dev, vq, free_head);
 
 
-    qvirtio_wait_used_elem(dev, vq, free_head, NULL,
+    qvirtio_wait_used_elem(qts, dev, vq, free_head, NULL,
                            QVIRTIO_BLK_TIMEOUT_US);
 
     status = readb(req_addr + 528);
@@ -569,6 +575,7 @@ static void idx(void *obj, void *u_data, QGuestAllocator *t_alloc)
     char *data;
     QOSGraphObject *blk_object = obj;
     QPCIDevice *pci_dev = blk_object->get_driver(blk_object, "pci-device");
+    QTestState *qts = global_qtest;
 
     if (qpci_check_buggy_msi(pci_dev)) {
         return;
@@ -603,12 +610,12 @@ static void idx(void *obj, void *u_data, QGuestAllocator *t_alloc)
 
     g_free(req.data);
 
-    free_head = qvirtqueue_add(vq, req_addr, 16, false, true);
-    qvirtqueue_add(vq, req_addr + 16, 512, false, true);
-    qvirtqueue_add(vq, req_addr + 528, 1, true, false);
-    qvirtqueue_kick(dev, vq, free_head);
+    free_head = qvirtqueue_add(qts, vq, req_addr, 16, false, true);
+    qvirtqueue_add(qts, vq, req_addr + 16, 512, false, true);
+    qvirtqueue_add(qts, vq, req_addr + 528, 1, true, false);
+    qvirtqueue_kick(qts, dev, vq, free_head);
 
-    qvirtio_wait_used_elem(dev, vq, free_head, NULL,
+    qvirtio_wait_used_elem(qts, dev, vq, free_head, NULL,
                            QVIRTIO_BLK_TIMEOUT_US);
 
     /* Write request */
@@ -623,15 +630,15 @@ static void idx(void *obj, void *u_data, QGuestAllocator *t_alloc)
     g_free(req.data);
 
     /* Notify after processing the third request */
-    qvirtqueue_set_used_event(vq, 2);
-    free_head = qvirtqueue_add(vq, req_addr, 16, false, true);
-    qvirtqueue_add(vq, req_addr + 16, 512, false, true);
-    qvirtqueue_add(vq, req_addr + 528, 1, true, false);
-    qvirtqueue_kick(dev, vq, free_head);
+    qvirtqueue_set_used_event(qts, vq, 2);
+    free_head = qvirtqueue_add(qts, vq, req_addr, 16, false, true);
+    qvirtqueue_add(qts, vq, req_addr + 16, 512, false, true);
+    qvirtqueue_add(qts, vq, req_addr + 528, 1, true, false);
+    qvirtqueue_kick(qts, dev, vq, free_head);
     write_head = free_head;
 
     /* No notification expected */
-    status = qvirtio_wait_status_byte_no_isr(dev,
+    status = qvirtio_wait_status_byte_no_isr(qts, dev,
                                              vq, req_addr + 528,
                                              QVIRTIO_BLK_TIMEOUT_US);
     g_assert_cmpint(status, ==, 0);
@@ -648,16 +655,16 @@ static void idx(void *obj, void *u_data, QGuestAllocator *t_alloc)
 
     g_free(req.data);
 
-    free_head = qvirtqueue_add(vq, req_addr, 16, false, true);
-    qvirtqueue_add(vq, req_addr + 16, 512, true, true);
-    qvirtqueue_add(vq, req_addr + 528, 1, true, false);
+    free_head = qvirtqueue_add(qts, vq, req_addr, 16, false, true);
+    qvirtqueue_add(qts, vq, req_addr + 16, 512, true, true);
+    qvirtqueue_add(qts, vq, req_addr + 528, 1, true, false);
 
-    qvirtqueue_kick(dev, vq, free_head);
+    qvirtqueue_kick(qts, dev, vq, free_head);
 
     /* We get just one notification for both requests */
-    qvirtio_wait_used_elem(dev, vq, write_head, NULL,
+    qvirtio_wait_used_elem(qts, dev, vq, write_head, NULL,
                            QVIRTIO_BLK_TIMEOUT_US);
-    g_assert(qvirtqueue_get_buf(vq, &desc_idx, NULL));
+    g_assert(qvirtqueue_get_buf(qts, vq, &desc_idx, NULL));
     g_assert_cmpint(desc_idx, ==, free_head);
 
     status = readb(req_addr + 528);
diff --git a/tests/virtio-net-test.c b/tests/virtio-net-test.c
index 7aa9622f30..1071dd82c9 100644
--- a/tests/virtio-net-test.c
+++ b/tests/virtio-net-test.c
@@ -33,6 +33,7 @@ static void rx_test(QVirtioDevice *dev,
                     QGuestAllocator *alloc, QVirtQueue *vq,
                     int socket)
 {
+    QTestState *qts = global_qtest;
     uint64_t req_addr;
     uint32_t free_head;
     char test[] = "TEST";
@@ -51,13 +52,14 @@ static void rx_test(QVirtioDevice *dev,
 
     req_addr = guest_alloc(alloc, 64);
 
-    free_head = qvirtqueue_add(vq, req_addr, 64, true, false);
-    qvirtqueue_kick(dev, vq, free_head);
+    free_head = qvirtqueue_add(qts, vq, req_addr, 64, true, false);
+    qvirtqueue_kick(qts, dev, vq, free_head);
 
     ret = iov_send(socket, iov, 2, 0, sizeof(len) + sizeof(test));
     g_assert_cmpint(ret, ==, sizeof(test) + sizeof(len));
 
-    qvirtio_wait_used_elem(dev, vq, free_head, NULL, QVIRTIO_NET_TIMEOUT_US);
+    qvirtio_wait_used_elem(qts, dev, vq, free_head, NULL,
+                           QVIRTIO_NET_TIMEOUT_US);
     memread(req_addr + VNET_HDR_SIZE, buffer, sizeof(test));
     g_assert_cmpstr(buffer, ==, "TEST");
 
@@ -68,6 +70,7 @@ static void tx_test(QVirtioDevice *dev,
                     QGuestAllocator *alloc, QVirtQueue *vq,
                     int socket)
 {
+    QTestState *qts = global_qtest;
     uint64_t req_addr;
     uint32_t free_head;
     uint32_t len;
@@ -77,10 +80,11 @@ static void tx_test(QVirtioDevice *dev,
     req_addr = guest_alloc(alloc, 64);
     memwrite(req_addr + VNET_HDR_SIZE, "TEST", 4);
 
-    free_head = qvirtqueue_add(vq, req_addr, 64, false, false);
-    qvirtqueue_kick(dev, vq, free_head);
+    free_head = qvirtqueue_add(qts, vq, req_addr, 64, false, false);
+    qvirtqueue_kick(qts, dev, vq, free_head);
 
-    qvirtio_wait_used_elem(dev, vq, free_head, NULL, QVIRTIO_NET_TIMEOUT_US);
+    qvirtio_wait_used_elem(qts, dev, vq, free_head, NULL,
+                           QVIRTIO_NET_TIMEOUT_US);
     guest_free(alloc, req_addr);
 
     ret = qemu_recv(socket, &len, sizeof(len), 0);
@@ -95,6 +99,7 @@ static void rx_stop_cont_test(QVirtioDevice *dev,
                               QGuestAllocator *alloc, QVirtQueue *vq,
                               int socket)
 {
+    QTestState *qts = global_qtest;
     uint64_t req_addr;
     uint32_t free_head;
     char test[] = "TEST";
@@ -114,8 +119,8 @@ static void rx_stop_cont_test(QVirtioDevice *dev,
 
     req_addr = guest_alloc(alloc, 64);
 
-    free_head = qvirtqueue_add(vq, req_addr, 64, true, false);
-    qvirtqueue_kick(dev, vq, free_head);
+    free_head = qvirtqueue_add(qts, vq, req_addr, 64, true, false);
+    qvirtqueue_kick(qts, dev, vq, free_head);
 
     rsp = qmp("{ 'execute' : 'stop'}");
     qobject_unref(rsp);
@@ -131,7 +136,8 @@ static void rx_stop_cont_test(QVirtioDevice *dev,
     rsp = qmp("{ 'execute' : 'cont'}");
     qobject_unref(rsp);
 
-    qvirtio_wait_used_elem(dev, vq, free_head, NULL, QVIRTIO_NET_TIMEOUT_US);
+    qvirtio_wait_used_elem(qts, dev, vq, free_head, NULL,
+                           QVIRTIO_NET_TIMEOUT_US);
     memread(req_addr + VNET_HDR_SIZE, buffer, sizeof(test));
     g_assert_cmpstr(buffer, ==, "TEST");
 
@@ -283,19 +289,20 @@ static void large_tx(void *obj, void *data, QGuestAllocator *t_alloc)
     uint64_t req_addr;
     uint32_t free_head;
     size_t alloc_size = (size_t)data / 64;
+    QTestState *qts = global_qtest;
     int i;
 
     /* Bypass the limitation by pointing several descriptors to a single
      * smaller area */
     req_addr = guest_alloc(t_alloc, alloc_size);
-    free_head = qvirtqueue_add(vq, req_addr, alloc_size, false, true);
+    free_head = qvirtqueue_add(qts, vq, req_addr, alloc_size, false, true);
 
     for (i = 0; i < 64; i++) {
-        qvirtqueue_add(vq, req_addr, alloc_size, false, i != 63);
+        qvirtqueue_add(qts, vq, req_addr, alloc_size, false, i != 63);
     }
-    qvirtqueue_kick(dev->vdev, vq, free_head);
+    qvirtqueue_kick(qts, dev->vdev, vq, free_head);
 
-    qvirtio_wait_used_elem(dev->vdev, vq, free_head, NULL,
+    qvirtio_wait_used_elem(qts, dev->vdev, vq, free_head, NULL,
                            QVIRTIO_NET_TIMEOUT_US);
     guest_free(t_alloc, req_addr);
 }
diff --git a/tests/virtio-scsi-test.c b/tests/virtio-scsi-test.c
index 1ad9f75d74..6f8b310cf8 100644
--- a/tests/virtio-scsi-test.c
+++ b/tests/virtio-scsi-test.c
@@ -72,6 +72,7 @@ static uint8_t virtio_scsi_do_command(QVirtioSCSIQueues *vs,
     uint64_t req_addr, resp_addr, data_in_addr = 0, data_out_addr = 0;
     uint8_t response;
     uint32_t free_head;
+    QTestState *qts = global_qtest;
 
     vq = vs->vq[2];
 
@@ -83,24 +84,24 @@ static uint8_t virtio_scsi_do_command(QVirtioSCSIQueues *vs,
 
     /* Add request header */
     req_addr = qvirtio_scsi_alloc(vs, sizeof(req), &req);
-    free_head = qvirtqueue_add(vq, req_addr, sizeof(req), false, true);
+    free_head = qvirtqueue_add(qts, vq, req_addr, sizeof(req), false, true);
 
     if (data_out_len) {
         data_out_addr = qvirtio_scsi_alloc(vs, data_out_len, data_out);
-        qvirtqueue_add(vq, data_out_addr, data_out_len, false, true);
+        qvirtqueue_add(qts, vq, data_out_addr, data_out_len, false, true);
     }
 
     /* Add response header */
     resp_addr = qvirtio_scsi_alloc(vs, sizeof(resp), &resp);
-    qvirtqueue_add(vq, resp_addr, sizeof(resp), true, !!data_in_len);
+    qvirtqueue_add(qts, vq, resp_addr, sizeof(resp), true, !!data_in_len);
 
     if (data_in_len) {
         data_in_addr = qvirtio_scsi_alloc(vs, data_in_len, data_in);
-        qvirtqueue_add(vq, data_in_addr, data_in_len, true, false);
+        qvirtqueue_add(qts, vq, data_in_addr, data_in_len, true, false);
     }
 
-    qvirtqueue_kick(vs->dev, vq, free_head);
-    qvirtio_wait_used_elem(vs->dev, vq, free_head, NULL,
+    qvirtqueue_kick(qts, vs->dev, vq, free_head);
+    qvirtio_wait_used_elem(qts, vs->dev, vq, free_head, NULL,
                            QVIRTIO_SCSI_TIMEOUT_US);
 
     response = readb(resp_addr +
-- 
2.18.1



^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, back to index

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-13  9:30 [Qemu-devel] [PATCH 0/6] First batch of global_qtest-removement patches for QEMU 4.2 Thomas Huth
2019-08-13  9:30 ` [Qemu-devel] [PATCH 1/6] tests/libqos: Make generic virtio code independent from global_qtest Thomas Huth
2019-08-13 15:18   ` Eric Blake
2019-08-14 19:59     ` [Qemu-devel] [PATCH v2] " Thomas Huth
2019-08-13  9:30 ` [Qemu-devel] [PATCH 2/6] tests/libqos: Make virtio-pci " Thomas Huth
2019-08-13 15:19   ` Eric Blake
2019-08-13  9:30 ` [Qemu-devel] [PATCH 3/6] tests/libqtest: Remove unused function hmp() Thomas Huth
2019-08-13 15:20   ` Eric Blake
2019-08-13 17:38     ` Thomas Huth
2019-08-13  9:30 ` [Qemu-devel] [PATCH 4/6] tests/libqtest: Clean up qtest_cb_for_every_machine() wrt global_qtest Thomas Huth
2019-08-13 15:21   ` Eric Blake
2019-08-13  9:30 ` [Qemu-devel] [PATCH 5/6] tests/libqtest: Make qtest_qmp_device_add/del independent from global_qtest Thomas Huth
2019-08-13 15:22   ` Eric Blake
2019-08-13  9:30 ` [Qemu-devel] [PATCH 6/6] tests/libqtest: Make qmp_assert_success() " Thomas Huth
2019-08-13 15:24   ` Eric Blake
2019-08-13 15:00 ` [Qemu-devel] [PATCH 0/6] First batch of global_qtest-removement patches for QEMU 4.2 Stefan Hajnoczi

QEMU-Devel Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/qemu-devel/0 qemu-devel/git/0.git
	git clone --mirror https://lore.kernel.org/qemu-devel/1 qemu-devel/git/1.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 qemu-devel qemu-devel/ https://lore.kernel.org/qemu-devel \
		qemu-devel@nongnu.org qemu-devel@archiver.kernel.org
	public-inbox-index qemu-devel


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.nongnu.qemu-devel


AGPL code for this site: git clone https://public-inbox.org/ public-inbox