Igt-dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] tests/intel/xe_vm: Add BO partial mmap test
@ 2024-08-14 15:58 Matthew Brost
  2024-08-14 16:48 ` Matthew Auld
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Matthew Brost @ 2024-08-14 15:58 UTC (permalink / raw)
  To: igt-dev

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@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


^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2024-08-15  0:44 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-14 15:58 [PATCH] tests/intel/xe_vm: Add BO partial mmap test Matthew Brost
2024-08-14 16:48 ` Matthew Auld
2024-08-14 17:00   ` Matthew Brost
2024-08-14 17:40 ` ✓ CI.xeBAT: success for " Patchwork
2024-08-14 17:51 ` ✗ Fi.CI.BAT: failure " Patchwork
2024-08-15  0:44 ` ✗ CI.xeFULL: " Patchwork

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox