summaryrefslogtreecommitdiff
path: root/tools/testing
diff options
context:
space:
mode:
authorJosh Hilke <jrhilke@google.com>2025-08-22 21:24:52 +0000
committerAlex Williamson <alex.williamson@redhat.com>2025-08-27 12:14:02 -0600
commitb477e7bcd25ecb4da91bb52d5f980611cc77d543 (patch)
tree180ec2948ebed6b5068626f5abf9d5f7eb242960 /tools/testing
parent790588f06e9ce58c281faeada453f47361bc06b6 (diff)
vfio: selftests: Move vfio dma mapping test to their own file
Move the dma_map_unmap test from vfio_pci_device_test to a new test: vfio_dma_mapping_test. We are going to add more complex dma mapping tests, so it makes sense to separate this from the vfio pci device test which is more of a sanity check for vfio pci functionality. Signed-off-by: Josh Hilke <jrhilke@google.com> Acked-by: Shuah Khan <skhan@linuxfoundation.org> Signed-off-by: David Matlack <dmatlack@google.com> Link: https://lore.kernel.org/r/20250822212518.4156428-6-dmatlack@google.com Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
Diffstat (limited to 'tools/testing')
-rw-r--r--tools/testing/selftests/vfio/Makefile1
-rw-r--r--tools/testing/selftests/vfio/vfio_dma_mapping_test.c51
-rw-r--r--tools/testing/selftests/vfio/vfio_pci_device_test.c18
3 files changed, 52 insertions, 18 deletions
diff --git a/tools/testing/selftests/vfio/Makefile b/tools/testing/selftests/vfio/Makefile
index e4a5d6eadff3..05c5a585cca6 100644
--- a/tools/testing/selftests/vfio/Makefile
+++ b/tools/testing/selftests/vfio/Makefile
@@ -1,4 +1,5 @@
CFLAGS = $(KHDR_INCLUDES)
+TEST_GEN_PROGS += vfio_dma_mapping_test
TEST_GEN_PROGS += vfio_iommufd_setup_test
TEST_GEN_PROGS += vfio_pci_device_test
include ../lib.mk
diff --git a/tools/testing/selftests/vfio/vfio_dma_mapping_test.c b/tools/testing/selftests/vfio/vfio_dma_mapping_test.c
new file mode 100644
index 000000000000..b56cebbf97eb
--- /dev/null
+++ b/tools/testing/selftests/vfio/vfio_dma_mapping_test.c
@@ -0,0 +1,51 @@
+// SPDX-License-Identifier: GPL-2.0-only
+#include <fcntl.h>
+
+#include <sys/mman.h>
+
+#include <linux/sizes.h>
+#include <linux/vfio.h>
+
+#include <vfio_util.h>
+
+#include "../kselftest_harness.h"
+
+static const char *device_bdf;
+
+FIXTURE(vfio_dma_mapping_test) {
+ struct vfio_pci_device *device;
+};
+
+FIXTURE_SETUP(vfio_dma_mapping_test)
+{
+ self->device = vfio_pci_device_init(device_bdf, VFIO_TYPE1_IOMMU);
+}
+
+FIXTURE_TEARDOWN(vfio_dma_mapping_test)
+{
+ vfio_pci_device_cleanup(self->device);
+}
+
+TEST_F(vfio_dma_mapping_test, dma_map_unmap)
+{
+ const u64 size = SZ_2M;
+ void *mem;
+ u64 iova;
+
+ mem = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0);
+ ASSERT_NE(mem, MAP_FAILED);
+
+ iova = (u64)mem;
+
+ vfio_pci_dma_map(self->device, iova, size, mem);
+ printf("Mapped HVA %p (size 0x%lx) at IOVA 0x%lx\n", mem, size, iova);
+ vfio_pci_dma_unmap(self->device, iova, size);
+
+ ASSERT_TRUE(!munmap(mem, size));
+}
+
+int main(int argc, char *argv[])
+{
+ device_bdf = vfio_selftests_get_bdf(&argc, argv);
+ return test_harness_run(argc, argv);
+}
diff --git a/tools/testing/selftests/vfio/vfio_pci_device_test.c b/tools/testing/selftests/vfio/vfio_pci_device_test.c
index 3e7049b9c8f6..a2e41398d184 100644
--- a/tools/testing/selftests/vfio/vfio_pci_device_test.c
+++ b/tools/testing/selftests/vfio/vfio_pci_device_test.c
@@ -36,24 +36,6 @@ FIXTURE_TEARDOWN(vfio_pci_device_test)
vfio_pci_device_cleanup(self->device);
}
-TEST_F(vfio_pci_device_test, dma_map_unmap)
-{
- const u64 size = SZ_2M;
- void *mem;
- u64 iova;
-
- mem = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0);
- ASSERT_NE(mem, MAP_FAILED);
-
- iova = (u64)mem;
-
- vfio_pci_dma_map(self->device, iova, size, mem);
- printf("Mapped HVA %p (size 0x%lx) at IOVA 0x%lx\n", mem, size, iova);
- vfio_pci_dma_unmap(self->device, iova, size);
-
- ASSERT_TRUE(!munmap(mem, SZ_2M));
-}
-
#define read_pci_id_from_sysfs(_file) ({ \
char __sysfs_path[PATH_MAX]; \
char __buf[32]; \