add random ports for all make check scripts, unique ready file
This commit is contained in:
parent
37b8e60537
commit
22385f2b39
@ -195,6 +195,7 @@ static void Usage(void)
|
||||
printf("-c <file> Certificate file, default %s\n", svrCert);
|
||||
printf("-k <file> Key file, default %s\n", svrKey);
|
||||
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
|
||||
printf("-D <file> Diffie-Hellman Params file, default %s\n", dhParam);
|
||||
printf("-Z <num> Minimum DH key bits, default %d\n",
|
||||
@ -210,7 +211,6 @@ static void Usage(void)
|
||||
printf("-u Use UDP DTLS,"
|
||||
" add -v 2 for DTLSv1, -v 3 for DTLSv1.2 (default)\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("-N Use Non-blocking sockets\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 fewerPackets = 0;
|
||||
int pkCallbacks = 0;
|
||||
int serverReadyFile = 0;
|
||||
int wc_shutdown = 0;
|
||||
int resume = 0;
|
||||
int resumeCount = 0;
|
||||
@ -269,6 +268,7 @@ THREAD_RETURN CYASSL_THREAD server_test(void* args)
|
||||
int doListen = 1;
|
||||
int crlFlags = 0;
|
||||
int ret;
|
||||
char* serverReadyFile = NULL;
|
||||
char* alpnList = NULL;
|
||||
unsigned char alpn_opt = 0;
|
||||
char* cipherList = NULL;
|
||||
@ -276,6 +276,7 @@ THREAD_RETURN CYASSL_THREAD server_test(void* args)
|
||||
const char* ourCert = svrCert;
|
||||
const char* ourKey = svrKey;
|
||||
const char* ourDhParam = dhParam;
|
||||
tcp_ready* readySignal = NULL;
|
||||
int argc = ((func_args*)args)->argc;
|
||||
char** argv = ((func_args*)args)->argv;
|
||||
|
||||
@ -312,6 +313,7 @@ THREAD_RETURN CYASSL_THREAD server_test(void* args)
|
||||
(void)alpnList;
|
||||
(void)alpn_opt;
|
||||
(void)crlFlags;
|
||||
(void)readySignal;
|
||||
|
||||
#ifdef CYASSL_TIRTOS
|
||||
fdOpenSession(Task_self());
|
||||
@ -320,7 +322,7 @@ THREAD_RETURN CYASSL_THREAD server_test(void* args)
|
||||
#ifdef WOLFSSL_VXWORKS
|
||||
useAnyAddr = 1;
|
||||
#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) {
|
||||
switch (ch) {
|
||||
case '?' :
|
||||
@ -358,7 +360,7 @@ THREAD_RETURN CYASSL_THREAD server_test(void* args)
|
||||
break;
|
||||
|
||||
case 'R' :
|
||||
serverReadyFile = 1;
|
||||
serverReadyFile = myoptarg;
|
||||
break;
|
||||
|
||||
case 'r' :
|
||||
@ -375,7 +377,7 @@ THREAD_RETURN CYASSL_THREAD server_test(void* args)
|
||||
|
||||
case 'p' :
|
||||
port = (word16)atoi(myoptarg);
|
||||
#if !defined(NO_MAIN_DRIVER) || defined(USE_WINDOWS_API)
|
||||
#if defined(USE_WINDOWS_API)
|
||||
if (port == 0)
|
||||
err_sys("port number cannot be 0");
|
||||
#endif
|
||||
@ -740,8 +742,12 @@ THREAD_RETURN CYASSL_THREAD server_test(void* args)
|
||||
#endif
|
||||
|
||||
/* do accept */
|
||||
readySignal = ((func_args*)args)->signal;
|
||||
if (readySignal) {
|
||||
readySignal->srfName = serverReadyFile;
|
||||
}
|
||||
tcp_accept(&sockfd, &clientfd, (func_args*)args, port, useAnyAddr,
|
||||
doDTLS, serverReadyFile, doListen);
|
||||
doDTLS, serverReadyFile ? 1 : 0, doListen);
|
||||
doListen = 0; /* Don't listen next time */
|
||||
|
||||
SSL_set_fd(ssl, clientfd);
|
||||
@ -903,6 +909,7 @@ THREAD_RETURN CYASSL_THREAD server_test(void* args)
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
func_args args;
|
||||
tcp_ready ready;
|
||||
|
||||
#ifdef HAVE_CAVIUM
|
||||
int ret = OpenNitroxDevice(CAVIUM_DIRECT, CAVIUM_DEV_ID);
|
||||
@ -914,6 +921,8 @@ THREAD_RETURN CYASSL_THREAD server_test(void* args)
|
||||
|
||||
args.argc = argc;
|
||||
args.argv = argv;
|
||||
args.signal = &ready;
|
||||
InitTcpReady(&ready);
|
||||
|
||||
CyaSSL_Init();
|
||||
#if defined(DEBUG_CYASSL) && !defined(WOLFSSL_MDK_SHELL)
|
||||
@ -927,6 +936,7 @@ THREAD_RETURN CYASSL_THREAD server_test(void* args)
|
||||
server_test(&args);
|
||||
#endif
|
||||
CyaSSL_Cleanup();
|
||||
FreeTcpReady(&ready);
|
||||
|
||||
#ifdef HAVE_CAVIUM
|
||||
CspShutdown(CAVIUM_DEV_ID);
|
||||
|
@ -5,16 +5,22 @@
|
||||
revocation_code="-361"
|
||||
exit_code=1
|
||||
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=-1
|
||||
#server_pid captured on startup, stores the id of the server process
|
||||
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() {
|
||||
if test -e /tmp/wolfssl_server_ready; then
|
||||
echo -e "removing exisitng server_ready file"
|
||||
rm /tmp/wolfssl_server_ready
|
||||
if test -e $ready_file; then
|
||||
echo -e "removing exisitng ready file"
|
||||
rm $ready_file
|
||||
fi
|
||||
}
|
||||
|
||||
@ -53,16 +59,26 @@ run_test() {
|
||||
# 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
|
||||
# into the variable server_pid
|
||||
./examples/server/server -R -p $crl_port -c certs/server-revoked-cert.pem \
|
||||
-k certs/server-revoked-key.pem &
|
||||
./examples/server/server -R $ready_file -p $crl_port \
|
||||
-c certs/server-revoked-cert.pem -k certs/server-revoked-key.pem &
|
||||
server_pid=$!
|
||||
|
||||
while [ ! -s /tmp/wolfssl_server_ready -a "$counter" -lt 20 ]; do
|
||||
echo -e "waiting for server_ready file..."
|
||||
while [ ! -s $ready_file -a "$counter" -lt 20 ]; do
|
||||
echo -e "waiting for ready file..."
|
||||
sleep 0.1
|
||||
counter=$((counter+ 1))
|
||||
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
|
||||
capture_out=$(./examples/client/client -p $crl_port 2>&1)
|
||||
client_result=$?
|
||||
|
@ -3,16 +3,22 @@
|
||||
#reusme.test
|
||||
|
||||
# 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
|
||||
server_pid=$no_pid
|
||||
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() {
|
||||
if test -e /tmp/wolfssl_server_ready; then
|
||||
echo -e "removing exisitng server_ready file"
|
||||
rm /tmp/wolfssl_server_ready
|
||||
if test -e $ready_file; then
|
||||
echo -e "removing exisitng ready file"
|
||||
rm $ready_file
|
||||
fi
|
||||
}
|
||||
|
||||
@ -39,15 +45,26 @@ trap do_trap INT TERM
|
||||
echo -e "\nStarting example server for resume test...\n"
|
||||
|
||||
remove_ready_file
|
||||
./examples/server/server -r -R -p $resume_port &
|
||||
./examples/server/server -r -R $ready_file -p $resume_port &
|
||||
server_pid=$!
|
||||
|
||||
while [ ! -s /tmp/wolfssl_server_ready -a "$counter" -lt 20 ]; do
|
||||
echo -e "waiting for server_ready file..."
|
||||
while [ ! -s $ready_file -a "$counter" -lt 20 ]; do
|
||||
echo -e "waiting for ready file..."
|
||||
sleep 0.1
|
||||
counter=$((counter+ 1))
|
||||
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
|
||||
client_result=$?
|
||||
|
||||
|
23
tests/unit.c
23
tests/unit.c
@ -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
|
||||
}
|
||||
|
@ -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)
|
||||
{
|
||||
FILE* f;
|
||||
|
@ -267,6 +267,7 @@
|
||||
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;
|
||||
@ -274,8 +275,30 @@ typedef struct tcp_ready {
|
||||
} tcp_ready;
|
||||
|
||||
|
||||
void InitTcpReady(tcp_ready*);
|
||||
void FreeTcpReady(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 WOLFSSL_METHOD* (*method_provider)(void);
|
||||
typedef void (*ctx_callback)(WOLFSSL_CTX* ctx);
|
||||
@ -296,6 +319,9 @@ typedef struct func_args {
|
||||
callback_functions *callbacks;
|
||||
} func_args;
|
||||
|
||||
|
||||
|
||||
|
||||
void wait_tcp_ready(func_args*);
|
||||
|
||||
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)
|
||||
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) {
|
||||
socklen_t len = sizeof(addr);
|
||||
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 */
|
||||
{
|
||||
tcp_ready* ready = args->signal;
|
||||
pthread_mutex_lock(&ready->mutex);
|
||||
ready->ready = 1;
|
||||
ready->port = port;
|
||||
pthread_cond_signal(&ready->cond);
|
||||
pthread_mutex_unlock(&ready->mutex);
|
||||
if (ready) {
|
||||
pthread_mutex_lock(&ready->mutex);
|
||||
ready->ready = 1;
|
||||
ready->port = port;
|
||||
pthread_cond_signal(&ready->cond);
|
||||
pthread_mutex_unlock(&ready->mutex);
|
||||
}
|
||||
}
|
||||
#elif defined (WOLFSSL_TIRTOS)
|
||||
/* Need mutex? */
|
||||
@ -829,18 +857,24 @@ static INLINE void tcp_accept(SOCKET_T* sockfd, SOCKET_T* clientfd,
|
||||
#endif
|
||||
|
||||
if (ready_file) {
|
||||
#ifndef NO_FILESYSTEM
|
||||
#ifndef USE_WINDOWS_API
|
||||
FILE* srf = fopen("/tmp/wolfssl_server_ready", "w");
|
||||
#else
|
||||
FILE* srf = fopen("wolfssl_server_ready", "w");
|
||||
#endif
|
||||
#ifndef NO_FILESYSTEM
|
||||
FILE* srf = NULL;
|
||||
tcp_ready* ready = args ? args->signal : NULL;
|
||||
|
||||
if (srf) {
|
||||
fputs("ready", srf);
|
||||
fclose(srf);
|
||||
if (ready) {
|
||||
srf = fopen(ready->srfName, "w");
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user