From 80cc737ffa02a910410fe3d4bf1279100b3229f8 Mon Sep 17 00:00:00 2001 From: toddouska Date: Tue, 6 Dec 2016 11:27:05 -0800 Subject: [PATCH] add pkcallbacks script test --- configure.ac | 2 + scripts/include.am | 5 ++ scripts/pkcallbacks.test | 113 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 120 insertions(+) create mode 100755 scripts/pkcallbacks.test diff --git a/configure.ac b/configure.ac index ee8d9822c..e59c210f5 100644 --- a/configure.ac +++ b/configure.ac @@ -474,6 +474,8 @@ then AM_CFLAGS="$AM_CFLAGS -DHAVE_PK_CALLBACKS" fi +AM_CONDITIONAL([BUILD_PKCALLBACKS], [ test "x$ENABLED_PKCALLBACKS" = "xyes" ]) + # SNIFFER AC_ARG_ENABLE([sniffer], diff --git a/scripts/include.am b/scripts/include.am index 1701ad97e..0a49b14af 100644 --- a/scripts/include.am +++ b/scripts/include.am @@ -47,6 +47,11 @@ if BUILD_TRUST_PEER_CERT dist_noinst_SCRIPTS+= scripts/trusted_peer.test endif +if BUILD_PKCALLBACKS +dist_noinst_SCRIPTS+= scripts/pkcallbacks.test +scripts/pkcallbacks.log: scripts/resume.log +endif + endif # end of BUILD_EXAMPLE_SERVERS if BUILD_EXAMPLE_CLIENTS diff --git a/scripts/pkcallbacks.test b/scripts/pkcallbacks.test new file mode 100755 index 000000000..6a0e1c569 --- /dev/null +++ b/scripts/pkcallbacks.test @@ -0,0 +1,113 @@ +#!/bin/sh + +#pkcallbacks.test + +exit_code=1 +counter=0 +# need a unique resume port since may run the same time as testsuite +# use server port zero hack to get one +pk_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_pk_ready$$ + +remove_ready_file() { + if test -e $ready_file; then + echo -e "removing existing ready file" + rm $ready_file + fi +} + +# trap this function so if user aborts with ^C or other kill signal we still +# get an exit that will in turn clean up the file system +abort_trap() { + echo "script aborted" + + if [ $server_pid != $no_pid ] + then + echo "killing server" + kill -9 $server_pid + fi + + exit_code=2 #different exit code in case of user interrupt + + echo "got abort signal, exiting with $exit_code" + exit $exit_code +} +trap abort_trap INT TERM + + +# trap this function so that if we exit on an error the file system will still +# be restored and the other tests may still pass. Never call this function +# instead use "exit " and this function will run automatically +restore_file_system() { + remove_ready_file +} +trap restore_file_system EXIT + +run_test() { + echo -e "\nStarting example server for pkcallbacks test...\n" + + remove_ready_file + + # starts the server on pk_port, -R generates ready file to be used as a + # mutex lock, -P does pkcallbacks. We capture the processid + # into the variable server_pid + ./examples/server/server -P -R $ready_file -p $pk_port & + server_pid=$! + + 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 + pk_port=`cat $ready_file` + + # starts client on pk_port with pkcallbacks, captures the output from client + capture_out=$(./examples/client/client -P -p $pk_port 2>&1) + 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 "server failed!" + do_cleanup + exit 1 + fi + +} + + +######### begin program ######### + +# run the test +run_test + +# If we get to this, success +echo "Success!" +exit 0 +########## end program ########## +