From patchwork Fri Jan 10 17:20:42 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: jeff.mcgee@intel.com X-Patchwork-Id: 3467261 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.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id BC1A2C02DC for ; Fri, 10 Jan 2014 17:16:15 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 8D9A420122 for ; Fri, 10 Jan 2014 17:16:14 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 81F0E200E5 for ; Fri, 10 Jan 2014 17:16:12 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 20E3AFB607; Fri, 10 Jan 2014 09:16:11 -0800 (PST) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by gabe.freedesktop.org (Postfix) with ESMTP id E5162FB600 for ; Fri, 10 Jan 2014 09:16:09 -0800 (PST) Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga102.jf.intel.com with ESMTP; 10 Jan 2014 09:11:43 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.95,639,1384329600"; d="scan'208";a="464787944" Received: from jeffdesk.fso.intel.com ([10.5.53.1]) by orsmga002.jf.intel.com with ESMTP; 10 Jan 2014 09:15:28 -0800 From: jeff.mcgee@intel.com To: intel-gfx@lists.freedesktop.org Date: Fri, 10 Jan 2014 11:20:42 -0600 Message-Id: <1389374442-20325-1-git-send-email-jeff.mcgee@intel.com> X-Mailer: git-send-email 1.8.5.2 Subject: [Intel-gfx] [PATCH] pm_rps: Improve file I/O and restore utilities X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: intel-gfx-bounces@lists.freedesktop.org Errors-To: intel-gfx-bounces@lists.freedesktop.org X-Spam-Status: No, score=-4.3 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 From: Jeff McGee Use unbuffered file I/O to simplify and ensure proper sysfs access. Bionic C library may not re-read a read-only file unless unbuffered, which results in failure to monitor changes in gt_cur_freq_mhz. Adapt do_writeval to assert that no write error occurs when we expect none. Expand use of restore_assert macro to ensure that original min/max frequencies are always in place after a test failure. Signed-off-by: Jeff McGee --- tests/pm_rps.c | 87 +++++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 55 insertions(+), 32 deletions(-) diff --git a/tests/pm_rps.c b/tests/pm_rps.c index e8affdb..5223760 100644 --- a/tests/pm_rps.c +++ b/tests/pm_rps.c @@ -22,6 +22,7 @@ * * Authors: * Ben Widawsky + * Jeff McGee * */ @@ -35,14 +36,6 @@ static bool verbose = false; static int origmin, origmax; -#define restore_assert(COND) do { \ - if (!(COND)) { \ - writeval(stuff[MIN].filp, origmin); \ - writeval(stuff[MAX].filp, origmax); \ - igt_assert(0); \ - } \ -} while (0); - static const char sysfs_base_path[] = "/sys/class/drm/card%d/gt_%s_freq_mhz"; enum { CUR, @@ -66,7 +59,6 @@ static int readval(FILE *filp) int val; int scanned; - fflush(filp); rewind(filp); scanned = fscanf(filp, "%d", &val); igt_assert(scanned == 1); @@ -74,32 +66,63 @@ static int readval(FILE *filp) return val; } +#define fcur (readval(stuff[CUR].filp)) +#define fmin (readval(stuff[MIN].filp)) +#define fmax (readval(stuff[MAX].filp)) +#define frp0 (readval(stuff[RP0].filp)) +#define frp1 (readval(stuff[RP1].filp)) +#define frpn (readval(stuff[RPn].filp)) + +static void restore(void) +{ + rewind(stuff[MIN].filp); + rewind(stuff[MAX].filp); + + if (origmin > fmax) { + fprintf(stuff[MAX].filp, "%d", origmax); + fprintf(stuff[MIN].filp, "%d", origmin); + } else { + fprintf(stuff[MIN].filp, "%d", origmin); + fprintf(stuff[MAX].filp, "%d", origmax); + } +} + +#define restore_assert(COND) do { \ + if (!(COND)) { \ + restore(); \ + igt_assert(0); \ + } \ +} while (0); + static int do_writeval(FILE *filp, int val, int lerrno) { - /* Must write twice to sysfs since the first one simply calculates the size and won't return the error */ int ret; + rewind(filp); ret = fprintf(filp, "%d", val); - rewind(filp); - ret = fprintf(filp, "%d", val); - if (ret && lerrno) - igt_assert(errno = lerrno); - fflush(filp); + if (lerrno) { + /* Expecting specific error */ + restore_assert(ret == EOF && errno == lerrno); + } else { + /* Expecting no error */ + restore_assert(ret != EOF); + } + return ret; } -#define writeval(filp, val) do_writeval(filp, val, 0) -#define fcur (readval(stuff[CUR].filp)) -#define fmin (readval(stuff[MIN].filp)) -#define fmax (readval(stuff[MAX].filp)) -#define frp0 (readval(stuff[RP0].filp)) -#define frp1 (readval(stuff[RP1].filp)) -#define frpn (readval(stuff[RPn].filp)) +#define writeval(filp, val) do_writeval(filp, val, 0) +#define writeval_inval(filp, val) do_writeval(filp, val, EINVAL) static void setfreq(int val) { - writeval(stuff[MIN].filp, val); - writeval(stuff[MAX].filp, val); + if (val > fmax) { + writeval(stuff[MAX].filp, val); + writeval(stuff[MIN].filp, val); + } else { + writeval(stuff[MIN].filp, val); + writeval(stuff[MAX].filp, val); + } } static void checkit(void) @@ -146,6 +169,7 @@ igt_simple_main igt_assert(ret != -1); junk->filp = fopen(path, junk->mode); igt_require(junk->filp); + setbuf(junk->filp, NULL); val = readval(junk->filp); igt_assert(val >= 0); @@ -173,17 +197,16 @@ igt_simple_main checkit(); /* And some errors */ - writeval(stuff[MIN].filp, frpn - 1); - writeval(stuff[MAX].filp, frp0 + 1000); + writeval_inval(stuff[MIN].filp, frpn - 1); + writeval_inval(stuff[MAX].filp, frp0 + 1000); checkit(); - writeval(stuff[MIN].filp, fmax + 1000); - writeval(stuff[MAX].filp, fmin - 1); + writeval_inval(stuff[MIN].filp, fmax + 1000); + writeval_inval(stuff[MAX].filp, fmin - 1); checkit(); - do_writeval(stuff[MIN].filp, 0x11111110, EINVAL); - do_writeval(stuff[MAX].filp, 0, EINVAL); + writeval_inval(stuff[MIN].filp, 0x11111110); + writeval_inval(stuff[MAX].filp, 0); - writeval(stuff[MIN].filp, origmin); - writeval(stuff[MAX].filp, origmax); + restore(); }