diff options
author | Thomas Huth <thuth@redhat.com> | 2019-05-18 10:23:24 +0200 |
---|---|---|
committer | Thomas Huth <thuth@redhat.com> | 2019-08-15 19:23:59 +0200 |
commit | 1999a70a05ad603d1c76e0a7d230bcfed0d626ac (patch) | |
tree | 967aed417b9d954d6b7436dc19b2e22dfce8a3b4 /tests/libqos | |
parent | ca1ef1e62e581f61c40f8be49d222007739691c4 (diff) | |
download | qemu-1999a70a05ad603d1c76e0a7d230bcfed0d626ac.zip qemu-1999a70a05ad603d1c76e0a7d230bcfed0d626ac.tar.gz qemu-1999a70a05ad603d1c76e0a7d230bcfed0d626ac.tar.bz2 |
tests/libqos: Make generic virtio code independent from global_qtest
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.
Message-Id: <20190814195920.32023-1-thuth@redhat.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
Diffstat (limited to 'tests/libqos')
-rw-r--r-- | tests/libqos/virtio.c | 81 | ||||
-rw-r--r-- | tests/libqos/virtio.h | 30 |
2 files changed, 61 insertions, 50 deletions
diff --git a/tests/libqos/virtio.c b/tests/libqos/virtio.c index b4c01dc..91ce069 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 7b97f5e..037176d 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); |