Skip to content

Commit 558ae03

Browse files
avaginshuahkh
authored andcommitted
selftests/timens: handle a case when alarm clocks are not supported
This can happen if a testing node doesn't have RTC (real time clock) hardware or it doesn't support alarms. Fixes: 61c5767 ("selftests/timens: Add Time Namespace test for supported clocks") Acked-by: Vincenzo Frascino <[email protected]> Reported-by: Vincenzo Frascino <[email protected]> Signed-off-by: Andrei Vagin <[email protected]> Signed-off-by: Shuah Khan <[email protected]>
1 parent 5627f9c commit 558ae03

File tree

5 files changed

+24
-3
lines changed

5 files changed

+24
-3
lines changed

tools/testing/selftests/timens/clock_nanosleep.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ int main(int argc, char *argv[])
119119

120120
ksft_set_plan(4);
121121

122-
check_config_posix_timers();
122+
check_supported_timers();
123123

124124
if (unshare_timens())
125125
return 1;

tools/testing/selftests/timens/timens.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ int main(int argc, char *argv[])
155155

156156
nscheck();
157157

158-
check_config_posix_timers();
158+
check_supported_timers();
159159

160160
ksft_set_plan(ARRAY_SIZE(clocks) * 2);
161161

tools/testing/selftests/timens/timens.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,26 @@
1414
#endif
1515

1616
static int config_posix_timers = true;
17+
static int config_alarm_timers = true;
1718

18-
static inline void check_config_posix_timers(void)
19+
static inline void check_supported_timers(void)
1920
{
21+
struct timespec ts;
22+
2023
if (timer_create(-1, 0, 0) == -1 && errno == ENOSYS)
2124
config_posix_timers = false;
25+
26+
if (clock_gettime(CLOCK_BOOTTIME_ALARM, &ts) == -1 && errno == EINVAL)
27+
config_alarm_timers = false;
2228
}
2329

2430
static inline bool check_skip(int clockid)
2531
{
32+
if (!config_alarm_timers && clockid == CLOCK_BOOTTIME_ALARM) {
33+
ksft_test_result_skip("CLOCK_BOOTTIME_ALARM isn't supported\n");
34+
return true;
35+
}
36+
2637
if (config_posix_timers)
2738
return false;
2839

tools/testing/selftests/timens/timer.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ int run_test(int clockid, struct timespec now)
2222
timer_t fd;
2323
int i;
2424

25+
if (check_skip(clockid))
26+
return 0;
27+
2528
for (i = 0; i < 2; i++) {
2629
struct sigevent sevp = {.sigev_notify = SIGEV_NONE};
2730
int flags = 0;
@@ -74,6 +77,8 @@ int main(int argc, char *argv[])
7477

7578
nscheck();
7679

80+
check_supported_timers();
81+
7782
ksft_set_plan(3);
7883

7984
clock_gettime(CLOCK_MONOTONIC, &mtime_now);

tools/testing/selftests/timens/timerfd.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ int run_test(int clockid, struct timespec now)
2828
long long elapsed;
2929
int fd, i;
3030

31+
if (check_skip(clockid))
32+
return 0;
33+
3134
if (tclock_gettime(clockid, &now))
3235
return pr_perror("clock_gettime(%d)", clockid);
3336

@@ -81,6 +84,8 @@ int main(int argc, char *argv[])
8184

8285
nscheck();
8386

87+
check_supported_timers();
88+
8489
ksft_set_plan(3);
8590

8691
clock_gettime(CLOCK_MONOTONIC, &mtime_now);

0 commit comments

Comments
 (0)