unit.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /* unit.c unit tests driver */
  2. #ifdef HAVE_CONFIG_H
  3. #include <config.h>
  4. #endif
  5. #include <cyassl/ctaocrypt/settings.h>
  6. #include <stdio.h>
  7. #include <tests/unit.h>
  8. int myoptind = 0;
  9. char* myoptarg = NULL;
  10. int main(int argc, char** argv)
  11. {
  12. int ret;
  13. (void)argc;
  14. (void)argv;
  15. printf("starting unit tests...\n");
  16. #ifdef HAVE_CAVIUM
  17. ret = OpenNitroxDevice(CAVIUM_DIRECT, CAVIUM_DEV_ID);
  18. if (ret != 0)
  19. err_sys("Cavium OpenNitroxDevice failed");
  20. #endif /* HAVE_CAVIUM */
  21. if (CurrentDir("tests"))
  22. ChangeDirBack(1);
  23. else if (CurrentDir("build"))
  24. ChangeDirBack(2);
  25. if ( (ret = ApiTest()) != 0) {
  26. printf("api test failed with %d\n", ret);
  27. return ret;
  28. }
  29. if ( (ret = HashTest()) != 0){
  30. printf("hash test failed with %d\n", ret);
  31. return ret;
  32. }
  33. if ( (ret = SuiteTest()) != 0){
  34. printf("suite test failed with %d\n", ret);
  35. return ret;
  36. }
  37. #ifdef HAVE_CAVIUM
  38. CspShutdown(CAVIUM_DEV_ID);
  39. #endif
  40. return 0;
  41. }
  42. void wait_tcp_ready(func_args* args)
  43. {
  44. #if defined(_POSIX_THREADS) && !defined(__MINGW32__)
  45. pthread_mutex_lock(&args->signal->mutex);
  46. if (!args->signal->ready)
  47. pthread_cond_wait(&args->signal->cond, &args->signal->mutex);
  48. args->signal->ready = 0; /* reset */
  49. pthread_mutex_unlock(&args->signal->mutex);
  50. #else
  51. (void)args;
  52. #endif
  53. }
  54. void start_thread(THREAD_FUNC fun, func_args* args, THREAD_TYPE* thread)
  55. {
  56. #if defined(_POSIX_THREADS) && !defined(__MINGW32__)
  57. pthread_create(thread, 0, fun, args);
  58. return;
  59. #else
  60. *thread = (THREAD_TYPE)_beginthreadex(0, 0, fun, args, 0, 0);
  61. #endif
  62. }
  63. void join_thread(THREAD_TYPE thread)
  64. {
  65. #if defined(_POSIX_THREADS) && !defined(__MINGW32__)
  66. pthread_join(thread, 0);
  67. #else
  68. int res = WaitForSingleObject((HANDLE)thread, INFINITE);
  69. assert(res == WAIT_OBJECT_0);
  70. res = CloseHandle((HANDLE)thread);
  71. assert(res);
  72. #endif
  73. }
  74. void InitTcpReady(tcp_ready* ready)
  75. {
  76. ready->ready = 0;
  77. ready->port = 0;
  78. #if defined(_POSIX_THREADS) && !defined(__MINGW32__)
  79. pthread_mutex_init(&ready->mutex, 0);
  80. pthread_cond_init(&ready->cond, 0);
  81. #endif
  82. }
  83. void FreeTcpReady(tcp_ready* ready)
  84. {
  85. #if defined(_POSIX_THREADS) && !defined(__MINGW32__)
  86. pthread_mutex_destroy(&ready->mutex);
  87. pthread_cond_destroy(&ready->cond);
  88. #else
  89. (void)ready;
  90. #endif
  91. }