[LTP] [PATCH 3/3] rtc02: loosen the compare precision with few seconds

Li Wang liwang@redhat.com
Thu Apr 28 15:26:56 CEST 2022


That possibly has time elapse between twice operations, especially
on VM we can't guarantee the time precisely equal, let's lose a few
seconds to make the test happy:

  tst_test.c:1433: TINFO: Timeout per run is 0h 10m 00s
  rtc02.c:66: TINFO: To set RTC date/time is: 2020-10-09 13:23:30
  rtc02.c:80: TINFO: read RTC date/time is: 2020-10-09 13:23:31
  rtc02.c:83: TFAIL: RTC SET TEST

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

diff --git a/testcases/kernel/device-drivers/rtc/rtc02.c b/testcases/kernel/device-drivers/rtc/rtc02.c
index 6198a5d5d..a008971d5 100644
--- a/testcases/kernel/device-drivers/rtc/rtc02.c
+++ b/testcases/kernel/device-drivers/rtc/rtc02.c
@@ -41,10 +41,48 @@ static char *rtctime_to_str(struct rtc_time *tm)
 
 static int rtc_tm_cmp(struct rtc_time *set_tm, struct rtc_time *read_tm)
 {
-	return !((set_tm->tm_sec == read_tm->tm_sec)
-		&& (set_tm->tm_min == read_tm->tm_min)
-		&& (set_tm->tm_hour == read_tm->tm_hour)
-		&& (set_tm->tm_mday == read_tm->tm_mday)
+	int delta = read_tm->tm_sec - set_tm->tm_sec;
+
+	/*
+	 * To handle the normal and special situations:
+	 * 1#
+	 *       set_tm:  2022-04-28 13:00:50
+	 *       read_tm: 2022-04-28 13:00:50
+	 * 2#
+	 *       set_tm:  2022-04-28 13:00:50
+	 *       read_tm: 2022-04-28 13:00:51
+	 * 3#
+	 *       set_tm:  2022-04-28 13:00:59
+	 *       read_tm: 2022-04-28 13:01:00
+	 * 4#
+	 *       set_tm:  2022-04-28 13:59:59
+	 *       read_tm: 2022-04-28 14:00:00
+	 *
+	 * Note: as we have avoided testing around the zero
+	 * clock, so it's impossible to hit situation 5#
+	 *       set_tm:  2022-04-28 23:59:59
+	 *       read_tm: 2022-04-29 00:00:00
+	 */
+
+	/* 1~3 */
+	if (set_tm->tm_hour == read_tm->tm_hour) {
+		if (set_tm->tm_min == read_tm->tm_min - 1)
+			delta += 60;
+		else if (set_tm->tm_min != read_tm->tm_min)
+			return 1;
+	}
+
+	/* 4 */
+	if ((set_tm->tm_hour == read_tm->tm_hour - 1) &&
+			(set_tm->tm_min == read_tm->tm_min + 59))
+		delta += 60;
+	else if ((set_tm->tm_hour != read_tm->tm_hour))
+		return 1;
+
+	if (delta < 0 || delta > 3)
+		return 1;
+
+	return !((set_tm->tm_mday == read_tm->tm_mday)
 		&& (set_tm->tm_mon == read_tm->tm_mon)
 		&& (set_tm->tm_year == read_tm->tm_year));
 }
-- 
2.35.1



More information about the ltp mailing list