[igt-dev] [PATCH i-g-t 1/5] lib/igt_sysfs: Add support to iterate over engines

priyanka.dandamudi at intel.com priyanka.dandamudi at intel.com
Sun Jun 25 11:13:12 UTC 2023


From: Priyanka Dandamudi <priyanka.dandamudi at intel.com>

It helps to test engines by iterating over sysfs/engines.

Cc: Janga Rahul Kumar <janga.rahul.kumar at intel.com>
Cc: Tejas Upadhyay <tejas.upadhyay at intel.com>
Signed-off-by: Priyanka Dandamudi <priyanka.dandamudi at intel.com>
---
 lib/igt_sysfs.c | 35 +++++++++++++++++++++++++++++++++++
 lib/igt_sysfs.h |  3 +++
 2 files changed, 38 insertions(+)

diff --git a/lib/igt_sysfs.c b/lib/igt_sysfs.c
index 35a4faa9..07a0bd1d 100644
--- a/lib/igt_sysfs.c
+++ b/lib/igt_sysfs.c
@@ -856,3 +856,38 @@ void igt_sysfs_rw_attr_verify(igt_sysfs_rw_attr_t *rw)
 	igt_assert_eq(get, prev);
 	igt_assert(!ret);
 }
+
+void igt_sysfs_engines(int xe, int engines, const char *file,
+					   void (*test)(int, int))
+{
+	struct dirent *de;
+	DIR *dir;
+
+	lseek(engines, 0, SEEK_SET);
+
+	dir = fdopendir(engines);
+	if (!dir)
+		close(engines);
+
+	while ((de = readdir(dir))) {
+		int engine;
+
+		if (*de->d_name == '.')
+			continue;
+
+		engine = openat(engines, de->d_name, O_RDONLY);
+		if (engine < 0)
+			continue;
+
+		igt_dynamic(de->d_name) {
+				if (file) {
+					struct stat st;
+
+					igt_require(fstatat(engine, file, &st, 0) == 0);
+				}
+				errno = 0;
+				test(xe, engine);
+		}
+		close(engine);
+	}
+}
diff --git a/lib/igt_sysfs.h b/lib/igt_sysfs.h
index 978b6906..c89780ac 100644
--- a/lib/igt_sysfs.h
+++ b/lib/igt_sysfs.h
@@ -147,4 +147,7 @@ typedef struct igt_sysfs_rw_attr {
 
 void igt_sysfs_rw_attr_verify(igt_sysfs_rw_attr_t *rw);
 
+void igt_sysfs_engines(int xe, int gt, const char *file,
+		       void (*test)(int, int));
+
 #endif /* __IGT_SYSFS_H__ */
-- 
2.25.1



More information about the igt-dev mailing list