From patchwork Tue Mar 28 19:10:56 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Timur Tabi X-Patchwork-Id: 9650353 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 9C310601E9 for ; Tue, 28 Mar 2017 19:11:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8C1891FF12 for ; Tue, 28 Mar 2017 19:11:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7E39C283E8; Tue, 28 Mar 2017 19:11:32 +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=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 066A71FF12 for ; Tue, 28 Mar 2017 19:11:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:List-Subscribe:List-Help: List-Post:List-Archive:List-Unsubscribe:List-Id:Message-Id:Date:Subject:To: From:Reply-To:Cc:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=p+RNI7hMA42WBaz+9FMcI9sYl9Zx7IVnSv0DdCSDXnE=; b=duRaQeNPxaQrJ4 RQwbaVKsYlTE0FbilSqQuuXnskDB+24gCD6Oo2Gp17UpffdNib0B7CWr5H1tsReMjNUOA+1zJictb 56XwY51i/4+W+yMVW1fZstEwB+7d+V6o+PrL0SSvhz/pD/RstnGR5Eim5KTrH9gF6lAuJKLnIsZSa 1S8yibiaILtmE6BCWjhxI+GYhX+cv7Dy4xvXKLdOYehzDHmpJxGuMU1moKVbtnnRI9NEhVLJ5EgMJ vAveD1fpiUu6lpMfr0cbgO7z5UCvl05GkjFiVZi1M0zA7M81LG3PUkzQtkDFgKdM3qumhs0RTDzkg qrJL6ZFT5vJn4niCvZgA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1cswWa-0001BA-HL; Tue, 28 Mar 2017 19:11:24 +0000 Received: from smtp.codeaurora.org ([198.145.29.96]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1cswWX-00019u-6b for linux-arm-kernel@lists.infradead.org; Tue, 28 Mar 2017 19:11:23 +0000 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id E948960F5C; Tue, 28 Mar 2017 19:11:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1490728260; bh=FjfcL9mO1Xh1+h+ubYgNjIQkhJryXDTPeF4FEVpWQbM=; h=From:To:Subject:Date:From; b=PiC6cJX0cfzMTRvonX2STPg5Xv07J4CEKAy+0xRU1+V4DpzfDPafsEHI5ryvLbPWY ZlDOscWOKaWeCpseokBE70pHx6VYfFxPZqxzRane00o4RpECDEyeZbHQAb+PvT6xFp VBvth0ZIHpR3i6eqqGjr0MabSVz754Y2XmNm/GDQ= Received: from timur-ubuntu.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: timur@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id 11D7860F32; Tue, 28 Mar 2017 19:10:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1490728260; bh=FjfcL9mO1Xh1+h+ubYgNjIQkhJryXDTPeF4FEVpWQbM=; h=From:To:Subject:Date:From; b=PiC6cJX0cfzMTRvonX2STPg5Xv07J4CEKAy+0xRU1+V4DpzfDPafsEHI5ryvLbPWY ZlDOscWOKaWeCpseokBE70pHx6VYfFxPZqxzRane00o4RpECDEyeZbHQAb+PvT6xFp VBvth0ZIHpR3i6eqqGjr0MabSVz754Y2XmNm/GDQ= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 11D7860F32 Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=none smtp.mailfrom=timur@codeaurora.org From: Timur Tabi To: Arnd Bergmann , Guenter Roeck , linux-watchdog@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH] selftests: watchdog: accept multiple params on command line Date: Tue, 28 Mar 2017 14:10:56 -0500 Message-Id: <1490728256-24143-1-git-send-email-timur@codeaurora.org> X-Mailer: git-send-email 1.9.1 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170328_121121_291534_A1FD018E X-CRM114-Status: GOOD ( 15.25 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Watchdog drivers are not required to retain programming information, such as timeouts, after the watchdog device is closed. Therefore, the watchdog test should be able to perform multiple actions after opening the watchdog device. For example, to set the timeout to 10s and ping every 5s: watchdog-test -t 10 -p 5 -e Also, display the periodic decimal point only if the keep-alive call succeeds. Signed-off-by: Timur Tabi --- tools/testing/selftests/watchdog/watchdog-test.c | 61 +++++++++++++----------- 1 file changed, 34 insertions(+), 27 deletions(-) diff --git a/tools/testing/selftests/watchdog/watchdog-test.c b/tools/testing/selftests/watchdog/watchdog-test.c index 6983d05..a74c9d7 100644 --- a/tools/testing/selftests/watchdog/watchdog-test.c +++ b/tools/testing/selftests/watchdog/watchdog-test.c @@ -24,9 +24,11 @@ static void keep_alive(void) { int dummy; + int ret; - printf("."); - ioctl(fd, WDIOC_KEEPALIVE, &dummy); + ret = ioctl(fd, WDIOC_KEEPALIVE, &dummy); + if (!ret) + printf("."); } /* @@ -51,6 +53,7 @@ int main(int argc, char *argv[]) int flags; unsigned int ping_rate = 1; int ret; + int i; setbuf(stdout, NULL); @@ -61,31 +64,35 @@ int main(int argc, char *argv[]) exit(-1); } - if (argc > 1) { - if (!strncasecmp(argv[1], "-d", 2)) { - flags = WDIOS_DISABLECARD; - ioctl(fd, WDIOC_SETOPTIONS, &flags); - printf("Watchdog card disabled.\n"); - goto end; - } else if (!strncasecmp(argv[1], "-e", 2)) { - flags = WDIOS_ENABLECARD; - ioctl(fd, WDIOC_SETOPTIONS, &flags); - printf("Watchdog card enabled.\n"); - goto end; - } else if (!strncasecmp(argv[1], "-t", 2) && argv[2]) { - flags = atoi(argv[2]); - ioctl(fd, WDIOC_SETTIMEOUT, &flags); - printf("Watchdog timeout set to %u seconds.\n", flags); - goto end; - } else if (!strncasecmp(argv[1], "-p", 2) && argv[2]) { - ping_rate = strtoul(argv[2], NULL, 0); - printf("Watchdog ping rate set to %u seconds.\n", ping_rate); - } else { - printf("-d to disable, -e to enable, -t to set " \ - "the timeout,\n-p to set the ping rate, and \n"); - printf("run by itself to tick the card.\n"); - goto end; - } + for (i = 1; i < argc; i++) { + if (!strncasecmp(argv[i], "-d", 2)) { + flags = WDIOS_DISABLECARD; + ret = ioctl(fd, WDIOC_SETOPTIONS, &flags); + if (!ret) + printf("Watchdog card disabled.\n"); + } else if (!strncasecmp(argv[i], "-e", 2)) { + flags = WDIOS_ENABLECARD; + ret = ioctl(fd, WDIOC_SETOPTIONS, &flags); + if (!ret) + printf("Watchdog card enabled.\n"); + } else if (!strncasecmp(argv[i], "-t", 2) && argv[2]) { + flags = atoi(argv[i + 1]); + ret = ioctl(fd, WDIOC_SETTIMEOUT, &flags); + if (!ret) + printf("Watchdog timeout set to %u seconds.\n", flags); + i++; + } else if (!strncasecmp(argv[i], "-p", 2) && argv[2]) { + ping_rate = strtoul(argv[i + 1], NULL, 0); + printf("Watchdog ping rate set to %u seconds.\n", ping_rate); + i++; + } else { + printf("-d to disable, -e to enable, -t to set " + "the timeout,\n-p to set the ping rate, and "); + printf("run by itself to tick the card.\n"); + printf("Parameters are parsed left-to-right in real-time.\n"); + printf("Example: %s -d -t 10 -p 5 -e\n", argv[0]); + goto end; + } } printf("Watchdog Ticking Away!\n");