From patchwork Mon Jun 19 09:36:21 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 9795615 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 61BB960381 for ; Mon, 19 Jun 2017 09:50:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 990E022A68 for ; Mon, 19 Jun 2017 09:50:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8DB5D24B5B; Mon, 19 Jun 2017 09:50:29 +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=unavailable 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 0554427E71 for ; Mon, 19 Jun 2017 09:50:29 +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:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=dXZbI8Nz7sFkFvJG9JPUt24HpB3yhBxZM5js+Low9zM=; b=haixCSG8jBOgGD5Folop30K7IS jxFJH7ojESRIH6g2SwQw+33Rp+YAgLRx/XKST4f2wtNH6dEUKSIjR6D+se8bsFNxSRX+bZpvf8fZO hM8EzcVBQqsRknHMglG/s1gPQ86v0P3d8VGIuk0RPG8gyjw8fcZETwC1fGZrQVHj5PjexY0c8N0Cm tQ87JdTDadZTMw+a7qWy2rndjsPfp8HMdnn3txVo+g+BFfQ9zFGulD8EGUeHX5jT2QKa5oY8+iA2S aC+V3Vwdcu0JYo4R24ZqU/6MsSCikOZz/eFWpmGkxv73HMZ0nXjfXFY5e9Fo8kJxOYIhCK0PNyIeQ ZgT4wtAQ==; 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 1dMtKC-0003Tb-5D; Mon, 19 Jun 2017 09:50:24 +0000 Received: from mail-wm0-x235.google.com ([2a00:1450:400c:c09::235]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dMt7Y-0005zP-DY for linux-arm-kernel@lists.infradead.org; Mon, 19 Jun 2017 09:37:22 +0000 Received: by mail-wm0-x235.google.com with SMTP id m125so74063414wmm.1 for ; Mon, 19 Jun 2017 02:36:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=FbCt3l0hrNin0GsxE7vtSdlS4zINZAxU5/0qZ0h9j6w=; b=Z/Op1DjD0Tgy1COCeoIvXSJsTfK0mkI6a9BKV4KDSmKRUehj6dQCFEeMCK1cLJT4n9 1gzeWAlS5XzwR2oh547176iz5UlE/h3tp0HbH+zHO86A5NqScJ2dWEmdgJT8xj5ABHlE TiRg4QP9ddujbGsG/egj2BU3r/8iaE36R9ODk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=FbCt3l0hrNin0GsxE7vtSdlS4zINZAxU5/0qZ0h9j6w=; b=jGxklEvYGNq0Z4AZu8Ub3Hha3URq+q5KDDEp2QDHvQWIoNqr3tDBYP0H7d+ezRWxP8 9SIoIVQ9QrxkEMlaicWmER//wAdxiIc0A2fL2j9C1kXAan+2d6GiHdphLQ7d427NmuLr ue+sHp/a9ws4SlcRzWCIPpaaoEND/bIQa6C6jhXLNt/VTYo40siOrq3VH+r7nA2XlHxb dAsRFapaGRZVmc0RVI0uOb8m1JQbGnDSJiJ5q9L1jlgYy2fBXb6NR+RYn0lFqDJTsoCv +P4d41iM8UjUys16i5vbrCPJDn5dsLfpJkt1rObijnSImvJHHVFmBNpIrJw1vaR3MPp8 djdQ== X-Gm-Message-State: AKS2vOwzq/cR+Bhn58/NJs6gMG6SgkkFH0jnvB3tQ86n166k3xaGxX7V GuGFFHsH9sptQmgL X-Received: by 10.28.87.132 with SMTP id l126mr14963452wmb.95.1497865017687; Mon, 19 Jun 2017 02:36:57 -0700 (PDT) Received: from lmenx321.st.com. ([80.215.35.135]) by smtp.gmail.com with ESMTPSA id y2sm11037024wme.12.2017.06.19.02.36.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 19 Jun 2017 02:36:57 -0700 (PDT) From: Benjamin Gaignard To: john.stultz@linaro.org, tglx@linutronix.de, sboyd@codeaurora.org, shuah@kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, patrice.chotard@st.com, a.zummo@towertech.it, alexandre.belloni@free-electrons.com, linux-arm-kernel@lists.infradead.org, rtc-linux@googlegroups.com Subject: [PATCH v2 2/3] tool: timer: rtctest add check for problematic dates Date: Mon, 19 Jun 2017 11:36:21 +0200 Message-Id: <1497864982-29284-3-git-send-email-benjamin.gaignard@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1497864982-29284-1-git-send-email-benjamin.gaignard@linaro.org> References: <1497864982-29284-1-git-send-email-benjamin.gaignard@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170619_023720_640592_0C7AA1A7 X-CRM114-Status: GOOD ( 15.92 ) 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: , Cc: linaro-kernel@lists.linaro.org, Benjamin Gaignard 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 Some dates could be problematic because they reach the limits of RTC hardware capabilities. This patch add various of them but since it will change RTC date it will be activated only when 'd' args is set. Signed-off-by: Benjamin Gaignard --- tools/testing/selftests/timers/rtctest.c | 121 ++++++++++++++++++++++++++++++- 1 file changed, 117 insertions(+), 4 deletions(-) diff --git a/tools/testing/selftests/timers/rtctest.c b/tools/testing/selftests/timers/rtctest.c index 4230d30..715a016 100644 --- a/tools/testing/selftests/timers/rtctest.c +++ b/tools/testing/selftests/timers/rtctest.c @@ -21,6 +21,9 @@ #include #include +#ifndef ARRAY_SIZE +# define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) +#endif /* * This expects the new RTC class driver framework, working with @@ -29,23 +32,77 @@ */ static const char default_rtc[] = "/dev/rtc0"; +static struct rtc_time cutoff_dates[] = { + { + .tm_year = 70, /* 1970 -1900 */ + .tm_mday = 1, + }, + { + .tm_year = 137, /* 2037 -1900 */ + .tm_mday = 1, + }, + { + .tm_year = 138, /* 2038 -1900 */ + .tm_mday = 1, + }, + { + .tm_year = 199, /* 2099 -1900 */ + .tm_mday = 1, + }, + { + .tm_year = 200, /* 2100 -1900 */ + .tm_mday = 1, + }, + { + .tm_year = 205, /* 2105 -1900 */ + .tm_mday = 1, + }, + { + .tm_year = 206, /* 2106 -1900 */ + .tm_mday = 1, + }, + { + .tm_year = 361, /* 2261 -1900 */ + .tm_mday = 1, + }, + { + .tm_year = 362, /* 2262 -1900 */ + .tm_mday = 1, + }, +}; + +static int compare_dates(struct rtc_time *a, struct rtc_time *b) +{ + if (a->tm_year != b->tm_year || + a->tm_mon != b->tm_mon || + a->tm_mday != b->tm_mday || + a->tm_hour != b->tm_hour || + a->tm_min != b->tm_min || + ((b->tm_sec - a->tm_sec) > 1)) + return 1; + + return 0; +} int main(int argc, char **argv) { - int i, fd, retval, irqcount = 0; + int i, fd, retval, irqcount = 0, dangerous = 0; unsigned long tmp, data; struct rtc_time rtc_tm; const char *rtc = default_rtc; struct timeval start, end, diff; switch (argc) { + case 3: + if (*argv[2] == 'd') + dangerous = 1; case 2: rtc = argv[1]; /* FALLTHROUGH */ case 1: break; default: - fprintf(stderr, "usage: rtctest [rtcdev]\n"); + fprintf(stderr, "usage: rtctest [rtcdev] [d]\n"); return 1; } @@ -202,7 +259,7 @@ int main(int argc, char **argv) /* not all RTCs support periodic IRQs */ if (errno == EINVAL) { fprintf(stderr, "\nNo periodic IRQ support\n"); - goto done; + goto test_DATE; } perror("RTC_IRQP_READ ioctl"); exit(errno); @@ -221,7 +278,7 @@ int main(int argc, char **argv) if (errno == EINVAL) { fprintf(stderr, "\n...Periodic IRQ rate is fixed\n"); - goto done; + goto test_DATE; } perror("RTC_IRQP_SET ioctl"); exit(errno); @@ -269,6 +326,62 @@ int main(int argc, char **argv) } } +test_DATE: + if (!dangerous) + goto done; + + fprintf(stderr, "\nTesting problematic dates\n"); + + for (i = 0; i < ARRAY_SIZE(cutoff_dates); i++) { + struct rtc_time current; + + /* Write the new date in RTC */ + retval = ioctl(fd, RTC_SET_TIME, &cutoff_dates[i]); + if (retval == -1) { + perror("RTC_SET_TIME ioctl"); + close(fd); + exit(errno); + } + + /* Read back */ + retval = ioctl(fd, RTC_RD_TIME, ¤t); + if (retval == -1) { + perror("RTC_RD_TIME ioctl"); + exit(errno); + } + + if(compare_dates(&cutoff_dates[i], ¤t)) { + fprintf(stderr,"Setting date %d failed\n", + cutoff_dates[i].tm_year + 1900); + goto done; + } + + cutoff_dates[i].tm_sec += 5; + + /* Write the new alarm in RTC */ + retval = ioctl(fd, RTC_ALM_SET, &cutoff_dates[i]); + if (retval == -1) { + perror("RTC_ALM_SET ioctl"); + close(fd); + exit(errno); + } + + /* Read back */ + retval = ioctl(fd, RTC_ALM_READ, ¤t); + if (retval == -1) { + perror("RTC_ALM_READ ioctl"); + exit(errno); + } + + if(compare_dates(&cutoff_dates[i], ¤t)) { + fprintf(stderr,"Setting alarm %d failed\n", + cutoff_dates[i].tm_year + 1900); + goto done; + } + + fprintf(stderr, "Setting year %d is OK \n", + cutoff_dates[i].tm_year + 1900); + } done: fprintf(stderr, "\n\n\t\t\t *** Test complete ***\n");