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

selftests: sync: convert to use TAP13 ksft framework

Convert test to use TAP13 ksft framework. Output after conversion:

TAP version 13
# [RUN] Testing sync framework
ok 1 [RUN] test_alloc_timeline
ok 2 [RUN] test_alloc_fence
ok 3 [RUN] test_alloc_fence_negative
ok 4 [RUN] test_fence_one_timeline_wait
ok 5 [RUN] test_fence_one_timeline_merge
ok 6 [RUN] test_fence_merge_same_fence
ok 7 [RUN] test_fence_multi_timeline_wait
ok 8 [RUN] test_stress_two_threads_shared_timeline
ok 9 [RUN] test_consumer_stress_multi_producer_single_consumer
ok 10 [RUN] test_merge_stress_random_merge
Pass 10 Fail 0 Xfail 0 Xpass 0 Skip 0
1..10

Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com>
Reviewed-by: Gustavo Padovan <gustavo.padovan@collabora.com>

+41 -34
+39 -33
tools/testing/selftests/sync/sync_test.c
··· 32 32 #include <sys/stat.h> 33 33 #include <sys/wait.h> 34 34 #include <errno.h> 35 + #include <string.h> 35 36 37 + #include "../kselftest.h" 36 38 #include "synctest.h" 37 39 38 40 static int run_test(int (*test)(void), char *name) 39 41 { 40 42 int result; 41 43 pid_t childpid; 44 + int ret; 42 45 43 46 fflush(stdout); 44 47 childpid = fork(); 45 48 46 49 if (childpid) { 47 50 waitpid(childpid, &result, 0); 48 - if (WIFEXITED(result)) 49 - return WEXITSTATUS(result); 51 + if (WIFEXITED(result)) { 52 + ret = WEXITSTATUS(result); 53 + if (!ret) 54 + ksft_test_result_pass("[RUN]\t%s\n", name); 55 + else 56 + ksft_test_result_fail("[RUN]\t%s\n", name); 57 + return ret; 58 + } 50 59 return 1; 51 60 } 52 61 53 - printf("[RUN]\tExecuting %s\n", name); 54 62 exit(test()); 55 63 } 56 64 57 - static int sync_api_supported(void) 65 + static void sync_api_supported(void) 58 66 { 59 67 struct stat sbuf; 60 68 int ret; 61 69 62 70 ret = stat("/sys/kernel/debug/sync/sw_sync", &sbuf); 63 71 if (!ret) 64 - return 0; 72 + return; 65 73 66 - if (errno == ENOENT) { 67 - printf("SKIP: Sync framework not supported by kernel\n"); 68 - exit(0); 69 - } 70 - if (errno == EACCES) { 71 - printf("SKIP: Run Sync test as root.\n"); 72 - exit(0); 73 - } 74 + if (errno == ENOENT) 75 + ksft_exit_skip("Sync framework not supported by kernel\n"); 74 76 75 - perror("stat"); 76 - exit(ret); 77 + if (errno == EACCES) 78 + ksft_exit_skip("Run Sync test as root.\n"); 77 79 80 + ksft_exit_fail_msg("stat failed on /sys/kernel/debug/sync/sw_sync: %s", 81 + strerror(errno)); 78 82 } 79 83 80 84 int main(void) 81 85 { 82 - int err = 0; 86 + int err; 83 87 84 - if (!sync_api_supported()) 85 - return 0; 88 + ksft_print_header(); 86 89 87 - printf("[RUN]\tTesting sync framework\n"); 90 + sync_api_supported(); 88 91 89 - err += RUN_TEST(test_alloc_timeline); 90 - err += RUN_TEST(test_alloc_fence); 91 - err += RUN_TEST(test_alloc_fence_negative); 92 + ksft_print_msg("[RUN]\tTesting sync framework\n"); 92 93 93 - err += RUN_TEST(test_fence_one_timeline_wait); 94 - err += RUN_TEST(test_fence_one_timeline_merge); 95 - err += RUN_TEST(test_fence_merge_same_fence); 96 - err += RUN_TEST(test_fence_multi_timeline_wait); 97 - err += RUN_TEST(test_stress_two_threads_shared_timeline); 98 - err += RUN_TEST(test_consumer_stress_multi_producer_single_consumer); 99 - err += RUN_TEST(test_merge_stress_random_merge); 94 + RUN_TEST(test_alloc_timeline); 95 + RUN_TEST(test_alloc_fence); 96 + RUN_TEST(test_alloc_fence_negative); 100 97 98 + RUN_TEST(test_fence_one_timeline_wait); 99 + RUN_TEST(test_fence_one_timeline_merge); 100 + RUN_TEST(test_fence_merge_same_fence); 101 + RUN_TEST(test_fence_multi_timeline_wait); 102 + RUN_TEST(test_stress_two_threads_shared_timeline); 103 + RUN_TEST(test_consumer_stress_multi_producer_single_consumer); 104 + RUN_TEST(test_merge_stress_random_merge); 105 + 106 + err = ksft_get_fail_cnt(); 101 107 if (err) 102 - printf("[FAIL]\tsync errors: %d\n", err); 103 - else 104 - printf("[OK]\tsync\n"); 108 + ksft_exit_fail_msg("%d out of %d sync tests failed\n", 109 + err, ksft_test_num()); 105 110 106 - return !!err; 111 + /* need this return to keep gcc happy */ 112 + return ksft_exit_pass(); 107 113 }
+2 -1
tools/testing/selftests/sync/synctest.h
··· 29 29 #define SELFTESTS_SYNCTEST_H 30 30 31 31 #include <stdio.h> 32 + #include "../kselftest.h" 32 33 33 34 #define ASSERT(cond, msg) do { \ 34 35 if (!(cond)) { \ 35 - printf("[ERROR]\t%s", (msg)); \ 36 + ksft_print_msg("[ERROR]\t%s", (msg)); \ 36 37 return 1; \ 37 38 } \ 38 39 } while (0)