selftests/timens: handle a case when alarm clocks are not supported
authorAndrei Vagin <avagin@gmail.com>
Thu, 21 May 2020 07:52:52 +0000 (00:52 -0700)
committerShuah Khan <skhan@linuxfoundation.org>
Fri, 22 May 2020 19:29:55 +0000 (13:29 -0600)
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>
tools/testing/selftests/timens/clock_nanosleep.c
tools/testing/selftests/timens/timens.c
tools/testing/selftests/timens/timens.h
tools/testing/selftests/timens/timer.c
tools/testing/selftests/timens/timerfd.c

index 8e7b7c72ef65f68d9af273c5a553c3530e90f8c1..72d41b955fb2263ae74c34b446fb322d1bd50c6a 100644 (file)
@@ -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;
index 098be7c83be3e9de4e37f4bc64241949f2be28c4..52b6a1185f52a2dde0ba87a6cfb7ff31cda2ca8a 100644 (file)
@@ -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);
 
index e09e7e39bc52fad3581923b33505422e68a1691e..d4fc52d4714627d3b8d4a9de9526d4944e9e6d8e 100644 (file)
 #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;
 
index 96dba11ebe446a971f247ebcea01acf6880e6fe8..5e7f0051bd7be1896ddf8ee181b8225138c6c6c2 100644 (file)
@@ -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);
index eff1ec5ff215b7ff442736f3eb92fc4ce64a774f..9edd43d6b2c1334eb9638180755d321f1ac3c94b 100644 (file)
@@ -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);