[PATCH i-g-t v2 25/66] tests/xe_eudebug: Add basic-vm-bind-metadata-discovery

Christoph Manszewski christoph.manszewski at intel.com
Tue Jul 30 11:44:42 UTC 2024


From: Maciej Patelczyk <maciej.patelczyk at intel.com>

Added VM BIND Discovery type test that shall detect attached metadata.

Signed-off-by: Maciej Patelczyk <maciej.patelczyk at intel.com>
Cc: Dominik Grzegorzek <dominik.grzegorzek at intel.com>
---
 tests/intel/xe_eudebug.c | 89 +++++++++++++++++++++++++++++-----------
 1 file changed, 64 insertions(+), 25 deletions(-)

diff --git a/tests/intel/xe_eudebug.c b/tests/intel/xe_eudebug.c
index 3edb2bc99..d4036ba05 100644
--- a/tests/intel/xe_eudebug.c
+++ b/tests/intel/xe_eudebug.c
@@ -55,18 +55,67 @@ static void test_sysfs_toggle(int fd)
 #define VM_BIND_VM_DESTROY (1 << 3)
 #define VM_BIND_EXTENDED (1 << 4)
 #define VM_METADATA (1 << 5)
+#define VM_BIND_METADATA (1 << 6)
 #define TEST_DISCOVERY (1 << 31)
 
+#define PAGE_SIZE 4096
+static struct drm_xe_vm_bind_op_ext_attach_debug *
+basic_vm_bind_metadata_ext_prepare(int fd, struct xe_eudebug_client *c,
+				   uint8_t **data, uint32_t data_size)
+{
+	struct drm_xe_vm_bind_op_ext_attach_debug *ext;
+	int i;
+
+	*data = calloc(data_size, sizeof(*data));
+	igt_assert(*data);
+
+	for (i = 0; i < data_size; i++)
+		(*data)[i] = 0xff & (i + (i > PAGE_SIZE));
+
+
+	ext = calloc(WORK_IN_PROGRESS_DRM_XE_DEBUG_METADATA_NUM, sizeof(*ext));
+	igt_assert(ext);
+
+	for (i = 0; i < WORK_IN_PROGRESS_DRM_XE_DEBUG_METADATA_NUM; i++) {
+		ext[i].base.name = XE_VM_BIND_OP_EXTENSIONS_ATTACH_DEBUG;
+		ext[i].metadata_id = xe_eudebug_client_metadata_create(c, fd, i,
+								       (i + 1) * PAGE_SIZE, *data);
+		ext[i].cookie = i;
+
+		if (i < WORK_IN_PROGRESS_DRM_XE_DEBUG_METADATA_NUM - 1)
+			ext[i].base.next_extension = to_user_pointer(&ext[i+1]);
+	}
+	return ext;
+}
+
+static void basic_vm_bind_metadata_ext_del(int fd, struct xe_eudebug_client *c,
+					   struct drm_xe_vm_bind_op_ext_attach_debug *ext,
+					   uint8_t *data)
+{
+	for (int i = 0; i < WORK_IN_PROGRESS_DRM_XE_DEBUG_METADATA_NUM; i++)
+		xe_eudebug_client_metadata_destroy(c, fd, ext[i].metadata_id,
+							   i, (i + 1) * PAGE_SIZE);
+	free(ext);
+	free(data);
+}
+
 static void basic_vm_bind_client(int fd, struct xe_eudebug_client *c)
 {
+	struct drm_xe_vm_bind_op_ext_attach_debug *ext = NULL;
 	uint32_t vm = xe_eudebug_client_vm_create(c, fd, 0, 0);
 	size_t bo_size = xe_get_default_alignment(fd);
 	bool test_discovery = c->flags & TEST_DISCOVERY;
+	bool test_metadata = c->flags & VM_BIND_METADATA;
 	uint32_t bo = xe_bo_create(fd, 0, bo_size,
 				   system_memory(fd), 0);
 	uint64_t addr = 0x1a0000;
+	uint8_t *data = NULL;
+
+	if (test_metadata)
+		ext = basic_vm_bind_metadata_ext_prepare(fd, c, &data, PAGE_SIZE);
 
-	xe_eudebug_client_vm_bind(c, fd, vm, bo, 0, addr, bo_size);
+	xe_eudebug_client_vm_bind_flags(c, fd, vm, bo, 0, addr,
+					bo_size, 0, NULL, 0, to_user_pointer(ext));
 
 	if (test_discovery) {
 		xe_eudebug_client_signal_stage(c, STAGE_PRE_DEBUG_RESOURCES_DONE);
@@ -75,6 +124,9 @@ static void basic_vm_bind_client(int fd, struct xe_eudebug_client *c)
 
 	xe_eudebug_client_vm_unbind(c, fd, vm, 0, addr, bo_size);
 
+	if (test_metadata)
+		basic_vm_bind_metadata_ext_del(fd, c, ext, data);
+
 	gem_close(fd, bo);
 	xe_eudebug_client_vm_destroy(c, fd, vm);
 }
@@ -367,7 +419,7 @@ static void run_basic_client(struct xe_eudebug_client *c)
 		xe_eudebug_client_vm_destroy(c, fd,  vm);
 	}
 
