diff --git a/examples/client/client.c b/examples/client/client.c index 5a2cdd47..19cc942c 100644 --- a/examples/client/client.c +++ b/examples/client/client.c @@ -19,9 +19,6 @@ */ -#define SINGLE_THREADED - /* The client doesn't use threading. */ - #include #include #include "examples/client/client.h" @@ -33,26 +30,18 @@ const char testString[] = "Hello, wolfSSH!"; -#ifndef USE_WINDOWS_API - static struct termios originalTerm; -#else - static DWORD originalTerm; -#endif - -static int InitEcho(void) -{ -#ifndef USE_WINDOWS_API - return tcgetattr(STDIN_FILENO, &originalTerm); -#else - HANDLE stdinHandle = GetStdHandle(STD_INPUT_HANDLE); - return (GetConsoleMode(stdinHandle, &originalTerm) == 0); -#endif -} - - static int SetEcho(int on) { #ifndef USE_WINDOWS_API + static int echoInit = 0; + static struct termios originalTerm; + if (!echoInit) { + if (tcgetattr(STDIN_FILENO, &originalTerm) != 0) { + printf("Couldn't get the original terminal settings.\n"); + return -1; + } + echoInit = 1; + } if (on) { if (tcsetattr(STDIN_FILENO, TCSANOW, &originalTerm) != 0) { printf("Couldn't restore the terminal settings.\n"); @@ -72,7 +61,16 @@ static int SetEcho(int on) } } #else + static int echoInit = 0; + static DWORD originalTerm; HANDLE stdinHandle = GetStdHandle(STD_INPUT_HANDLE); + if (!echoInit) { + if (GetConsoleMode(stdinHandle, &originalTerm) == 0) { + printf("Couldn't get the original terminal settings.\n"); + return -1; + } + echoInit = 1; + } if (on) { if (SetConsoleMode(stdinHandle, originalTerm) == 0) { printf("Couldn't restore the terminal settings.\n"); @@ -208,7 +206,10 @@ THREAD_RETURN WOLFSSH_THREAD client_test(void* args) if (ctx == NULL) err_sys("Couldn't create wolfSSH client context."); - wolfSSH_SetUserAuth(ctx, wsUserAuth); + if (((func_args*)args)->user_auth == NULL) + wolfSSH_SetUserAuth(ctx, wsUserAuth); + else + wolfSSH_SetUserAuth(ctx, ((func_args*)args)->user_auth); ssh = wolfSSH_new(ctx); if (ssh == NULL) @@ -267,12 +268,10 @@ THREAD_RETURN WOLFSSH_THREAD client_test(void* args) args.argc = argc; args.argv = argv; args.return_code = 0; + args.user_auth = NULL; WSTARTTCP(); - if (InitEcho() != 0) - err_sys("Couldn't initialize terminal."); - #ifdef DEBUG_WOLFSSH wolfSSH_Debugging_ON(); #endif @@ -280,9 +279,7 @@ THREAD_RETURN WOLFSSH_THREAD client_test(void* args) wolfSSH_Init(); ChangeToWolfSshRoot(); - #ifndef NO_WOLFSSH_CLIENT - client_test(&args); - #endif /* NO_WOLFSSH_CLIENT */ + client_test(&args); wolfSSH_Cleanup(); diff --git a/examples/echoserver/echoserver.c b/examples/echoserver/echoserver.c index b9ec8659..3a04dd96 100644 --- a/examples/echoserver/echoserver.c +++ b/examples/echoserver/echoserver.c @@ -461,42 +461,68 @@ static int wsUserAuth(byte authType, static void ShowUsage(void) { printf("echoserver %s\n", LIBWOLFSSH_VERSION_STRING); - printf("-h Help, print this usage\n"); - printf("-m Allow multiple connections\n"); - printf("-e Use ECC private key\n"); + printf(" -? display this help and exit\n"); + printf(" -1 exit after single (one) connection\n"); + printf(" -e use ECC private key\n"); + printf(" -p port to connect on, default %d\n", wolfSshPort); +} + + +static void SignalTcpReady(func_args* serverArgs, word16 port) +{ +#if defined(_POSIX_THREADS) && defined(NO_MAIN_DRIVER) && !defined(__MINGW32__) + tcp_ready* ready = serverArgs->signal; + pthread_mutex_lock(&ready->mutex); + ready->ready = 1; + ready->port = port; + pthread_cond_signal(&ready->cond); + pthread_mutex_unlock(&ready->mutex); +#else + (void)serverArgs; + (void)port; +#endif } THREAD_RETURN WOLFSSH_THREAD echoserver_test(void* args) { + func_args* serverArgs = (func_args*)args; WOLFSSH_CTX* ctx = NULL; PwMapList pwMapList; SOCKET_T listenFd = 0; word32 defaultHighwater = EXAMPLE_HIGHWATER_MARK; word32 threadCount = 0; - int multipleConnections = 0; + int multipleConnections = 1; int useEcc = 0; char ch; word16 port = wolfSshPort; - int argc = ((func_args*)args)->argc; - char** argv = ((func_args*)args)->argv; - ((func_args*)args)->return_code = 0; + int argc = serverArgs->argc; + char** argv = serverArgs->argv; + serverArgs->return_code = 0; - while ((ch = mygetopt(argc, argv, "hme")) != -1) { + while ((ch = mygetopt(argc, argv, "?1ep:")) != -1) { switch (ch) { - case 'h' : + case '?' : ShowUsage(); exit(EXIT_SUCCESS); - case 'm' : - multipleConnections = 1; + case '1': + multipleConnections = 0; break; case 'e' : useEcc = 1; break; + case 'p': + port = (word16)atoi(myoptarg); + #if !defined(NO_MAIN_DRIVER) || defined(USE_WINDOWS_API) + if (port == 0) + err_sys("port number cannot be 0"); + #endif + break; + default: ShowUsage(); exit(MY_EX_USAGE); @@ -516,7 +542,10 @@ THREAD_RETURN WOLFSSH_THREAD echoserver_test(void* args) } memset(&pwMapList, 0, sizeof(pwMapList)); - wolfSSH_SetUserAuth(ctx, wsUserAuth); + if (serverArgs->user_auth == NULL) + wolfSSH_SetUserAuth(ctx, wsUserAuth); + else + wolfSSH_SetUserAuth(ctx, ((func_args*)args)->user_auth); wolfSSH_CTX_SetBanner(ctx, echoserverBanner); { @@ -556,7 +585,6 @@ THREAD_RETURN WOLFSSH_THREAD echoserver_test(void* args) SOCKET_T clientFd = 0; SOCKADDR_IN_T clientAddr; socklen_t clientAddrSz = sizeof(clientAddr); - THREAD_TYPE thread; WOLFSSH* ssh; thread_ctx_t* threadCtx; @@ -578,6 +606,8 @@ THREAD_RETURN WOLFSSH_THREAD echoserver_test(void* args) wolfSSH_SetHighwater(ssh, defaultHighwater); } + SignalTcpReady(serverArgs, port); + clientFd = accept(listenFd, (struct sockaddr*)&clientAddr, &clientAddrSz); if (clientFd == -1) @@ -589,12 +619,7 @@ THREAD_RETURN WOLFSSH_THREAD echoserver_test(void* args) threadCtx->fd = clientFd; threadCtx->id = threadCount++; - start_thread(server_worker, threadCtx, &thread); - - if (multipleConnections) - detach_thread(thread); - else - join_thread(thread); + server_worker(threadCtx); } while (multipleConnections); @@ -617,16 +642,17 @@ THREAD_RETURN WOLFSSH_THREAD echoserver_test(void* args) args.argc = argc; args.argv = argv; args.return_code = 0; + args.user_auth = NULL; WSTARTTCP(); - ChangeToWolfSshRoot(); #ifdef DEBUG_WOLFSSH wolfSSH_Debugging_ON(); #endif wolfSSH_Init(); + ChangeToWolfSshRoot(); echoserver_test(&args); wolfSSH_Cleanup(); diff --git a/ide/winvs/include.am b/ide/winvs/include.am index c4b755b1..8da37685 100644 --- a/ide/winvs/include.am +++ b/ide/winvs/include.am @@ -14,3 +14,5 @@ EXTRA_DIST+= ide/winvs/client/client.vcxproj EXTRA_DIST+= ide/winvs/client/client.vcxproj.user EXTRA_DIST+= ide/winvs/echoserver/echoserver.vcxproj EXTRA_DIST+= ide/winvs/echoserver/echoserver.vcxproj.user +EXTRA_DIST+= ide/winvs/testsuite/testsuite.vcxproj +EXTRA_DIST+= ide/winvs/testsuite/testsuite.vcxproj.user diff --git a/ide/winvs/testsuite/testsuite.vcxproj b/ide/winvs/testsuite/testsuite.vcxproj new file mode 100644 index 00000000..01d379e1 --- /dev/null +++ b/ide/winvs/testsuite/testsuite.vcxproj @@ -0,0 +1,336 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + DLL Debug + Win32 + + + DLL Debug + x64 + + + DLL Release + Win32 + + + DLL Release + x64 + + + Release + Win32 + + + Release + x64 + + + + + + + + + + {7c2ccf0d-a155-4914-bd1c-9a47c0530e65} + + + + {BD09DA06-6D2E-4FB0-AE39-1BAE9FDAA9DD} + Win32Proj + testsuite + + + + Application + true + v110 + Unicode + + + Application + true + v110 + Unicode + + + Application + true + v110 + Unicode + + + Application + true + v110 + Unicode + + + Application + false + v110 + true + Unicode + + + Application + false + v110 + true + Unicode + + + Application + false + v110 + true + Unicode + + + Application + false + v110 + true + Unicode + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + false + $(Configuration)\$(Platform)\obj\ + $(SolutionDir)$(Configuration)\$(Platform)\ + + + false + $(Configuration)\$(Platform)\obj\ + $(SolutionDir)$(Configuration)\$(Platform)\ + + + false + $(Configuration)\$(Platform)\obj\ + $(SolutionDir)$(Configuration)\$(Platform)\ + + + false + $(Configuration)\$(Platform)\obj\ + $(SolutionDir)$(Configuration)\$(Platform)\ + + + false + $(SolutionDir)$(Configuration)\$(Platform)\ + $(Configuration)\$(Platform)\obj\ + + + false + $(SolutionDir)$(Configuration)\$(Platform)\ + $(Configuration)\$(Platform)\obj\ + + + false + $(SolutionDir)$(Configuration)\$(Platform)\ + $(Configuration)\$(Platform)\obj\ + + + false + $(SolutionDir)$(Configuration)\$(Platform)\ + $(Configuration)\$(Platform)\obj\ + + + + + + Level3 + Disabled + WIN32;_DEBUG;_CONSOLE;WOLFSSL_USER_SETTINGS;NO_MAIN_DRIVER;%(PreprocessorDefinitions) + ..;..\..\..;$(wolfCryptDir);%(AdditionalIncludeDirectories) + ProgramDatabase + + + Console + true + wolfssl.lib;ws2_32.lib;%(AdditionalDependencies) + msvcrt.lib + $(wolfCryptDebug32) + + + + + + + Level3 + Disabled + WIN32;_DEBUG;_CONSOLE;WOLFSSL_USER_SETTINGS;NO_MAIN_DRIVER;%(PreprocessorDefinitions) + ..;..\..\..;$(wolfCryptDir);%(AdditionalIncludeDirectories) + ProgramDatabase + + + Console + true + wolfssl.lib;ws2_32.lib;%(AdditionalDependencies) + msvcrt.lib + $(wolfCryptDllDebug32) + + + + + + + Level3 + Disabled + WIN32;_DEBUG;_CONSOLE;WOLFSSL_USER_SETTINGS;NO_MAIN_DRIVER;%(PreprocessorDefinitions) + ..;..\..\..;$(wolfCryptDir);%(AdditionalIncludeDirectories) + ProgramDatabase + + + Console + true + wolfssl.lib;ws2_32.lib;%(AdditionalDependencies) + msvcrt.lib + $(wolfCryptDebug64) + + + + + + + Level3 + Disabled + WIN32;_DEBUG;_CONSOLE;WOLFSSL_USER_SETTINGS;NO_MAIN_DRIVER;%(PreprocessorDefinitions) + ..;..\..\..;$(wolfCryptDir);%(AdditionalIncludeDirectories) + ProgramDatabase + + + Console + true + wolfssl.lib;ws2_32.lib;%(AdditionalDependencies) + msvcrt.lib + $(wolfCryptDllDebug64) + + + + + Level3 + + + MaxSpeed + true + true + WIN32;NDEBUG;_CONSOLE;WOLFSSL_USER_SETTINGS;NO_MAIN_DRIVER;%(PreprocessorDefinitions) + ..;..\..\..;$(wolfCryptDir);%(AdditionalIncludeDirectories) + + + Console + true + wolfssl.lib;ws2_32.lib;%(AdditionalDependencies) + true + true + $(wolfCryptRelease32) + + + + + Level3 + + + MaxSpeed + true + true + WIN32;NDEBUG;_CONSOLE;WOLFSSL_USER_SETTINGS;NO_MAIN_DRIVER;%(PreprocessorDefinitions) + ..;..\..\..;$(wolfCryptDir);%(AdditionalIncludeDirectories) + + + Console + true + wolfssl.lib;ws2_32.lib;%(AdditionalDependencies) + true + true + $(wolfCryptDllRelease32) + + + + + Level3 + + + MaxSpeed + true + true + WIN32;NDEBUG;_CONSOLE;WOLFSSL_USER_SETTINGS;NO_MAIN_DRIVER;%(PreprocessorDefinitions) + ..;..\..\..;$(wolfCryptDir);%(AdditionalIncludeDirectories) + + + Console + true + wolfssl.lib;ws2_32.lib;%(AdditionalDependencies) + true + true + $(wolfCryptRelease64) + + + + + Level3 + + + MaxSpeed + true + true + WIN32;NDEBUG;_CONSOLE;WOLFSSL_USER_SETTINGS;NO_MAIN_DRIVER;%(PreprocessorDefinitions) + ..;..\..\..;$(wolfCryptDir);%(AdditionalIncludeDirectories) + + + Console + true + wolfssl.lib;ws2_32.lib;%(AdditionalDependencies) + true + true + $(wolfCryptDllRelease64) + + + + + + diff --git a/ide/winvs/testsuite/testsuite.vcxproj.user b/ide/winvs/testsuite/testsuite.vcxproj.user new file mode 100644 index 00000000..23a5dce7 --- /dev/null +++ b/ide/winvs/testsuite/testsuite.vcxproj.user @@ -0,0 +1,19 @@ + + + + WindowsLocalDebugger + PATH=$(wolfCryptDllDebug32);%PATH% + + + WindowsLocalDebugger + PATH=$(wolfCryptDllDebug64);%PATH% + + + WindowsLocalDebugger + PATH=$(wolfCryptDllRelease32);%PATH% + + + WindowsLocalDebugger + PATH=$(wolfCryptDllRelease64);%PATH% + + diff --git a/ide/winvs/user_settings.h b/ide/winvs/user_settings.h index e9fd2aaf..56d5d3fa 100644 --- a/ide/winvs/user_settings.h +++ b/ide/winvs/user_settings.h @@ -23,5 +23,6 @@ #define USE_FAST_MATH #define TFM_TIMING_RESISTANT #define ECC_TIMING_RESISTANT +#define WOLFSSL_PUBLIC_MP #endif /* _WIN_USER_SETTINGS_H_ */ diff --git a/ide/winvs/wolfssh.sln b/ide/winvs/wolfssh.sln old mode 100755 new mode 100644 index 545f61d3..34958361 --- a/ide/winvs/wolfssh.sln +++ b/ide/winvs/wolfssh.sln @@ -17,6 +17,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "unit-test", "unit-test\unit EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "client", "client\client.vcxproj", "{663A7133-B13B-4C37-A5EC-97CA4D60CA3A}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "testsuite", "testsuite\testsuite.vcxproj", "{BD09DA06-6D2E-4FB0-AE39-1BAE9FDAA9DD}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Win32 = Debug|Win32 @@ -109,6 +111,18 @@ Global {663A7133-B13B-4C37-A5EC-97CA4D60CA3A}.Release|Win32.Build.0 = Release|Win32 {663A7133-B13B-4C37-A5EC-97CA4D60CA3A}.Release|x64.ActiveCfg = Release|x64 {663A7133-B13B-4C37-A5EC-97CA4D60CA3A}.Release|x64.Build.0 = Release|x64 + {BD09DA06-6D2E-4FB0-AE39-1BAE9FDAA9DD}.Debug|Win32.ActiveCfg = Debug|Win32 + {BD09DA06-6D2E-4FB0-AE39-1BAE9FDAA9DD}.Debug|Win32.Build.0 = Debug|Win32 + {BD09DA06-6D2E-4FB0-AE39-1BAE9FDAA9DD}.Debug|x64.ActiveCfg = Debug|x64 + {BD09DA06-6D2E-4FB0-AE39-1BAE9FDAA9DD}.DLL Debug|Win32.ActiveCfg = DLL Debug|Win32 + {BD09DA06-6D2E-4FB0-AE39-1BAE9FDAA9DD}.DLL Debug|Win32.Build.0 = DLL Debug|Win32 + {BD09DA06-6D2E-4FB0-AE39-1BAE9FDAA9DD}.DLL Debug|x64.ActiveCfg = DLL Debug|x64 + {BD09DA06-6D2E-4FB0-AE39-1BAE9FDAA9DD}.DLL Release|Win32.ActiveCfg = DLL Release|Win32 + {BD09DA06-6D2E-4FB0-AE39-1BAE9FDAA9DD}.DLL Release|Win32.Build.0 = DLL Release|Win32 + {BD09DA06-6D2E-4FB0-AE39-1BAE9FDAA9DD}.DLL Release|x64.ActiveCfg = DLL Release|x64 + {BD09DA06-6D2E-4FB0-AE39-1BAE9FDAA9DD}.Release|Win32.ActiveCfg = Release|Win32 + {BD09DA06-6D2E-4FB0-AE39-1BAE9FDAA9DD}.Release|Win32.Build.0 = Release|Win32 + {BD09DA06-6D2E-4FB0-AE39-1BAE9FDAA9DD}.Release|x64.ActiveCfg = Release|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/src/internal.c b/src/internal.c index 5f3f856a..36bbeea2 100644 --- a/src/internal.c +++ b/src/internal.c @@ -2914,6 +2914,7 @@ static int DoUserAuthRequestEcc(WOLFSSH* ssh, WS_UserAuthData_PublicKey* pk, if (ret == WS_SUCCESS) { curveName = pk->publicKey + i; + (void)curveName; /* Not used at the moment, hush the compiler. */ i += curveNameSz; ret = GetUint32(&qSz, pk->publicKey, pk->publicKeySz, &i); } diff --git a/src/memory.c b/src/memory.c index f431954e..915c4b35 100644 --- a/src/memory.c +++ b/src/memory.c @@ -51,7 +51,7 @@ int wolfSSH_SetAllocators(wolfSSH_Malloc_cb mf, if (mf) malloc_function = mf; - else + else res = WS_BAD_ARGUMENT; if (ff) diff --git a/tests/include.am b/tests/include.am index 162b91be..0026472b 100644 --- a/tests/include.am +++ b/tests/include.am @@ -2,17 +2,27 @@ # included from Top Level Makefile.am # All paths should be given relative to the root -check_PROGRAMS += tests/unit.test tests/api.test -noinst_PROGRAMS += tests/unit.test tests/api.test +check_PROGRAMS += tests/unit.test tests/api.test \ + tests/testsuite.test +noinst_PROGRAMS += tests/unit.test tests/api.test \ + tests/testsuite.test tests_unit_test_SOURCES = tests/unit.c tests_unit_test_CFLAGS = -DNO_MAIN_DRIVER $(AM_CFLAGS) tests_unit_test_LDADD = src/libwolfssh.la $(LIB_STATIC_ADD) tests_unit_test_DEPENDENCIES = src/libwolfssh.la -tests_api_test_SOURCES = tests/api.c -tests_api_test_CFLAGS = -DNO_MAIN_DRIVER $(AM_CFLAGS) -tests_api_test_LDADD = src/libwolfssh.la $(LIB_STATIC_ADD) -tests_api_test_DEPENDENCIES = src/libwolfssh.la +tests_api_test_SOURCES = tests/api.c +tests_api_test_CFLAGS = -DNO_MAIN_DRIVER $(AM_CFLAGS) +tests_api_test_LDADD = src/libwolfssh.la $(LIB_STATIC_ADD) +tests_api_test_DEPENDENCIES = src/libwolfssh.la -DISTCLEANFILES+= tests/.libs/unit.test tests/.libs/api.test +tests_testsuite_test_SOURCES = tests/testsuite.c \ + examples/echoserver/echoserver.c \ + examples/client/client.c +tests_testsuite_test_CFLAGS = -DNO_MAIN_DRIVER $(AM_CFLAGS) +tests_testsuite_test_LDADD = src/libwolfssh.la $(LIB_STATIC_ADD) +tests_testsuite_test_DEPENDENCIES = src/libwolfssh.la + +DISTCLEANFILES+= tests/.libs/unit.test tests/.libs/api.test \ + tests/.libs/testsuite.test diff --git a/tests/testsuite.c b/tests/testsuite.c new file mode 100644 index 00000000..ff1e19c0 --- /dev/null +++ b/tests/testsuite.c @@ -0,0 +1,233 @@ +/* testsuite.c + * + * Copyright (C) 2014-2017 wolfSSL Inc. + * + * This file is part of wolfSSH. + * + * wolfSSH is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * wolfSSH is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with wolfSSH. If not, see . + */ + + +#include + +#ifdef WOLFSSL_USER_SETTINGS + #include +#else + #include +#endif + +#include +#include +#include +#include "examples/echoserver/echoserver.h" +#include "examples/client/client.h" + + +#ifndef NO_TESTSUITE_MAIN_DRIVER + +static int TestsuiteTest(int argc, char** argv); + +int main(int argc, char** argv) +{ + return TestsuiteTest(argc, argv); +} + + +int myoptind = 0; +char* myoptarg = NULL; + +#endif /* NO_TESTSUITE_MAIN_DRIVER */ + + +static int tsClientUserAuth(byte authType, WS_UserAuthData* authData, void* ctx) +{ + static char password[] = "upthehill"; + + (void)authType; + (void)ctx; + + authData->sf.password.password = (byte*)password; + authData->sf.password.passwordSz = (word32)WSTRLEN(password); + return WOLFSSH_USERAUTH_SUCCESS; +} + + +#if !defined(NO_WOLFSSH_SERVER) && !defined(NO_WOLFSSH_CLIENT) + +#define NUMARGS 5 +#define ARGLEN 32 + +int TestsuiteTest(int argc, char** argv) +{ + tcp_ready ready; + THREAD_TYPE serverThread; + func_args serverArgs; + func_args clientArgs; + char sA[NUMARGS][ARGLEN]; + char *serverArgv[NUMARGS] = + { sA[0], sA[1], sA[2], sA[3], sA[4] }; + char cA[NUMARGS][ARGLEN]; + char *clientArgv[NUMARGS] = + { cA[0], cA[1], cA[2], cA[3], cA[4] }; + int serverArgc = 0; + int clientArgc = 0; + + (void)argc; + (void)argv; + + WSTARTTCP(); + + wolfSSH_Init(); + #if defined(DEBUG_WOLFSSH) + wolfSSH_Debugging_ON(); + #endif + #if !defined(WOLFSSL_TIRTOS) + ChangeToWolfSshRoot(); + #endif + + InitTcpReady(&ready); + + WSTRNCPY(serverArgv[serverArgc++], "echoserver", ARGLEN); + WSTRNCPY(serverArgv[serverArgc++], "-1", ARGLEN); + #ifndef USE_WINDOWS_API + WSTRNCPY(serverArgv[serverArgc++], "-p", ARGLEN); + WSTRNCPY(serverArgv[serverArgc++], "-0", ARGLEN); + #endif + + serverArgs.argc = serverArgc; + serverArgs.argv = serverArgv; + serverArgs.return_code = EXIT_SUCCESS; + serverArgs.signal = &ready; + serverArgs.user_auth = NULL; + ThreadStart(echoserver_test, &serverArgs, &serverThread); + WaitTcpReady(&serverArgs); + + WSTRNCPY(cA[clientArgc++], "client", ARGLEN); + WSTRNCPY(cA[clientArgc++], "-u", ARGLEN); + WSTRNCPY(cA[clientArgc++], "jill", ARGLEN); + #ifndef USE_WINDOWS_API + WSTRNCPY(cA[clientArgc++], "-p", ARGLEN); + WSNPRINTF(cA[clientArgc++], ARGLEN, "%d", ready.port); + #endif + + clientArgs.argc = clientArgc; + clientArgs.argv = clientArgv; + clientArgs.return_code = EXIT_SUCCESS; + clientArgs.signal = &ready; + clientArgs.user_auth = tsClientUserAuth; + + client_test(&clientArgs); + if (clientArgs.return_code != 0) { + return clientArgs.return_code; + } + + ThreadJoin(serverThread); + + wolfSSH_Cleanup(); + FreeTcpReady(&ready); + return EXIT_SUCCESS; +} + +#else /* !NO_WOLFSSH_SERVER && !NO_WOLFSSH_CLIENT */ + +int TestsuiteTest(int argc, char** argv) + + (void)argc; + (void)argv; + return EXIT_SUCCESS; +} + +#endif /* !NO_WOLFSSH_SERVER && !NO_WOLFSSH_CLIENT */ + + +void WaitTcpReady(func_args* args) +{ +#if defined(_POSIX_THREADS) && !defined(__MINGW32__) + 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); +#else + (void)args; +#endif +} + + +void ThreadStart(THREAD_FUNC fun, void* args, THREAD_TYPE* thread) +{ +#if defined(_POSIX_THREADS) && !defined(__MINGW32__) + pthread_create(thread, 0, fun, args); + return; +#elif defined(WOLFSSL_TIRTOS) + /* Initialize the defaults and set the parameters. */ + Task_Params taskParams; + Task_Params_init(&taskParams); + taskParams.arg0 = (UArg)args; + taskParams.stackSize = 65535; + *thread = Task_create((Task_FuncPtr)fun, &taskParams, NULL); + if (*thread == NULL) { + printf("Failed to create new Task\n"); + } + Task_yield(); +#else + *thread = (THREAD_TYPE)_beginthreadex(0, 0, fun, args, 0, 0); +#endif +} + + +void ThreadJoin(THREAD_TYPE thread) +{ +#if defined(_POSIX_THREADS) && !defined(__MINGW32__) + pthread_join(thread, 0); +#elif defined(WOLFSSL_TIRTOS) + while(1) { + if (Task_getMode(thread) == Task_Mode_TERMINATED) { + Task_sleep(5); + break; + } + Task_yield(); + } +#else + int res = WaitForSingleObject((HANDLE)thread, INFINITE); + assert(res == WAIT_OBJECT_0); + res = CloseHandle((HANDLE)thread); + assert(res); + (void)res; /* Suppress un-used variable warning */ +#endif +} + + +void ThreadDetach(THREAD_TYPE thread) +{ +#if defined(_POSIX_THREADS) && !defined(__MINGW32__) + pthread_detach(thread); +#elif defined(WOLFSSL_TIRTOS) +#if 0 + while(1) { + if (Task_getMode(thread) == Task_Mode_TERMINATED) { + Task_sleep(5); + break; + } + Task_yield(); + } +#endif +#else + int res = CloseHandle((HANDLE)thread); + assert(res); + (void)res; /* Suppress un-used variable warning */ +#endif +} diff --git a/wolfssh/test.h b/wolfssh/test.h index 49e43e43..4fb9efa3 100644 --- a/wolfssh/test.h +++ b/wolfssh/test.h @@ -140,94 +140,20 @@ static INLINE void FreeTcpReady(tcp_ready* ready) } -typedef void (*ctx_callback)(WOLFSSH_CTX*); -typedef void (*ssh_callback)(WOLFSSH*); - -typedef struct callback_functions { - ctx_callback ctx_ready; - ssh_callback ssh_ready; - ssh_callback on_result; -} callback_functions; - typedef struct func_args { int argc; char** argv; int return_code; tcp_ready* signal; - callback_functions *callbacks; + WS_CallbackUserAuth user_auth; } func_args; -#ifndef SINGLE_THREADED - typedef THREAD_RETURN WOLFSSH_THREAD THREAD_FUNC(void*); - -static void start_thread(THREAD_FUNC fun, void* args, THREAD_TYPE* thread) -{ -#if defined(_POSIX_THREADS) && !defined(__MINGW32__) - pthread_create(thread, 0, fun, args); - return; -#elif defined(WOLFSSL_TIRTOS) - /* Initialize the defaults and set the parameters. */ - Task_Params taskParams; - Task_Params_init(&taskParams); - taskParams.arg0 = (UArg)args; - taskParams.stackSize = 65535; - *thread = Task_create((Task_FuncPtr)fun, &taskParams, NULL); - if (*thread == NULL) { - printf("Failed to create new Task\n"); - } - Task_yield(); -#else - *thread = (THREAD_TYPE)_beginthreadex(0, 0, fun, args, 0, 0); -#endif -} - - -static void join_thread(THREAD_TYPE thread) -{ -#if defined(_POSIX_THREADS) && !defined(__MINGW32__) - pthread_join(thread, 0); -#elif defined(WOLFSSL_TIRTOS) - while(1) { - if (Task_getMode(thread) == Task_Mode_TERMINATED) { - Task_sleep(5); - break; - } - Task_yield(); - } -#else - int res = WaitForSingleObject((HANDLE)thread, INFINITE); - assert(res == WAIT_OBJECT_0); - res = CloseHandle((HANDLE)thread); - assert(res); - (void)res; /* Suppress un-used variable warning */ -#endif -} - - -static void detach_thread(THREAD_TYPE thread) -{ -#if defined(_POSIX_THREADS) && !defined(__MINGW32__) - pthread_detach(thread); -#elif defined(WOLFSSL_TIRTOS) -#if 0 - while(1) { - if (Task_getMode(thread) == Task_Mode_TERMINATED) { - Task_sleep(5); - break; - } - Task_yield(); - } -#endif -#else - int res = CloseHandle((HANDLE)thread); - assert(res); - (void)res; /* Suppress un-used variable warning */ -#endif -} - -#endif /* SINGLE_THREADED */ +void ThreadStart(THREAD_FUNC, void*, THREAD_TYPE*); +void ThreadJoin(THREAD_TYPE); +void ThreadDetach(THREAD_TYPE); +void WaitTcpReady(func_args*); #ifndef TEST_IPV6