From patchwork Tue Jul 21 17:08:23 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paulo Zanoni X-Patchwork-Id: 6837241 Return-Path: X-Original-To: patchwork-intel-gfx@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 8AB83C05AC for ; Tue, 21 Jul 2015 17:09:14 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 488AD20483 for ; Tue, 21 Jul 2015 17:09:13 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id E529B2044B for ; Tue, 21 Jul 2015 17:09:11 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 98FA26E23B; Tue, 21 Jul 2015 10:09:10 -0700 (PDT) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mail-qk0-f172.google.com (mail-qk0-f172.google.com [209.85.220.172]) by gabe.freedesktop.org (Postfix) with ESMTPS id 635FE6E23B for ; Tue, 21 Jul 2015 10:09:09 -0700 (PDT) Received: by qkfc129 with SMTP id c129so94314902qkf.1 for ; Tue, 21 Jul 2015 10:09:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=vSF2e9EAy7834Ot7ApOEp5vn8mrQTPynRXLGThRgUlY=; b=Ba9lE0g6ZsxEmen0VfuKNlYpmAHPHqGtpWRJIapV7TbmLisL2fpkWF6pYGgHHE4Lr4 JLVOn4M4ntlvcB4J4fhQhfsz4GKVM4gXW3i3xe1gvHxGIRFxQFDnlaSX0q1ukBZwrS2u WDgm7+htNhesZ6Z/oq6bD9TrOVu+Y5aKC78rKBvzu8ccPJHwMDDTn8u3mATwTyCecese IEmJbjO8S9KS6wXw8RMzFstEBXjLdCjt5Bhs4FpBFRqLcpIUKtzE6VS7YdkzL/wVsCf2 UFF33V1k7EUhd5mN52RXLExkzH8c8Di8UNooMr/VjRUxWxBkd9NKqVUySa7YMX/aOy0v NpGg== X-Received: by 10.140.149.76 with SMTP id 73mr52108489qhv.94.1437498548534; Tue, 21 Jul 2015 10:09:08 -0700 (PDT) Received: from localhost.localdomain (r130-pw-tresbarras.ibys.com.br. [189.76.1.243]) by smtp.gmail.com with ESMTPSA id a65sm13066172qkh.43.2015.07.21.10.09.07 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 21 Jul 2015 10:09:07 -0700 (PDT) From: Paulo Zanoni To: intel-gfx@lists.freedesktop.org Date: Tue, 21 Jul 2015 14:08:23 -0300 Message-Id: <1437498503-24646-1-git-send-email-przanoni@gmail.com> X-Mailer: git-send-email 2.1.4 Cc: Paulo Zanoni Subject: [Intel-gfx] [PATCH igt] lib: add igt_debugfs_read() X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Spam-Status: No, score=-5.3 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Paulo Zanoni 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. Signed-off-by: Paulo Zanoni --- lib/igt_debugfs.c | 27 +++++++++++++++++++++++++++ lib/igt_debugfs.h | 1 + tests/kms_fbc_crc.c | 18 ++++-------------- tests/kms_fbcon_fbt.c | 25 ++++--------------------- tests/kms_frontbuffer_tracking.c | 33 ++++++++------------------------- 5 files changed, 44 insertions(+), 60 deletions(-) diff --git a/lib/igt_debugfs.c b/lib/igt_debugfs.c index a2c6fe2..bc1bb05 100644 --- a/lib/igt_debugfs.c +++ b/lib/igt_debugfs.c @@ -185,6 +185,33 @@ FILE *igt_debugfs_fopen(const char *filename, return fopen(buf, mode); } +/** + * igt_debugfs_read: + * @filename: file name + * @buf: buffer where the contents will be stored, allocated by the caller + * @buf_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(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); +} + /* * Pipe CRC */ diff --git a/lib/igt_debugfs.h b/lib/igt_debugfs.h index ece7148..a0bb75e 100644 --- a/lib/igt_debugfs.h +++ b/lib/igt_debugfs.h @@ -34,6 +34,7 @@ enum pipe; int igt_debugfs_open(const char *filename, int mode); FILE *igt_debugfs_fopen(const char *filename, const char *mode); +void igt_debugfs_read(const char *filename, char *buf, int buf_size); /* * Pipe CRC diff --git a/tests/kms_fbc_crc.c b/tests/kms_fbc_crc.c index f2a86a6..28cc165 100644 --- a/tests/kms_fbc_crc.c +++ b/tests/kms_fbc_crc.c @@ -215,14 +215,9 @@ static void fill_mmap_gtt(data_t *data, uint32_t handle, unsigned char color) static bool fbc_enabled(data_t *data) { - FILE *status; - char str[64] = {}; + char str[128] = {}; - status = igt_debugfs_fopen("i915_fbc_status", "r"); - igt_assert(status); - - igt_assert(fread(str, 1, sizeof(str) - 1, status) > 0); - fclose(status); + igt_debugfs_read("i915_fbc_status", str, sizeof(str)); return strstr(str, "FBC enabled") != NULL; } @@ -544,8 +539,7 @@ igt_main igt_skip_on_simulation(); igt_fixture { - char buf[64]; - FILE *status; + char buf[128]; data.drm_fd = drm_open_any_master(); kmstest_set_vt_graphics_mode(); @@ -554,11 +548,7 @@ igt_main igt_require_pipe_crc(); - status = igt_debugfs_fopen("i915_fbc_status", "r"); - igt_require_f(status, "No i915_fbc_status found\n"); - igt_assert_lt(0, fread(buf, 1, sizeof(buf), status)); - fclose(status); - buf[sizeof(buf) - 1] = '\0'; + igt_debugfs_read("i915_fbc_status", buf, sizeof(buf)); igt_require_f(!strstr(buf, "unsupported on this chipset"), "FBC not supported\n"); diff --git a/tests/kms_fbcon_fbt.c b/tests/kms_fbcon_fbt.c index f075014..c201fde 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, ARRAY_SIZE(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, ARRAY_SIZE(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, ARRAY_SIZE(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, ARRAY_SIZE(buf)); return strstr(buf, "\nActive: yes\n"); } diff --git a/tests/kms_frontbuffer_tracking.c b/tests/kms_frontbuffer_tracking.c index e9be045..e162e91 100644 --- a/tests/kms_frontbuffer_tracking.c +++ b/tests/kms_frontbuffer_tracking.c @@ -556,28 +556,11 @@ static bool set_mode_for_params(struct modeset_params *params) return (rc == 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_is_enabled(void) { char buf[128]; - debugfs_read("i915_fbc_status", buf, ARRAY_SIZE(buf)); + igt_debugfs_read("i915_fbc_status", buf, ARRAY_SIZE(buf)); return strstr(buf, "FBC enabled\n"); } @@ -585,7 +568,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, ARRAY_SIZE(buf)); return (strstr(buf, "\nActive: yes\n")); } @@ -596,7 +579,7 @@ static struct timespec fbc_get_last_action(void) char *action; ssize_t n_read; - debugfs_read("i915_fbc_status", buf, ARRAY_SIZE(buf)); + igt_debugfs_read("i915_fbc_status", buf, ARRAY_SIZE(buf)); action = strstr(buf, "\nLast action:"); igt_assert(action); @@ -645,7 +628,7 @@ static void fbc_setup_last_action(void) char buf[128]; char *action; - debugfs_read("i915_fbc_status", buf, ARRAY_SIZE(buf)); + igt_debugfs_read("i915_fbc_status", buf, ARRAY_SIZE(buf)); action = strstr(buf, "\nLast action:"); if (!action) { @@ -664,7 +647,7 @@ static bool fbc_is_compressing(void) { char buf[128]; - debugfs_read("i915_fbc_status", buf, ARRAY_SIZE(buf)); + igt_debugfs_read("i915_fbc_status", buf, ARRAY_SIZE(buf)); return strstr(buf, "\nCompressing: yes\n") != NULL; } @@ -677,7 +660,7 @@ static void fbc_setup_compressing(void) { char buf[128]; - debugfs_read("i915_fbc_status", buf, ARRAY_SIZE(buf)); + igt_debugfs_read("i915_fbc_status", buf, ARRAY_SIZE(buf)); if (strstr(buf, "\nCompressing:")) fbc.supports_compressing = true; @@ -1187,7 +1170,7 @@ 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, ARRAY_SIZE(buf)); return !strstr(buf, "FBC unsupported on this chipset\n"); } @@ -1211,7 +1194,7 @@ static bool psr_sink_has_support(void) { char buf[256]; - debugfs_read("i915_edp_psr_status", buf, ARRAY_SIZE(buf)); + igt_debugfs_read("i915_edp_psr_status", buf, ARRAY_SIZE(buf)); return strstr(buf, "Sink_Support: yes\n"); }