Grouping test header functions into test-client, test-server, or

test-threading blocks. Adding flags to the examples and testsuite to
enable various test functions.
pull/107/head
John Safranek 2018-09-20 16:10:13 -07:00
parent ba4fae0054
commit cf959db741
6 changed files with 80 additions and 51 deletions

View File

@ -18,6 +18,8 @@
* along with wolfSSH. If not, see <http://www.gnu.org/licenses/>. * along with wolfSSH. If not, see <http://www.gnu.org/licenses/>.
*/ */
#define WOLFSSH_TEST_CLIENT
#include <wolfssh/ssh.h> #include <wolfssh/ssh.h>
#include <wolfssh/test.h> #include <wolfssh/test.h>

View File

@ -18,6 +18,9 @@
* along with wolfSSH. If not, see <http://www.gnu.org/licenses/>. * along with wolfSSH. If not, see <http://www.gnu.org/licenses/>.
*/ */
#define WOLFSSH_TEST_SERVER
#define WOLFSSH_TEST_THREADING
#ifdef WOLFSSL_USER_SETTINGS #ifdef WOLFSSL_USER_SETTINGS
#include <wolfssl/wolfcrypt/settings.h> #include <wolfssl/wolfcrypt/settings.h>

View File

@ -18,6 +18,9 @@
* along with wolfSSH. If not, see <http://www.gnu.org/licenses/>. * along with wolfSSH. If not, see <http://www.gnu.org/licenses/>.
*/ */
#define WOLFSSH_TEST_SERVER
#define WOLFSSH_TEST_THREADING
#ifdef WOLFSSL_USER_SETTINGS #ifdef WOLFSSL_USER_SETTINGS
#include <wolfssl/wolfcrypt/settings.h> #include <wolfssl/wolfcrypt/settings.h>

View File

@ -18,6 +18,9 @@
* along with wolfSSH. If not, see <http://www.gnu.org/licenses/>. * along with wolfSSH. If not, see <http://www.gnu.org/licenses/>.
*/ */
#define WOLFSSH_TEST_CLIENT
#define WOLFSSH_TEST_SERVER
#include <stdio.h> #include <stdio.h>
#include <termios.h> #include <termios.h>

View File

@ -18,6 +18,10 @@
* along with wolfSSH. If not, see <http://www.gnu.org/licenses/>. * along with wolfSSH. If not, see <http://www.gnu.org/licenses/>.
*/ */
#define WOLFSSH_TEST_CLIENT
#define WOLFSSH_TEST_SERVER
#define WOLFSSH_TEST_THREADING
#include <stdio.h> #include <stdio.h>

View File

