diff mbox series

[igt,v3,2/4] lib/igt_debugfs: Add helper for detecting debugfs files

Message ID 20211116003042.439107-3-robdclark@gmail.com (mailing list archive)
State Not Applicable
Headers show
Series msm: Add tests for gpu fault handling | expand

Commit Message

Rob Clark Nov. 16, 2021, 12:30 a.m. UTC
From: Rob Clark <robdclark@chromium.org>

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>
---
 lib/igt_debugfs.c | 21 +++++++++++++++++++++
 lib/igt_debugfs.h |  1 +
 2 files changed, 22 insertions(+)

Comments

Petri Latvala Nov. 16, 2021, 4:59 a.m. UTC | #1
On Mon, Nov 15, 2021 at 04:30:40PM -0800, Rob Clark wrote:
> From: Rob Clark <robdclark@chromium.org>
> 
> 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>

> ---
>  lib/igt_debugfs.c | 21 +++++++++++++++++++++
>  lib/igt_debugfs.h |  1 +
>  2 files changed, 22 insertions(+)
> 
> diff --git a/lib/igt_debugfs.c b/lib/igt_debugfs.c
> index dd6f2995..7211c410 100644
> --- a/lib/igt_debugfs.c
> +++ b/lib/igt_debugfs.c
> @@ -307,6 +307,27 @@ int igt_debugfs_open(int device, const char *filename, int mode)
>  	return ret;
>  }
>  
> +/**
> + * 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
> diff --git a/lib/igt_debugfs.h b/lib/igt_debugfs.h
> index b4867681..37e85067 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);
> -- 
> 2.33.1
>
diff mbox series

Patch

diff --git a/lib/igt_debugfs.c b/lib/igt_debugfs.c
index dd6f2995..7211c410 100644
--- a/lib/igt_debugfs.c
+++ b/lib/igt_debugfs.c
@@ -307,6 +307,27 @@  int igt_debugfs_open(int device, const char *filename, int mode)
 	return ret;
 }
 
+/**
+ * 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
diff --git a/lib/igt_debugfs.h b/lib/igt_debugfs.h
index b4867681..37e85067 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);