add resume test to example server and script test

This commit is contained in:
toddouska 2015-04-28 12:21:54 -07:00
parent 1e9647023c
commit d927aa4334
5 changed files with 130 additions and 21 deletions

View File

@ -813,12 +813,6 @@ THREAD_RETURN WOLFSSL_THREAD client_test(void* args)
#ifndef NO_SESSION_CACHE
if (resumeSession) {
if (doDTLS) {
strncpy(msg, "break", 6);
msgSz = (int)strlen(msg);
/* try to send session close */
wolfSSL_write(ssl, msg, msgSz);
}
session = wolfSSL_get_session(ssl);
sslResume = wolfSSL_new(ctx);
}
@ -950,7 +944,9 @@ THREAD_RETURN WOLFSSL_THREAD client_test(void* args)
#if defined(DEBUG_WOLFSSL) && !defined(WOLFSSL_MDK_SHELL) && !defined(STACK_TRAP)
wolfSSL_Debugging_ON();
#endif
if (CurrentDir("client"))
if (CurrentDir("_build"))
ChangeDirBack(1);
else if (CurrentDir("client"))
ChangeDirBack(2);
else if (CurrentDir("Debug") || CurrentDir("Release"))
ChangeDirBack(3);

View File

@ -60,6 +60,7 @@
Timeval srvTo;
#endif
static void NonBlockingSSL_Accept(SSL* ssl)
{
#ifndef CYASSL_CALLBACKS
@ -132,7 +133,8 @@ static void Usage(void)
printf("-u Use UDP DTLS,"
" add -v 2 for DTLSv1 (default), -v 3 for DTLSv1.2\n");
printf("-f Fewer packets/group messages\n");
printf("-r Create server ready file, for external monitor\n");
printf("-R Create server ready file, for external monitor\n");
printf("-r Allow one client Resumption\n");
printf("-N Use Non-blocking sockets\n");
printf("-S <str> Use Host Name Indication\n");
printf("-w Wait for bidirectional shutdown\n");
@ -175,7 +177,8 @@ THREAD_RETURN CYASSL_THREAD server_test(void* args)
int fewerPackets = 0;
int pkCallbacks = 0;
int serverReadyFile = 0;
int wc_shutdown = 0;
int wc_shutdown = 0;
int resume = 0; /* do resume, and resume count */
int ret;
char* cipherList = NULL;
const char* verifyCert = cliCert;
@ -213,7 +216,8 @@ THREAD_RETURN CYASSL_THREAD server_test(void* args)
fdOpenSession(Task_self());
#endif
while ((ch = mygetopt(argc, argv, "?dbstnNufrawPp:v:l:A:c:k:S:oO:")) != -1) {
while ((ch = mygetopt(argc, argv, "?dbstnNufrRawPp:v:l:A:c:k:S:oO:"))
!= -1) {
switch (ch) {
case '?' :
Usage();
@ -249,10 +253,16 @@ THREAD_RETURN CYASSL_THREAD server_test(void* args)
fewerPackets = 1;
break;
case 'r' :
case 'R' :
serverReadyFile = 1;
break;
case 'r' :
#ifndef NO_SESSION_CACHE
resume = 1;
#endif
break;
case 'P' :
#ifdef HAVE_PK_CALLBACKS
pkCallbacks = 1;
@ -502,6 +512,24 @@ THREAD_RETURN CYASSL_THREAD server_test(void* args)
err_sys("UseSNI failed");
#endif
while (1) { /* allow resume option */
if (resume > 1) { /* already did listen, just do accept */
if (doDTLS == 0) {
SOCKADDR_IN_T client;
socklen_t client_len = sizeof(client);
clientfd = accept(sockfd, (struct sockaddr*)&client,
(ACCEPT_THIRD_T)&client_len);
} else {
tcp_listen(&sockfd, &port, useAnyAddr, doDTLS);
clientfd = udp_read_connect(sockfd);
}
#ifdef USE_WINDOWS_API
if (clientfd == INVALID_SOCKET) err_sys("tcp accept failed");
#else
if (clientfd == -1) err_sys("tcp accept failed");
#endif
}
ssl = SSL_new(ctx);
if (ssl == NULL)
err_sys("unable to get SSL");
@ -528,10 +556,10 @@ THREAD_RETURN CYASSL_THREAD server_test(void* args)
SetupPkCallbacks(ctx, ssl);
#endif
tcp_accept(&sockfd, &clientfd, (func_args*)args, port, useAnyAddr, doDTLS,
serverReadyFile);
if (!doDTLS)
CloseSocket(sockfd);
if (resume < 2) { /* do listen and accept */
tcp_accept(&sockfd, &clientfd, (func_args*)args, port, useAnyAddr,
doDTLS, serverReadyFile);
}
SSL_set_fd(ssl, clientfd);
if (usePsk == 0 || useAnon == 1 || cipherList != NULL || needDH == 1) {
@ -579,13 +607,23 @@ THREAD_RETURN CYASSL_THREAD server_test(void* args)
Task_yield();
#endif
ret = SSL_shutdown(ssl);
if (wc_shutdown && ret == SSL_SHUTDOWN_NOT_DONE)
SSL_shutdown(ssl); /* bidirectional shutdown */
if (doDTLS == 0) {
ret = SSL_shutdown(ssl);
if (wc_shutdown && ret == SSL_SHUTDOWN_NOT_DONE)
SSL_shutdown(ssl); /* bidirectional shutdown */
}
SSL_free(ssl);
if (resume == 1) {
CloseSocket(clientfd);
resume++; /* only do one resume for testing */
continue;
}
break; /* out of while loop, done with normal and resume option */
}
SSL_CTX_free(ctx);
CloseSocket(clientfd);
CloseSocket(sockfd);
((func_args*)args)->return_code = 0;
@ -631,7 +669,9 @@ THREAD_RETURN CYASSL_THREAD server_test(void* args)
#if defined(DEBUG_CYASSL) && !defined(CYASSL_MDK_SHELL)
CyaSSL_Debugging_ON();
#endif
if (CurrentDir("server"))
if (CurrentDir("_build"))
ChangeDirBack(1);
else if (CurrentDir("server"))
ChangeDirBack(2);
else if (CurrentDir("Debug") || CurrentDir("Release"))
ChangeDirBack(3);

View File

@ -3,7 +3,13 @@
# All paths should be given relative to the root
if BUILD_SNIFFTEST
dist_noinst_SCRIPTS+= scripts/sniffer-testsuite.test
endif
if BUILD_EXAMPLES
dist_noinst_SCRIPTS+= scripts/resume.test
endif
EXTRA_DIST += scripts/testsuite.pcap

63
scripts/resume.test Executable file
View File

@ -0,0 +1,63 @@
#!/bin/bash
#reusme.test
# need a unique resume port since may run the same time as testsuite
resume_port=11112
no_pid=-1
server_pid=$no_pid
do_cleanup() {
echo "in cleanup"
if [[ $server_pid != $no_pid ]]
then
echo "killing server"
kill -9 $server_pid
fi
}
do_trap() {
echo "got trap"
do_cleanup
exit -1
}
trap do_trap INT TERM
echo -e "\nStarting example server for resume test...\n"
if test -e /tmp/wolfssl_server_ready; then
echo -e "removing exisitng server_ready file"
rm /tmp/wolfssl_server_ready
fi
./examples/server/server -r -R -p $resume_port &
server_pid=$!
while [ ! -s /tmp/wolfssl_server_ready ]; do
echo -e "waiting for server_ready file..."
sleep 0.1
done
./examples/client/client -r -p $resume_port
client_result=$?
if [[ $client_result != 0 ]] ;
then
echo -e "client failed!"
do_cleanup
exit 1
fi
wait $server_pid
server_result=$?
if [[ $server_result != 0 ]] ;
then
echo -e "client failed!"
exit 1
fi
echo -e "\nSuccess!\n"
exit 0

View File

@ -728,7 +728,11 @@ static INLINE void tcp_accept(SOCKET_T* sockfd, SOCKET_T* clientfd,
if (ready_file) {
#ifndef NO_FILESYSTEM
FILE* srf = fopen("./server_ready", "w+");
#ifndef USE_WINDOWS_API
FILE* srf = fopen("/tmp/wolfssl_server_ready", "w");
#else
FILE* srf = fopen("wolfssl_server_ready", "w");
#endif
if (srf) {
fputs("ready", srf);