From 995f2738adece4f7423f9ce9ac34ab0477844840 Mon Sep 17 00:00:00 2001 From: Paulo Zanoni Date: Mon, 13 Jul 2015 14:04:25 -0300 Subject: lib: add igt_debugfs_read() A helpful function for when you want to read a whole debugfs file to a string and don't want to worry about opening and closing file descriptors and asserting buffer sizes. We've been using this already for kms_frontbuffer_tracking and kms_fbcon_fbt, so the only test with new code here is kms_fbc_crc. Also notice that for kms_fbc_crc we had to increase the buffer size since the file can sometimes be bigger than 64 bytes - depending on the reason why FBC is disabled. Of course, there are probably many other programs we can patch, but I'm not doing this now. v2: Add the macro to wrap sizeof() (Daniel). v3: Add documentation for the macro too (Daniel). Signed-off-by: Paulo Zanoni --- tests/kms_fbcon_fbt.c | 25 ++++--------------------- 1 file changed, 4 insertions(+), 21 deletions(-) (limited to 'tests/kms_fbcon_fbt.c') diff --git a/tests/kms_fbcon_fbt.c b/tests/kms_fbcon_fbt.c index f0750145..7a494708 100644 --- a/tests/kms_fbcon_fbt.c +++ b/tests/kms_fbcon_fbt.c @@ -86,28 +86,11 @@ static void teardown_drm(struct drm_info *drm) igt_assert(close(drm->fd) == 0); } -static void debugfs_read(const char *filename, char *buf, int buf_size) -{ - FILE *file; - size_t n_read; - - file = igt_debugfs_fopen(filename, "r"); - igt_assert(file); - - n_read = fread(buf, 1, buf_size - 1, file); - igt_assert(n_read > 0); - igt_assert(feof(file)); - - buf[n_read] = '\0'; - - igt_assert(fclose(file) == 0); -} - static bool fbc_supported_on_chipset(void) { char buf[128]; - debugfs_read("i915_fbc_status", buf, ARRAY_SIZE(buf)); + igt_debugfs_read("i915_fbc_status", buf); return !strstr(buf, "FBC unsupported on this chipset\n"); } @@ -120,7 +103,7 @@ static bool fbc_is_enabled(void) { char buf[128]; - debugfs_read("i915_fbc_status", buf, ARRAY_SIZE(buf)); + igt_debugfs_read("i915_fbc_status", buf); return strstr(buf, "FBC enabled\n"); } @@ -172,7 +155,7 @@ static bool psr_supported_on_chipset(void) { char buf[256]; - debugfs_read("i915_edp_psr_status", buf, ARRAY_SIZE(buf)); + igt_debugfs_read("i915_edp_psr_status", buf); return strstr(buf, "Sink_Support: yes\n"); } @@ -185,7 +168,7 @@ static bool psr_is_enabled(void) { char buf[256]; - debugfs_read("i915_edp_psr_status", buf, ARRAY_SIZE(buf)); + igt_debugfs_read("i915_edp_psr_status", buf); return strstr(buf, "\nActive: yes\n"); } -- cgit v1.2.3