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: 105811 Delivered-To: patch@linaro.org Received: by 10.140.91.2 with SMTP id y2csp786833qgd; Mon, 19 Jun 2017 02:37:16 -0700 (PDT) X-Received: by 10.98.202.210 with SMTP id y79mr24745834pfk.230.1497865036607; Mon, 19 Jun 2017 02:37:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1497865036; cv=none; d=google.com; s=arc-20160816; b=RDkQndjkSlCeE+aPqURR8bdwmqEhWPaZ+qQhg3DWMccxUU/RMb44Y+ahvAfj1t659k 8Hkc3H3WzkanGzVF5TrE5wVgW7zdWRTjH1NXN4D7EGjl/XDvK0W/ZuXLHvJZl6DH2zb8 GsVH6NAOGhnylXp0w03Iqon3zObmhx/tVAxl/b3txGU0XjUk5opQJ8waXKEbh4iUSZwM dqaps2xJYGTx+B/phZL4nk9TIksHTD0ppp4h3mPwdOhe0+krca+sYELDm2t0+NT+lXIP /Xcc6w6Z3JNNc3oyv4gg/xmZClLWI2BrmKvswvt1sGbSYXbkq4YWsy242XLflap/4kUJ r6WA== 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=aDscxiEh3kfhaecNLT7CVn6qG5e+DMfx9s5gdFXuXFE=; b=NviX6d1RH+uG48cCNH8pu9tgqCAxsCZqae4f00AtTyaQ3qp0cK5NTxmV5f9iUs5vnF 0xw6+qmYgeV77evtSE40PHbULXPatIQzIfJ75M5fGOSfzirpVRcflhD3kaTnkleFZat0 0se52+CS+gd1wASRd+cHQ3e1r72aarjLeGF1uLnwRJb/rCQfYC51qSUfXjTjih3c4TLh 40cVB3QtzvuVRV0Epbpoa+cn8CC+G+hhrMAi+J9sQLTR4mpASSK7lvEKLLsnorxNyipX tNnB9d0jZjK/c3DaCRztfY9JrIAVi7PzXGEYjq66DHa3G2LzBFG74bp8kJI969E7uHBf F5Eg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.b=P42io1RG; 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.16; Mon, 19 Jun 2017 02:37:16 -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=P42io1RG; 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 S1753925AbdFSJhA (ORCPT + 25 others); Mon, 19 Jun 2017 05:37:00 -0400 Received: from mail-wm0-f46.google.com ([74.125.82.46]:36178 "EHLO mail-wm0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753783AbdFSJg5 (ORCPT ); Mon, 19 Jun 2017 05:36:57 -0400 Received: by mail-wm0-f46.google.com with SMTP id m125so74062695wmm.1 for ; Mon, 19 Jun 2017 02:36:56 -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=Ae1B60dQNM83uBgBBhinff9T5iwDIQD0C422hpgMJmrPoC1Jj4G/JZSBkVIVvGPhbW pr+sYXP/kqkoeWZQCi/K3WVmcGlU1Gt1daYB5rXt9EkPhsR7/ite70btUGIHBIKtOFB0 EQbacapZ26Bp9qtvMU+yPnIeRQfJUF9wkJJp7jTrVcXbZrJHRehnYw11lykouxSKO97n RczBaee+GV/QSVvSwZ4W9F6owtOVb9mOti+2B0AmxR0/XvvrySBQYGCqIzvSrU0WdkKg 2ImwxEWMNtCuiteJxExJLUVC13HPA7KITgA52l4m++k9/DElCfzM5AWd69fijogAczL3 izaA== X-Gm-Message-State: AKS2vOxi77C3IPdElijL5YehhLnCGs1AxT1gKQGmngD9NSpk1L7GqJlb g9mJtPO71gnIKG3y 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 Cc: linaro-kernel@lists.linaro.org, Benjamin Gaignard 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> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 -- 1.9.1 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; +}