From patchwork Fri Jun 16 14:03:51 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 105746 Delivered-To: patch@linaro.org Received: by 10.140.91.77 with SMTP id y71csp1321297qgd; Fri, 16 Jun 2017 07:05:22 -0700 (PDT) X-Received: by 10.84.178.4 with SMTP id y4mr13153258plb.158.1497621922030; Fri, 16 Jun 2017 07:05:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1497621922; cv=none; d=google.com; s=arc-20160816; b=Eyh2oFci9/PK21FE/0SkzAIb4CmbsLmUYdWv+xugqj3Wz4/gIB+B47v9WTLCvvxzKi nvxNcEMIvwitiJ42QUeDtieTzQKH/jJYHI2JVoQ/WK2MZ4whP9F6dpWZDTnzR+2RgjTK ppBv4G7/ckjr1gsLQx9OIvyUwpnSHgllF5fW30nOeS1i0z8VCjI5LhrIbzkXxQj24rKt U+30JnH8XnBTg16e7HDTIeEtVs/rCNoA0JEa8S/gVpIyJp4sueLELvW87Q0n/RHLJ09N UZUyS21fk+qqjSqsaS/TT4QKnzCASL9l6c9ghaRDGmrrDlV+/tiAe3ReLcM5abqUOt9v BMXA== 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=EQ83oXWnJ3h0/EErc0CML5PVjPp/VmeMQvU8x3q+a3U=; b=YCYsI6IYdb41Gvb2jJMDRE7RKswt/8e39ziwhlxq/sSL3qmL030bBYZdrJmWjQtwtJ SJ9trNp4HJ+t70DWyap3beNurnbfibpW9ORRfp8IKhC9pbcdm97vBM80IQQdFDMllSqH EfDmmMScvJgtekGynx5ayqET6TgGqT5N1exZxpikjpcLBRG6WJUna7zv7y7zh439waWp eo1ijxJ9ga9aKVhAny5FW+2xiPUIDHyTp3P7WBKnl/qUPHWHMRo/dx20HZKsWHEHjZGk mqlJC42rS1e0WRH7bpwy9auDtR79LNa2Qdq3I0lNXCq33mZIZOJVb8L8Pnn8qLnCrw0T Qh8Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.b=AnFHnPDt; 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 f192si2049730pgc.179.2017.06.16.07.05.21; Fri, 16 Jun 2017 07:05:22 -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=AnFHnPDt; 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 S1754036AbdFPOE4 (ORCPT + 25 others); Fri, 16 Jun 2017 10:04:56 -0400 Received: from mail-wm0-f51.google.com ([74.125.82.51]:33745 "EHLO mail-wm0-f51.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754020AbdFPOEw (ORCPT ); Fri, 16 Jun 2017 10:04:52 -0400 Received: by mail-wm0-f51.google.com with SMTP id m7so4144061wmg.0 for ; Fri, 16 Jun 2017 07:04:51 -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=EQ83oXWnJ3h0/EErc0CML5PVjPp/VmeMQvU8x3q+a3U=; b=AnFHnPDthTQGfGbpo1wZ/9YdlwnGGp0ydELjdw7vYvNsAYHxM5+BpcqMJJDZxrmjUN m7MP6Bbq/N8KIh1shS5NJTuawCktixk83KVw6oWmksh46WdH0/gITZW6thdvX1SEUhpu Q9V6wiSZh/2Ggfmt9t2/8j/34hFbNlY53GKQc= 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=EQ83oXWnJ3h0/EErc0CML5PVjPp/VmeMQvU8x3q+a3U=; b=q9t+4zK5rRC4AN7yOIuUst6S+O4wEwUljXayieWNuBJsCEb15BC+YCZnZvxo4t2Rj7 B39ObYj8JReZx0mn0PCKvmc2aF+QIXEoeV8TLBhsv99v9yfi/sZXmhasw85PDMG8OfrX 4O0GJW96Xjg06uadicXS0MR8M/uXw5E2fouFhejvnLX4JfRNB23pRM73TydlBOZAcNuL pf0X/K8rIC9rF7wSLDDVa+CQT9tan9EpqV7aZsI850nGaZv9cltjnqw5GpA7iGuvTblN GgMVhQ+4XMYBGL52A/nMzPVFtAmvpfFA7kISp+HOyZdeIwW3GMi3LwQJj3gq21FGpCxL 1SeA== X-Gm-Message-State: AKS2vOyge43wEzTNPvg++PhmIatctb6WIe8wEtLhCuqXBGEzqkWUO03M PnHRYWXVJEFIZF0O X-Received: by 10.28.196.2 with SMTP id u2mr7621789wmf.104.1497621891011; Fri, 16 Jun 2017 07:04:51 -0700 (PDT) Received: from lmenx321.st.com. ([80.214.78.131]) by smtp.gmail.com with ESMTPSA id h12sm1883277wrc.43.2017.06.16.07.04.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 16 Jun 2017 07:04:50 -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 1/3] tools: timer: add rtctest_setdate Date: Fri, 16 Jun 2017 16:03:51 +0200 Message-Id: <1497621833-9942-2-git-send-email-benjamin.gaignard@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1497621833-9942-1-git-send-email-benjamin.gaignard@linaro.org> References: <1497621833-9942-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 "strut 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; +}