-	if (c->flags & VM_BIND)
+	if (c->flags & VM_BIND || c->flags & VM_BIND_METADATA)
 		basic_vm_bind_client(fd, c);
 
 	if (c->flags & VM_BIND_EXTENDED)
@@ -646,6 +698,11 @@ static void test_basic_sessions(int fd, unsigned int flags, int count, bool matc
  *	Attach the debugger to a process that performs vm-bind before attaching
  *	and check if the discovery process reports it.
  *
+ * SUBTEST: basic-vm-bind-metadata-discovery
+ * Description:
+ *	Attach the debugger to a process that performs vm-bind with metadata attached
+ *	before attaching and check if the discovery process reports it.
+ *
  * SUBTEST: basic-vm-bind-vm-destroy-discovery
  * Description:
  *	Attach the debugger to a process that performs vm bind, and destroys
@@ -1129,24 +1186,7 @@ static void metadata_access_client(struct xe_eudebug_client *c)
 	vm = xe_eudebug_client_vm_create(c, fd, 0, 0);
 	bo = xe_bo_create(fd, vm, bo_size, system_memory(fd), 0);
 
-	data = calloc(MDATA_SIZE, sizeof(*data));
-	igt_assert(data);
-
-	for (i = 0; i < MDATA_SIZE; i++)
-		data[i] = 0xff & (i + (i > PAGE_SIZE));
-
-	ext = calloc(WORK_IN_PROGRESS_DRM_XE_DEBUG_METADATA_SIP_AREA + 1, sizeof(*ext));
-	igt_assert(ext);
-
-	for (i = 0; i < WORK_IN_PROGRESS_DRM_XE_DEBUG_METADATA_SIP_AREA + 1; i++) {
-		ext[i].base.name = XE_VM_BIND_OP_EXTENSIONS_ATTACH_DEBUG;
-		ext[i].metadata_id = xe_eudebug_client_metadata_create(c, fd, i,
-								       (i + 1) * PAGE_SIZE, data);
-		ext[i].cookie = i;
-
-		if (i < WORK_IN_PROGRESS_DRM_XE_DEBUG_METADATA_SIP_AREA)
-			ext[i].base.next_extension = to_user_pointer(&ext[i+1]);
-	}
+	ext = basic_vm_bind_metadata_ext_prepare(fd, c, &data, MDATA_SIZE);
 
 	xe_eudebug_client_vm_bind_flags(c, fd, vm, bo, 0, addr,
 					bo_size, 0, NULL, 0, to_user_pointer(ext));
@@ -1156,17 +1196,13 @@ static void metadata_access_client(struct xe_eudebug_client *c)
 
 	xe_eudebug_client_vm_unbind(c, fd, vm, 0, addr, bo_size);
 
-	for (i = 0; i < WORK_IN_PROGRESS_DRM_XE_DEBUG_METADATA_SIP_AREA + 1; i++)
-		xe_eudebug_client_metadata_destroy(c, fd, ext[i].metadata_id, i, (i + 1) * PAGE_SIZE);
+	basic_vm_bind_metadata_ext_del(fd, c, ext, data);
 
 	close(bo);
 	xe_eudebug_client_vm_destroy(c, fd, vm);
 
 	xe_device_put(fd);
 	xe_eudebug_client_close_driver(c, fd);
-
-	free(data);
-	free(ext);
 }
 
 static void debugger_test_metadata(struct xe_eudebug_debugger *d,
@@ -1311,6 +1347,9 @@ igt_main
 	igt_subtest("basic-vm-bind-discovery")
 		test_basic_discovery(fd, VM_BIND, true);
 
+	igt_subtest("basic-vm-bind-metadata-discovery")
+		test_basic_discovery(fd, VM_BIND_METADATA, true);
+
 	igt_subtest("basic-vm-bind-vm-destroy")
 		test_basic_sessions(fd, VM_BIND_VM_DESTROY, 1, false);
 
-- 
2.34.1



More information about the igt-dev mailing list