From patchwork Wed Sep 23 16:08:14 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Wood X-Patchwork-Id: 7250951 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 02BA6BEEC1 for ; Wed, 23 Sep 2015 16:08:37 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 154372093D for ; Wed, 23 Sep 2015 16:08:36 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 0B9E0208EF for ; Wed, 23 Sep 2015 16:08:35 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 733E26E2C8; Wed, 23 Sep 2015 09:08:34 -0700 (PDT) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by gabe.freedesktop.org (Postfix) with ESMTP id DF46B6E2C8 for ; Wed, 23 Sep 2015 09:08:32 -0700 (PDT) Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga103.jf.intel.com with ESMTP; 23 Sep 2015 09:08:19 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.17,577,1437462000"; d="scan'208";a="650829190" Received: from pistachio.isw.intel.com ([10.237.224.84]) by orsmga003.jf.intel.com with ESMTP; 23 Sep 2015 09:08:18 -0700 From: Thomas Wood To: intel-gfx@lists.freedesktop.org Date: Wed, 23 Sep 2015 17:08:14 +0100 Message-Id: <1443024494-4123-1-git-send-email-thomas.wood@intel.com> X-Mailer: git-send-email 2.4.3 Organization: Intel Corporation (UK) Ltd. - Co. Reg. #1134945 - Pipers Way, Swindon SN3 1RJ Subject: [Intel-gfx] [PATCH i-g-t] lib: add igt_debugfs_search 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=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, 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 Add igt_debugfs_search to search each line in a debugfs file for a specified substring. Signed-off-by: Thomas Wood --- lib/igt_debugfs.c | 31 +++++++++++++++++++++++++++++++ lib/igt_debugfs.h | 1 + tests/gem_ppgtt.c | 35 ++--------------------------------- tests/gem_tiled_swapping.c | 13 +------------ 4 files changed, 35 insertions(+), 45 deletions(-) diff --git a/lib/igt_debugfs.c b/lib/igt_debugfs.c index 5c13279..c603369 100644 --- a/lib/igt_debugfs.c +++ b/lib/igt_debugfs.c @@ -212,6 +212,37 @@ void __igt_debugfs_read(const char *filename, char *buf, int buf_size) igt_assert(fclose(file) == 0); } +/** + * igt_debugfs_search: + * @filename: file name + * @substring: string to search for in @filename + * + * Searches each line in @filename for the substring specified in @substring. + * + * Returns: True if the @substring is found to occur in @filename + */ +bool igt_debugfs_search(const char *filename, const char *substring) +{ + FILE *file; + size_t n = 0; + char *line = NULL; + bool matched = false; + + file = igt_debugfs_fopen(filename, O_RDONLY); + igt_assert(file); + + while (getline(&line, &n, file) >= 0) { + matched = (strstr(line, substring) != NULL); + if (matched) + break; + } + + free(line); + fclose(file); + + return matched; +} + /* * Pipe CRC */ diff --git a/lib/igt_debugfs.h b/lib/igt_debugfs.h index 78cb5e1..ee9ff40 100644 --- a/lib/igt_debugfs.h +++ b/lib/igt_debugfs.h @@ -35,6 +35,7 @@ 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); +bool igt_debugfs_search(const char *filename, const char *substring); /** * igt_debugfs_read: diff --git a/tests/gem_ppgtt.c b/tests/gem_ppgtt.c index 0b8e1ff..de295b9 100644 --- a/tests/gem_ppgtt.c +++ b/tests/gem_ppgtt.c @@ -266,37 +266,6 @@ static void flink_and_close(void) close(fd2); } -static bool grep_name(const char *fname, const char *match) -{ - int fd; - FILE *fh; - size_t n = 0; - char *line = NULL; - char *matched = NULL; - - fd = igt_debugfs_open(fname, O_RDONLY); - igt_assert(fd >= 0); - - fh = fdopen(fd, "r"); - igt_assert(fh); - - while (getline(&line, &n, fh) >= 0) { - matched = strstr(line, match); - if (line) { - free(line); - line = NULL; - } - if (matched) - break; - } - - if (line) - free(line); - fclose(fh); - - return matched != NULL; -} - static void flink_and_exit(void) { uint32_t fd, fd2; @@ -323,7 +292,7 @@ static void flink_and_exit(void) gem_sync(fd2, flinked_bo); /* Verify looking for string works OK. */ - matched = grep_name("i915_gem_gtt", match); + matched = igt_debugfs_search("i915_gem_gtt", match); igt_assert_eq(matched, true); gem_close(fd2, flinked_bo); @@ -338,7 +307,7 @@ retry: /* The flinked bo VMA should have been cleared now, so list of VMAs * in debugfs should not contain the one for the imported object. */ - matched = grep_name("i915_gem_gtt", match); + matched = igt_debugfs_search("i915_gem_gtt", match); if (matched && retry++ < retries) goto retry; diff --git a/tests/gem_tiled_swapping.c b/tests/gem_tiled_swapping.c index 537b53a..d232aee 100644 --- a/tests/gem_tiled_swapping.c +++ b/tests/gem_tiled_swapping.c @@ -157,19 +157,8 @@ static void thread_fini(struct thread *t) static void check_memory_layout(void) { - FILE *tiling_debugfs_file; - char *line = NULL; - size_t sz = 0; - - tiling_debugfs_file = igt_debugfs_fopen("i915_swizzle_info", "r"); - igt_assert(tiling_debugfs_file); - - while (getline(&line, &sz, tiling_debugfs_file) > 0) { - if (strstr(line, "L-shaped") == NULL) - continue; - + if (igt_debugfs_search("i915_swizzle_info", "L-shaped")) igt_skip("L-shaped memory configuration detected\n"); - } igt_debug("normal memory configuration detected, continuing\n"); }