1 /* unit.c unit tests driver */
6 #include <cyassl/ctaocrypt/settings.h>
9 #include <tests/unit.h>
13 char* myoptarg = NULL;
16 int main(int argc, char** argv)
22 printf("starting unit tests...\n");
25 ret = OpenNitroxDevice(CAVIUM_DIRECT, CAVIUM_DEV_ID);
27 err_sys("Cavium OpenNitroxDevice failed");
28 #endif /* HAVE_CAVIUM */
30 if (CurrentDir("tests") || CurrentDir("_build"))
32 else if (CurrentDir("Debug") || CurrentDir("Release"))
35 if ( (ret = ApiTest()) != 0) {
36 printf("api test failed with %d\n", ret);
40 if ( (ret = HashTest()) != 0){
41 printf("hash test failed with %d\n", ret);
45 #ifndef SINGLE_THREADED
46 if ( (ret = SuiteTest()) != 0){
47 printf("suite test failed with %d\n", ret);
53 CspShutdown(CAVIUM_DEV_ID);
61 void wait_tcp_ready(func_args* args)
63 #ifdef SINGLE_THREADED
65 #elif defined(_POSIX_THREADS) && !defined(__MINGW32__)
66 pthread_mutex_lock(&args->signal->mutex);
68 if (!args->signal->ready)
69 pthread_cond_wait(&args->signal->cond, &args->signal->mutex);
70 args->signal->ready = 0; /* reset */
72 pthread_mutex_unlock(&args->signal->mutex);
79 void start_thread(THREAD_FUNC fun, func_args* args, THREAD_TYPE* thread)
81 #ifdef SINGLE_THREADED
85 #elif defined(_POSIX_THREADS) && !defined(__MINGW32__)
86 pthread_create(thread, 0, fun, args);
89 *thread = (THREAD_TYPE)_beginthreadex(0, 0, fun, args, 0, 0);
94 void join_thread(THREAD_TYPE thread)
96 #ifdef SINGLE_THREADED
98 #elif defined(_POSIX_THREADS) && !defined(__MINGW32__)
99 pthread_join(thread, 0);
101 int res = WaitForSingleObject((HANDLE)thread, INFINITE);
102 assert(res == WAIT_OBJECT_0);
103 res = CloseHandle((HANDLE)thread);
109 void InitTcpReady(tcp_ready* ready)
113 #ifdef SINGLE_THREADED
114 #elif defined(_POSIX_THREADS) && !defined(__MINGW32__)
115 pthread_mutex_init(&ready->mutex, 0);
116 pthread_cond_init(&ready->cond, 0);
121 void FreeTcpReady(tcp_ready* ready)
123 #ifdef SINGLE_THREADED
125 #elif defined(_POSIX_THREADS) && !defined(__MINGW32__)
126 pthread_mutex_destroy(&ready->mutex);
127 pthread_cond_destroy(&ready->cond);