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