2011-12-14 21:20:46 +04:00
|
|
|
/* unit.c unit tests driver */
|
2012-09-22 00:29:04 +04:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include <config.h>
|
|
|
|
#endif
|
|
|
|
|
2013-04-10 23:17:23 +04:00
|
|
|
#include <cyassl/ctaocrypt/settings.h>
|
|
|
|
|
2011-12-14 21:20:46 +04:00
|
|
|
#include <stdio.h>
|
2012-08-07 04:14:31 +04:00
|
|
|
#include <tests/unit.h>
|
2011-12-14 21:20:46 +04:00
|
|
|
|
2012-08-03 00:41:40 +04:00
|
|
|
|
|
|
|
int myoptind = 0;
|
|
|
|
char* myoptarg = NULL;
|
|
|
|
|
|
|
|
|
2011-12-14 21:20:46 +04:00
|
|
|
int main(int argc, char** argv)
|
|
|
|
{
|
2012-08-07 04:14:31 +04:00
|
|
|
int ret;
|
2011-12-14 21:20:46 +04:00
|
|
|
|
2012-09-21 02:39:15 +04:00
|
|
|
(void)argc;
|
|
|
|
(void)argv;
|
2012-10-30 02:39:42 +04:00
|
|
|
printf("starting unit tests...\n");
|
2011-12-14 22:02:05 +04:00
|
|
|
|
2013-02-02 00:21:38 +04:00
|
|
|
#ifdef HAVE_CAVIUM
|
|
|
|
ret = OpenNitroxDevice(CAVIUM_DIRECT, CAVIUM_DEV_ID);
|
|
|
|
if (ret != 0)
|
|
|
|
err_sys("Cavium OpenNitroxDevice failed");
|
|
|
|
#endif /* HAVE_CAVIUM */
|
|
|
|
|
2014-01-29 00:22:16 +04:00
|
|
|
if (CurrentDir("tests") || CurrentDir("_build"))
|
2012-12-06 22:01:01 +04:00
|
|
|
ChangeDirBack(1);
|
2013-12-20 03:23:57 +04:00
|
|
|
else if (CurrentDir("Debug") || CurrentDir("Release"))
|
|
|
|
ChangeDirBack(3);
|
2012-12-06 22:01:01 +04:00
|
|
|
|
2012-08-07 04:14:31 +04: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 22:55:19 +04:00
|
|
|
|
2013-02-02 00:21:38 +04:00
|
|
|
#ifdef HAVE_CAVIUM
|
|
|
|
CspShutdown(CAVIUM_DEV_ID);
|
|
|
|
#endif
|
|
|
|
|
2011-12-14 21:20:46 +04:00
|
|
|
return 0;
|
|
|
|
}
|
2012-08-07 04:14:31 +04:00
|
|
|
|
|
|
|
|
|
|
|
void wait_tcp_ready(func_args* args)
|
|
|
|
{
|
2013-05-02 00:17:11 +04:00
|
|
|
#if defined(_POSIX_THREADS) && !defined(__MINGW32__)
|
2012-08-07 04:14:31 +04:00
|
|
|
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);
|
2013-05-02 00:17:11 +04:00
|
|
|
#else
|
|
|
|
(void)args;
|
2012-08-07 04:14:31 +04:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void start_thread(THREAD_FUNC fun, func_args* args, THREAD_TYPE* thread)
|
|
|
|
{
|
2013-05-02 00:17:11 +04:00
|
|
|
#if defined(_POSIX_THREADS) && !defined(__MINGW32__)
|
2012-08-07 04:14:31 +04:00
|
|
|
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)
|
|
|
|
{
|
2013-05-02 00:17:11 +04:00
|
|
|
#if defined(_POSIX_THREADS) && !defined(__MINGW32__)
|
2012-08-07 04:14:31 +04:00
|
|
|
pthread_join(thread, 0);
|
|
|
|
#else
|
2013-05-02 00:17:11 +04:00
|
|
|
int res = WaitForSingleObject((HANDLE)thread, INFINITE);
|
2012-08-07 04:14:31 +04:00
|
|
|
assert(res == WAIT_OBJECT_0);
|
2013-05-02 00:17:11 +04:00
|
|
|
res = CloseHandle((HANDLE)thread);
|
2012-08-07 04:14:31 +04:00
|
|
|
assert(res);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InitTcpReady(tcp_ready* ready)
|
|
|
|
{
|
|
|
|
ready->ready = 0;
|
2013-03-27 09:00:39 +04:00
|
|
|
ready->port = 0;
|
2013-05-02 00:17:11 +04:00
|
|
|
#if defined(_POSIX_THREADS) && !defined(__MINGW32__)
|
2012-08-07 04:14:31 +04:00
|
|
|
pthread_mutex_init(&ready->mutex, 0);
|
|
|
|
pthread_cond_init(&ready->cond, 0);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void FreeTcpReady(tcp_ready* ready)
|
|
|
|
{
|
2013-05-02 00:17:11 +04:00
|
|
|
#if defined(_POSIX_THREADS) && !defined(__MINGW32__)
|
2012-08-07 04:14:31 +04:00
|
|
|
pthread_mutex_destroy(&ready->mutex);
|
|
|
|
pthread_cond_destroy(&ready->cond);
|
2013-05-02 00:17:11 +04:00
|
|
|
#else
|
|
|
|
(void)ready;
|
2012-08-07 04:14:31 +04:00
|
|
|
#endif
|
2012-09-20 10:38:41 +04:00
|
|
|
}
|