public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
From: Li Wang <liwang@redhat.com>
To: ltp@lists.linux.it
Cc: Vitaly Kuznetsov <vkuznets@redhat.com>,
	Eirik Fuller <efuller@redhat.com>
Subject: [LTP] [PATCH 2/3] rtc02: reset backward 1 hour to RTC time
Date: Thu, 28 Apr 2022 21:26:55 +0800	[thread overview]
Message-ID: <20220428132656.11075-3-liwang@redhat.com> (raw)
In-Reply-To: <20220428132656.11075-1-liwang@redhat.com>

If there's a limit on how much backward time can be set to RTC,
rtc02 easily get an EINVAL error as well. (Note: that limitation
may enforced by the host or by EFI firmware)

  rtc02.c:70: TFAIL: ioctl() RTC_SET_TIME: EINVAL (22)
  tst_rtctime.c:116: TWARN: open(/dev/rtc,0,21042104211) failed: EBUSY (16)
  tst_wallclock.c:117: TWARN: tst_rtc_settime() realtime failed: EBADF (9)

To show the problem by manually performing `hwclock -w`.

  # date -s "2020-10-09 13:23:30"
  Fri Oct  9 13:23:30 EDT 2020
  # hwclock -w
  hwclock: ioctl(RTC_SET_TIME) to /dev/rtc0 to set the time failed: Invalid argument

If just go with a few days backwards things work:

  # date -s "2022-03-12 13:23:30"
  Sat Mar 12 13:23:30 EST 2022
  # hwclock -w
  # echo $?
  0

To be on the safe side, here reset backward +/-1 hour (in case of zero clock).

Signed-off-by: Li Wang <liwang@redhat.com>
Cc: Vitaly Kuznetsov <vkuznets@redhat.com>
Cc: Eirik Fuller <efuller@redhat.com>
---
 testcases/kernel/device-drivers/rtc/rtc02.c | 27 ++++++++++++---------
 1 file changed, 15 insertions(+), 12 deletions(-)

diff --git a/testcases/kernel/device-drivers/rtc/rtc02.c b/testcases/kernel/device-drivers/rtc/rtc02.c
index 8484a0074..6198a5d5d 100644
--- a/testcases/kernel/device-drivers/rtc/rtc02.c
+++ b/testcases/kernel/device-drivers/rtc/rtc02.c
@@ -51,19 +51,23 @@ static int rtc_tm_cmp(struct rtc_time *set_tm, struct rtc_time *read_tm)
 
 static void set_rtc_test(void)
 {
-	struct rtc_time read_tm;
+	struct rtc_time read_tm, set_tm;
 	int ret;
 
-	struct rtc_time set_tm = {
-		.tm_sec = 30,
-		.tm_min = 23,
-		.tm_hour = 13,
-		.tm_mday = 9,
-		.tm_mon = 9,
-		.tm_year = 120,
-	};
+	/* Read current RTC Time */
+	ret = tst_rtc_gettime(rtc_dev, &read_tm);
+	if (ret != 0) {
+		tst_res(TFAIL | TERRNO, "ioctl() RTC_RD_TIME");
+		return;
+	}
+
+	/* set rtc to +/-1 hour */
+	set_tm = read_tm;
+	if (set_tm.tm_hour == 0)
+		set_tm.tm_hour += 1;
+	else
+		set_tm.tm_hour -= 1;
 
-	/* set rtc to 2020.10.9 13:23:30 */
 	tst_res(TINFO, "To set RTC date/time is: %s", rtctime_to_str(&set_tm));
 
 	ret = tst_rtc_settime(rtc_dev, &set_tm);
@@ -76,7 +80,7 @@ static void set_rtc_test(void)
 		return;
 	}
 
-	/* Read current RTC Time */
+	/* Read new RTC Time */
 	ret = tst_rtc_gettime(rtc_dev, &read_tm);
 	if (ret != 0) {
 		tst_res(TFAIL | TERRNO, "ioctl() RTC_RD_TIME");
@@ -89,7 +93,6 @@ static void set_rtc_test(void)
 		return;
 	}
 	tst_res(TPASS, "The read RTC time is consistent with set time");
-
 }
 
 static void rtc_setup(void)
-- 
2.35.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

  parent reply	other threads:[~2022-04-28 13:27 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-28 13:26 [LTP] [PATCH 0/3] fix some bugs in rct02 Li Wang
2022-04-28 13:26 ` [LTP] [PATCH 1/3] rtc02: skip test with unsupport set RTC platform Li Wang
2022-04-29 11:07   ` Cyril Hrubis
2022-04-29 11:12     ` Li Wang
2022-04-28 13:26 ` Li Wang [this message]
2022-04-29 11:09   ` [LTP] [PATCH 2/3] rtc02: reset backward 1 hour to RTC time Cyril Hrubis
2022-04-28 13:26 ` [LTP] [PATCH 3/3] rtc02: loosen the compare precision with few seconds Li Wang
2022-05-05 14:05   ` Cyril Hrubis
2022-05-08  2:22     ` Li Wang
2022-05-08  3:05       ` [LTP] [PATCH v2] " Li Wang
2022-05-08  4:19         ` Li Wang
2022-05-10 14:08         ` Cyril Hrubis
2022-05-11  1:54           ` Li Wang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220428132656.11075-3-liwang@redhat.com \
    --to=liwang@redhat.com \
    --cc=efuller@redhat.com \
    --cc=ltp@lists.linux.it \
    --cc=vkuznets@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox