public inbox for igt-dev@lists.freedesktop.org
 help / color / mirror / Atom feed
From: Dhinakaran Pandiyan <dhinakaran.pandiyan@intel.com>
To: igt-dev@lists.freedesktop.org
Cc: Dhinakaran Pandiyan <dhinakaran.pandiyan@intel.com>
Subject: [igt-dev] [CI 1/5] lib/debugfs: Function to read debugfs with the directory already open
Date: Wed,  5 Sep 2018 14:15:55 -0700	[thread overview]
Message-ID: <20180905211559.30713-1-dhinakaran.pandiyan@intel.com> (raw)

tests/kms_frontbuffer_tracking and tests/kms_psr read debugfs nodes
several times after opening the directory once. There is already an
implementation of this in the kms_frontbuffer_tracking, moving that
functionality to the library will allow us to share the code with kms_psr
and kms_fbcon_fbt

Signed-off-by: Dhinakaran Pandiyan <dhinakaran.pandiyan@intel.com>
Reviewed-by: José Roberto de Souza <jose.souza@intel.com>
---
 lib/igt_debugfs.c                | 39 ++++++++++++++++++++++++--------
 lib/igt_debugfs.h                |  3 ++-
 tests/kms_frontbuffer_tracking.c |  7 ++----
 3 files changed, 34 insertions(+), 15 deletions(-)

diff --git a/lib/igt_debugfs.c b/lib/igt_debugfs.c
index 14753a9e..baedc225 100644
--- a/lib/igt_debugfs.c
+++ b/lib/igt_debugfs.c
@@ -262,26 +262,47 @@ int igt_debugfs_open(int device, const char *filename, int mode)
 	return ret;
 }
 
+/**
+ * igt_debugfs_simple_read:
+ * @filename: file name
+ * @buf: buffer where the contents will be stored, allocated by the caller
+ * @size: size of the buffer
+ *
+ * This function is similar to __igt_debugfs_read, the difference is that it
+ * expects the debugfs directory to be open and it's descriptor passed as the
+ * first argument.
+ *
+ * Returns:
+ * -errorno on failure or bytes read on success
+ */
+int igt_debugfs_simple_read(int dir, const char *filename, char *buf, int size)
+{
+	int len;
+
+	len = igt_sysfs_read(dir, filename, buf, size - 1);
+	if (len < 0)
+		buf[0] = '\0';
+	else
+		buf[len] = '\0';
+
+	return len;
+}
+
 /**
  * __igt_debugfs_read:
  * @filename: file name
  * @buf: buffer where the contents will be stored, allocated by the caller
- * @buf_size: size of the buffer
+ * @size: size of the buffer
  *
  * This function opens the debugfs file, reads it, stores the content in the
  * provided buffer, then closes the file. Users should make sure that the buffer
  * provided is big enough to fit the whole file, plus one byte.
  */
-void __igt_debugfs_read(int fd, const char *filename, char *buf, int buf_size)
+void __igt_debugfs_read(int fd, const char *filename, char *buf, int size)
 {
-	int dir;
-	int len;
+	int dir = igt_debugfs_dir(fd);
 
-	dir = igt_debugfs_dir(fd);
-	len = igt_sysfs_read(dir, filename, buf, buf_size - 1);
-	if (len < 0)
-		len = 0;
-	buf[len] = '\0';
+	igt_debugfs_simple_read(dir, filename, buf, size);
 	close(dir);
 }
 
diff --git a/lib/igt_debugfs.h b/lib/igt_debugfs.h
index db634a82..ff8612dc 100644
--- a/lib/igt_debugfs.h
+++ b/lib/igt_debugfs.h
@@ -37,7 +37,8 @@ char *igt_debugfs_path(int device, char *path, int pathlen);
 int igt_debugfs_dir(int device);
 
 int igt_debugfs_open(int fd, const char *filename, int mode);
-void __igt_debugfs_read(int fd, const char *filename, char *buf, int buf_size);
+void __igt_debugfs_read(int fd, const char *filename, char *buf, int size);
+int igt_debugfs_simple_read(int dir, const char *filename, char *buf, int size);
 bool igt_debugfs_search(int fd, const char *filename, const char *substring);
 
 /**
diff --git a/tests/kms_frontbuffer_tracking.c b/tests/kms_frontbuffer_tracking.c
index 921aaffc..eab84926 100644
--- a/tests/kms_frontbuffer_tracking.c
+++ b/tests/kms_frontbuffer_tracking.c
@@ -720,12 +720,9 @@ static void set_mode_for_params(struct modeset_params *params)
 
 static void __debugfs_read(const char *param, char *buf, int len)
 {
-	len = igt_sysfs_read(drm.debugfs, param, buf, len - 1);
-	if (len < 0) {
+	len = igt_debugfs_simple_read(drm.debugfs, param, buf, len);
+	if (len < 0)
 		igt_assert_eq(len, -ENODEV);
-		len = 0;
-	}
-	buf[len] = '\0';
 }
 
 static int __debugfs_write(const char *param, char *buf, int len)
-- 
2.17.1

_______________________________________________
igt-dev mailing list
igt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev

             reply	other threads:[~2018-09-05 21:16 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-09-05 21:15 Dhinakaran Pandiyan [this message]
2018-09-05 21:15 ` [igt-dev] [CI 2/5] tests/psr: Avoid opening of already open debugfs dir Dhinakaran Pandiyan
2018-09-05 21:15 ` [igt-dev] [CI 3/5] tests/fbcon_fbt: Avoid opening debugfs dir repeatedly Dhinakaran Pandiyan
2018-09-05 21:15 ` [igt-dev] [CI 4/5] tests/psr: Test PSR1 in kms_psr Dhinakaran Pandiyan
2018-09-05 21:15 ` [igt-dev] [CI 5/5] tests/fbcon_fbt: Enable PSR1 via debugfs Dhinakaran Pandiyan
2018-09-05 22:58 ` [igt-dev] ✓ Fi.CI.BAT: success for series starting with [CI,1/5] lib/debugfs: Function to read debugfs with the directory already open Patchwork
2018-09-06  8:10 ` [igt-dev] ✓ Fi.CI.IGT: " Patchwork

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180905211559.30713-1-dhinakaran.pandiyan@intel.com \
    --to=dhinakaran.pandiyan@intel.com \
    --cc=igt-dev@lists.freedesktop.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox