selftests: timers: nanosleep: adapt to kselftest framework
authorWolfram Sang <wsa+renesas@sang-engineering.com>
Wed, 13 Jul 2022 20:46:15 +0000 (22:46 +0200)
committerShuah Khan <skhan@linuxfoundation.org>
Thu, 14 Jul 2022 20:36:13 +0000 (14:36 -0600)
So we have proper counters at the end of a test, e.g.:
  # Totals: pass:4 fail:0 xfail:0 xpass:0 skip:8 error:0

Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
Acked-by: John Stultz <jstultz@google.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
tools/testing/selftests/timers/nanosleep.c

index 71b5441c2fd9f6f3abb39a9c661556b3e5e13931..df1d03516e7bbad668a7abfc63b33928180299ab 100644 (file)
@@ -133,33 +133,37 @@ int main(int argc, char **argv)
        long long length;
        int clockid, ret;
 
+       ksft_print_header();
+       ksft_set_plan(NR_CLOCKIDS);
+
        for (clockid = CLOCK_REALTIME; clockid < NR_CLOCKIDS; clockid++) {
 
                /* Skip cputime clockids since nanosleep won't increment cputime */
                if (clockid == CLOCK_PROCESS_CPUTIME_ID ||
                                clockid == CLOCK_THREAD_CPUTIME_ID ||
-                               clockid == CLOCK_HWSPECIFIC)
+                               clockid == CLOCK_HWSPECIFIC) {
+                       ksft_test_result_skip("%-31s\n", clockstring(clockid));
                        continue;
+               }
 
-               printf("Nanosleep %-31s ", clockstring(clockid));
                fflush(stdout);
 
                length = 10;
                while (length <= (NSEC_PER_SEC * 10)) {
                        ret = nanosleep_test(clockid, length);
                        if (ret == UNSUPPORTED) {
-                               printf("[UNSUPPORTED]\n");
+                               ksft_test_result_skip("%-31s\n", clockstring(clockid));
                                goto next;
                        }
                        if (ret < 0) {
-                               printf("[FAILED]\n");
-                               return ksft_exit_fail();
+                               ksft_test_result_fail("%-31s\n", clockstring(clockid));
+                               ksft_exit_fail();
                        }
                        length *= 100;
                }
-               printf("[OK]\n");
+               ksft_test_result_pass("%-31s\n", clockstring(clockid));
 next:
                ret = 0;
        }
-       return ksft_exit_pass();
+       ksft_exit_pass();
 }