Merge pull request #226 from toddouska/ranports-scripts

add random ports for all make check scripts, unique ready file
pull/228/head
Kaleb Joseph Himes 2015-12-23 12:49:16 -07:00
commit 558d2566cc
6 changed files with 116 additions and 84 deletions

View File

@ -195,6 +195,7 @@ static void Usage(void)
printf("-c <file> Certificate file, default %s\n", svrCert); printf("-c <file> Certificate file, default %s\n", svrCert);
printf("-k <file> Key file, default %s\n", svrKey); printf("-k <file> Key file, default %s\n", svrKey);
printf("-A <file> Certificate Authority file, default %s\n", cliCert); printf("-A <file> Certificate Authority file, default %s\n", cliCert);
printf("-R <file> Create Ready file for external monitor default none\n");
#ifndef NO_DH #ifndef NO_DH
printf("-D <file> Diffie-Hellman Params file, default %s\n", dhParam); printf("-D <file> Diffie-Hellman Params file, default %s\n", dhParam);
printf("-Z <num> Minimum DH key bits, default %d\n", printf("-Z <num> Minimum DH key bits, default %d\n",
@ -210,7 +211,6 @@ static void Usage(void)
printf("-u Use UDP DTLS," printf("-u Use UDP DTLS,"
" add -v 2 for DTLSv1, -v 3 for DTLSv1.2 (default)\n"); " add -v 2 for DTLSv1, -v 3 for DTLSv1.2 (default)\n");
printf("-f Fewer packets/group messages\n"); printf("-f Fewer packets/group messages\n");
printf("-R Create server ready file, for external monitor\n");
printf("-r Allow one client Resumption\n"); printf("-r Allow one client Resumption\n");
printf("-N Use Non-blocking sockets\n"); printf("-N Use Non-blocking sockets\n");
printf("-S <str> Use Host Name Indication\n"); printf("-S <str> Use Host Name Indication\n");
@ -258,7 +258,6 @@ THREAD_RETURN CYASSL_THREAD server_test(void* args)
int trackMemory = 0; int trackMemory = 0;
int fewerPackets = 0; int fewerPackets = 0;
int pkCallbacks = 0; int pkCallbacks = 0;
int serverReadyFile = 0;
int wc_shutdown = 0; int wc_shutdown = 0;
int resume = 0; int resume = 0;
int resumeCount = 0; int resumeCount = 0;
@ -269,6 +268,7 @@ THREAD_RETURN CYASSL_THREAD server_test(void* args)
int doListen = 1; int doListen = 1;
int crlFlags = 0; int crlFlags = 0;
int ret; int ret;
char* serverReadyFile = NULL;
char* alpnList = NULL; char* alpnList = NULL;
unsigned char alpn_opt = 0; unsigned char alpn_opt = 0;
char* cipherList = NULL; char* cipherList = NULL;
@ -276,6 +276,7 @@ THREAD_RETURN CYASSL_THREAD server_test(void* args)
const char* ourCert = svrCert; const char* ourCert = svrCert;
const char* ourKey = svrKey; const char* ourKey = svrKey;
const char* ourDhParam = dhParam; const char* ourDhParam = dhParam;
tcp_ready* readySignal = NULL;
int argc = ((func_args*)args)->argc; int argc = ((func_args*)args)->argc;
char** argv = ((func_args*)args)->argv; char** argv = ((func_args*)args)->argv;
@ -312,6 +313,7 @@ THREAD_RETURN CYASSL_THREAD server_test(void* args)
(void)alpnList; (void)alpnList;
(void)alpn_opt; (void)alpn_opt;
(void)crlFlags; (void)crlFlags;
(void)readySignal;
#ifdef CYASSL_TIRTOS #ifdef CYASSL_TIRTOS
fdOpenSession(Task_self()); fdOpenSession(Task_self());
@ -320,7 +322,7 @@ THREAD_RETURN CYASSL_THREAD server_test(void* args)
#ifdef WOLFSSL_VXWORKS #ifdef WOLFSSL_VXWORKS
useAnyAddr = 1; useAnyAddr = 1;
#else #else
while ((ch = mygetopt(argc, argv, "?dbstnNufrRawPIp:v:l:A:c:k:Z:S:oO:D:L:ieB:")) while ((ch = mygetopt(argc, argv, "?dbstnNufrawPIR:p:v:l:A:c:k:Z:S:oO:D:L:ieB:"))
!= -1) { != -1) {
switch (ch) { switch (ch) {
case '?' : case '?' :
@ -358,7 +360,7 @@ THREAD_RETURN CYASSL_THREAD server_test(void* args)
break; break;
case 'R' : case 'R' :
serverReadyFile = 1; serverReadyFile = myoptarg;
break; break;
case 'r' : case 'r' :
@ -375,7 +377,7 @@ THREAD_RETURN CYASSL_THREAD server_test(void* args)
case 'p' : case 'p' :
port = (word16)atoi(myoptarg); port = (word16)atoi(myoptarg);
#if !defined(NO_MAIN_DRIVER) || defined(USE_WINDOWS_API) #if defined(USE_WINDOWS_API)
if (port == 0) if (port == 0)
err_sys("port number cannot be 0"); err_sys("port number cannot be 0");
#endif #endif
@ -740,8 +742,12 @@ THREAD_RETURN CYASSL_THREAD server_test(void* args)
#endif #endif
/* do accept */ /* do accept */
readySignal = ((func_args*)args)->signal;
if (readySignal) {
readySignal->srfName = serverReadyFile;
}
tcp_accept(&sockfd, &clientfd, (func_args*)args, port, useAnyAddr, tcp_accept(&sockfd, &clientfd, (func_args*)args, port, useAnyAddr,
doDTLS, serverReadyFile, doListen); doDTLS, serverReadyFile ? 1 : 0, doListen);
doListen = 0; /* Don't listen next time */ doListen = 0; /* Don't listen next time */
SSL_set_fd(ssl, clientfd); SSL_set_fd(ssl, clientfd);
@ -903,6 +909,7 @@ THREAD_RETURN CYASSL_THREAD server_test(void* args)
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
func_args args; func_args args;
tcp_ready ready;
#ifdef HAVE_CAVIUM #ifdef HAVE_CAVIUM
int ret = OpenNitroxDevice(CAVIUM_DIRECT, CAVIUM_DEV_ID); int ret = OpenNitroxDevice(CAVIUM_DIRECT, CAVIUM_DEV_ID);
@ -914,6 +921,8 @@ THREAD_RETURN CYASSL_THREAD server_test(void* args)
args.argc = argc; args.argc = argc;
args.argv = argv; args.argv = argv;
args.signal = &ready;
InitTcpReady(&ready);
CyaSSL_Init(); CyaSSL_Init();
#if defined(DEBUG_CYASSL) && !defined(WOLFSSL_MDK_SHELL) #if defined(DEBUG_CYASSL) && !defined(WOLFSSL_MDK_SHELL)
@ -927,6 +936,7 @@ THREAD_RETURN CYASSL_THREAD server_test(void* args)
server_test(&args); server_test(&args);
#endif #endif
CyaSSL_Cleanup(); CyaSSL_Cleanup();
FreeTcpReady(&ready);
#ifdef HAVE_CAVIUM #ifdef HAVE_CAVIUM
CspShutdown(CAVIUM_DEV_ID); CspShutdown(CAVIUM_DEV_ID);

View File

@ -5,16 +5,22 @@
revocation_code="-361" revocation_code="-361"
exit_code=1 exit_code=1
counter=0 counter=0
crl_port=11113 # need a unique resume port since may run the same time as testsuite
# use server port zero hack to get one
crl_port=0
#no_pid tells us process was never started if -1 #no_pid tells us process was never started if -1
no_pid=-1 no_pid=-1
#server_pid captured on startup, stores the id of the server process #server_pid captured on startup, stores the id of the server process
server_pid=$no_pid server_pid=$no_pid
# let's use absolute path to a local dir (make distcheck may be in sub dir)
# also let's add some randomness by adding pid in case multiple 'make check's
# per source tree
ready_file=`pwd`/wolfssl_crl_ready$$
remove_ready_file() { remove_ready_file() {
if test -e /tmp/wolfssl_server_ready; then if test -e $ready_file; then
echo -e "removing exisitng server_ready file" echo -e "removing exisitng ready file"
rm /tmp/wolfssl_server_ready rm $ready_file
fi fi
} }
@ -53,16 +59,26 @@ run_test() {
# starts the server on crl_port, -R generates ready file to be used as a # starts the server on crl_port, -R generates ready file to be used as a
# mutex lock, -c loads the revoked certificate. We capture the processid # mutex lock, -c loads the revoked certificate. We capture the processid
# into the variable server_pid # into the variable server_pid
./examples/server/server -R -p $crl_port -c certs/server-revoked-cert.pem \ ./examples/server/server -R $ready_file -p $crl_port \
-k certs/server-revoked-key.pem & -c certs/server-revoked-cert.pem -k certs/server-revoked-key.pem &
server_pid=$! server_pid=$!
while [ ! -s /tmp/wolfssl_server_ready -a "$counter" -lt 20 ]; do while [ ! -s $ready_file -a "$counter" -lt 20 ]; do
echo -e "waiting for server_ready file..." echo -e "waiting for ready file..."
sleep 0.1 sleep 0.1
counter=$((counter+ 1)) counter=$((counter+ 1))
done done
if test -e $ready_file; then
echo -e "found ready file, starting client..."
else
echo -e "NO ready file ending test..."
exit 1
fi
# get created port 0 ephemeral port
crl_port=`cat $ready_file`
# starts client on crl_port and captures the output from client # starts client on crl_port and captures the output from client
capture_out=$(./examples/client/client -p $crl_port 2>&1) capture_out=$(./examples/client/client -p $crl_port 2>&1)
client_result=$? client_result=$?

View File

@ -3,16 +3,22 @@
#reusme.test #reusme.test
# need a unique resume port since may run the same time as testsuite # need a unique resume port since may run the same time as testsuite
resume_port=11112 # use server port zero hack to get one
resume_port=0
no_pid=-1 no_pid=-1
server_pid=$no_pid server_pid=$no_pid
counter=0 counter=0
# let's use absolute path to a local dir (make distcheck may be in sub dir)
# also let's add some randomness by adding pid in case multiple 'make check's
# per source tree
ready_file=`pwd`/wolfssl_resume_ready$$
echo "ready file $ready_file"
remove_ready_file() { remove_ready_file() {
if test -e /tmp/wolfssl_server_ready; then if test -e $ready_file; then
echo -e "removing exisitng server_ready file" echo -e "removing exisitng ready file"
rm /tmp/wolfssl_server_ready rm $ready_file
fi fi
} }
@ -39,15 +45,26 @@ trap do_trap INT TERM
echo -e "\nStarting example server for resume test...\n" echo -e "\nStarting example server for resume test...\n"
remove_ready_file remove_ready_file
./examples/server/server -r -R -p $resume_port & ./examples/server/server -r -R $ready_file -p $resume_port &
server_pid=$! server_pid=$!
while [ ! -s /tmp/wolfssl_server_ready -a "$counter" -lt 20 ]; do while [ ! -s $ready_file -a "$counter" -lt 20 ]; do
echo -e "waiting for server_ready file..." echo -e "waiting for ready file..."
sleep 0.1 sleep 0.1
counter=$((counter+ 1)) counter=$((counter+ 1))
done done
if test -e $ready_file; then
echo -e "found ready file, starting client..."
else
echo -e "NO ready file ending test..."
do_cleanup
exit 1
fi
# get created port 0 ephemeral port
resume_port=`cat $ready_file`
./examples/client/client -r -p $resume_port ./examples/client/client -r -p $resume_port
client_result=$? client_result=$?

View File

@ -155,26 +155,3 @@ void join_thread(THREAD_TYPE thread)
} }
void InitTcpReady(tcp_ready* ready)
{
ready->ready = 0;
ready->port = 0;
#ifdef SINGLE_THREADED
#elif defined(_POSIX_THREADS) && !defined(__MINGW32__)
pthread_mutex_init(&ready->mutex, 0);
pthread_cond_init(&ready->cond, 0);
#endif
}
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
}

View File

@ -333,28 +333,6 @@ void join_thread(THREAD_TYPE thread)
} }
void InitTcpReady(tcp_ready* ready)
{
ready->ready = 0;
ready->port = 0;
#if defined(_POSIX_THREADS) && !defined(__MINGW32__)
pthread_mutex_init(&ready->mutex, 0);
pthread_cond_init(&ready->cond, 0);
#endif
}
void FreeTcpReady(tcp_ready* ready)
{
#if defined(_POSIX_THREADS) && !defined(__MINGW32__)
pthread_mutex_destroy(&ready->mutex);
pthread_cond_destroy(&ready->cond);
#else
(void)ready;
#endif
}
void file_test(const char* file, byte* check) void file_test(const char* file, byte* check)
{ {
FILE* f; FILE* f;

View File

@ -267,6 +267,7 @@
typedef struct tcp_ready { typedef struct tcp_ready {
word16 ready; /* predicate */ word16 ready; /* predicate */
word16 port; word16 port;
char* srfName; /* server ready file name */
#if defined(_POSIX_THREADS) && !defined(__MINGW32__) #if defined(_POSIX_THREADS) && !defined(__MINGW32__)
pthread_mutex_t mutex; pthread_mutex_t mutex;
pthread_cond_t cond; pthread_cond_t cond;
@ -274,8 +275,30 @@ typedef struct tcp_ready {
} tcp_ready; } tcp_ready;
void InitTcpReady(tcp_ready*); static INLINE void InitTcpReady(tcp_ready* ready)
void FreeTcpReady(tcp_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 WOLFSSL_METHOD* (*method_provider)(void); typedef WOLFSSL_METHOD* (*method_provider)(void);
typedef void (*ctx_callback)(WOLFSSL_CTX* ctx); typedef void (*ctx_callback)(WOLFSSL_CTX* ctx);
@ -296,6 +319,9 @@ typedef struct func_args {
callback_functions *callbacks; callback_functions *callbacks;
} func_args; } func_args;
void wait_tcp_ready(func_args*); void wait_tcp_ready(func_args*);
typedef THREAD_RETURN WOLFSSL_THREAD THREAD_FUNC(void*); typedef THREAD_RETURN WOLFSSL_THREAD THREAD_FUNC(void*);
@ -702,7 +728,7 @@ static INLINE void tcp_listen(SOCKET_T* sockfd, word16* port, int useAnyAddr,
if (listen(*sockfd, 5) != 0) if (listen(*sockfd, 5) != 0)
err_sys("tcp listen failed"); err_sys("tcp listen failed");
} }
#if (defined(NO_MAIN_DRIVER) && !defined(USE_WINDOWS_API)) && !defined(WOLFSSL_TIRTOS) #if !defined(USE_WINDOWS_API) && !defined(WOLFSSL_TIRTOS)
if (*port == 0) { if (*port == 0) {
socklen_t len = sizeof(addr); socklen_t len = sizeof(addr);
if (getsockname(*sockfd, (struct sockaddr*)&addr, &len) == 0) { if (getsockname(*sockfd, (struct sockaddr*)&addr, &len) == 0) {
@ -815,11 +841,13 @@ static INLINE void tcp_accept(SOCKET_T* sockfd, SOCKET_T* clientfd,
/* signal ready to tcp_accept */ /* signal ready to tcp_accept */
{ {
tcp_ready* ready = args->signal; tcp_ready* ready = args->signal;
pthread_mutex_lock(&ready->mutex); if (ready) {
ready->ready = 1; pthread_mutex_lock(&ready->mutex);
ready->port = port; ready->ready = 1;
pthread_cond_signal(&ready->cond); ready->port = port;
pthread_mutex_unlock(&ready->mutex); pthread_cond_signal(&ready->cond);
pthread_mutex_unlock(&ready->mutex);
}
} }
#elif defined (WOLFSSL_TIRTOS) #elif defined (WOLFSSL_TIRTOS)
/* Need mutex? */ /* Need mutex? */
@ -829,18 +857,24 @@ static INLINE void tcp_accept(SOCKET_T* sockfd, SOCKET_T* clientfd,
#endif #endif
if (ready_file) { if (ready_file) {
#ifndef NO_FILESYSTEM #ifndef NO_FILESYSTEM
#ifndef USE_WINDOWS_API FILE* srf = NULL;
FILE* srf = fopen("/tmp/wolfssl_server_ready", "w"); tcp_ready* ready = args ? args->signal : NULL;
#else
FILE* srf = fopen("wolfssl_server_ready", "w");
#endif
if (srf) { if (ready) {
fputs("ready", srf); srf = fopen(ready->srfName, "w");
fclose(srf);
if (srf) {
/* let's write port sever is listening on to ready file
external monitor can then do ephemeral ports by passing
-p 0 to server on supported platforms with -R ready_file
client can then wait for exisitence of ready_file and see
which port the server is listening on. */
fprintf(srf, "%d\n", (int)port);
fclose(srf);
}
} }
#endif #endif
} }
} }