From b6d4f10222ae454f8ff2993fc5d6d6df48cee9a3 Mon Sep 17 00:00:00 2001 From: John Safranek Date: Tue, 11 Feb 2014 18:59:20 -0800 Subject: [PATCH] Reenabled examples when building single-threaded. Changed testsuite and unit tests to leave out tests cases that require threading. --- configure.ac | 1 - tests/api.c | 8 ++++++++ tests/unit.c | 25 +++++++++++++++++++----- testsuite/testsuite.c | 44 +++++++++++++++++++++++++++++++++++-------- 4 files changed, 64 insertions(+), 14 deletions(-) diff --git a/configure.ac b/configure.ac index d59587eaf..ff4b5a687 100644 --- a/configure.ac +++ b/configure.ac @@ -1422,7 +1422,6 @@ AC_ARG_ENABLE([examples], [ ENABLED_EXAMPLES=yes ] ) -AS_IF([test "x$ENABLED_SINGLETHREADED" = "xyes"], [ENABLED_EXAMPLES="no"]) AS_IF([test "x$ENABLED_FILESYSTEM" = "xno"], [ENABLED_EXAMPLES="no"]) AS_IF([test "x$ENABLED_INLINE" = "xno"], [ENABLED_EXAMPLES="no"]) # certs still have sha signatures for now diff --git a/tests/api.c b/tests/api.c index 94a232f06..efbce2d33 100644 --- a/tests/api.c +++ b/tests/api.c @@ -44,7 +44,9 @@ static int test_CyaSSL_CTX_load_verify_locations(void); #ifndef NO_RSA static int test_server_CyaSSL_new(void); static int test_client_CyaSSL_new(void); +#ifndef SINGLE_THREADED static int test_CyaSSL_read_write(void); +#endif /* SINGLE_THREADED */ #endif /* NO_RSA */ #endif /* NO_FILESYSTEM */ #ifdef HAVE_SNI @@ -107,7 +109,9 @@ int ApiTest(void) #ifndef NO_RSA test_server_CyaSSL_new(); test_client_CyaSSL_new(); +#ifndef SINGLE_THREADED test_CyaSSL_read_write(); +#endif /* SINGLE_THREADED */ #endif /* NO_RSA */ #endif /* NO_FILESYSTEM */ #ifdef HAVE_SNI @@ -892,6 +896,8 @@ int test_client_CyaSSL_new(void) } +#ifndef SINGLE_THREADED + static int test_CyaSSL_read_write(void) { /* The unit testing for read and write shall happen simutaneously, since @@ -1278,4 +1284,6 @@ void test_CyaSSL_client_server(callback_functions* client_callbacks, FreeTcpReady(&ready); } +#endif /* SINGLE_THREADED*/ + #endif /* NO_FILESYSTEM */ diff --git a/tests/unit.c b/tests/unit.c index f1926f2e9..287ad3cf7 100644 --- a/tests/unit.c +++ b/tests/unit.c @@ -42,10 +42,12 @@ int main(int argc, char** argv) return ret; } +#ifndef SINGLE_THREADED if ( (ret = SuiteTest()) != 0){ printf("suite test failed with %d\n", ret); return ret; } +#endif #ifdef HAVE_CAVIUM CspShutdown(CAVIUM_DEV_ID); @@ -55,9 +57,12 @@ int main(int argc, char** argv) } + void wait_tcp_ready(func_args* args) { -#if defined(_POSIX_THREADS) && !defined(__MINGW32__) +#ifdef SINGLE_THREADED + (void)args; +#elif defined(_POSIX_THREADS) && !defined(__MINGW32__) pthread_mutex_lock(&args->signal->mutex); if (!args->signal->ready) @@ -73,7 +78,11 @@ void wait_tcp_ready(func_args* args) void start_thread(THREAD_FUNC fun, func_args* args, THREAD_TYPE* thread) { -#if defined(_POSIX_THREADS) && !defined(__MINGW32__) +#ifdef SINGLE_THREADED + (void)fun; + (void)args; + (void)thread; +#elif defined(_POSIX_THREADS) && !defined(__MINGW32__) pthread_create(thread, 0, fun, args); return; #else @@ -84,7 +93,9 @@ void start_thread(THREAD_FUNC fun, func_args* args, THREAD_TYPE* thread) void join_thread(THREAD_TYPE thread) { -#if defined(_POSIX_THREADS) && !defined(__MINGW32__) +#ifdef SINGLE_THREADED + (void)thread; +#elif defined(_POSIX_THREADS) && !defined(__MINGW32__) pthread_join(thread, 0); #else int res = WaitForSingleObject((HANDLE)thread, INFINITE); @@ -99,7 +110,8 @@ void InitTcpReady(tcp_ready* ready) { ready->ready = 0; ready->port = 0; -#if defined(_POSIX_THREADS) && !defined(__MINGW32__) +#ifdef SINGLE_THREADED +#elif defined(_POSIX_THREADS) && !defined(__MINGW32__) pthread_mutex_init(&ready->mutex, 0); pthread_cond_init(&ready->cond, 0); #endif @@ -108,10 +120,13 @@ void InitTcpReady(tcp_ready* ready) void FreeTcpReady(tcp_ready* ready) { -#if defined(_POSIX_THREADS) && !defined(__MINGW32__) +#ifdef SINGLE_THREADED + (void)ready; +#elif defined(_POSIX_THREADS) && !defined(__MINGW32__) pthread_mutex_destroy(&ready->mutex); pthread_cond_destroy(&ready->cond); #else (void)ready; #endif } + diff --git a/testsuite/testsuite.c b/testsuite/testsuite.c index 8629f0b10..2a5ba498f 100644 --- a/testsuite/testsuite.c +++ b/testsuite/testsuite.c @@ -25,22 +25,18 @@ #include -#include #include -#include - #include "ctaocrypt/test/test.h" -#ifdef SINGLE_THREADED - #error testsuite needs threads to run, please run ctaocrypt/test, \ - and the examples/ individually -#endif +#ifndef SINGLE_THREADED + +#include +#include #include "examples/echoclient/echoclient.h" #include "examples/echoserver/echoserver.h" #include "examples/server/server.h" #include "examples/client/client.h" -#include "ctaocrypt/test/test.h" void file_test(const char* file, byte* hash); @@ -336,3 +332,35 @@ void file_test(const char* file, byte* check) } +#else /* SINGLE_THREADED */ + + +int myoptind = 0; +char* myoptarg = NULL; + + +int main(int argc, char** argv) +{ + func_args server_args; + + server_args.argc = argc; + server_args.argv = argv; + + if (CurrentDir("testsuite") || CurrentDir("_build")) + ChangeDirBack(1); + else if (CurrentDir("Debug") || CurrentDir("Release")) + ChangeDirBack(3); /* Xcode->Preferences->Locations->Locations*/ + /* Derived Data Advanced -> Custom */ + /* Relative to Workspace, Build/Products */ + /* Debug or Release */ + + ctaocrypt_test(&server_args); + if (server_args.return_code != 0) return server_args.return_code; + + printf("\nAll tests passed!\n"); + return EXIT_SUCCESS; +} + + +#endif /* SINGLE_THREADED */ +