0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028 #include <stdio.h>
0029 #include <unistd.h>
0030 #include <stdlib.h>
0031 #include <sys/types.h>
0032 #include <sys/stat.h>
0033 #include <sys/wait.h>
0034 #include <errno.h>
0035 #include <string.h>
0036
0037 #include "../kselftest.h"
0038 #include "synctest.h"
0039
0040 static int run_test(int (*test)(void), char *name)
0041 {
0042 int result;
0043 pid_t childpid;
0044 int ret;
0045
0046 fflush(stdout);
0047 childpid = fork();
0048
0049 if (childpid) {
0050 waitpid(childpid, &result, 0);
0051 if (WIFEXITED(result)) {
0052 ret = WEXITSTATUS(result);
0053 if (!ret)
0054 ksft_test_result_pass("[RUN]\t%s\n", name);
0055 else
0056 ksft_test_result_fail("[RUN]\t%s\n", name);
0057 return ret;
0058 }
0059 return 1;
0060 }
0061
0062 exit(test());
0063 }
0064
0065 static void sync_api_supported(void)
0066 {
0067 struct stat sbuf;
0068 int ret;
0069
0070 ret = stat("/sys/kernel/debug/sync/sw_sync", &sbuf);
0071 if (!ret)
0072 return;
0073
0074 if (errno == ENOENT)
0075 ksft_exit_skip("Sync framework not supported by kernel\n");
0076
0077 if (errno == EACCES)
0078 ksft_exit_skip("Run Sync test as root.\n");
0079
0080 ksft_exit_fail_msg("stat failed on /sys/kernel/debug/sync/sw_sync: %s",
0081 strerror(errno));
0082 }
0083
0084 int main(void)
0085 {
0086 int err;
0087
0088 ksft_print_header();
0089
0090 sync_api_supported();
0091 ksft_set_plan(3 + 7);
0092
0093 ksft_print_msg("[RUN]\tTesting sync framework\n");
0094
0095 RUN_TEST(test_alloc_timeline);
0096 RUN_TEST(test_alloc_fence);
0097 RUN_TEST(test_alloc_fence_negative);
0098
0099 RUN_TEST(test_fence_one_timeline_wait);
0100 RUN_TEST(test_fence_one_timeline_merge);
0101 RUN_TEST(test_fence_merge_same_fence);
0102 RUN_TEST(test_fence_multi_timeline_wait);
0103 RUN_TEST(test_stress_two_threads_shared_timeline);
0104 RUN_TEST(test_consumer_stress_multi_producer_single_consumer);
0105 RUN_TEST(test_merge_stress_random_merge);
0106
0107 err = ksft_get_fail_cnt();
0108 if (err)
0109 ksft_exit_fail_msg("%d out of %d sync tests failed\n",
0110 err, ksft_test_num());
0111
0112
0113 return ksft_exit_pass();
0114 }