[igt-dev] [PATCH v2 2/2] tests/vc4_mmap: Create test for VC4's Mmap BO IOCTL

Maíra Canal mcanal at igalia.com
Thu Dec 29 20:00:01 UTC 2022


Add two igt_subtests for DRM_IOCTL_VC4_MMAP_BO, which tests the possible
invalid parameters for the IOCTL and also the read/write coherency of a
newly mapped bo. Moreover, also adds a check to assure that the mmap's
offset is a multiple of the page size as returned by sysconf(_SC_PAGE_SIZE).

Reviewed-by: Melissa Wen <mwen at igalia.com>
Signed-off-by: Maíra Canal <mcanal at igalia.com>
---
 lib/igt_vc4.c             |  2 ++
 tests/vc4/meson.build     |  1 +
 tests/vc4/vc4_mmap.c      | 53 +++++++++++++++++++++++++++++++++++++++
 tests/vc4_ci/vc4.testlist |  2 ++
 4 files changed, 58 insertions(+)
 create mode 100644 tests/vc4/vc4_mmap.c

diff --git a/lib/igt_vc4.c b/lib/igt_vc4.c
index 91f7f4b5..6b6ad16c 100644
--- a/lib/igt_vc4.c
+++ b/lib/igt_vc4.c
@@ -138,6 +138,8 @@ igt_vc4_mmap_bo(int fd, uint32_t handle, uint32_t size, unsigned prot)
 
 	do_ioctl(fd, DRM_IOCTL_VC4_MMAP_BO, &mmap_bo);
 
+	igt_assert_eq(mmap_bo.offset % sysconf(_SC_PAGE_SIZE), 0);
+
 	ptr = mmap(0, size, prot, MAP_SHARED, fd, mmap_bo.offset);
 	if (ptr == MAP_FAILED)
 		return NULL;
diff --git a/tests/vc4/meson.build b/tests/vc4/meson.build
index 76e6f16c..518f6043 100644
--- a/tests/vc4/meson.build
+++ b/tests/vc4/meson.build
@@ -3,6 +3,7 @@ vc4_progs = [
 	'vc4_dmabuf_poll',
 	'vc4_label_bo',
 	'vc4_lookup_fail',
+	'vc4_mmap',
 	'vc4_perfmon',
 	'vc4_purgeable_bo',
 	'vc4_tiling',
diff --git a/tests/vc4/vc4_mmap.c b/tests/vc4/vc4_mmap.c
new file mode 100644
index 00000000..8094f4a2
--- /dev/null
+++ b/tests/vc4/vc4_mmap.c
@@ -0,0 +1,53 @@
+// SPDX-License-Identifier: MIT
+/*
+ * Copyright © 2022 Igalia S.L.
+ */
+
+#include "igt.h"
+#include "igt_vc4.h"
+
+IGT_TEST_DESCRIPTION("Tests for the VC4's mmap IOCTL");
+
+igt_main
+{
+	int fd;
+
+	igt_fixture {
+		fd = drm_open_driver(DRIVER_VC4);
+		igt_require(igt_vc4_is_v3d(fd));
+	}
+
+	igt_describe("Make sure an invalid BO cannot be mapped.");
+	igt_subtest("mmap-bad-handle") {
+		struct drm_vc4_mmap_bo get = {
+			.handle = 0xd0d0d0d0,
+		};
+		do_ioctl_err(fd, DRM_IOCTL_VC4_MMAP_BO, &get, EINVAL);
+	}
+
+	igt_describe("Test basics of newly mapped bo like default content, write and read "
+		     "coherency, mapping existence after gem_close and unmapping.");
+	igt_subtest("mmap-bo") {
+		int handle = igt_vc4_create_bo(fd, PAGE_SIZE);
+		uint32_t *map = igt_vc4_mmap_bo(fd, handle, PAGE_SIZE, PROT_READ | PROT_WRITE);
+		uint8_t expected[PAGE_SIZE];
+
+		/* Testing contents of newly created objects. */
+		memset(expected, 0, sizeof(expected));
+		igt_assert_eq(memcmp(map, expected, sizeof(expected)), 0);
+
+		memset(map, 0xd0, PAGE_SIZE);
+		memset(expected, 0xd0, PAGE_SIZE);
+		igt_assert_eq(memcmp(expected, map, sizeof(expected)), 0);
+
+		/* Testing that mapping stays after close */
+		gem_close(fd, handle);
+		igt_assert_eq(memcmp(expected, map, sizeof(expected)), 0);
+
+		/* Testing unmapping */
+		munmap(map, PAGE_SIZE);
+	}
+
+	igt_fixture
+		close(fd);
+}
diff --git a/tests/vc4_ci/vc4.testlist b/tests/vc4_ci/vc4.testlist
index 1b41538e..889d0035 100644
--- a/tests/vc4_ci/vc4.testlist
+++ b/tests/vc4_ci/vc4.testlist
@@ -8,6 +8,8 @@ igt at vc4/vc4_label_bo at set-bad-handle
 igt at vc4/vc4_label_bo at set-bad-name
 igt at vc4/vc4_label_bo at set-kernel-name
 igt at vc4/vc4_lookup_fail at bad-color-write
+igt at vc4/vc4_mmap at mmap-bad-handle
+igt at vc4/vc4_mmap at mmap-bo
 igt at vc4/vc4_perfmon at create-perfmon-0
 igt at vc4/vc4_perfmon at create-perfmon-exceed
 igt at vc4/vc4_perfmon at create-perfmon-invalid-events
-- 
2.38.1



More information about the igt-dev mailing list