Skip to contentSkip to conversation

tests: enable virtio tests on SPAPR

PATCH In review Laurent Vivier 4 participants 13 messages Oct 17, 2016 – Oct 18, 2016

lore
Share & tools
lore
#0 lore raw

v5 cover tests: enable virtio tests on SPAPR

This series enables virtio tests on SPAPR by starting machines using qtest_pc_boot() or qtest_spapr_boot() to use the good libqos PCI framework (pc or spapr).

It adds also some byte-swapping in virtio-pci.c as PCI is always little-endian and the endianness of the virtio device depends on the endianness of the guest.

This series does not enable virtio PCI MSI-X tests on SPAPR as this needs more work and will be the aim of another series.

v5:
- minor updates:
- remove declaration within the code
- update comment about qtest_vboot()
(terminates on failure)
v4:
- rebase on papr/ppc-for-2.8
- add a patch to rename target_big_endian() to qvirtio_is_big_endian()
- Add a patch to remove the QVirtioBus arguments from all virtio functions

v3:
- remove "ppc" from allowed archs for virtio-blk-test
- remove g_assert_nonnull() after g_malloc()
- add a patch to fix "vs" memory leak in virtio-scsi-test
- add a patch to remove g_assert() after qtest_spapr_boot() and update comment qtest_vboot() to explain it never returns NULL.

v2:
- update comments (virtio-1.0, log)
- move g_assert_nonnull() to qtest_boot()
- exit gracefully if the architecture is not supported
- replace qtest_pc_shutdown() by qtest_shutdown()
- move qvirtio_scsi_stop() to qvirtio_scsi_pci_free()

Laurent Vivier (6):
tests: fix memory leak in virtio-scsi-test
tests: don't check if qtest_spapr_boot() returns NULL
tests: move QVirtioBus pointer into QVirtioDevice
tests: rename target_big_endian() as qvirtio_is_big_endian()
tests: use qtest_pc_boot()/qtest_shutdown() in virtio tests
tests: enable virtio tests on SPAPR

 tests/Makefile.include     |   3 +-
 tests/libqos/libqos.c      |   2 +
 tests/libqos/virtio-mmio.c |   1 +
 tests/libqos/virtio-pci.c  |  28 +++-
 tests/libqos/virtio.c      |  77 +++++------
 tests/libqos/virtio.h      |  57 ++++----
 tests/libqtest.h           |  10 --
 tests/rtas-test.c          |   1 -
 tests/vhost-user-test.c    |  33 +++--
 tests/virtio-9p-test.c     |  69 +++++-----
 tests/virtio-blk-test.c    | 322 +++++++++++++++++++++------------------------
 tests/virtio-net-test.c    | 106 +++++++--------
 tests/virtio-rng-test.c    |   7 +-
 tests/virtio-scsi-test.c   |  91 ++++++-------
 14 files changed, 400 insertions(+), 407 deletions(-)
Signature · 1 line
2.7.4
#1 lore raw

PATCH v5 1/6 tests: fix memory leak in virtio-scsi-test

vs is allocated in qvirtio_scsi_pci_init() and never freed.

---
 tests/virtio-scsi-test.c | 1 +
 1 file changed, 1 insertion(+)
tests/virtio-scsi-test.c +1 -0
index 79088bb..94d75b1 100644
@@ -64,6 +64,7 @@ static void qvirtio_scsi_pci_free(QVirtIOSCSI *vs)
     qvirtio_pci_device_disable(container_of(vs->dev, QVirtioPCIDevice, vdev));
     g_free(vs->dev);
     qpci_free_pc(vs->bus);
