Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: 61c57676035d ("selftests/timens: Add Time Namespace test for supported clocks")
Acked-by: Vincenzo Frascino <vincenzo.frascino@arm.com>
Reported-by: Vincenzo Frascino <vincenzo.frascino@arm.com>
Signed-off-by: Andrei Vagin <avagin@gmail.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>

authored by

Andrei Vagin and committed by
Shuah Khan
558ae035 5627f9cf

+24 -3
+1 -1
tools/testing/selftests/timens/clock_nanosleep.c
··· 119 119 120 120 ksft_set_plan(4); 121 121 122 - check_config_posix_timers(); 122 + check_supported_timers(); 123 123 124 124 if (unshare_timens()) 125 125 return 1;
+1 -1
tools/testing/selftests/timens/timens.c
··· 155 155 156 156 nscheck(); 157 157 158 - check_config_posix_timers(); 158 + check_supported_timers(); 159 159 160 160 ksft_set_plan(ARRAY_SIZE(clocks) * 2); 161 161
+12 -1
tools/testing/selftests/timens/timens.h
··· 14 14 #endif 15 15 16 16 static int config_posix_timers = true; 17 + static int config_alarm_timers = true; 17 18 18 - static inline void check_config_posix_timers(void) 19 + static inline void check_supported_timers(void) 19 20 { 21 + struct timespec ts; 22 + 20 23 if (timer_create(-1, 0, 0) == -1 && errno == ENOSYS) 21 24 config_posix_timers = false; 25 + 26 + if (clock_gettime(CLOCK_BOOTTIME_ALARM, &ts) == -1 && errno == EINVAL) 27 + config_alarm_timers = false; 22 28 } 23 29 24 30 static inline bool check_skip(int clockid) 25 31 { 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 + 26 37 if (config_posix_timers) 27 38 return false; 28 39
+5
tools/testing/selftests/timens/timer.c
··· 22 22 timer_t fd; 23 23 int i; 24 24 25 + if (check_skip(clockid)) 26 + return 0; 27 + 25 28 for (i = 0; i < 2; i++) { 26 29 struct sigevent sevp = {.sigev_notify = SIGEV_NONE}; 27 30 int flags = 0; ··· 76 73 struct timespec btime_now, mtime_now; 77 74 78 75 nscheck(); 76 + 77 + check_supported_timers(); 79 78 80 79 ksft_set_plan(3); 81 80
+5
tools/testing/selftests/timens/timerfd.c
··· 28 28 long long elapsed; 29 29 int fd, i; 30 30 31 + if (check_skip(clockid)) 32 + return 0; 33 + 31 34 if (tclock_gettime(clockid, &now)) 32 35 return pr_perror("clock_gettime(%d)", clockid); 33 36 ··· 83 80 struct timespec btime_now, mtime_now; 84 81 85 82 nscheck(); 83 + 84 + check_supported_timers(); 86 85 87 86 ksft_set_plan(3); 88 87