summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Clark <robdclark@chromium.org>2021-11-13 11:57:10 -0800
committerRob Clark <robdclark@chromium.org>2021-11-29 16:32:09 -0800
commit6480970a1f7b121d39e8ea0c3d6787542664d353 (patch)
tree5ee161aece19ae825021d89b12005bae8599eb00
parent77fd5c719be64cef31dfea81c6405ced2aa7992c (diff)
lib/igt_debugfs: Add helper for detecting debugfs files
Add a helper that can be used with, for ex, igt_require() so that tests can be skipped if the kernel is too old. Signed-off-by: Rob Clark <robdclark@chromium.org> Reviewed-by: Petri Latvala <petri.latvala@intel.com>
-rw-r--r--lib/igt_debugfs.c21
-rw-r--r--lib/igt_debugfs.h1
2 files changed, 22 insertions, 0 deletions
diff --git a/lib/igt_debugfs.c b/lib/igt_debugfs.c
index dd6f2995c..7211c4102 100644
--- a/lib/igt_debugfs.c
+++ b/lib/igt_debugfs.c
@@ -308,6 +308,27 @@ int igt_debugfs_open(int device, const char *filename, int mode)
}
/**
+ * igt_debugfs_exists:
+ * @device: the drm device file fd
+ * @filename: file name
+ * @mode: mode bits as used by open()
+ *
+ * Test that the specified debugfs file exists and can be opened with the
+ * requested mode.
+ */
+bool igt_debugfs_exists(int device, const char *filename, int mode)
+{
+ int fd = igt_debugfs_open(device, filename, mode);
+
+ if (fd >= 0) {
+ close(fd);
+ return true;
+ }
+
+ return false;
+}
+
+/**
* igt_debugfs_simple_read:
* @filename: file name
* @buf: buffer where the contents will be stored, allocated by the caller
diff --git a/lib/igt_debugfs.h b/lib/igt_debugfs.h
index b48676815..37e85067b 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_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);
int igt_debugfs_simple_read(int dir, const char *filename, char *buf, int size);