+    g_free(vs);
 }
 
 static uint64_t qvirtio_scsi_alloc(QVirtIOSCSI *vs, size_t alloc_size,
Signature · 1 line
2.7.4
Reviewed-by on v5 1/6
#2 lore raw

Re: [Qemu-devel] [PATCH v5 1/6] tests: fix memory leak in virtio-scsi-test

Quoted 14 lines · Laurent Vivier

vs is allocated in qvirtio_scsi_pci_init() and never freed.

---
 tests/virtio-scsi-test.c | 1 +
 1 file changed, 1 insertion(+)
tests/virtio-scsi-test.c +0 -0
index 79088bb..94d75b1 100644

tests/virtio-scsi-test.c static void qvirtio_scsi_pci_free(QVirtIOSCSI *vs) · line 70

Quoted 7 lines
tests/virtio-scsi-test.c +1 -0
@@ -64,6 +64,7 @@ static void qvirtio_scsi_pci_free(QVirtIOSCSI *vs)
     qvirtio_pci_device_disable(container_of(vs->dev, QVirtioPCIDevice, vdev));
     g_free(vs->dev);
     qpci_free_pc(vs->bus);
+    g_free(vs);
 }
 
 static uint64_t qvirtio_scsi_alloc(QVirtIOSCSI *vs, size_t alloc_size,
#3 lore raw

PATCH v5 2/6 tests: don't check if qtest_spapr_boot() returns NULL

In reply to Laurent Vivier

qtest_spapr_boot()/qtest_pc_boot()/qtest_boot() call qtest_vboot() and qtest_vboot() calls g_malloc(),
and g_malloc() never fails:
if memory allocation fails, the application is terminated.

---
 tests/libqos/libqos.c | 2 ++
 tests/rtas-test.c     | 1 -
 2 files changed, 2 insertions(+), 1 deletion(-)
tests/libqos/libqos.c +2 -0
index 7abb482..6226546 100644
@@ -10,6 +10,8 @@
 /**
  * Launch QEMU with the given command line,
  * and then set up interrupts and our guest malloc interface.
+ * Never returns NULL:
+ * Terminates the application in case an error is encountered.
  */
 QOSState *qtest_vboot(QOSOps *ops, const char *cmdline_fmt, va_list ap)
 {
tests/rtas-test.c +0 -1
index ba0867a..276c87e 100644
@@ -14,7 +14,6 @@ static void test_rtas_get_time_of_day(void)
     time_t t1, t2;
 
     qs = qtest_spapr_boot("-machine pseries");
-    g_assert(qs != NULL);
 
     t1 = time(NULL);
     ret = qrtas_get_time_of_day(qs->alloc, &tm, &ns);
Signature · 1 line
2.7.4
Reviewed-by on v5 2/6
#4 lore raw

Re: [Qemu-devel] [PATCH v5 2/6] tests: don't check if qtest_spapr_boot() returns NULL

Quoted 30 lines · Laurent Vivier

qtest_spapr_boot()/qtest_pc_boot()/qtest_boot() call qtest_vboot() and qtest_vboot() calls g_malloc(),
and g_malloc() never fails:
if memory allocation fails, the application is terminated.

---
 tests/libqos/libqos.c | 2 ++
 tests/rtas-test.c     | 1 -
 2 files changed, 2 insertions(+), 1 deletion(-)
tests/libqos/libqos.c +2 -0
index 7abb482..6226546 100644
@@ -10,6 +10,8 @@
 /**
  * Launch QEMU with the given command line,
  * and then set up interrupts and our guest malloc interface.
+ * Never returns NULL:
+ * Terminates the application in case an error is encountered.
  */
 QOSState *qtest_vboot(QOSOps *ops, const char *cmdline_fmt, va_list ap)
 {
tests/rtas-test.c +0 -0
index ba0867a..276c87e 100644

tests/rtas-test.c static void test_rtas_get_time_of_day(void) · line 19

Quoted 7 lines
tests/rtas-test.c +0 -1
@@ -14,7 +14,6 @@ static void test_rtas_get_time_of_day(void)
     time_t t1, t2;
 
     qs = qtest_spapr_boot("-machine pseries");
-    g_assert(qs != NULL);
 
     t1 = time(NULL);
     ret = qrtas_get_time_of_day(qs->alloc, &tm, &ns);
Reviewed-by on v5 2/6
#5 lore raw

Re: [Qemu-devel] [PATCH v5 2/6] tests: don't check if qtest_spapr_boot() returns NULL

In reply to Laurent Vivier
Quoted 7 lines · On Mon, 17 Oct 2016 12:30:20 +0200 Laurent Vivier <[email protected]> wrote:

qtest_spapr_boot()/qtest_pc_boot()/qtest_boot() call qtest_vboot() and qtest_vboot() calls g_malloc(),
and g_malloc() never fails:
if memory allocation fails, the application is terminated.

---

Quoted 29 lines
 tests/libqos/libqos.c | 2 ++
 tests/rtas-test.c     | 1 -
 2 files changed, 2 insertions(+), 1 deletion(-)
tests/libqos/libqos.c +2 -0
index 7abb482..6226546 100644
@@ -10,6 +10,8 @@
 /**
  * Launch QEMU with the given command line,
  * and then set up interrupts and our guest malloc interface.
+ * Never returns NULL:
+ * Terminates the application in case an error is encountered.
  */
 QOSState *qtest_vboot(QOSOps *ops, const char *cmdline_fmt, va_list ap)
 {
tests/rtas-test.c +0 -1
index ba0867a..276c87e 100644
@@ -14,7 +14,6 @@ static void test_rtas_get_time_of_day(void)
     time_t t1, t2;
 
     qs = qtest_spapr_boot("-machine pseries");
-    g_assert(qs != NULL);
 
     t1 = time(NULL);
     ret = qrtas_get_time_of_day(qs->alloc, &tm, &ns);
#6 lore raw

PATCH v5 3/6 tests: move QVirtioBus pointer into QVirtioDevice

In reply to Laurent Vivier

This allows to not have to pass bus and device for every virtio functions.

---
 tests/libqos/virtio-mmio.c |   1 +
 tests/libqos/virtio-pci.c  |   2 +
 tests/libqos/virtio.c      |  77 +++++++++++-------------
 tests/libqos/virtio.h      |  51 +++++++---------
 tests/vhost-user-test.c    |  33 +++++-----
 tests/virtio-9p-test.c     |  15 +++--
 tests/virtio-blk-test.c    | 147 ++++++++++++++++++++-------------------------
 tests/virtio-net-test.c    |  59 +++++++++---------
 tests/virtio-scsi-test.c   |  17 +++---
 9 files changed, 185 insertions(+), 217 deletions(-)
tests/libqos/virtio-mmio.c +1 -0
index 0cab38f..bced680 100644
@@ -199,6 +199,7 @@ QVirtioMMIODevice *qvirtio_mmio_init_device(uint64_t addr, uint32_t page_size)
     dev->addr = addr;
     dev->page_size = page_size;
     dev->vdev.device_type = readl(addr + QVIRTIO_MMIO_DEVICE_ID);
+    dev->vdev.bus = &qvirtio_mmio;
 
     writel(addr + QVIRTIO_MMIO_GUEST_PAGE_SIZE, page_size);
 
tests/libqos/virtio-pci.c +2 -0
index 6e005c1..bbfed58 100644
@@ -286,6 +286,8 @@ QVirtioPCIDevice *qvirtio_pci_device_find(QPCIBus *bus, uint16_t device_type)
     QVirtioPCIDevice *dev = NULL;
     qvirtio_pci_foreach(bus, device_type, qvirtio_pci_assign_device, &dev);
 
+    dev->vdev.bus = &qvirtio_pci;
+
     return dev;
 }
 
tests/libqos/virtio.c +34 -43

162 lines not on this page · raw message

tests/libqos/virtio.h +23 -28

86 lines not on this page · raw message

tests/vhost-user-test.c +16 -17
index d7c48c5..067b5a2 100644
@@ -170,15 +170,15 @@ static void init_virtio_dev(TestServer *s)
     g_assert_nonnull(dev);
 
     qvirtio_pci_device_enable(dev);
-    qvirtio_reset(&qvirtio_pci, &dev->vdev);
-    qvirtio_set_acknowledge(&qvirtio_pci, &dev->vdev);
-    qvirtio_set_driver(&qvirtio_pci, &dev->vdev);
+    qvirtio_reset(&dev->vdev);
+    qvirtio_set_acknowledge(&dev->vdev);
+    qvirtio_set_driver(&dev->vdev);
 
-    features = qvirtio_get_features(&qvirtio_pci, &dev->vdev);
+    features = qvirtio_get_features(&dev->vdev);
     features = features & VIRTIO_NET_F_MAC;
-    qvirtio_set_features(&qvirtio_pci, &dev->vdev, features);
+    qvirtio_set_features(&dev->vdev, features);
 
-    qvirtio_set_driver_ok(&qvirtio_pci, &dev->vdev);
+    qvirtio_set_driver_ok(&dev->vdev);
 }
 
 static void wait_for_fds(TestServer *s)
@@ -840,24 +840,24 @@ static QVirtioPCIDevice *virtio_net_pci_init(QPCIBus *bus, int slot)
     g_assert_cmphex(dev->vdev.device_type, ==, VIRTIO_ID_NET);
 
     qvirtio_pci_device_enable(dev);
-    qvirtio_reset(&qvirtio_pci, &dev->vdev);
-    qvirtio_set_acknowledge(&qvirtio_pci, &dev->vdev);
-    qvirtio_set_driver(&qvirtio_pci, &dev->vdev);
+    qvirtio_reset(&dev->vdev);
+    qvirtio_set_acknowledge(&dev->vdev);
+    qvirtio_set_driver(&dev->vdev);
 
     return dev;
 }
 
-static void driver_init(const QVirtioBus *bus, QVirtioDevice *dev)
+static void driver_init(QVirtioDevice *dev)
 {
     uint32_t features;
 
-    features = qvirtio_get_features(bus, dev);
+    features = qvirtio_get_features(dev);
     features = features & ~(QVIRTIO_F_BAD_FEATURE |
                             (1u << VIRTIO_RING_F_INDIRECT_DESC) |
                             (1u << VIRTIO_RING_F_EVENT_IDX));
-    qvirtio_set_features(bus, dev, features);
+    qvirtio_set_features(dev, features);
 
-    qvirtio_set_driver_ok(bus, dev);
+    qvirtio_set_driver_ok(dev);
 }
 
 #define PCI_SLOT                0x04
@@ -889,16 +889,15 @@ static void test_multiqueue(void)
 
     alloc = pc_alloc_init();
     for (i = 0; i < queues * 2; i++) {
-        vq[i] = (QVirtQueuePCI *)qvirtqueue_setup(&qvirtio_pci, &dev->vdev,
-                                              alloc, i);
+        vq[i] = (QVirtQueuePCI *)qvirtqueue_setup(&dev->vdev, alloc, i);
     }
 
-    driver_init(&qvirtio_pci, &dev->vdev);
+    driver_init(&dev->vdev);
     wait_for_rings_started(s, queues * 2);
 
     /* End test */
     for (i = 0; i < queues * 2; i++) {
-        qvirtqueue_cleanup(&qvirtio_pci, &vq[i]->vq, alloc);
+        qvirtqueue_cleanup(dev->vdev.bus, &vq[i]->vq, alloc);
     }
     pc_alloc_uninit(alloc);
     qvirtio_pci_device_disable(dev);
tests/virtio-9p-test.c +7 -8
index e8b2196..2341622 100644
@@ -71,17 +71,17 @@ static QVirtIO9P *qvirtio_9p_pci_init(void)
     v9p->dev = (QVirtioDevice *) dev;
 
     qvirtio_pci_device_enable(dev);
-    qvirtio_reset(&qvirtio_pci, v9p->dev);
-    qvirtio_set_acknowledge(&qvirtio_pci, v9p->dev);
-    qvirtio_set_driver(&qvirtio_pci, v9p->dev);
+    qvirtio_reset(v9p->dev);
+    qvirtio_set_acknowledge(v9p->dev);
+    qvirtio_set_driver(v9p->dev);
 
-    v9p->vq = qvirtqueue_setup(&qvirtio_pci, v9p->dev, v9p->alloc, 0);
+    v9p->vq = qvirtqueue_setup(v9p->dev, v9p->alloc, 0);
     return v9p;
 }
 
 static void qvirtio_9p_pci_free(QVirtIO9P *v9p)
 {
-    qvirtqueue_cleanup(&qvirtio_pci, v9p->vq, v9p->alloc);
+    qvirtqueue_cleanup(v9p->dev->bus, v9p->vq, v9p->alloc);
     pc_alloc_uninit(v9p->alloc);
     qvirtio_pci_device_disable(container_of(v9p->dev, QVirtioPCIDevice, vdev));
     g_free(v9p->dev);
@@ -101,15 +101,14 @@ static void pci_basic_config(void)
     v9p = qvirtio_9p_pci_init();
 
     addr = ((QVirtioPCIDevice *) v9p->dev)->addr + VIRTIO_PCI_CONFIG_OFF(false);
-    tag_len = qvirtio_config_readw(&qvirtio_pci, v9p->dev,
+    tag_len = qvirtio_config_readw(v9p->dev,
                                    (uint64_t)(uintptr_t)addr);
     g_assert_cmpint(tag_len, ==, strlen(mount_tag));
     addr += sizeof(uint16_t);
 
     tag = g_malloc(tag_len);
     for (i = 0; i < tag_len; i++) {
-        tag[i] = qvirtio_config_readb(&qvirtio_pci, v9p->dev,
-                                      (uint64_t)(uintptr_t)addr + i);
+        tag[i] = qvirtio_config_readb(v9p->dev, (uint64_t)(uintptr_t)addr + i);
     }
     g_assert_cmpmem(tag, tag_len, mount_tag, tag_len);
     g_free(tag);
tests/virtio-blk-test.c +66 -81

360 lines not on this page · raw message

tests/virtio-net-test.c +28 -31

151 lines not on this page · raw message

tests/virtio-scsi-test.c +8 -9
index 94d75b1..3dbec2f 100644
@@ -58,7 +58,7 @@ static void qvirtio_scsi_pci_free(QVirtIOSCSI *vs)
     int i;
 
     for (i = 0; i < vs->num_queues + 2; i++) {
-        qvirtqueue_cleanup(&qvirtio_pci, vs->vq[i], vs->alloc);
+        qvirtqueue_cleanup(vs->dev->bus, vs->vq[i], vs->alloc);
     }
     pc_alloc_uninit(vs->alloc);
     qvirtio_pci_device_disable(container_of(vs->dev, QVirtioPCIDevice, vdev));
@@ -119,8 +119,8 @@ static uint8_t virtio_scsi_do_command(QVirtIOSCSI *vs, const uint8_t *cdb,
         qvirtqueue_add(vq, data_in_addr, data_in_len, true, false);
     }
 
-    qvirtqueue_kick(&qvirtio_pci, vs->dev, vq, free_head);
-    qvirtio_wait_queue_isr(&qvirtio_pci, vs->dev, vq, QVIRTIO_SCSI_TIMEOUT_US);
+    qvirtqueue_kick(vs->dev, vq, free_head);
+    qvirtio_wait_queue_isr(vs->dev, vq, QVIRTIO_SCSI_TIMEOUT_US);
 
     response = readb(resp_addr +
                      offsetof(struct virtio_scsi_cmd_resp, response));
@@ -155,18 +155,17 @@ static QVirtIOSCSI *qvirtio_scsi_pci_init(int slot)
     g_assert_cmphex(vs->dev->device_type, ==, VIRTIO_ID_SCSI);
 
     qvirtio_pci_device_enable(dev);
-    qvirtio_reset(&qvirtio_pci, vs->dev);
-    qvirtio_set_acknowledge(&qvirtio_pci, vs->dev);
-    qvirtio_set_driver(&qvirtio_pci, vs->dev);
+    qvirtio_reset(vs->dev);
+    qvirtio_set_acknowledge(vs->dev);
+    qvirtio_set_driver(vs->dev);
 
     addr = dev->addr + VIRTIO_PCI_CONFIG_OFF(false);
-    vs->num_queues = qvirtio_config_readl(&qvirtio_pci, vs->dev,
-                                          (uint64_t)(uintptr_t)addr);
+    vs->num_queues = qvirtio_config_readl(vs->dev, (uint64_t)(uintptr_t)addr);
 
     g_assert_cmpint(vs->num_queues, <, MAX_NUM_QUEUES);
 
     for (i = 0; i < vs->num_queues + 2; i++) {
-        vs->vq[i] = qvirtqueue_setup(&qvirtio_pci, vs->dev, vs->alloc, i);
+        vs->vq[i] = qvirtqueue_setup(vs->dev, vs->alloc, i);
     }
 
     /* Clear the POWER ON OCCURRED unit attention */
Signature · 1 line
2.7.4
Reviewed-by on v5 3/6
#7 lore raw

Re: [Qemu-devel] [PATCH v5 3/6] tests: move QVirtioBus pointer into QVirtioDevice

Quoted 4 lines · Laurent Vivier

This allows to not have to pass bus and device for every virtio functions.

Quoted 11 lines
---
 tests/libqos/virtio-mmio.c |   1 +
 tests/libqos/virtio-pci.c  |   2 +
 tests/libqos/virtio.c      |  77 +++++++++++-------------
 tests/libqos/virtio.h      |  51 +++++++---------
 tests/vhost-user-test.c    |  33 +++++-----
 tests/virtio-9p-test.c     |  15 +++--
 tests/virtio-blk-test.c    | 147 ++++++++++++++++++++-------------------------
 tests/virtio-net-test.c    |  59 +++++++++---------
 tests/virtio-scsi-test.c   |  17 +++---
 9 files changed, 185 insertions(+), 217 deletions(-)
#8 lore raw

PATCH v5 4/6 tests: rename target_big_endian() as qvirtio_is_big_endian()

In reply to Laurent Vivier

Move the definition to libqos/virtio.h as it must be used only with virtio functions.

Add a QVirtioDevice parameter as it will be needed to know if the virtio device is using virtio 1.0 specification and thus is always little-endian (to do)

---
 tests/libqos/virtio-pci.c |  2 +-
 tests/libqos/virtio.h     |  6 ++++++
 tests/libqtest.h          | 10 ----------
 tests/virtio-blk-test.c   | 36 ++++++++++++++++++------------------
 4 files changed, 25 insertions(+), 29 deletions(-)
tests/libqos/virtio-pci.c +1 -1
index bbfed58..7aa29b1 100644
@@ -86,7 +86,7 @@ static uint64_t qvirtio_pci_config_readq(QVirtioDevice *d, uint64_t addr)
     int i;
     uint64_t u64 = 0;
 
-    if (target_big_endian()) {
+    if (qvirtio_is_big_endian(d)) {
         for (i = 0; i < 8; ++i) {
             u64 |= (uint64_t)qpci_io_readb(dev->pdev,
                                 (void *)(uintptr_t)addr + i) << (7 - i) * 8;
tests/libqos/virtio.h +6 -0
index ac4669a..3397a08 100644
@@ -89,6 +89,12 @@ struct QVirtioBus {
     void (*virtqueue_kick)(QVirtioDevice *d, QVirtQueue *vq);
 };
 
+static inline bool qvirtio_is_big_endian(QVirtioDevice *d)
+{
+    /* FIXME: virtio 1.0 is always little-endian */
+    return qtest_big_endian(global_qtest);
+}
+
 static inline uint32_t qvring_size(uint32_t num, uint32_t align)
 {
     return ((sizeof(struct vring_desc) * num + sizeof(uint16_t) * (3 + num)
tests/libqtest.h +0 -10
index 4be1f77..0224f06 100644
@@ -881,16 +881,6 @@ static inline int64_t clock_set(int64_t val)
     return qtest_clock_set(global_qtest, val);
 }
 
-/**
- * target_big_endian:
- *
- * Returns: True if the architecture under test has a big endian configuration.
- */
-static inline bool target_big_endian(void)
-{
-    return qtest_big_endian(global_qtest);
-}
-
 QDict *qmp_fd_receive(int fd);
 void qmp_fd_sendv(int fd, const char *fmt, va_list ap);
 void qmp_fd_send(int fd, const char *fmt, ...);
tests/virtio-blk-test.c +18 -18
index 9a6f2cf..79e21c5 100644
@@ -117,23 +117,23 @@ static QVirtioPCIDevice *virtio_blk_pci_init(QPCIBus *bus, int slot)
     return dev;
 }
 
-static inline void virtio_blk_fix_request(QVirtioBlkReq *req)
+static inline void virtio_blk_fix_request(QVirtioDevice *d, QVirtioBlkReq *req)
 {
 #ifdef HOST_WORDS_BIGENDIAN
-    bool host_endian = true;
+    const bool host_is_big_endian = true;
 #else
-    bool host_endian = false;
+    const bool host_is_big_endian = false;
 #endif
 
-    if (target_big_endian() != host_endian) {
+    if (qvirtio_is_big_endian(d) != host_is_big_endian) {
         req->type = bswap32(req->type);
         req->ioprio = bswap32(req->ioprio);
         req->sector = bswap64(req->sector);
     }
 }
 
-static uint64_t virtio_blk_request(QGuestAllocator *alloc, QVirtioBlkReq *req,
-                                                            uint64_t data_size)
+static uint64_t virtio_blk_request(QGuestAllocator *alloc, QVirtioDevice *d,
+                                   QVirtioBlkReq *req, uint64_t data_size)
 {
     uint64_t addr;
     uint8_t status = 0xFF;
@@ -141,7 +141,7 @@ static uint64_t virtio_blk_request(QGuestAllocator *alloc, QVirtioBlkReq *req,
     g_assert_cmpuint(data_size % 512, ==, 0);
     addr = guest_alloc(alloc, sizeof(*req) + data_size);
 
-    virtio_blk_fix_request(req);
+    virtio_blk_fix_request(d, req);
 
     memwrite(addr, req, 16);
     memwrite(addr + 16, req->data, data_size);
@@ -182,7 +182,7 @@ static void test_basic(QVirtioDevice *dev, QGuestAllocator *alloc,
     req.data = g_malloc0(512);
     strcpy(req.data, "TEST");
 
-    req_addr = virtio_blk_request(alloc, &req, 512);
+    req_addr = virtio_blk_request(alloc, dev, &req, 512);
 
     g_free(req.data);
 
@@ -204,7 +204,7 @@ static void test_basic(QVirtioDevice *dev, QGuestAllocator *alloc,
     req.sector = 0;
     req.data = g_malloc0(512);
 
-    req_addr = virtio_blk_request(alloc, &req, 512);
+    req_addr = virtio_blk_request(alloc, dev, &req, 512);
 
     g_free(req.data);
 
@@ -234,7 +234,7 @@ static void test_basic(QVirtioDevice *dev, QGuestAllocator *alloc,
         req.data = g_malloc0(512);
         strcpy(req.data, "TEST");
 
-        req_addr = virtio_blk_request(alloc, &req, 512);
+        req_addr = virtio_blk_request(alloc, dev, &req, 512);
 
         g_free(req.data);
 
@@ -254,7 +254,7 @@ static void test_basic(QVirtioDevice *dev, QGuestAllocator *alloc,
         req.sector = 1;
         req.data = g_malloc0(512);
 
-        req_addr = virtio_blk_request(alloc, &req, 512);
+        req_addr = virtio_blk_request(alloc, dev, &req, 512);
 
         g_free(req.data);
 
@@ -348,7 +348,7 @@ static void pci_indirect(void)
     req.data = g_malloc0(512);
     strcpy(req.data, "TEST");
 
-    req_addr = virtio_blk_request(alloc, &req, 512);
+    req_addr = virtio_blk_request(alloc, &dev->vdev, &req, 512);
 
     g_free(req.data);
 
@@ -373,7 +373,7 @@ static void pci_indirect(void)
     req.data = g_malloc0(512);
     strcpy(req.data, "TEST");
 
-    req_addr = virtio_blk_request(alloc, &req, 512);
+    req_addr = virtio_blk_request(alloc, &dev->vdev, &req, 512);
 
     g_free(req.data);
 
@@ -495,7 +495,7 @@ static void pci_msix(void)
     req.data = g_malloc0(512);
     strcpy(req.data, "TEST");
 
-    req_addr = virtio_blk_request(alloc, &req, 512);
+    req_addr = virtio_blk_request(alloc, &dev->vdev, &req, 512);
 
     g_free(req.data);
 
@@ -518,7 +518,7 @@ static void pci_msix(void)
     req.sector = 0;
     req.data = g_malloc0(512);
 
-    req_addr = virtio_blk_request(alloc, &req, 512);
+    req_addr = virtio_blk_request(alloc, &dev->vdev, &req, 512);
 
     g_free(req.data);
 
@@ -600,7 +600,7 @@ static void pci_idx(void)
     req.data = g_malloc0(512);
     strcpy(req.data, "TEST");
 
-    req_addr = virtio_blk_request(alloc, &req, 512);
+    req_addr = virtio_blk_request(alloc, &dev->vdev, &req, 512);
 
     g_free(req.data);
 
@@ -618,7 +618,7 @@ static void pci_idx(void)
     req.data = g_malloc0(512);
     strcpy(req.data, "TEST");
 
-    req_addr = virtio_blk_request(alloc, &req, 512);
+    req_addr = virtio_blk_request(alloc, &dev->vdev, &req, 512);
 
     g_free(req.data);
 
@@ -643,7 +643,7 @@ static void pci_idx(void)
     req.sector = 1;
     req.data = g_malloc0(512);
 
-    req_addr = virtio_blk_request(alloc, &req, 512);
+    req_addr = virtio_blk_request(alloc, &dev->vdev, &req, 512);
 
     g_free(req.data);
 
Signature · 1 line
2.7.4
Reviewed-by on v5 4/6
#9 lore raw

Re: [Qemu-devel] [PATCH v5 4/6] tests: rename target_big_endian() as qvirtio_is_big_endian()

Quoted 7 lines · Laurent Vivier

Move the definition to libqos/virtio.h as it must be used only with virtio functions.

Add a QVirtioDevice parameter as it will be needed to know if the virtio device is using virtio 1.0 specification and thus is always little-endian (to do)

Quoted 9 lines
---
 tests/libqos/virtio-pci.c |  2 +-
 tests/libqos/virtio.h     |  6 ++++++
 tests/libqtest.h          | 10 ----------
 tests/virtio-blk-test.c   | 36 ++++++++++++++++++------------------
 4 files changed, 25 insertions(+), 29 deletions(-)
#10 lore raw

PATCH v5 5/6 tests: use qtest_pc_boot()/qtest_shutdown() in virtio tests

In reply to Laurent Vivier

This patch replaces calls to qtest_start() and qtest_end() by calls to qtest_pc_boot() and qtest_shutdown().

This allows to initialize memory allocator and PCI interface functions. This will ease to enable virtio tests on other architectures by only adding a specific qtest_XXX_boot() (like qtest_spapr_boot()).

---
 tests/virtio-9p-test.c   |  50 +++++++---------
 tests/virtio-blk-test.c  | 148 ++++++++++++++++++++---------------------------
 tests/virtio-net-test.c  |  39 +++++--------
 tests/virtio-scsi-test.c |  67 ++++++++++-----------
 4 files changed, 128 insertions(+), 176 deletions(-)
tests/virtio-9p-test.c +22 -28
index 2341622..851ec99 100644
@@ -10,62 +10,57 @@
 #include "qemu/osdep.h"
 #include "libqtest.h"
 #include "qemu-common.h"
-#include "libqos/pci-pc.h"
+#include "libqos/libqos-pc.h"
 #include "libqos/virtio.h"
 #include "libqos/virtio-pci.h"
-#include "libqos/malloc.h"
-#include "libqos/malloc-pc.h"
 #include "standard-headers/linux/virtio_ids.h"
 #include "standard-headers/linux/virtio_pci.h"
 
 static const char mount_tag[] = "qtest";
 static char *test_share;
 
-static void qvirtio_9p_start(void)
+
+static QOSState *qvirtio_9p_start(void)
 {
-    char *args;
+    const char *cmd = "-fsdev local,id=fsdev0,security_model=none,path=%s "
+                      "-device virtio-9p-pci,fsdev=fsdev0,mount_tag=%s";
 
     test_share = g_strdup("/tmp/qtest.XXXXXX");
     g_assert_nonnull(mkdtemp(test_share));
 
-    args = g_strdup_printf("-fsdev local,id=fsdev0,security_model=none,path=%s "
-                           "-device virtio-9p-pci,fsdev=fsdev0,mount_tag=%s",
-                           test_share, mount_tag);
-
-    qtest_start(args);
-    g_free(args);
+    return qtest_pc_boot(cmd, test_share, mount_tag);
 }
 
-static void qvirtio_9p_stop(void)
+static void qvirtio_9p_stop(QOSState *qs)
 {
-    qtest_end();
+    qtest_shutdown(qs);
     rmdir(test_share);
     g_free(test_share);
 }
 
 static void pci_nop(void)
 {
-    qvirtio_9p_start();
-    qvirtio_9p_stop();
+    QOSState *qs;
+
+    qs = qvirtio_9p_start();
+    qvirtio_9p_stop(qs);
 }
 
 typedef struct {
     QVirtioDevice *dev;
-    QGuestAllocator *alloc;
-    QPCIBus *bus;
+    QOSState *qs;
     QVirtQueue *vq;
 } QVirtIO9P;
 
-static QVirtIO9P *qvirtio_9p_pci_init(void)
+static QVirtIO9P *qvirtio_9p_pci_init(QOSState *qs)
 {
     QVirtIO9P *v9p;
     QVirtioPCIDevice *dev;
 
     v9p = g_new0(QVirtIO9P, 1);
-    v9p->alloc = pc_alloc_init();
-    v9p->bus = qpci_init_pc(NULL);
 
-    dev = qvirtio_pci_device_find(v9p->bus, VIRTIO_ID_9P);
+    v9p->qs = qs;
+    dev = qvirtio_pci_device_find(v9p->qs->pcibus, VIRTIO_ID_9P);
     g_assert_nonnull(dev);
     g_assert_cmphex(dev->vdev.device_type, ==, VIRTIO_ID_9P);
     v9p->dev = (QVirtioDevice *) dev;
@@ -75,17 +70,15 @@ static QVirtIO9P *qvirtio_9p_pci_init(void)
     qvirtio_set_acknowledge(v9p->dev);
     qvirtio_set_driver(v9p->dev);
 
-    v9p->vq = qvirtqueue_setup(v9p->dev, v9p->alloc, 0);
+    v9p->vq = qvirtqueue_setup(v9p->dev, v9p->qs->alloc, 0);
     return v9p;
 }
 
 static void qvirtio_9p_pci_free(QVirtIO9P *v9p)
 {
-    qvirtqueue_cleanup(v9p->dev->bus, v9p->vq, v9p->alloc);
-    pc_alloc_uninit(v9p->alloc);
+    qvirtqueue_cleanup(v9p->dev->bus, v9p->vq, v9p->qs->alloc);
     qvirtio_pci_device_disable(container_of(v9p->dev, QVirtioPCIDevice, vdev));
     g_free(v9p->dev);
-    qpci_free_pc(v9p->bus);
     g_free(v9p);
 }
 
@@ -96,9 +89,10 @@ static void pci_basic_config(void)
     size_t tag_len;
     char *tag;
     int i;
+    QOSState *qs;
 
-    qvirtio_9p_start();
-    v9p = qvirtio_9p_pci_init();
+    qs = qvirtio_9p_start();
+    v9p = qvirtio_9p_pci_init(qs);
 
     addr = ((QVirtioPCIDevice *) v9p->dev)->addr + VIRTIO_PCI_CONFIG_OFF(false);
     tag_len = qvirtio_config_readw(v9p->dev,
@@ -114,7 +108,7 @@ static void pci_basic_config(void)
     g_free(tag);
 
     qvirtio_9p_pci_free(v9p);
-    qvirtio_9p_stop();
+    qvirtio_9p_stop(qs);
 }
 
 int main(int argc, char **argv)
tests/virtio-blk-test.c +63 -85

387 lines not on this page · raw message

tests/virtio-net-test.c +14 -25
index 6fa385e..6bec784 100644
@@ -12,12 +12,9 @@
 #include "qemu-common.h"
 #include "qemu/sockets.h"
 #include "qemu/iov.h"
-#include "libqos/pci-pc.h"
+#include "libqos/libqos-pc.h"
 #include "libqos/virtio.h"
 #include "libqos/virtio-pci.h"
-#include "libqos/malloc.h"
-#include "libqos/malloc-pc.h"
-#include "libqos/malloc-generic.h"
 #include "qemu/bswap.h"
 #include "hw/virtio/virtio-net.h"
 #include "standard-headers/linux/virtio_ids.h"
@@ -53,16 +50,12 @@ static QVirtioPCIDevice *virtio_net_pci_init(QPCIBus *bus, int slot)
     return dev;
 }
 
-static QPCIBus *pci_test_start(int socket)
+static QOSState *pci_test_start(int socket)
 {
-    char *cmdline;
+    const char *cmd = "-netdev socket,fd=%d,id=hs0 -device "
+                      "virtio-net-pci,netdev=hs0";
 
-    cmdline = g_strdup_printf("-netdev socket,fd=%d,id=hs0 -device "
-                              "virtio-net-pci,netdev=hs0", socket);
-    qtest_start(cmdline);
-    g_free(cmdline);
-
-    return qpci_init_pc(NULL);
+    return qtest_pc_boot(cmd, socket);
 }
 
 static void driver_init(QVirtioDevice *dev)
@@ -205,9 +198,8 @@ static void stop_cont_test(QVirtioDevice *dev,
 static void pci_basic(gconstpointer data)
 {
     QVirtioPCIDevice *dev;
-    QPCIBus *bus;
+    QOSState *qs;
     QVirtQueuePCI *tx, *rx;
-    QGuestAllocator *alloc;
     void (*func) (QVirtioDevice *dev,
                   QGuestAllocator *alloc,
                   QVirtQueue *rvq,
@@ -218,26 +210,23 @@ static void pci_basic(gconstpointer data)
     ret = socketpair(PF_UNIX, SOCK_STREAM, 0, sv);
     g_assert_cmpint(ret, !=, -1);
 
-    bus = pci_test_start(sv[1]);
-    dev = virtio_net_pci_init(bus, PCI_SLOT);
+    qs = pci_test_start(sv[1]);
+    dev = virtio_net_pci_init(qs->pcibus, PCI_SLOT);
 
-    alloc = pc_alloc_init();
-    rx = (QVirtQueuePCI *)qvirtqueue_setup(&dev->vdev, alloc, 0);
-    tx = (QVirtQueuePCI *)qvirtqueue_setup(&dev->vdev, alloc, 1);
+    rx = (QVirtQueuePCI *)qvirtqueue_setup(&dev->vdev, qs->alloc, 0);
+    tx = (QVirtQueuePCI *)qvirtqueue_setup(&dev->vdev, qs->alloc, 1);
 
     driver_init(&dev->vdev);
-    func(&dev->vdev, alloc, &rx->vq, &tx->vq, sv[0]);
+    func(&dev->vdev, qs->alloc, &rx->vq, &tx->vq, sv[0]);
 
     /* End test */
     close(sv[0]);
-    qvirtqueue_cleanup(dev->vdev.bus, &tx->vq, alloc);
-    qvirtqueue_cleanup(dev->vdev.bus, &rx->vq, alloc);
-    pc_alloc_uninit(alloc);
+    qvirtqueue_cleanup(dev->vdev.bus, &tx->vq, qs->alloc);
+    qvirtqueue_cleanup(dev->vdev.bus, &rx->vq, qs->alloc);
     qvirtio_pci_device_disable(dev);
     g_free(dev->pdev);
     g_free(dev);
-    qpci_free_pc(bus);
-    test_end();
+    qtest_shutdown(qs);
 }
 #endif
 
tests/virtio-scsi-test.c +29 -38

153 lines not on this page · raw message

Signature · 1 line
2.7.4
#11 lore raw

PATCH v5 6/6 tests: enable virtio tests on SPAPR

In reply to Laurent Vivier

but disable MSI-X tests on SPAPR as we can't check the result (the memory region used on PC is not readable on SPAPR).

---
 tests/Makefile.include    |  3 ++-
 tests/libqos/virtio-pci.c | 24 ++++++++++++++++++++++--
 tests/virtio-9p-test.c    | 12 +++++++++++-
 tests/virtio-blk-test.c   | 25 ++++++++++++++++++++-----
 tests/virtio-net-test.c   | 18 ++++++++++++++++--
 tests/virtio-rng-test.c   |  7 ++++++-
 tests/virtio-scsi-test.c  | 12 +++++++++++-
 7 files changed, 88 insertions(+), 13 deletions(-)
tests/Makefile.include +2 -1
index a77777c..4480b08 100644
@@ -278,6 +278,7 @@ check-qtest-ppc64-y += tests/usb-hcd-uhci-test$(EXESUF)
 gcov-files-ppc64-y += hw/usb/hcd-uhci.c
 check-qtest-ppc64-y += tests/usb-hcd-xhci-test$(EXESUF)
 gcov-files-ppc64-y += hw/usb/hcd-xhci.c
+check-qtest-ppc64-y += $(check-qtest-virtio-y)
 
 check-qtest-sh4-y = tests/endianness-test$(EXESUF)
 
@@ -604,7 +605,7 @@ libqos-pc-obj-y += tests/libqos/ahci.o
 libqos-omap-obj-y = $(libqos-obj-y) tests/libqos/i2c-omap.o
 libqos-imx-obj-y = $(libqos-obj-y) tests/libqos/i2c-imx.o
 libqos-usb-obj-y = $(libqos-spapr-obj-y) $(libqos-pc-obj-y) tests/libqos/usb.o
-libqos-virtio-obj-y = $(libqos-pc-obj-y) tests/libqos/virtio.o tests/libqos/virtio-pci.o tests/libqos/virtio-mmio.o tests/libqos/malloc-generic.o
+libqos-virtio-obj-y = $(libqos-spapr-obj-y) $(libqos-pc-obj-y) tests/libqos/virtio.o tests/libqos/virtio-pci.o tests/libqos/virtio-mmio.o tests/libqos/malloc-generic.o
 
 tests/device-introspect-test$(EXESUF): tests/device-introspect-test.o
 tests/rtc-test$(EXESUF): tests/rtc-test.o
tests/libqos/virtio-pci.c +22 -2
index 7aa29b1..7e60b3a 100644
@@ -68,16 +68,36 @@ static uint8_t qvirtio_pci_config_readb(QVirtioDevice *d, uint64_t addr)
     return qpci_io_readb(dev->pdev, (void *)(uintptr_t)addr);
 }
 
+/* PCI is always read in little-endian order
+ * but virtio ( < 1.0) is in guest order
+ * so with a big-endian guest the order has been reversed,
+ * reverse it again
+ * virtio-1.0 is always little-endian, like PCI, but this
+ * case will be managed inside qvirtio_is_big_endian()
+ */
+
 static uint16_t qvirtio_pci_config_readw(QVirtioDevice *d, uint64_t addr)
 {
     QVirtioPCIDevice *dev = (QVirtioPCIDevice *)d;
-    return qpci_io_readw(dev->pdev, (void *)(uintptr_t)addr);
+    uint16_t value;
+
+    value = qpci_io_readw(dev->pdev, (void *)(uintptr_t)addr);
+    if (qvirtio_is_big_endian(d)) {
+        value = bswap16(value);
+    }
+    return value;
 }
 
 static uint32_t qvirtio_pci_config_readl(QVirtioDevice *d, uint64_t addr)
 {
     QVirtioPCIDevice *dev = (QVirtioPCIDevice *)d;
-    return qpci_io_readl(dev->pdev, (void *)(uintptr_t)addr);
+    uint32_t value;
+
+    value = qpci_io_readl(dev->pdev, (void *)(uintptr_t)addr);
+    if (qvirtio_is_big_endian(d)) {
+        value = bswap32(value);
+    }
+    return value;
 }
 
 static uint64_t qvirtio_pci_config_readq(QVirtioDevice *d, uint64_t addr)
tests/virtio-9p-test.c +11 -1
index 851ec99..693920a 100644
@@ -11,6 +11,7 @@
 #include "libqtest.h"
 #include "qemu-common.h"
 #include "libqos/libqos-pc.h"
+#include "libqos/libqos-spapr.h"
 #include "libqos/virtio.h"
 #include "libqos/virtio-pci.h"
 #include "standard-headers/linux/virtio_ids.h"
@@ -22,13 +23,22 @@ static char *test_share;
 
 static QOSState *qvirtio_9p_start(void)
 {
+    const char *arch = qtest_get_arch();
     const char *cmd = "-fsdev local,id=fsdev0,security_model=none,path=%s "
                       "-device virtio-9p-pci,fsdev=fsdev0,mount_tag=%s";
 
     test_share = g_strdup("/tmp/qtest.XXXXXX");
     g_assert_nonnull(mkdtemp(test_share));
 
-    return qtest_pc_boot(cmd, test_share, mount_tag);
+    if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
+        return qtest_pc_boot(cmd, test_share, mount_tag);
+    }
+    if (strcmp(arch, "ppc64") == 0) {
+        return qtest_spapr_boot(cmd, test_share, mount_tag);
+    }
+
+    g_printerr("virtio-9p tests are only available on x86 or ppc64\n");
+    exit(EXIT_FAILURE);
 }
 
 static void qvirtio_9p_stop(QOSState *qs)
tests/virtio-blk-test.c +20 -5
index 2382eb5..f737c40 100644
@@ -11,6 +11,7 @@
 #include "qemu/osdep.h"
 #include "libqtest.h"
 #include "libqos/libqos-pc.h"
+#include "libqos/libqos-spapr.h"
 #include "libqos/virtio.h"
 #include "libqos/virtio-pci.h"
 #include "libqos/virtio-mmio.h"
@@ -59,6 +60,7 @@ static char *drive_create(void)
 static QOSState *pci_test_start(void)
 {
     QOSState *qs;
+    const char *arch = qtest_get_arch();
     char *tmp_path;
     const char *cmd = "-drive if=none,id=drive0,file=%s,format=raw "
                       "-drive if=none,id=drive1,file=/dev/null,format=raw "
@@ -67,7 +69,14 @@ static QOSState *pci_test_start(void)
 
     tmp_path = drive_create();
 
-    qs = qtest_pc_boot(cmd, tmp_path, PCI_SLOT, PCI_FN);
+    if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
+        qs = qtest_pc_boot(cmd, tmp_path, PCI_SLOT, PCI_FN);
+    } else if (strcmp(arch, "ppc64") == 0) {
+        qs = qtest_spapr_boot(cmd, tmp_path, PCI_SLOT, PCI_FN);
+    } else {
+        g_printerr("virtio-blk tests are only available on x86 or ppc64\n");
+        exit(EXIT_FAILURE);
+    }
     unlink(tmp_path);
     g_free(tmp_path);
     return qs;
@@ -659,6 +668,7 @@ static void pci_hotplug(void)
 {
     QVirtioPCIDevice *dev;
     QOSState *qs;
+    const char *arch = qtest_get_arch();
 
     qs = pci_test_start();
 
@@ -672,7 +682,9 @@ static void pci_hotplug(void)
     g_free(dev);
 
     /* unplug secondary disk */
-    qpci_unplug_acpi_device_test("drv1", PCI_SLOT_HP);
+    if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
+        qpci_unplug_acpi_device_test("drv1", PCI_SLOT_HP);
+    }
     qtest_shutdown(qs);
 }
 
@@ -720,12 +732,15 @@ int main(int argc, char **argv)
 
     g_test_init(&argc, &argv, NULL);
 
-    if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
+    if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0 ||
+        strcmp(arch, "ppc64") == 0) {
         qtest_add_func("/virtio/blk/pci/basic", pci_basic);
         qtest_add_func("/virtio/blk/pci/indirect", pci_indirect);
         qtest_add_func("/virtio/blk/pci/config", pci_config);
-        qtest_add_func("/virtio/blk/pci/msix", pci_msix);
-        qtest_add_func("/virtio/blk/pci/idx", pci_idx);
+        if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
+            qtest_add_func("/virtio/blk/pci/msix", pci_msix);
+            qtest_add_func("/virtio/blk/pci/idx", pci_idx);
+        }
         qtest_add_func("/virtio/blk/pci/hotplug", pci_hotplug);
     } else if (strcmp(arch, "arm") == 0) {
         qtest_add_func("/virtio/blk/mmio/basic", mmio_basic);
tests/virtio-net-test.c +16 -2
index 6bec784..8f94360 100644
@@ -13,6 +13,7 @@
 #include "qemu/sockets.h"
 #include "qemu/iov.h"
 #include "libqos/libqos-pc.h"
+#include "libqos/libqos-spapr.h"
 #include "libqos/virtio.h"
 #include "libqos/virtio-pci.h"
 #include "qemu/bswap.h"
@@ -52,10 +53,18 @@ static QVirtioPCIDevice *virtio_net_pci_init(QPCIBus *bus, int slot)
 
 static QOSState *pci_test_start(int socket)
 {
+    const char *arch = qtest_get_arch();
     const char *cmd = "-netdev socket,fd=%d,id=hs0 -device "
                       "virtio-net-pci,netdev=hs0";
 
-    return qtest_pc_boot(cmd, socket);
+    if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
+        return qtest_pc_boot(cmd, socket);
+    }
+    if (strcmp(arch, "ppc64") == 0) {
+        return qtest_spapr_boot(cmd, socket);
+    }
+    g_printerr("virtio-net tests are only available on x86 or ppc64\n");
+    exit(EXIT_FAILURE);
 }
 
 static void driver_init(QVirtioDevice *dev)
@@ -232,10 +241,15 @@ static void pci_basic(gconstpointer data)
 
 static void hotplug(void)
 {
+    const char *arch = qtest_get_arch();
+
     qtest_start("-device virtio-net-pci");
 
     qpci_plug_device_test("virtio-net-pci", "net1", PCI_SLOT_HP, NULL);
-    qpci_unplug_acpi_device_test("net1", PCI_SLOT_HP);
+
+    if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
+        qpci_unplug_acpi_device_test("net1", PCI_SLOT_HP);
+    }
 
     test_end();
 }
tests/virtio-rng-test.c +6 -1
index e1b2640..dcecf77 100644
@@ -20,8 +20,13 @@ static void pci_nop(void)
 
 static void hotplug(void)
 {
+    const char *arch = qtest_get_arch();
+
     qpci_plug_device_test("virtio-rng-pci", "rng1", PCI_SLOT_HP, NULL);
-    qpci_unplug_acpi_device_test("rng1", PCI_SLOT_HP);
+
+    if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
+        qpci_unplug_acpi_device_test("rng1", PCI_SLOT_HP);
+    }
 }
 
 int main(int argc, char **argv)
tests/virtio-scsi-test.c +11 -1
index 7d697ab..60dc9ab 100644
@@ -12,6 +12,7 @@
 #include "libqtest.h"
 #include "block/scsi.h"
 #include "libqos/libqos-pc.h"
+#include "libqos/libqos-spapr.h"
 #include "libqos/virtio.h"
 #include "libqos/virtio-pci.h"
 #include "standard-headers/linux/virtio_ids.h"
@@ -33,11 +34,20 @@ typedef struct {
 
 static QOSState *qvirtio_scsi_start(const char *extra_opts)
 {
+    const char *arch = qtest_get_arch();
     const char *cmd = "-drive id=drv0,if=none,file=/dev/null,format=raw "
                       "-device virtio-scsi-pci,id=vs0 "
                       "-device scsi-hd,bus=vs0.0,drive=drv0 %s";
 
-    return qtest_pc_boot(cmd, extra_opts ? : "");
+    if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
+        return qtest_pc_boot(cmd, extra_opts ? : "");
+    }
+    if (strcmp(arch, "ppc64") == 0) {
+        return qtest_spapr_boot(cmd, extra_opts ? : "");
+    }
+
+    g_printerr("virtio-scsi tests are only available on x86 or ppc64\n");
+    exit(EXIT_FAILURE);
 }
 
 static void qvirtio_scsi_stop(QOSState *qs)
Signature · 1 line
2.7.4
#12 lore raw
In reply to Laurent Vivier
Quoted 4 lines · Laurent Vivier

This series enables virtio tests on SPAPR by starting machines using qtest_pc_boot() or qtest_spapr_boot() to use the good libqos PCI framework (pc or spapr).

Quoted 8 lines

It adds also some byte-swapping in virtio-pci.c as PCI is always little-endian and the endianness of the virtio device depends on the endianness of the guest.

This series does not enable virtio PCI MSI-X tests on SPAPR as this needs more work and will be the aim of another series.

Looking good to me. I've tentatively merged this to ppc-for-2.8, unless someone thinks it doesn't belong there.

Quoted 50 lines

v5:
- minor updates:
- remove declaration within the code
- update comment about qtest_vboot()
(terminates on failure)
v4:
- rebase on papr/ppc-for-2.8
- add a patch to rename target_big_endian() to qvirtio_is_big_endian()
- Add a patch to remove the QVirtioBus arguments from all virtio functions

v3:
- remove "ppc" from allowed archs for virtio-blk-test
- remove g_assert_nonnull() after g_malloc()
- add a patch to fix "vs" memory leak in virtio-scsi-test
- add a patch to remove g_assert() after qtest_spapr_boot() and update comment qtest_vboot() to explain it never returns NULL.

v2:
- update comments (virtio-1.0, log)
- move g_assert_nonnull() to qtest_boot()
- exit gracefully if the architecture is not supported
- replace qtest_pc_shutdown() by qtest_shutdown()
- move qvirtio_scsi_stop() to qvirtio_scsi_pci_free()

Laurent Vivier (6):
tests: fix memory leak in virtio-scsi-test
tests: don't check if qtest_spapr_boot() returns NULL
tests: move QVirtioBus pointer into QVirtioDevice
tests: rename target_big_endian() as qvirtio_is_big_endian()
tests: use qtest_pc_boot()/qtest_shutdown() in virtio tests
tests: enable virtio tests on SPAPR

 tests/Makefile.include     |   3 +-
 tests/libqos/libqos.c      |   2 +
 tests/libqos/virtio-mmio.c |   1 +
 tests/libqos/virtio-pci.c  |  28 +++-
 tests/libqos/virtio.c      |  77 +++++------
 tests/libqos/virtio.h      |  57 ++++----
 tests/libqtest.h           |  10 --
 tests/rtas-test.c          |   1 -
 tests/vhost-user-test.c    |  33 +++--
 tests/virtio-9p-test.c     |  69 +++++-----
 tests/virtio-blk-test.c    | 322 +++++++++++++++++++++------------------------
 tests/virtio-net-test.c    | 106 +++++++--------
 tests/virtio-rng-test.c    |   7 +-
 tests/virtio-scsi-test.c   |  91 ++++++-------
 14 files changed, 400 insertions(+), 407 deletions(-)
Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson