Skip to content

Commit 0cd73ab

Browse files
Wolfram Sangalexandrebelloni
authored andcommitted
selftest: rtc: skip some tests if the alarm only supports minutes
There are alarms which have only minute-granularity. The RTC core already has a flag to describe them. Use this flag to skip tests which require the alarm to support seconds. Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com> Link: https://lore.kernel.org/r/20250218101548.6514-1-wsa+renesas@sang-engineering.com Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
1 parent c2004b6 commit 0cd73ab

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

tools/testing/selftests/rtc/rtctest.c

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ enum rtc_alarm_state {
2929
RTC_ALARM_UNKNOWN,
3030
RTC_ALARM_ENABLED,
3131
RTC_ALARM_DISABLED,
32+
RTC_ALARM_RES_MINUTE,
3233
};
3334

3435
FIXTURE(rtc) {
@@ -88,7 +89,7 @@ static void nanosleep_with_retries(long ns)
8889
}
8990
}
9091

91-
static enum rtc_alarm_state get_rtc_alarm_state(int fd)
92+
static enum rtc_alarm_state get_rtc_alarm_state(int fd, int need_seconds)
9293
{
9394
struct rtc_param param = { 0 };
9495
int rc;
@@ -103,6 +104,10 @@ static enum rtc_alarm_state get_rtc_alarm_state(int fd)
103104
if ((param.uvalue & _BITUL(RTC_FEATURE_ALARM)) == 0)
104105
return RTC_ALARM_DISABLED;
105106

107+
/* Check if alarm has desired granularity */
108+
if (need_seconds && (param.uvalue & _BITUL(RTC_FEATURE_ALARM_RES_MINUTE)))
109+
return RTC_ALARM_RES_MINUTE;
110+
106111
return RTC_ALARM_ENABLED;
107112
}
108113

@@ -227,9 +232,11 @@ TEST_F(rtc, alarm_alm_set) {
227232
SKIP(return, "Skipping test since %s does not exist", rtc_file);
228233
ASSERT_NE(-1, self->fd);
229234

230-
alarm_state = get_rtc_alarm_state(self->fd);
235+
alarm_state = get_rtc_alarm_state(self->fd, 1);
231236
if (alarm_state == RTC_ALARM_DISABLED)
232237
SKIP(return, "Skipping test since alarms are not supported.");
238+
if (alarm_state == RTC_ALARM_RES_MINUTE)
239+
SKIP(return, "Skipping test since alarms has only minute granularity.");
233240

234241
rc = ioctl(self->fd, RTC_RD_TIME, &tm);
235242
ASSERT_NE(-1, rc);
@@ -295,9 +302,11 @@ TEST_F(rtc, alarm_wkalm_set) {
295302
SKIP(return, "Skipping test since %s does not exist", rtc_file);
296303
ASSERT_NE(-1, self->fd);
297304

298-
alarm_state = get_rtc_alarm_state(self->fd);
305+
alarm_state = get_rtc_alarm_state(self->fd, 1);
299306
if (alarm_state == RTC_ALARM_DISABLED)
300307
SKIP(return, "Skipping test since alarms are not supported.");
308+
if (alarm_state == RTC_ALARM_RES_MINUTE)
309+
SKIP(return, "Skipping test since alarms has only minute granularity.");
301310

302311
rc = ioctl(self->fd, RTC_RD_TIME, &alarm.time);
303312
ASSERT_NE(-1, rc);
@@ -357,7 +366,7 @@ TEST_F_TIMEOUT(rtc, alarm_alm_set_minute, 65) {
357366
SKIP(return, "Skipping test since %s does not exist", rtc_file);
358367
ASSERT_NE(-1, self->fd);
359368

360-
alarm_state = get_rtc_alarm_state(self->fd);
369+
alarm_state = get_rtc_alarm_state(self->fd, 0);
361370
if (alarm_state == RTC_ALARM_DISABLED)
362371
SKIP(return, "Skipping test since alarms are not supported.");
363372

@@ -425,7 +434,7 @@ TEST_F_TIMEOUT(rtc, alarm_wkalm_set_minute, 65) {
425434
SKIP(return, "Skipping test since %s does not exist", rtc_file);
426435
ASSERT_NE(-1, self->fd);
427436

428-
alarm_state = get_rtc_alarm_state(self->fd);
437+
alarm_state = get_rtc_alarm_state(self->fd, 0);
429438
if (alarm_state == RTC_ALARM_DISABLED)
430439
SKIP(return, "Skipping test since alarms are not supported.");
431440

0 commit comments

Comments
 (0)