selftests/timens: handle a case when alarm clocks are not supported
PATCH 1/1 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.
Cc Vincenzo Frascino <[email protected]>
Signed-off-by Andrei Vagin <[email protected]>
--- tools/testing/selftests/timens/clock_nanosleep.c | 2 +- tools/testing/selftests/timens/timens.c | 2 +- tools/testing/selftests/timens/timens.h | 13 ++++++++++++- 3 files changed, 14 insertions(+), 3 deletions(-)
tools/testing/selftests/timens/clock_nanosleep.c +1 -1
@@ -119,7 +119,7 @@ int main(int argc, char *argv[])ksft_set_plan (4 ); -check_config_posix_timers (); +check_supported_timers ();if (unshare_timens ())return 1 ;
tools/testing/selftests/timens/timens.c +1 -1
@@ -156,7 +156,7 @@ int main(int argc, char *argv[])nscheck (); -check_config_posix_timers (); +check_supported_timers ();ksft_set_plan (ARRAY_SIZE (clocks) *2 );
tools/testing/selftests/timens/timens.h +12 -1
@@ -14,15 +14,26 @@#endif static int config_posix_timers = true; +static int config_alarm_timers = true; -static inline void check_config_posix_timers (void ) +static inline void check_supported_timers (void ) { +struct timespec ts; +if (timer_create (-1 ,0 ,0 ) ==-1 && errno ==ENOSYS ) config_posix_timers = false; + +if (clock_gettime (CLOCK_BOOTTIME_ALARM , &ts) ==-1 && errno ==EINVAL ) + config_alarm_timers = false; }static inline bool check_skip (int clockid) { +if (!config_alarm_timers && clockid ==CLOCK_BOOTTIME_ALARM ) { +ksft_test_result_skip ("CLOCK_BOOTTIME_ALARM isn't supported\n" ); +return true; + } +if (config_posix_timers)return false;
Signature · 1 line
2.24.1
PATCH v2 1/1 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.
Cc Vincenzo Frascino <[email protected]>
Signed-off-by Andrei Vagin <[email protected]>
---
v2: fix timer.c and timerfd.c too.
tools/testing/selftests/timens/clock_nanosleep.c | 2 +- tools/testing/selftests/timens/timens.c | 2 +- tools/testing/selftests/timens/timens.h | 13 ++++++++++++- tools/testing/selftests/timens/timer.c | 5 +++++ tools/testing/selftests/timens/timerfd.c | 5 +++++ 5 files changed, 24 insertions(+), 3 deletions(-)
tools/testing/selftests/timens/clock_nanosleep.c +1 -1
@@ -119,7 +119,7 @@ int main(int argc, char *argv[])ksft_set_plan (4 ); -check_config_posix_timers (); +check_supported_timers ();if (unshare_timens ())return 1 ;
tools/testing/selftests/timens/timens.c +1 -1
@@ -155,7 +155,7 @@ int main(int argc, char *argv[])nscheck (); -check_config_posix_timers (); +check_supported_timers ();ksft_set_plan (ARRAY_SIZE (clocks) *2 );
tools/testing/selftests/timens/timens.h +12 -1
@@ -14,15 +14,26 @@#endif static int config_posix_timers = true; +static int config_alarm_timers = true; -static inline void check_config_posix_timers (void ) +static inline void check_supported_timers (void ) { +struct timespec ts; +if (timer_create (-1 ,0 ,0 ) ==-1 && errno ==ENOSYS ) config_posix_timers = false; + +if (clock_gettime (CLOCK_BOOTTIME_ALARM , &ts) ==-1 && errno ==EINVAL ) + config_alarm_timers = false; }static inline bool check_skip (int clockid) { +if (!config_alarm_timers && clockid ==CLOCK_BOOTTIME_ALARM ) { +ksft_test_result_skip ("CLOCK_BOOTTIME_ALARM isn't supported\n" ); +return true; + } +if (config_posix_timers)return false;
tools/testing/selftests/timens/timer.c +5 -0
@@ -22,6 +22,9 @@ int run_test(int clockid, struct timespec now)timer_t fd;int i; +if (check_skip (clockid)) +return 0 ; +for (i =0 ; i <2 ; i++) {struct sigevent sevp = {.sigev_notify =SIGEV_NONE };int flags =0 ;
@@ -74,6 +77,8 @@ int main(int argc, char *argv[])nscheck (); +check_supported_timers (); +ksft_set_plan (3 );clock_gettime (CLOCK_MONOTONIC , &mtime_now);
tools/testing/selftests/timens/timerfd.c +5 -0
@@ -28,6 +28,9 @@ int run_test(int clockid, struct timespec now)long long elapsed;int fd, i; +if (check_skip (clockid)) +return 0 ; +if (tclock_gettime (clockid, &now))return pr_perror ("clock_gettime(%d)" , clockid);
@@ -81,6 +84,8 @@ int main(int argc, char *argv[])nscheck (); +check_supported_timers (); +ksft_set_plan (3 );clock_gettime (CLOCK_MONOTONIC , &mtime_now);
Signature · 1 line
2.24.1
Hi Andrei,
thanks for this.
Quoted 3 lines · Andrei Vagin
This can happen if a testing node doesn't have RTC (real time clock) hardware or it doesn't support alarms.
Could you please add the "Reported-by:" tag and the "Fixes:" one?
With this:
Quoted 67 lines
Cc Vincenzo Frascino <[email protected]>Signed-off-by Andrei Vagin <[email protected]>--- tools/testing/selftests/timens/clock_nanosleep.c | 2 +- tools/testing/selftests/timens/timens.c | 2 +- tools/testing/selftests/timens/timens.h | 13 ++++++++++++- 3 files changed, 14 insertions(+), 3 deletions(-)tools/testing/selftests/timens/clock_nanosleep.c +1
-1@@ -119,7 +119,7 @@ int main(int argc, char *argv[])ksft_set_plan (4 ); -check_config_posix_timers (); +check_supported_timers ();if (unshare_timens ())return 1 ;tools/testing/selftests/timens/timens.c +1
-1@@ -156,7 +156,7 @@ int main(int argc, char *argv[])nscheck (); -check_config_posix_timers (); +check_supported_timers ();ksft_set_plan (ARRAY_SIZE (clocks) *2 );tools/testing/selftests/timens/timens.h +12
-1@@ -14,15 +14,26 @@#endif static int config_posix_timers = true; +static int config_alarm_timers = true; -static inline void check_config_posix_timers (void ) +static inline void check_supported_timers (void ) { +struct timespec ts; +if (timer_create (-1 ,0 ,0 ) ==-1 && errno ==ENOSYS ) config_posix_timers = false; + +if (clock_gettime (CLOCK_BOOTTIME_ALARM , &ts) ==-1 && errno ==EINVAL ) + config_alarm_timers = false; }static inline bool check_skip (int clockid) { +if (!config_alarm_timers && clockid ==CLOCK_BOOTTIME_ALARM ) { +ksft_test_result_skip ("CLOCK_BOOTTIME_ALARM isn't supported\n" ); +return true; + } +if (config_posix_timers)return false;
Signature · 2 lines
Regards, Vincenzo