Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  *  sync test runner
0003  *  Copyright 2015-2016 Collabora Ltd.
0004  *
0005  *  Based on the implementation from the Android Open Source Project,
0006  *
0007  *  Copyright 2012 Google, Inc
0008  *
0009  *  Permission is hereby granted, free of charge, to any person obtaining a
0010  *  copy of this software and associated documentation files (the "Software"),
0011  *  to deal in the Software without restriction, including without limitation
0012  *  the rights to use, copy, modify, merge, publish, distribute, sublicense,
0013  *  and/or sell copies of the Software, and to permit persons to whom the
0014  *  Software is furnished to do so, subject to the following conditions:
0015  *
0016  *  The above copyright notice and this permission notice shall be included in
0017  *  all copies or substantial portions of the Software.
0018  *
0019  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
0020  *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
0021  *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
0022  *  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
0023  *  OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
0024  *  ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
0025  *  OTHER DEALINGS IN THE SOFTWARE.
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     /* need this return to keep gcc happy */
0113     return ksft_exit_pass();
0114 }