]> git.sur5r.net Git - freertos/blob - FreeRTOS-Plus/Source/CyaSSL/tests/unit.c
Update CyaSSL to latest version.
[freertos] / FreeRTOS-Plus / Source / CyaSSL / tests / unit.c
1 /* unit.c unit tests driver */
2 #ifdef HAVE_CONFIG_H
3     #include <config.h>
4 #endif
5
6 #include <cyassl/ctaocrypt/settings.h>
7
8 #include <stdio.h>
9 #include <tests/unit.h>
10
11
12 int myoptind = 0;
13 char* myoptarg = NULL;
14
15
16 int main(int argc, char** argv)
17 {
18     int ret;
19
20     (void)argc;
21     (void)argv;
22     printf("starting unit tests...\n");
23
24 #ifdef HAVE_CAVIUM
25     ret = OpenNitroxDevice(CAVIUM_DIRECT, CAVIUM_DEV_ID);
26     if (ret != 0)
27         err_sys("Cavium OpenNitroxDevice failed");
28 #endif /* HAVE_CAVIUM */
29
30     if (CurrentDir("tests") || CurrentDir("_build"))
31         ChangeDirBack(1);
32     else if (CurrentDir("Debug") || CurrentDir("Release"))
33         ChangeDirBack(3);
34
35     if ( (ret = ApiTest()) != 0) {
36         printf("api test failed with %d\n", ret);
37         return ret;
38     }
39
40     if ( (ret = HashTest()) != 0){
41         printf("hash test failed with %d\n", ret);
42         return ret;
43     }
44
45 #ifndef SINGLE_THREADED
46     if ( (ret = SuiteTest()) != 0){
47         printf("suite test failed with %d\n", ret);
48         return ret;
49     }
50 #endif
51
52 #ifdef HAVE_CAVIUM
53         CspShutdown(CAVIUM_DEV_ID);
54 #endif
55
56     return 0;
57 }
58
59
60
61 void wait_tcp_ready(func_args* args)
62 {
63 #ifdef SINGLE_THREADED
64     (void)args;
65 #elif defined(_POSIX_THREADS) && !defined(__MINGW32__)
66     pthread_mutex_lock(&args->signal->mutex);
67     
68     if (!args->signal->ready)
69         pthread_cond_wait(&args->signal->cond, &args->signal->mutex);
70     args->signal->ready = 0; /* reset */
71
72     pthread_mutex_unlock(&args->signal->mutex);
73 #else
74     (void)args;
75 #endif
76 }
77
78
79 void start_thread(THREAD_FUNC fun, func_args* args, THREAD_TYPE* thread)
80 {
81 #ifdef SINGLE_THREADED
82     (void)fun;
83     (void)args;
84     (void)thread;
85 #elif defined(_POSIX_THREADS) && !defined(__MINGW32__)
86     pthread_create(thread, 0, fun, args);
87     return;
88 #else
89     *thread = (THREAD_TYPE)_beginthreadex(0, 0, fun, args, 0, 0);
90 #endif
91 }
92
93
94 void join_thread(THREAD_TYPE thread)
95 {
96 #ifdef SINGLE_THREADED
97     (void)thread;
98 #elif defined(_POSIX_THREADS) && !defined(__MINGW32__)
99     pthread_join(thread, 0);
100 #else
101     int res = WaitForSingleObject((HANDLE)thread, INFINITE);
102     assert(res == WAIT_OBJECT_0);
103     res = CloseHandle((HANDLE)thread);
104     assert(res);
105 #endif
106 }
107
108
109 void InitTcpReady(tcp_ready* ready)
110 {
111     ready->ready = 0;
112     ready->port = 0;
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);
117 #endif
118 }
119
120
121 void FreeTcpReady(tcp_ready* ready)
122 {
123 #ifdef SINGLE_THREADED
124     (void)ready;
125 #elif defined(_POSIX_THREADS) && !defined(__MINGW32__)
126     pthread_mutex_destroy(&ready->mutex);
127     pthread_cond_destroy(&ready->cond);
128 #else
129     (void)ready;
130 #endif
131 }
132