[PATCH v2] tests/xe_debugfs: Improve test_gt subtest

Pravalika Gurram pravalika.gurram at intel.com
Mon Jan 13 13:45:58 UTC 2025


Read the debugfs entries in the loop to improve the readability.
Added library function to check whether the debugfs is a directory or not.

Signed-off-by: Pravalika Gurram <pravalika.gurram at intel.com>
---
 lib/igt_debugfs.c        | 27 +++++++++++++
 lib/igt_debugfs.h        |  1 +
 tests/intel/xe_debugfs.c | 82 ++++++----------------------------------
 3 files changed, 40 insertions(+), 70 deletions(-)

diff --git a/lib/igt_debugfs.c b/lib/igt_debugfs.c
index f4f749e30..cd604e7c6 100644
--- a/lib/igt_debugfs.c
+++ b/lib/igt_debugfs.c
@@ -376,6 +376,33 @@ igt_debugfs_gt_open(int device, unsigned int gt, const char *filename, int mode)
 	return ret;
 }
 
+/**
+ * igt_debugfs_is_dir:
+ * @drm_fd: fd of the device
+ * @name: name of the debugfs node to check
+ * @gt: gt instance number
+ *
+ * This helps to find the debugfs file is  a directory or not
+ *
+ * Returns:
+ * true if the debugfs is a directory
+ */
+bool igt_debugfs_is_dir(int drm_fd, const char *name, int gt_id)
+{
+	char path[128];
+	struct stat st;
+
+	if (fstat(drm_fd, &st) != 0)
+		return false;
+
+	snprintf(path, sizeof(path), "/sys/kernel/debug/dri/%d/gt%d/%s",
+						minor(st.st_rdev), gt_id, name);
+	if (!stat(path, &st) && S_ISDIR(st.st_mode))
+		return true;
+
+	return false;
+}
+
 /**
  * igt_debugfs_simple_read:
  * @dir: fd of the debugfs directory
diff --git a/lib/igt_debugfs.h b/lib/igt_debugfs.h
index 3e6194ade..f4044d545 100644
--- a/lib/igt_debugfs.h
+++ b/lib/igt_debugfs.h
@@ -39,6 +39,7 @@ int igt_debugfs_connector_dir(int device, char *conn_name, int mode);
 int igt_debugfs_pipe_dir(int device, int pipe, int mode);
 
 int igt_debugfs_open(int fd, const char *filename, int mode);
+bool igt_debugfs_is_dir(int drm_fd, const char *name, int gt_id);
 bool igt_debugfs_exists(int fd, const char *filename, int mode);
 void __igt_debugfs_read(int fd, const char *filename, char *buf, int size);
 void __igt_debugfs_write(int fd, const char *filename, const char *buf, int size);
diff --git a/tests/intel/xe_debugfs.c b/tests/intel/xe_debugfs.c
index bcbb5036a..c653daae4 100644
--- a/tests/intel/xe_debugfs.c
+++ b/tests/intel/xe_debugfs.c
@@ -180,77 +180,19 @@ test_gt(int fd, int gt_id)
 //		"guc_ct_selftest"
 	};
 
-	sprintf(name, "gt%d/hw_engines", gt_id);
-	igt_assert(igt_debugfs_exists(fd, name, O_RDONLY));
-	igt_debugfs_dump(fd, name);
-
-	sprintf(name, "gt%d/sa_info", gt_id);
-	igt_assert(igt_debugfs_exists(fd, name, O_RDONLY));
-	igt_debugfs_dump(fd, name);
-
-	sprintf(name, "gt%d/steering", gt_id);
-	igt_assert(igt_debugfs_exists(fd, name, O_RDONLY));
-	igt_debugfs_dump(fd, name);
-
-	sprintf(name, "gt%d/topology", gt_id);
-	igt_assert(igt_debugfs_exists(fd, name, O_RDONLY));
-	igt_debugfs_dump(fd, name);
-
-	sprintf(name, "gt%d/pat", gt_id);
-	igt_assert(igt_debugfs_exists(fd, name, O_RDONLY));
-	igt_debugfs_dump(fd, name);
-
-	sprintf(name, "gt%d/mocs", gt_id);
-	igt_assert(igt_debugfs_exists(fd, name, O_RDONLY));
-	igt_debugfs_dump(fd, name);
-
-	sprintf(name, "gt%d/ggtt", gt_id);
-	igt_assert(igt_debugfs_exists(fd, name, O_RDONLY));
-	igt_debugfs_dump(fd, name);
-
-	sprintf(name, "gt%d/register-save-restore", gt_id);
-	igt_assert(igt_debugfs_exists(fd, name, O_RDONLY));
-	igt_debugfs_dump(fd, name);
-
-	sprintf(name, "gt%d/workarounds", gt_id);
-	igt_assert(igt_debugfs_exists(fd, name, O_RDONLY));
-	igt_debugfs_dump(fd, name);
-
-	sprintf(name, "gt%d/default_lrc_rcs", gt_id);
-	igt_assert(igt_debugfs_exists(fd, name, O_RDONLY));
-	igt_debugfs_dump(fd, name);
-
-	sprintf(name, "gt%d/default_lrc_ccs", gt_id);
-	igt_assert(igt_debugfs_exists(fd, name, O_RDONLY));
-	igt_debugfs_dump(fd, name);
-
-	sprintf(name, "gt%d/default_lrc_bcs", gt_id);
-	igt_assert(igt_debugfs_exists(fd, name, O_RDONLY));
-	igt_debugfs_dump(fd, name);
-
-	sprintf(name, "gt%d/default_lrc_vecs", gt_id);
-	igt_assert(igt_debugfs_exists(fd, name, O_RDONLY));
-	igt_debugfs_dump(fd, name);
-
-	sprintf(name, "gt%d/default_lrc_vcs", gt_id);
-	igt_assert(igt_debugfs_exists(fd, name, O_RDONLY));
-	igt_debugfs_dump(fd, name);
-
-	sprintf(name, "gt%d/hwconfig", gt_id);
-	igt_assert(igt_debugfs_exists(fd, name, O_RDONLY));
-	igt_debugfs_dump(fd, name);
-
-	sprintf(name, "gt%d/uc/guc_info", gt_id);
-	igt_assert(igt_debugfs_exists(fd, name, O_RDONLY));
-	igt_debugfs_dump(fd, name);
-
-	sprintf(name, "gt%d/uc/huc_info", gt_id);
-	igt_assert(igt_debugfs_exists(fd, name, O_RDONLY));
-	igt_debugfs_dump(fd, name);
+	for (int i = 0; i < ARRAY_SIZE(expected_files); i++) {
+		sprintf(name, "gt%d/%s", gt_id, expected_files[i]);
+		igt_assert(igt_debugfs_exists(fd, name, O_RDONLY));
+		if (igt_debugfs_is_dir(fd, expected_files[i], gt_id))
+			continue;
+		igt_debugfs_dump(fd, name);
+	}
 
-	sprintf(name, "gt%d/uc/guc_log", gt_id);
-	igt_assert(igt_debugfs_exists(fd, name, O_RDONLY));
-	igt_debugfs_dump(fd, name);
+	for (int i = 0; i < ARRAY_SIZE(expected_files_uc); i++) {
+		sprintf(name, "gt%d/uc/%s", gt_id, expected_files_uc[i]);
+		igt_assert(igt_debugfs_exists(fd, name, O_RDONLY));
+		igt_debugfs_dump(fd, name);
+	}
 
 	sprintf(name, "/gt%d", gt_id);
 	validate_entries(fd, name, expected_files, ARRAY_SIZE(expected_files));
-- 
2.34.1



More information about the igt-dev mailing list