sync_test.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*
  2. * sync test runner
  3. * Copyright 2015-2016 Collabora Ltd.
  4. *
  5. * Based on the implementation from the Android Open Source Project,
  6. *
  7. * Copyright 2012 Google, Inc
  8. *
  9. * Permission is hereby granted, free of charge, to any person obtaining a
  10. * copy of this software and associated documentation files (the "Software"),
  11. * to deal in the Software without restriction, including without limitation
  12. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  13. * and/or sell copies of the Software, and to permit persons to whom the
  14. * Software is furnished to do so, subject to the following conditions:
  15. *
  16. * The above copyright notice and this permission notice shall be included in
  17. * all copies or substantial portions of the Software.
  18. *
  19. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  20. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  21. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  22. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
  23. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  24. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  25. * OTHER DEALINGS IN THE SOFTWARE.
  26. */
  27. #include <stdio.h>
  28. #include <unistd.h>
  29. #include <stdlib.h>
  30. #include <sys/types.h>
  31. #include <sys/stat.h>
  32. #include <sys/wait.h>
  33. #include <errno.h>
  34. #include <string.h>
  35. #include "../kselftest.h"
  36. #include "synctest.h"
  37. static int run_test(int (*test)(void), char *name)
  38. {
  39. int result;
  40. pid_t childpid;
  41. int ret;
  42. fflush(stdout);
  43. childpid = fork();
  44. if (childpid) {
  45. waitpid(childpid, &result, 0);
  46. if (WIFEXITED(result)) {
  47. ret = WEXITSTATUS(result);
  48. if (!ret)
  49. ksft_test_result_pass("[RUN]\t%s\n", name);
  50. else
  51. ksft_test_result_fail("[RUN]\t%s\n", name);
  52. return ret;
  53. }
  54. return 1;
  55. }
  56. exit(test());
  57. }
  58. static void sync_api_supported(void)
  59. {
  60. struct stat sbuf;
  61. int ret;
  62. ret = stat("/sys/kernel/debug/sync/sw_sync", &sbuf);
  63. if (!ret)
  64. return;
  65. if (errno == ENOENT)
  66. ksft_exit_skip("Sync framework not supported by kernel\n");
  67. if (errno == EACCES)
  68. ksft_exit_skip("Run Sync test as root.\n");
  69. ksft_exit_fail_msg("stat failed on /sys/kernel/debug/sync/sw_sync: %s",
  70. strerror(errno));
  71. }
  72. int main(void)
  73. {
  74. int err;
  75. ksft_print_header();
  76. sync_api_supported();
  77. ksft_print_msg("[RUN]\tTesting sync framework\n");
  78. RUN_TEST(test_alloc_timeline);
  79. RUN_TEST(test_alloc_fence);
  80. RUN_TEST(test_alloc_fence_negative);
  81. RUN_TEST(test_fence_one_timeline_wait);
  82. RUN_TEST(test_fence_one_timeline_merge);
  83. RUN_TEST(test_fence_merge_same_fence);
  84. RUN_TEST(test_fence_multi_timeline_wait);
  85. RUN_TEST(test_stress_two_threads_shared_timeline);
  86. RUN_TEST(test_consumer_stress_multi_producer_single_consumer);
  87. RUN_TEST(test_merge_stress_random_merge);
  88. err = ksft_get_fail_cnt();
  89. if (err)
  90. ksft_exit_fail_msg("%d out of %d sync tests failed\n",
  91. err, ksft_test_num());
  92. /* need this return to keep gcc happy */
  93. return ksft_exit_pass();
  94. }