From patchwork Thu Feb 23 02:31:18 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michel Thierry X-Patchwork-Id: 9587665 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id ADF42604A2 for ; Thu, 23 Feb 2017 02:31:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9D62F27B2F for ; Thu, 23 Feb 2017 02:31:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9218E286A3; Thu, 23 Feb 2017 02:31:21 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 3FF0827B2F for ; Thu, 23 Feb 2017 02:31:21 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id CC9626E935; Thu, 23 Feb 2017 02:31:20 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by gabe.freedesktop.org (Postfix) with ESMTPS id BE5466E935 for ; Thu, 23 Feb 2017 02:31:19 +0000 (UTC) Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 22 Feb 2017 18:31:19 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.35,197,1484035200"; d="scan'208";a="61317781" Received: from relo-linux-11.sc.intel.com ([10.3.160.214]) by orsmga004.jf.intel.com with ESMTP; 22 Feb 2017 18:31:19 -0800 From: Michel Thierry To: intel-gfx@lists.freedesktop.org Date: Wed, 22 Feb 2017 18:31:18 -0800 Message-Id: <20170223023118.35349-1-michel.thierry@intel.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: References: Subject: [Intel-gfx] [PATCH i-g-t v2] igt/drv_hangman: Fix clear_error_state 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-Virus-Scanned: ClamAV using ClamSMTP clear_error_state was not doing anything (igt_sysfs_set was not writing to the error file because strlen was 0). Also fix assert_entry to catch this issue; strcasecmp returns 0 when there's a match, or an integer in a mismatch. v2: Use new igt_sysfs_write, add len > 0 assert in igt_sysfs_set to catch future errors, clean-up strcasecmp logic (Chris). Cc: Chris Wilson Fixes: 79c6a84ca85b ("igt/drv_hangman: Migrate to sysfs") Signed-off-by: Michel Thierry --- lib/igt_sysfs.c | 26 ++++++++++++++++++++++++++ lib/igt_sysfs.h | 1 + tests/drv_hangman.c | 4 ++-- 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/lib/igt_sysfs.c b/lib/igt_sysfs.c index ded10a67..d244d9b6 100644 --- a/lib/igt_sysfs.c +++ b/lib/igt_sysfs.c @@ -172,6 +172,31 @@ int igt_sysfs_open_parameters(int device) return params; } + +/** + * igt_sysfs_write: + * @dir: directory for the device from igt_sysfs_open() + * @attr: name of the sysfs node to open + * + * This writes a single byte to the sysfs file. + * + * Returns: + * True on success, false on failure. + */ +bool igt_sysfs_write(int dir, const char *attr) +{ + int fd, ret; + + fd = openat(dir, attr, O_WRONLY); + if (fd < 0) + return false; + + ret = write(fd, "\0", 1); + close(fd); + + return ret; +} + /** * igt_sysfs_set: * @dir: directory for the device from igt_sysfs_open() @@ -192,6 +217,7 @@ bool igt_sysfs_set(int dir, const char *attr, const char *value) return false; len = strlen(value); + igt_assert(len > 0); ret = writeN(fd, value, len); close(fd); diff --git a/lib/igt_sysfs.h b/lib/igt_sysfs.h index 69b2e5ec..145a9be6 100644 --- a/lib/igt_sysfs.h +++ b/lib/igt_sysfs.h @@ -29,6 +29,7 @@ int igt_sysfs_open(int device, int *idx); int igt_sysfs_open_parameters(int device); +bool igt_sysfs_write(int dir, const char *attr); bool igt_sysfs_set(int dir, const char *attr, const char *value); char *igt_sysfs_get(int dir, const char *attr); diff --git a/tests/drv_hangman.c b/tests/drv_hangman.c index cafdf4c1..df9c763f 100644 --- a/tests/drv_hangman.c +++ b/tests/drv_hangman.c @@ -58,7 +58,7 @@ static void assert_entry(const char *s, bool expect) error = igt_sysfs_get(sysfs, "error"); igt_assert(error); - igt_assert_f(strcasecmp(error, s) != expect, + igt_assert_f(!!strcasecmp(error, s) != expect, "contents of error: '%s' (expected %s '%s')\n", error, expect ? "": "not", s); @@ -77,7 +77,7 @@ static void assert_error_state_collected(void) static void clear_error_state(void) { - igt_sysfs_set(sysfs, "error", ""); + igt_sysfs_write(sysfs, "error"); } static void test_error_state_basic(void)