[PATCH] tests/intel/xe_vm: Add BO partial mmap test

Matthew Brost matthew.brost at intel.com
Wed Aug 14 15:58:54 UTC 2024


Ensure BO partial mmap works by setting a BO to 0, partially mmap BO and
setting to a canned value, and then mmap entire BO ensure data
integrity.

Signed-off-by: Matthew Brost <matthew.brost at intel.com>
---
 tests/intel/xe_vm.c | 53 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 53 insertions(+)

diff --git a/tests/intel/xe_vm.c b/tests/intel/xe_vm.c
index c3960fedee..57534a2a8c 100644
--- a/tests/intel/xe_vm.c
+++ b/tests/intel/xe_vm.c
@@ -106,6 +106,56 @@ test_scratch(int fd)
 	xe_vm_destroy(fd, vm);
 }
 
+/**
+ * SUBTEST: bo-mmap-partial
+ * Description: Test partially mmap of a BO
+ * Functionality: BO mmap
+ * Test category: functionality test
+ */
+
+static void test_bo_mmap_partial(int fd, size_t bo_size)
+{
+#define MMAP_VALUE(idx)	((0xdeadull << 32) | idx)
+	uint32_t bo;
+	uint64_t offset;
+	uint64_t *ptr;
+	size_t partial_size = bo_size / 2;
+	void *map;
+	int i, j;
+
+	bo = xe_bo_create(fd, 0, bo_size, vram_if_possible(fd, 0),
+			  DRM_XE_GEM_CREATE_FLAG_NEEDS_VISIBLE_VRAM);
+
+	/* Set to zero */
+	map = xe_bo_map(fd, bo, bo_size);
+	memset(map, 0, bo_size);
+	munmap(map, bo_size);
+
+	/* Partial map */
+	offset = xe_bo_mmap_offset(fd, bo);
+	map = mmap(NULL, partial_size, PROT_WRITE, MAP_SHARED, fd,
+		   offset + partial_size);
+	igt_assert(map != MAP_FAILED);
+	ptr = map;
+	for (i = 0, j = partial_size / sizeof(uint64_t);
+	     j < bo_size / sizeof(uint64_t); ++i, ++j)
+		ptr[i] = MMAP_VALUE(j);
+	munmap(map, partial_size);
+
+	/* Map entire BO and check */
+	map = xe_bo_map(fd, bo, bo_size);
+	ptr = map;
+	for (i = 0; i < bo_size / sizeof(uint64_t); ++i) {
+		if (i < partial_size / sizeof(uint64_t))
+			igt_assert_eq(ptr[i], 0);
+		else
+			igt_assert_eq(ptr[i], MMAP_VALUE(i));
+	}
+	munmap(map, bo_size);
+	gem_close(fd, bo);
+#undef MMAP_VALUE
+}
+
 static void
 __test_bind_one_bo(int fd, uint32_t vm, int n_addrs, uint64_t *addrs)
 {
@@ -2354,6 +2404,9 @@ igt_main
 			}
 	}
 
+	igt_subtest("bo-mmap-partial")
+		test_bo_mmap_partial(fd, SZ_2M);
+
 	igt_subtest("bind-once")
 		test_bind_once(fd);
 
-- 
2.34.1



More information about the igt-dev mailing list