wolfssl/tests/unit.c

96 lines
1.7 KiB
C
Raw Normal View History

2011-12-14 11:20:46 -06:00
/* unit.c unit tests driver */
2012-09-21 15:29:04 -05:00
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
2011-12-14 11:20:46 -06:00
#include <stdio.h>
2012-08-06 19:14:31 -05:00
#include <tests/unit.h>
2011-12-14 11:20:46 -06:00
2012-08-02 15:41:40 -05:00
int myoptind = 0;
char* myoptarg = NULL;
2011-12-14 11:20:46 -06:00
int main(int argc, char** argv)
{
2012-08-06 19:14:31 -05:00
int ret;
2011-12-14 11:20:46 -06:00
2012-09-20 17:39:15 -05:00
(void)argc;
(void)argv;
2012-10-29 17:39:42 -05:00
printf("starting unit tests...\n");
2011-12-14 12:02:05 -06:00
2012-08-06 19:14:31 -05:00
if ( (ret = ApiTest()) != 0) {
printf("api test failed with %d\n", ret);
return ret;
}
if ( (ret = HashTest()) != 0){
printf("hash test failed with %d\n", ret);
return ret;
}
if ( (ret = SuiteTest()) != 0){
printf("suite test failed with %d\n", ret);
return ret;
}
2011-12-14 12:55:19 -06:00
2011-12-14 11:20:46 -06:00
return 0;
}
2012-08-06 19:14:31 -05:00
void wait_tcp_ready(func_args* args)
{
#ifdef _POSIX_THREADS
pthread_mutex_lock(&args->signal->mutex);
if (!args->signal->ready)
pthread_cond_wait(&args->signal->cond, &args->signal->mutex);
args->signal->ready = 0; /* reset */
pthread_mutex_unlock(&args->signal->mutex);
#endif
}
void start_thread(THREAD_FUNC fun, func_args* args, THREAD_TYPE* thread)
{
#ifdef _POSIX_THREADS
pthread_create(thread, 0, fun, args);
return;
#else
*thread = (THREAD_TYPE)_beginthreadex(0, 0, fun, args, 0, 0);
#endif
}
void join_thread(THREAD_TYPE thread)
{
#ifdef _POSIX_THREADS
pthread_join(thread, 0);
#else
int res = WaitForSingleObject(thread, INFINITE);
assert(res == WAIT_OBJECT_0);
res = CloseHandle(thread);
assert(res);
#endif
}
void InitTcpReady(tcp_ready* ready)
{
ready->ready = 0;
#ifdef _POSIX_THREADS
pthread_mutex_init(&ready->mutex, 0);
pthread_cond_init(&ready->cond, 0);
#endif
}
void FreeTcpReady(tcp_ready* ready)
{
#ifdef _POSIX_THREADS
pthread_mutex_destroy(&ready->mutex);
pthread_cond_destroy(&ready->cond);
#endif
}