Skip to contentSkip to conversation

tests: qtest: Add virtio-iommu test

PATCH Superseded Eric Auger 2 participants 2 messages Oct 19, 2021 – Oct 22, 2021 Arm/Amlogic Meson SoC support

v4 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Eric Auger

author
#0 lore raw

PATCH v4 1/1 tests: qtest: Add virtio-iommu test

Add the framework to test the virtio-iommu-pci device and tests exercising the attach/detach, map/unmap API.

---

This applies on top of jean-Philippe's
[PATCH v4 00/11] virtio-iommu: Add ACPI support
branch can be found at:
https://github.com/eauger/qemu.git
branch qtest-virtio-iommu-v4

To run the tests:
make tests/qtest/qos-test
cd build
QTEST_QEMU_STORAGE_DAEMON_BINARY=./storage-daemon/qemu-storage-daemon QTEST_QEMU_BINARY=x86_64-softmmu/qemu-system-x86_64 tests/qtest/qos-test

v3 -> v4:
- removed the virtio-iommu-device graph pieces thus fix arm make check execution
- s/end-point/endpoint
- initialize struct virtio_iommu_req_attach struct
- add cpu_to_lexx
- test overlapping map requests
- comment fixes
- check send_map returned value()
- introduce read_tail_status()
- remove Thomas' A-b due to code changes

v2 -> v3:
- s/memread/qtest_memread
- s/char buffer[64]/struct virtio_iommu_req_tail buffer
- added Thomas' A-b

v1 -> v2:
- fix the license info (Thomas)
- use UINT64_MAX (Philippe)

---
 tests/qtest/libqos/meson.build    |   1 +
 tests/qtest/libqos/virtio-iommu.c | 126 ++++++++++++
 tests/qtest/libqos/virtio-iommu.h |  40 ++++
 tests/qtest/meson.build           |   1 +
 tests/qtest/virtio-iommu-test.c   | 327 ++++++++++++++++++++++++++++++
 5 files changed, 495 insertions(+)
 create mode 100644 tests/qtest/libqos/virtio-iommu.c
 create mode 100644 tests/qtest/libqos/virtio-iommu.h
 create mode 100644 tests/qtest/virtio-iommu-test.c
tests/qtest/libqos/meson.build +1 -0
index 1f5c8f1053..ba90bbe2b8 100644
@@ -40,6 +40,7 @@ libqos_srcs = files('../libqtest.c',
         'virtio-rng.c',
         'virtio-scsi.c',
         'virtio-serial.c',
+        'virtio-iommu.c',
 
         # qgraph machines:
         'aarch64-xlnx-zcu102-machine.c',
tests/qtest/libqos/virtio-iommu.c new file +126 -0

126 lines not on this page · raw message

tests/qtest/libqos/virtio-iommu.h new file +40 -0
new file mode 100644
index 0000000000..d753761958
@@ -0,0 +1,40 @@
+/*
+ * libqos driver virtio-iommu-pci framework
+ *
+ * Copyright (c) 2021 Red Hat, Inc.
+ *
+ * Authors:
+ *  Eric Auger <[email protected]>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or (at your
+ * option) any later version.  See the COPYING file in the top-level directory.
+ *
+ */
+
+#ifndef TESTS_LIBQOS_VIRTIO_IOMMU_H
+#define TESTS_LIBQOS_VIRTIO_IOMMU_H
+
+#include "qgraph.h"
+#include "virtio.h"
+#include "virtio-pci.h"
+
+typedef struct QVirtioIOMMU QVirtioIOMMU;
+typedef struct QVirtioIOMMUPCI QVirtioIOMMUPCI;
+typedef struct QVirtioIOMMUDevice QVirtioIOMMUDevice;
+
+struct QVirtioIOMMU {
+    QVirtioDevice *vdev;
+    QVirtQueue *vq;
+};
+
+struct QVirtioIOMMUPCI {
+    QVirtioPCIDevice pci_vdev;
+    QVirtioIOMMU iommu;
+};
+
+struct QVirtioIOMMUDevice {
+    QOSGraphObject obj;
+    QVirtioIOMMU iommu;
+};
+
+#endif
tests/qtest/meson.build +1 -0
index c9d8458062..982ffb3e38 100644
@@ -230,6 +230,7 @@ qos_test_ss.add(
   'virtio-rng-test.c',
   'virtio-scsi-test.c',
   'virtio-serial-test.c',
+  'virtio-iommu-test.c',
   'vmxnet3-test.c',
 )
 if have_virtfs
tests/qtest/virtio-iommu-test.c new file +327 -0

327 lines not on this page · raw message

Signature · 1 line
2.26.3
Tested-by Reviewed-by on v4 1/1
#1 lore raw

tests/qtest/virtio-iommu-test.c line 34

Quoted 9 lines · Eric Auger
tests/qtest/virtio-iommu-test.c new file +9 -0
+static void pci_config(void *obj, void *data, QGuestAllocator *t_alloc)
+{
+    QVirtioIOMMU *v_iommu = obj;
+    QVirtioDevice *dev = v_iommu->vdev;
+    uint64_t input_range_start = qvirtio_config_readq(dev, 8);
+    uint64_t input_range_end = qvirtio_config_readq(dev, 16);
+    uint32_t domain_range_start = qvirtio_config_readl(dev, 24);
+    uint32_t domain_range_end = qvirtio_config_readl(dev, 28);
+    printf("%s  domain_range_end = %d\n", __func__, domain_range_end);

Looks like a debug leftover

Quoted 6 lines
tests/qtest/virtio-iommu-test.c new file +6 -0
+
+    g_assert_cmpint(input_range_start, ==, 0);
+    g_assert_cmphex(input_range_end, ==, UINT64_MAX);
+    g_assert_cmpint(domain_range_start, ==, 0);
+    g_assert_cmpint(domain_range_end, ==, 32);
+}

[...]

Quoted 1 line

+/* Test unmap scenari documented in the spec v0.12 */

Comment seems in the wrong place (also v0.12 was just to keep track during development)

Apart from that it looks good to me. The mappings should normally be aligned on the page granule, but as the device doesn't do alignment checks the tests are not incorrect. I'll update them when adding the alignment checks.

With the printf removed: