test_main.c 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488
  1. #include "pte_osal.h"
  2. #include "test.h"
  3. const char * error_string;
  4. int assertE;
  5. ///@todo: add cancellable wait for thread end for DSP/BIOS
  6. ///@todo: look at removing/changing ftime
  7. static void runBarrierTests(void)
  8. {
  9. printf("Barrier test #1\n");
  10. pthread_test_barrier1();
  11. printf("Barrier test #2\n");
  12. pthread_test_barrier2();
  13. printf("Barrier test #3\n");
  14. pthread_test_barrier3();
  15. printf("Barrier test #4\n");
  16. pthread_test_barrier4();
  17. printf("Barrier test #5\n");
  18. pthread_test_barrier5();
  19. }
  20. static void runSemTests(void)
  21. {
  22. printf("Semaphore test #1\n");
  23. pthread_test_semaphore1();
  24. printf("Semaphore test #2\n");
  25. pthread_test_semaphore2();
  26. printf("Semaphore test #3\n");
  27. pthread_test_semaphore3();
  28. printf("Semaphore test #4\n");
  29. pthread_test_semaphore4();
  30. printf("Semaphore test #4t\n");
  31. pthread_test_semaphore4t();
  32. printf("Semaphore test #5\n");
  33. pthread_test_semaphore5();
  34. printf("Semaphore test #6\n");
  35. pthread_test_semaphore6();
  36. }
  37. static void runThreadTests(void)
  38. {
  39. printf("Create test #1\n");
  40. pthread_test_create1();
  41. printf("Create test #2\n");
  42. pthread_test_create2();
  43. printf("Create test #3\n");
  44. pthread_test_create3();
  45. printf("Join test #0\n");
  46. pthread_test_join0();
  47. printf("Join test #1\n");
  48. pthread_test_join1();
  49. printf("Join test #2\n");
  50. pthread_test_join2();
  51. printf("Join test #3\n");
  52. pthread_test_join3();
  53. printf("Join test #4\n");
  54. pthread_test_join4();
  55. printf("Kill test #1\n");
  56. pthread_test_kill1();
  57. printf("Exit test #1\n");
  58. pthread_test_exit1();
  59. printf("Exit test #2\n");
  60. pthread_test_exit2();
  61. printf("Exit test #3\n");
  62. pthread_test_exit3();
  63. printf("Exit test #4\n");
  64. pthread_test_exit4();
  65. printf("Exit test #5\n");
  66. pthread_test_exit5();
  67. /* These tests can not be run in series with other tests,
  68. * as they rely on knowing what is on the reuse queue.
  69. */
  70. /*
  71. printf("Reuse test #1\n");
  72. pthread_test_reuse1();
  73. printf("Reuse test #2\n");
  74. pthread_test_reuse2();
  75. */
  76. printf("Priority test #1\n");
  77. pthread_test_priority1();
  78. printf("Priority test #2\n");
  79. pthread_test_priority2();
  80. // printf("Inherit test #1\n");
  81. // pthread_test_inherit1(); ///@todo
  82. }
  83. static void runMiscTests(void)
  84. {
  85. printf("Valid test #1\n");
  86. pthread_test_valid1();
  87. printf("Valid test #2\n");
  88. pthread_test_valid2();
  89. printf("Self test #1\n");
  90. pthread_test_self1();
  91. printf("Self test #2\n");
  92. pthread_test_self2();
  93. printf("Equal test #1\n");
  94. pthread_test_equal1();
  95. printf("Count test #1\n");
  96. pthread_test_count1();
  97. printf("Delay test #1\n");
  98. pthread_test_delay1();
  99. printf("Delay test #2\n");
  100. pthread_test_delay2();
  101. printf("Once test #1\n");
  102. pthread_test_once1();
  103. printf("Once test #2\n");
  104. pthread_test_once2();
  105. printf("Once test #3\n");
  106. pthread_test_once3();
  107. printf("Once test #4\n");
  108. pthread_test_once4();
  109. printf("TSD test #1\n");
  110. pthread_test_tsd1();
  111. printf("TSD test #2\n");
  112. pthread_test_tsd2();
  113. #ifdef THREAD_SAFE_ERRNO
  114. printf("Errno test #1\n");
  115. pthread_test_errno1();
  116. #endif // THREAD_SAFE_ERRNO
  117. printf("Detach test #1\n");
  118. pthread_test_detach1();
  119. }
  120. static void runMutexTests(void)
  121. {
  122. printf("Mutex test #1\n");
  123. pthread_test_mutex1();
  124. printf("Mutex test #1(e)\n");
  125. pthread_test_mutex1e();
  126. printf("Mutex test #1(n)\n");
  127. pthread_test_mutex1n();
  128. printf("Mutex test #1(r)\n");
  129. pthread_test_mutex1e();
  130. printf("Mutex test #2\n");
  131. pthread_test_mutex2();
  132. printf("Mutex test #2(e)\n");
  133. pthread_test_mutex2e();
  134. printf("Mutex test #2(r)\n");
  135. pthread_test_mutex2r();
  136. printf("Mutex test #3\n");
  137. pthread_test_mutex3();
  138. printf("Mutex test #3(e)\n");
  139. pthread_test_mutex3e();
  140. printf("Mutex test #3(r)\n");
  141. pthread_test_mutex3r();
  142. printf("Mutex test #4\n");
  143. pthread_test_mutex4();
  144. printf("Mutex test #5\n");
  145. pthread_test_mutex5();
  146. printf("Mutex test #6\n");
  147. pthread_test_mutex6();
  148. printf("Mutex test #6e\n");
  149. pthread_test_mutex6e();
  150. printf("Mutex test #6es\n");
  151. pthread_test_mutex6es();
  152. printf("Mutex test #6n\n");
  153. pthread_test_mutex6n();
  154. printf("Mutex test #6r\n");
  155. pthread_test_mutex6r();
  156. printf("Mutex test #6rs\n");
  157. pthread_test_mutex6rs();
  158. printf("Mutex test #6s\n");
  159. pthread_test_mutex6s();
  160. printf("Mutex test #7\n");
  161. pthread_test_mutex7();
  162. printf("Mutex test #7e\n");
  163. pthread_test_mutex7e();
  164. printf("Mutex test #7n\n");
  165. pthread_test_mutex7n();
  166. printf("Mutex test #7r\n");
  167. pthread_test_mutex7r();
  168. printf("Mutex test #8\n");
  169. pthread_test_mutex8();
  170. printf("Mutex test #8e\n");
  171. pthread_test_mutex8e();
  172. printf("Mutex test #8n\n");
  173. pthread_test_mutex8n();
  174. printf("Mutex test #8r\n");
  175. pthread_test_mutex8r();
  176. }
  177. static void runSpinTests()
  178. {
  179. printf("Spin test #1\n");
  180. pthread_test_spin1();
  181. printf("Spin test #2\n");
  182. pthread_test_spin2();
  183. printf("Spin test #3\n");
  184. pthread_test_spin3();
  185. printf("Spin test #4\n");
  186. pthread_test_spin4();
  187. }
  188. static void runCondvarTests()
  189. {
  190. printf("Condvar test #1\n");
  191. pthread_test_condvar1();
  192. printf("Condvar test #1-1\n");
  193. pthread_test_condvar1_1();
  194. printf("Condvar test #1-2\n");
  195. pthread_test_condvar1_2();
  196. printf("Condvar test #2\n");
  197. pthread_test_condvar2();
  198. printf("Condvar test #2-1\n");
  199. pthread_test_condvar2_1();
  200. printf("Condvar test #3\n");
  201. pthread_test_condvar3();
  202. printf("Condvar test #3-1\n");
  203. pthread_test_condvar3_1();
  204. printf("Condvar test #3-2\n");
  205. pthread_test_condvar3_2();
  206. printf("Condvar test #3-3\n");
  207. pthread_test_condvar3_3();
  208. printf("Condvar test #4\n");
  209. pthread_test_condvar4();
  210. printf("Condvar test #5\n");
  211. pthread_test_condvar5();
  212. printf("Condvar test #6\n");
  213. pthread_test_condvar6();
  214. printf("Condvar test #7\n");
  215. pthread_test_condvar7();
  216. printf("Condvar test #8\n");
  217. pthread_test_condvar8();
  218. printf("Condvar test #9\n");
  219. pthread_test_condvar9();
  220. }
  221. static void runStressTests()
  222. {
  223. printf("Stress test #1\n");
  224. pthread_test_stress1();
  225. }
  226. static void runRwlockTests()
  227. {
  228. printf("Rwlock test #1\n");
  229. pthread_test_rwlock1();
  230. printf("Rwlock test #2\n");
  231. pthread_test_rwlock2();
  232. printf("Rwlock test #2t\n");
  233. pthread_test_rwlock2t();
  234. printf("Rwlock test #3\n");
  235. pthread_test_rwlock3();
  236. printf("Rwlock test #3t\n");
  237. pthread_test_rwlock3t();
  238. printf("Rwlock test #4\n");
  239. pthread_test_rwlock4();
  240. printf("Rwlock test #4t\n");
  241. pthread_test_rwlock4t();
  242. printf("Rwlock test #5\n");
  243. pthread_test_rwlock5();
  244. printf("Rwlock test #5t\n");
  245. pthread_test_rwlock5t();
  246. printf("Rwlock test #6\n");
  247. pthread_test_rwlock6();
  248. printf("Rwlock test #6t\n");
  249. pthread_test_rwlock6t();
  250. printf("Rwlock test #6t2\n");
  251. pthread_test_rwlock6t2();
  252. printf("Rwlock test #7\n");
  253. pthread_test_rwlock7();
  254. printf("Rwlock test #8\n");
  255. pthread_test_rwlock8();
  256. }
  257. static void runCancelTests()
  258. {
  259. printf("Cancel test #1\n");
  260. pthread_test_cancel1();
  261. printf("Cancel test #2\n");
  262. pthread_test_cancel2();
  263. printf("Cancel test #3\n");
  264. pthread_test_cancel3();
  265. printf("Cancel test #4\n");
  266. pthread_test_cancel4();
  267. printf("Cancel test #5\n");
  268. pthread_test_cancel5();
  269. printf("Cancel test #6a\n");
  270. pthread_test_cancel6a();
  271. printf("Cancel test #6d\n");
  272. pthread_test_cancel6d();
  273. /* Cleanup only occurs for async cancellation.
  274. * If we don't support this, can't test it...
  275. */
  276. printf("Cleanup test #0\n");
  277. pthread_test_cleanup0();
  278. printf("Cleanup test #1\n");
  279. pthread_test_cleanup1();
  280. printf("Cleanup test #2\n");
  281. pthread_test_cleanup2();
  282. printf("Cleanup test #3\n");
  283. pthread_test_cleanup3();
  284. }
  285. static void runBenchTests()
  286. {
  287. printf("Benchmark test #1\n");
  288. pthread_test_bench1();
  289. printf("Benchmark test #2\n");
  290. pthread_test_bench2();
  291. printf("Benchmark test #3\n");
  292. pthread_test_bench3();
  293. printf("Benchmark test #4\n");
  294. pthread_test_bench4();
  295. }
  296. static void runExceptionTests()
  297. {
  298. printf("Exception test #1\n");
  299. pthread_test_exception1();
  300. /* This test intentially crashes the app
  301. (unhandled exception)
  302. printf("Exception test #2\n");
  303. pthread_test_exception2();
  304. */
  305. printf("Exception test #3\n");
  306. pthread_test_exception3();
  307. }
  308. void pte_test_main()
  309. {
  310. int i;
  311. if (!pthread_init())
  312. {
  313. printf("Failed to initialize pthreads library.\n");
  314. return;
  315. }
  316. printf("Running tests...\n");
  317. for (i=0;i<2;i++)
  318. {
  319. printf("=========================\n");
  320. printf(" Test iteration #%d\n\n",i);
  321. printf("=========================\n");
  322. runThreadTests();
  323. runMiscTests();
  324. runMutexTests();
  325. runSemTests();
  326. runCondvarTests();
  327. runBarrierTests();
  328. runSpinTests();
  329. runRwlockTests();
  330. runCancelTests();
  331. runExceptionTests();
  332. runBenchTests();
  333. runStressTests();
  334. }
  335. printf("Tests complete!\n");
  336. }