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: 105812 Delivered-To: patch@linaro.org Received: by 10.140.91.2 with SMTP id y2csp786835qgd; Mon, 19 Jun 2017 02:37:17 -0700 (PDT) X-Received: by 10.99.125.2 with SMTP id y2mr25212742pgc.10.1497865037331; Mon, 19 Jun 2017 02:37:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1497865037; cv=none; d=google.com; s=arc-20160816; b=eJ3fe/+YiWwgN5qgxvZwv2s3ndwAiqm/x7AixlvMMGb8AJ+Qc+9YTEONTtIwMDnQsK POu6uMrW4Z0n7wagkGZ3oLYQ99de6aprQyPWsXyuXLO8MjAVCM5disiPkSfVOndvi00z yqv4H32vdaCGHjmQjDiDYX/voAZi7T2sv3epV/AmkKv0LCad+4pRHguSebDnxSZqaHpw alNEW0q9HTA6wdrIJYCiSVkqZcYGSrcGLwkgVaYnzYKjS3fEnLfXU1g6EPRDiTfbbm0R 5s/E9700iGkMG9/ARwyjxkSHpY51CF8fGZ4Gn4iByKpuxd6W5+qXbiWv6vBd2aurlciU zPoQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=FbCt3l0hrNin0GsxE7vtSdlS4zINZAxU5/0qZ0h9j6w=; b=Pq3odG4R1DrT/6As2vNoD/bVm7LYEQ/k54M+IyQ6Mj86FTVPE7H36vYIRXrM0+Ujgd pf4H4LMQ4EBy4vll7LKVWqw1oCRDnYhE+Hz3Rzgcgvv3qN0mbhY8/rFIBJM+/3mbnEpc e64vQtylCb6AcqFsGzyerE4eMhlHSf0qllyM7HbIjzC2jgN8xkh1LHkygpARuTJwYs/p 3zGBubSf5ttNbcgA+PcREN4fhp3PUBHPVi7pVVbyqqlT+GXaQSFfuDIczSAm3RmzeH80 V6jm+l9xJS1IPl5JctuYlCiVbN3b78pG3UBymfjuxMZ2Vy06jiyi1JSKuJXOMjrdb2Se WZ7g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.b=Z/Op1DjD; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b24si6937568pfh.9.2017.06.19.02.37.17; Mon, 19 Jun 2017 02:37:17 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.b=Z/Op1DjD; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753926AbdFSJhG (ORCPT + 25 others); Mon, 19 Jun 2017 05:37:06 -0400 Received: from mail-wm0-f44.google.com ([74.125.82.44]:35619 "EHLO mail-wm0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753902AbdFSJg7 (ORCPT ); Mon, 19 Jun 2017 05:36:59 -0400 Received: by mail-wm0-f44.google.com with SMTP id x70so73699637wme.0 for ; Mon, 19 Jun 2017 02:36:58 -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=FeNx3ULFL1+tYlFVNEBpmnLotA5FoxIlhMGYAVQ6J3cnWU4x70bAjc5Pycubp0r5jW mXxfrnwm1Ea2lGbdJVX0tX5ucLcSzX1j4QmZq30s/O39mKog/d2kLSBVdOSDfIlo6TaW DPVLvnZqZRdsdV5UZV4g2JMscVcXTqjdeSyWkVLwzOY9esFpuXoLwAe51xMic6NMa3uq B5zdlD1PumZlNhL3ORf+p3XXbkZqnXOT2neAHn/Uru0etlIeWEn2Im6y/Q+HXi5e2UOy k4iIqoD/Fm4g4eoHQnL1xRJbyY/WvTRddp8FruDIuzr6+oorKmLtqsaf8/sxSQpXiUDl mNVA== X-Gm-Message-State: AKS2vOxHEHgDsgL7TY4ZdC9UANfXaMQEic8H+CTsgU72Gy0g3ruHCGzo X+Uy5Jamb09kn/6K 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 Cc: linaro-kernel@lists.linaro.org, Benjamin Gaignard 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> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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(-) -- 1.9.1 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");