@ -149,56 +149,6 @@
#define serverKeyRsaPemFile "./keys/server-key-rsa.pem" #define serverKeyRsaPemFile "./keys/server-key-rsa.pem"
typedef struct tcp_ready {
word16 ready; /* predicate */
word16 port;
char* srfName; /* server ready file name */
#if defined(_POSIX_THREADS) && !defined(__MINGW32__)
pthread_mutex_t mutex;
pthread_cond_t cond;
#endif
} tcp_ready;
static INLINE void InitTcpReady(tcp_ready* ready)
{
ready->ready = 0;
ready->port = 0;
ready->srfName = NULL;
#ifdef SINGLE_THREADED
#elif defined(_POSIX_THREADS) && !defined(__MINGW32__)
pthread_mutex_init(&ready->mutex, 0);
pthread_cond_init(&ready->cond, 0);
#endif
}
static INLINE void FreeTcpReady(tcp_ready* ready)
{
#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
}
typedef struct func_args {
int argc;
char** argv;
int return_code;
tcp_ready* signal;
WS_CallbackUserAuth user_auth;
} func_args;
typedef THREAD_RETURN WOLFSSH_THREAD THREAD_FUNC(void*);
void WaitTcpReady(func_args*);
#ifndef TEST_IPV6 #ifndef TEST_IPV6
static const char* const wolfSshIp = "127.0.0.1"; static const char* const wolfSshIp = "127.0.0.1";
#else /* TEST_IPV6 */ #else /* TEST_IPV6 */
@ -312,6 +262,8 @@ static INLINE int mygetopt(int argc, char** argv, const char* optstring)
* - 4996: deprecated function */ * - 4996: deprecated function */
#endif #endif
#if defined(WOLFSSH_TEST_CLIENT) || defined(WOLFSSH_TEST_SERVER)
#ifdef WOLFSSL_NUCLEUS #ifdef WOLFSSL_NUCLEUS
static INLINE void build_addr(struct addr_struct* addr, const char* peer, static INLINE void build_addr(struct addr_struct* addr, const char* peer,
word16 port) word16 port)
@ -447,7 +399,7 @@ static INLINE void build_addr(SOCKADDR_IN_T* addr, const char* peer,
} }
#endif #endif
} }
#endif /* WOLFSSL_NUCLEUS */ #endif /* WOLFSSH_NUCLEUS */
#ifdef USE_WINDOWS_API #ifdef USE_WINDOWS_API
#pragma warning(pop) #pragma warning(pop)
@ -513,11 +465,16 @@ static INLINE void tcp_socket(SOCKET_T* sockFd)
#endif /* USE_WINDOWS_API */ #endif /* USE_WINDOWS_API */
} }
#endif /* WOLFSSH_TEST_CLIENT || WOLFSSH_TEST_SERVER */
#ifndef XNTOHS #ifndef XNTOHS
#define XNTOHS(a) ntohs((a)) #define XNTOHS(a) ntohs((a))
#endif #endif
#ifdef WOLFSSH_TEST_SERVER
static INLINE void tcp_listen(SOCKET_T* sockfd, word16* port, int useAnyAddr) static INLINE void tcp_listen(SOCKET_T* sockfd, word16* port, int useAnyAddr)
{ {
#ifdef MICROCHIP_MPLAB_HARMONY #ifdef MICROCHIP_MPLAB_HARMONY
@ -580,6 +537,8 @@ static INLINE void tcp_listen(SOCKET_T* sockfd, word16* port, int useAnyAddr)
#endif /* MICROCHIP_MPLAB_HARMONY */ #endif /* MICROCHIP_MPLAB_HARMONY */
} }
#endif /* WOLFSSH_TEST_SERVER */
/* Wolf Root Directory Helper */ /* Wolf Root Directory Helper */
/* KEIL-RL File System does not support relative directory */ /* KEIL-RL File System does not support relative directory */
#if !defined(WOLFSSL_MDK_ARM) && !defined(WOLFSSL_KEIL_FS) && !defined(WOLFSSL_TIRTOS) \ #if !defined(WOLFSSL_MDK_ARM) && !defined(WOLFSSL_KEIL_FS) && !defined(WOLFSSL_TIRTOS) \
@ -617,6 +576,59 @@ static INLINE void tcp_listen(SOCKET_T* sockfd, word16* port, int useAnyAddr)
#endif /* !defined(WOLFSSL_MDK_ARM) && !defined(WOLFSSL_KEIL_FS) && !defined(WOL #endif /* !defined(WOLFSSL_MDK_ARM) && !defined(WOLFSSL_KEIL_FS) && !defined(WOL
FSSL_TIRTOS) */ FSSL_TIRTOS) */
typedef struct tcp_ready {
word16 ready; /* predicate */
word16 port;
char* srfName; /* server ready file name */
#if defined(_POSIX_THREADS) && !defined(__MINGW32__)
pthread_mutex_t mutex;
pthread_cond_t cond;
#endif
} tcp_ready;
typedef struct func_args {
int argc;
char** argv;
int return_code;
tcp_ready* signal;
WS_CallbackUserAuth user_auth;
} func_args;
#ifdef WOLFSSH_TEST_THREADING
static INLINE void InitTcpReady(tcp_ready* ready)
{
ready->ready = 0;
ready->port = 0;
ready->srfName = NULL;
#ifdef SINGLE_THREADED
#elif defined(_POSIX_THREADS) && !defined(__MINGW32__)
pthread_mutex_init(&ready->mutex, 0);
pthread_cond_init(&ready->cond, 0);
#endif
}
static INLINE void FreeTcpReady(tcp_ready* ready)
{
#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
}
typedef THREAD_RETURN WOLFSSH_THREAD THREAD_FUNC(void*);
void WaitTcpReady(func_args*);
static INLINE void ThreadStart(THREAD_FUNC fun, void* args, THREAD_TYPE* thread) static INLINE void ThreadStart(THREAD_FUNC fun, void* args, THREAD_TYPE* thread)
{ {
#ifdef SINGLE_THREADED #ifdef SINGLE_THREADED
@ -690,4 +702,6 @@ static INLINE void ThreadDetach(THREAD_TYPE thread)
#endif #endif
} }
#endif /* WOLFSSH_TEST_THREADING */
#endif /* _WOLFSSH_TEST_H_ */ #endif /* _WOLFSSH_TEST_H_ */