From patchwork Mon Jun 19 09:36:20 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 9795607 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 B4B576020B for ; Mon, 19 Jun 2017 09:37:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CD14A26E98 for ; Mon, 19 Jun 2017 09:37:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C201827E71; Mon, 19 Jun 2017 09:37:34 +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 60BEA26E98 for ; Mon, 19 Jun 2017 09:37:34 +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=CdxhQyH6dxOUTSHzsn/YLNINix2VGP2/wWSUjtaWi8I=; b=TKoaf4/SMr0bcA9++NGXj4krlo c/H2VIrZNwlzVabP+eVz6btbbJkS59YHZKJvhZbmDYTmovCEUQAXRA10NceUplNnwhoMTQ7+dWsQy QnduCugAH34aAelMp8y9yONKAbkUan+GT6/d9oMbeMi2NOxJCwOL6Zu7DNLS6xwRq7qqtwLd9/AJs DD/CF8WOXhCzACr1cOOdBQ9eS9dBwDHCn5tz8tjMbAxrbbrIegCtgxppWISfm/ou4uzMa5/DbWuEO Pk8bJMrkwhasGxELf8fnxqE0///gkRWWtC8c04Doyq+TdBFY8kNnTmNJqsrZAvVykjR2UeD/m2JtP 1F1m/sIQ==; 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 1dMt7l-0006PF-7d; Mon, 19 Jun 2017 09:37:33 +0000 Received: from mail-wm0-x230.google.com ([2a00:1450:400c:c09::230]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dMt7V-0005zO-K9 for linux-arm-kernel@lists.infradead.org; Mon, 19 Jun 2017 09:37:19 +0000 Received: by mail-wm0-x230.google.com with SMTP id x70so73698933wme.0 for ; Mon, 19 Jun 2017 02:36:57 -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=aDscxiEh3kfhaecNLT7CVn6qG5e+DMfx9s5gdFXuXFE=; b=P42io1RG9fFUovQuzSDCfhexhfJF0ia+iqUvtOtga4u1TowUTXhUGiTicOIGOP2E6p VZbK02VXjEJtsCUntpvf6KpPXpLme1XJIQNYQvU+tWPsfXCFLkVy9COdarsGNIgK/pCg VxdNIRbO+eySDTPK/iqLNntI9IfEZBVRSUgFw= 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=aDscxiEh3kfhaecNLT7CVn6qG5e+DMfx9s5gdFXuXFE=; b=ifdwv7yWiHnKDVIcxEQoZhNEQZ9kQUCHPnL5yf0+z8jOnZNmiolVrnOyCKu1t5mr0W JNpqUcTZcZbWjIMcK1WlSuDt4Qzs3+kQdPdT43V7wjFtNQU5wPz/W/GEhCZKAqFSVl1j sWVAUNryT4dI1qCT69yMr8ImpO6fjGNIptu9lF9nvv0PF+RP8lhPMG3X+St+FgATd6Qp 7eVEiyWj7TDtRnRgw3BFAUBURMTMSX9mP31l6TF8UI6GjLznfk8CkCDN9Sn+sw2YoCQK m6J4lwbng9OHSf/FGSHb1yIVwz+TM5Ydi73jJAXP714Hvvo69aGtE9EBuZP+Lmy+dIrC m//g== X-Gm-Message-State: AKS2vOxciRzTMmnUEqgtjTSyBtH7EgKDqk2ak6n6/nGWbxlm2I2013iM 2DIRqbEe/jejmKnS X-Received: by 10.28.11.145 with SMTP id 139mr12167224wml.11.1497865016090; Mon, 19 Jun 2017 02:36:56 -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.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 19 Jun 2017 02:36:55 -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 1/3] tools: timer: add rtctest_setdate Date: Mon, 19 Jun 2017 11:36:20 +0200 Message-Id: <1497864982-29284-2-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_023717_819852_859DD413 X-CRM114-Status: GOOD ( 17.17 ) 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 This tool allow to set directly the time and date to a RTC device. Unlike other tools isn't doens't use "struct timeval" or "time_t" so it is safe for 32bits platforms when testing for y2038/2106 bug. Signed-off-by: Benjamin Gaignard --- tools/testing/selftests/timers/Makefile | 2 +- tools/testing/selftests/timers/rtctest_setdate.c | 86 ++++++++++++++++++++++++ 2 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 tools/testing/selftests/timers/rtctest_setdate.c diff --git a/tools/testing/selftests/timers/Makefile b/tools/testing/selftests/timers/Makefile index 5fa1d7e9..54481f1 100644 --- a/tools/testing/selftests/timers/Makefile +++ b/tools/testing/selftests/timers/Makefile @@ -9,7 +9,7 @@ TEST_GEN_PROGS = posix_timers nanosleep nsleep-lat set-timer-lat mqueue-lat \ TEST_GEN_PROGS_EXTENDED = alarmtimer-suspend valid-adjtimex adjtick change_skew \ skew_consistency clocksource-switch leap-a-day \ - leapcrash set-tai set-2038 set-tz + leapcrash set-tai set-2038 set-tz rtctest_setdate include ../lib.mk diff --git a/tools/testing/selftests/timers/rtctest_setdate.c b/tools/testing/selftests/timers/rtctest_setdate.c new file mode 100644 index 0000000..2cb7848 --- /dev/null +++ b/tools/testing/selftests/timers/rtctest_setdate.c @@ -0,0 +1,86 @@ +/* Real Time Clock Driver Test + * by: Benjamin Gaignard (benjamin.gaignard@linaro.org) + * + * To build + * gcc rtctest_setdate.c -o rtctest_setdate + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static const char default_time[] = "00:00:00"; + +int main(int argc, char **argv) +{ + int fd, retval; + struct rtc_time new, current; + const char *rtc, *date; + const char *time = default_time; + + switch (argc) { + case 4: + time = argv[3]; + /* FALLTHROUGH */ + case 3: + date = argv[2]; + rtc = argv[1]; + break; + default: + fprintf(stderr, "usage: rtctest_setdate [HH:MM:SS]\n"); + return 1; + } + + fd = open(rtc, O_RDONLY); + if (fd == -1) { + perror(rtc); + exit(errno); + } + + sscanf(date, "%d-%d-%d", &new.tm_mday, &new.tm_mon, &new.tm_year); + new.tm_mon -= 1; + new.tm_year -= 1900; + sscanf(time, "%d:%d:%d", &new.tm_hour, &new.tm_min, &new.tm_sec); + + fprintf(stderr, "Test will set RTC date/time to %d-%d-%d, %02d:%02d:%02d.\n", + new.tm_mday, new.tm_mon + 1, new.tm_year + 1900, + new.tm_hour, new.tm_min, new.tm_sec); + + /* Write the new date in RTC */ + retval = ioctl(fd, RTC_SET_TIME, &new); + 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); + } + + fprintf(stderr, "\n\nCurrent RTC date/time is %d-%d-%d, %02d:%02d:%02d.\n", + current.tm_mday, current.tm_mon + 1, current.tm_year + 1900, + current.tm_hour, current.tm_min, current.tm_sec); + + close(fd); + return 0; +}