[igt-dev] [PATCH igt v3 2/4] lib/igt_debugfs: Add helper for detecting debugfs files
Petri Latvala
petri.latvala at intel.com
Tue Nov 16 04:59:46 UTC 2021
On Mon, Nov 15, 2021 at 04:30:40PM -0800, Rob Clark wrote:
> From: Rob Clark <robdclark at 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 at chromium.org>
Reviewed-by: Petri Latvala <petri.latvala at 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
>
More information about the igt-dev
mailing list