aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorPeter Maydell <peter.maydell@linaro.org>2017-06-30 13:26:41 +0100
committerPeter Maydell <peter.maydell@linaro.org>2017-06-30 13:26:41 +0100
commit0912d0f2c719e029c5101eacaacbaf2c755be099 (patch)
treeb3650273b353d450c5f8b3589bef0ff8f51e748d /tests
parent36f87b4513373b3cd79c87c9197d17face95d4ac (diff)
parentc324fd0a39cee43c13f6d1fb34f74fc5e2fb007b (diff)
downloadqemu-0912d0f2c719e029c5101eacaacbaf2c755be099.zip
qemu-0912d0f2c719e029c5101eacaacbaf2c755be099.tar.gz
qemu-0912d0f2c719e029c5101eacaacbaf2c755be099.tar.bz2
Merge remote-tracking branch 'remotes/stefanha/tags/block-pull-request' into staging
# gpg: Signature made Fri 30 Jun 2017 12:46:17 BST # gpg: using RSA key 0x9CA4ABB381AB73C8 # gpg: Good signature from "Stefan Hajnoczi <stefanha@redhat.com>" # gpg: aka "Stefan Hajnoczi <stefanha@gmail.com>" # Primary key fingerprint: 8695 A8BF D3F9 7CDA AC35 775A 9CA4 ABB3 81AB 73C8 * remotes/stefanha/tags/block-pull-request: virtio-pci: use ioeventfd even when KVM is disabled tests: fix virtio-net-test ISR dependence tests: fix virtio-blk-test ISR dependence tests: fix virtio-scsi-test ISR dependence libqos: add virtio used ring support libqos: fix typo in virtio.h QVirtQueue->used comment virtio-blk: trace vdev so devices can be distinguished Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Diffstat (limited to 'tests')
-rw-r--r--tests/libqos/virtio.c60
-rw-r--r--tests/libqos/virtio.h8
-rw-r--r--tests/virtio-blk-test.c27
-rw-r--r--tests/virtio-net-test.c6
-rw-r--r--tests/virtio-scsi-test.c2
5 files changed, 88 insertions, 15 deletions
diff --git a/tests/libqos/virtio.c b/tests/libqos/virtio.c
index ec30cb9..9880a69 100644
--- a/tests/libqos/virtio.c
+++ b/tests/libqos/virtio.c
@@ -116,6 +116,35 @@ uint8_t qvirtio_wait_status_byte_no_isr(QVirtioDevice *d,
return val;
}
+/*
+ * qvirtio_wait_used_elem:
+ * @desc_idx: The next expected vq->desc[] index in the used ring
+ * @timeout_us: How many microseconds to wait before failing
+ *
+ * This function waits for the next completed request on the used ring.
+ */
+void qvirtio_wait_used_elem(QVirtioDevice *d,
+ QVirtQueue *vq,
+ uint32_t desc_idx,
+ gint64 timeout_us)
+{
+ gint64 start_time = g_get_monotonic_time();
+
+ for (;;) {
+ uint32_t got_desc_idx;
+
+ clock_step(100);
+
+ if (d->bus->get_queue_isr_status(d, vq) &&
+ qvirtqueue_get_buf(vq, &got_desc_idx)) {
+ g_assert_cmpint(got_desc_idx, ==, desc_idx);
+ return;
+ }
+
+ g_assert(g_get_monotonic_time() - start_time <= timeout_us);
+ }
+}
+
void qvirtio_wait_config_isr(QVirtioDevice *d, gint64 timeout_us)
{
gint64 start_time = g_get_monotonic_time();
@@ -272,6 +301,37 @@ void qvirtqueue_kick(QVirtioDevice *d, QVirtQueue *vq, uint32_t free_head)
}
}
+/*
+ * qvirtqueue_get_buf:
+ * @desc_idx: A pointer that is filled with the vq->desc[] index, may be NULL
+ *
+ * This function gets the next used element if there is one ready.
+ *
+ * Returns: true if an element was ready, false otherwise
+ */
+bool qvirtqueue_get_buf(QVirtQueue *vq, uint32_t *desc_idx)
+{
+ uint16_t idx;
+
+ idx = readw(vq->used + offsetof(struct vring_used, idx));
+ if (idx == vq->last_used_idx) {
+ return false;
+ }
+
+ if (desc_idx) {
+ uint64_t elem_addr;
+
+ elem_addr = vq->used +
+ offsetof(struct vring_used, ring) +
+ (vq->last_used_idx % vq->size) *
+ sizeof(struct vring_used_elem);
+ *desc_idx = readl(elem_addr + offsetof(struct vring_used_elem, id));
+ }
+
+ vq->last_used_idx++;
+ return true;
+}
+
void qvirtqueue_set_used_event(QVirtQueue *vq, uint16_t idx)
{
g_assert(vq->event);
diff --git a/tests/libqos/virtio.h b/tests/libqos/virtio.h
index 3397a08..8fbcd18 100644
--- a/tests/libqos/virtio.h
+++ b/tests/libqos/virtio.h
@@ -26,12 +26,13 @@ typedef struct QVirtioDevice {
typedef struct QVirtQueue {
uint64_t desc; /* This points to an array of struct vring_desc */
uint64_t avail; /* This points to a struct vring_avail */
- uint64_t used; /* This points to a struct vring_desc */
+ uint64_t used; /* This points to a struct vring_used */
uint16_t index;
uint32_t size;
uint32_t free_head;
uint32_t num_free;
uint32_t align;
+ uint16_t last_used_idx;
bool indirect;
bool event;
} QVirtQueue;
@@ -120,6 +121,10 @@ uint8_t qvirtio_wait_status_byte_no_isr(QVirtioDevice *d,
QVirtQueue *vq,
uint64_t addr,
gint64 timeout_us);
+void qvirtio_wait_used_elem(QVirtioDevice *d,
+ QVirtQueue *vq,
+ uint32_t desc_idx,
+ gint64 timeout_us);
void qvirtio_wait_config_isr(QVirtioDevice *d, gint64 timeout_us);
QVirtQueue *qvirtqueue_setup(QVirtioDevice *d,
QGuestAllocator *alloc, uint16_t index);
@@ -135,6 +140,7 @@ 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);
void qvirtqueue_set_used_event(QVirtQueue *vq, uint16_t idx);
#endif
diff --git a/tests/virtio-blk-test.c b/tests/virtio-blk-test.c
index fd2078c..0576cb1 100644
--- a/tests/virtio-blk-test.c
+++ b/tests/virtio-blk-test.c
@@ -196,7 +196,7 @@ static void test_basic(QVirtioDevice *dev, QGuestAllocator *alloc,
qvirtqueue_kick(dev, vq, free_head);
- qvirtio_wait_queue_isr(dev, vq, QVIRTIO_BLK_TIMEOUT_US);
+ qvirtio_wait_used_elem(dev, vq, free_head, QVIRTIO_BLK_TIMEOUT_US);
status = readb(req_addr + 528);
g_assert_cmpint(status, ==, 0);
@@ -218,7 +218,7 @@ static void test_basic(QVirtioDevice *dev, QGuestAllocator *alloc,
qvirtqueue_kick(dev, vq, free_head);
- qvirtio_wait_queue_isr(dev, vq, QVIRTIO_BLK_TIMEOUT_US);
+ qvirtio_wait_used_elem(dev, vq, free_head, QVIRTIO_BLK_TIMEOUT_US);
status = readb(req_addr + 528);
g_assert_cmpint(status, ==, 0);
@@ -246,7 +246,7 @@ static void test_basic(QVirtioDevice *dev, QGuestAllocator *alloc,
qvirtqueue_add(vq, req_addr + 528, 1, true, false);
qvirtqueue_kick(dev, vq, free_head);
- qvirtio_wait_queue_isr(dev, vq, QVIRTIO_BLK_TIMEOUT_US);
+ qvirtio_wait_used_elem(dev, vq, free_head, QVIRTIO_BLK_TIMEOUT_US);
status = readb(req_addr + 528);
g_assert_cmpint(status, ==, 0);
@@ -267,7 +267,7 @@ static void test_basic(QVirtioDevice *dev, QGuestAllocator *alloc,
qvirtqueue_kick(dev, vq, free_head);
- qvirtio_wait_queue_isr(dev, vq, QVIRTIO_BLK_TIMEOUT_US);
+ qvirtio_wait_used_elem(dev, vq, free_head, QVIRTIO_BLK_TIMEOUT_US);
status = readb(req_addr + 528);
g_assert_cmpint(status, ==, 0);
@@ -348,7 +348,7 @@ static void pci_indirect(void)
free_head = qvirtqueue_add_indirect(&vqpci->vq, indirect);
qvirtqueue_kick(&dev->vdev, &vqpci->vq, free_head);
- qvirtio_wait_queue_isr(&dev->vdev, &vqpci->vq,
+ qvirtio_wait_used_elem(&dev->vdev, &vqpci->vq, free_head,
QVIRTIO_BLK_TIMEOUT_US);
status = readb(req_addr + 528);
g_assert_cmpint(status, ==, 0);
@@ -373,7 +373,7 @@ static void pci_indirect(void)
free_head = qvirtqueue_add_indirect(&vqpci->vq, indirect);
qvirtqueue_kick(&dev->vdev, &vqpci->vq, free_head);
- qvirtio_wait_queue_isr(&dev->vdev, &vqpci->vq,
+ qvirtio_wait_used_elem(&dev->vdev, &vqpci->vq, free_head,
QVIRTIO_BLK_TIMEOUT_US);
status = readb(req_addr + 528);
g_assert_cmpint(status, ==, 0);
@@ -484,7 +484,7 @@ static void pci_msix(void)
qvirtqueue_add(&vqpci->vq, req_addr + 528, 1, true, false);
qvirtqueue_kick(&dev->vdev, &vqpci->vq, free_head);
- qvirtio_wait_queue_isr(&dev->vdev, &vqpci->vq,
+ qvirtio_wait_used_elem(&dev->vdev, &vqpci->vq, free_head,
QVIRTIO_BLK_TIMEOUT_US);
status = readb(req_addr + 528);
@@ -509,7 +509,7 @@ static void pci_msix(void)
qvirtqueue_kick(&dev->vdev, &vqpci->vq, free_head);
- qvirtio_wait_queue_isr(&dev->vdev, &vqpci->vq,
+ qvirtio_wait_used_elem(&dev->vdev, &vqpci->vq, free_head,
QVIRTIO_BLK_TIMEOUT_US);
status = readb(req_addr + 528);
@@ -540,6 +540,8 @@ static void pci_idx(void)
uint64_t capacity;
uint32_t features;
uint32_t free_head;
+ uint32_t write_head;
+ uint32_t desc_idx;
uint8_t status;
char *data;
@@ -581,7 +583,8 @@ static void pci_idx(void)
qvirtqueue_add(&vqpci->vq, req_addr + 528, 1, true, false);
qvirtqueue_kick(&dev->vdev, &vqpci->vq, free_head);
- qvirtio_wait_queue_isr(&dev->vdev, &vqpci->vq, QVIRTIO_BLK_TIMEOUT_US);
+ qvirtio_wait_used_elem(&dev->vdev, &vqpci->vq, free_head,
+ QVIRTIO_BLK_TIMEOUT_US);
/* Write request */
req.type = VIRTIO_BLK_T_OUT;
@@ -600,6 +603,7 @@ static void pci_idx(void)
qvirtqueue_add(&vqpci->vq, req_addr + 16, 512, false, true);
qvirtqueue_add(&vqpci->vq, req_addr + 528, 1, true, false);
qvirtqueue_kick(&dev->vdev, &vqpci->vq, free_head);
+ write_head = free_head;
/* No notification expected */
status = qvirtio_wait_status_byte_no_isr(&dev->vdev,
@@ -625,8 +629,11 @@ static void pci_idx(void)
qvirtqueue_kick(&dev->vdev, &vqpci->vq, free_head);
- qvirtio_wait_queue_isr(&dev->vdev, &vqpci->vq,
+ /* We get just one notification for both requests */
+ qvirtio_wait_used_elem(&dev->vdev, &vqpci->vq, write_head,
QVIRTIO_BLK_TIMEOUT_US);
+ g_assert(qvirtqueue_get_buf(&vqpci->vq, &desc_idx));
+ g_assert_cmpint(desc_idx, ==, free_head);
status = readb(req_addr + 528);
g_assert_cmpint(status, ==, 0);
diff --git a/tests/virtio-net-test.c b/tests/virtio-net-test.c
index 8f94360..635b942 100644
--- a/tests/virtio-net-test.c
+++ b/tests/virtio-net-test.c
@@ -108,7 +108,7 @@ static void rx_test(QVirtioDevice *dev,
ret = iov_send(socket, iov, 2, 0, sizeof(len) + sizeof(test));
g_assert_cmpint(ret, ==, sizeof(test) + sizeof(len));
- qvirtio_wait_queue_isr(dev, vq, QVIRTIO_NET_TIMEOUT_US);
+ qvirtio_wait_used_elem(dev, vq, free_head, QVIRTIO_NET_TIMEOUT_US);
memread(req_addr + VNET_HDR_SIZE, buffer, sizeof(test));
g_assert_cmpstr(buffer, ==, "TEST");
@@ -131,7 +131,7 @@ static void tx_test(QVirtioDevice *dev,
free_head = qvirtqueue_add(vq, req_addr, 64, false, false);
qvirtqueue_kick(dev, vq, free_head);
- qvirtio_wait_queue_isr(dev, vq, QVIRTIO_NET_TIMEOUT_US);
+ qvirtio_wait_used_elem(dev, vq, free_head, QVIRTIO_NET_TIMEOUT_US);
guest_free(alloc, req_addr);
ret = qemu_recv(socket, &len, sizeof(len), 0);
@@ -182,7 +182,7 @@ static void rx_stop_cont_test(QVirtioDevice *dev,
rsp = qmp("{ 'execute' : 'cont'}");
QDECREF(rsp);
- qvirtio_wait_queue_isr(dev, vq, QVIRTIO_NET_TIMEOUT_US);
+ qvirtio_wait_used_elem(dev, vq, free_head, QVIRTIO_NET_TIMEOUT_US);
memread(req_addr + VNET_HDR_SIZE, buffer, sizeof(test));
g_assert_cmpstr(buffer, ==, "TEST");
diff --git a/tests/virtio-scsi-test.c b/tests/virtio-scsi-test.c
index eff71df..87a3b6e 100644
--- a/tests/virtio-scsi-test.c
+++ b/tests/virtio-scsi-test.c
@@ -121,7 +121,7 @@ static uint8_t virtio_scsi_do_command(QVirtIOSCSI *vs, const uint8_t *cdb,
}
qvirtqueue_kick(vs->dev, vq, free_head);
- qvirtio_wait_queue_isr(vs->dev, vq, QVIRTIO_SCSI_TIMEOUT_US);
+ qvirtio_wait_used_elem(vs->dev, vq, free_head, QVIRTIO_SCSI_TIMEOUT_US);
response = readb(resp_addr +
offsetof(struct virtio_scsi_cmd_resp, response));