diff options
Diffstat (limited to 'tests/scripts/common.sh')
-rw-r--r-- | tests/scripts/common.sh | 113 |
1 files changed, 72 insertions, 41 deletions
diff --git a/tests/scripts/common.sh b/tests/scripts/common.sh index fd6588d52f..ec8c7c3c4f 100644 --- a/tests/scripts/common.sh +++ b/tests/scripts/common.sh @@ -18,7 +18,10 @@ # along with this file; if not, write to the Free Software Foundation, # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -RPORT="$(((($$<<15)|RANDOM) % 63001 + 2000))" + +GETPORT='rc=0;while test $rc = 0;do PORT="$(((($$<<15)|RANDOM) % 63001 + 2000))"; + netstat -anl|grep "[\:\.]$PORT" >/dev/null 2>&1; + rc=$?;done;' fail() { PID="$1" @@ -28,56 +31,84 @@ fail() { exit 1 } +wait_for_port() +{ + local ret + local PORT="$1" + sleep 4 + + for i in 1 2 3 4 5 6;do + netstat -anl|grep "[\:\.]$PORT"|grep LISTEN >/dev/null 2>&1 + ret=$? + if test $ret != 0;then + netstat -anl|grep "[\:\.]$PORT" + echo try $i + sleep 2 + else + break + fi + done + return $ret +} + +wait_for_free_port() +{ + local ret + local PORT="$1" + + for i in 1 2 3 4 5 6;do + netstat -anl|grep "[\:\.]$PORT" >/dev/null 2>&1 + ret=$? + if test $ret != 0;then + break + else + sleep 20 + fi + done + return $ret +} + launch_server() { - PARENT="$1" - shift - ${SERV} ${DEBUG} -p "${PORT}" $* >/dev/null 2>&1 & - LOCALPID="$!" - trap "[ ! -z \"${LOCALPID}\" ] && kill ${LOCALPID};" 15 - wait "${LOCALPID}" - LOCALRET="$?" - if [ "${LOCALRET}" != "0" ] && [ "${LOCALRET}" != "143" ] ; then - # Houston, we'v got a problem... - echo "Failed to launch a gnutls-serv server !" - kill -10 ${PARENT} - fi + PARENT="$1" + shift + + wait_for_free_port ${PORT} + ${SERV} ${DEBUG} -p "${PORT}" $* >/dev/null 2>&1 & } launch_pkcs11_server() { - PARENT="$1" - shift - PROVIDER="$1" - shift - ${VALGRIND} ${SERV} ${PROVIDER} ${DEBUG} -p "${PORT}" $* & - LOCALPID="$!" - trap "[ ! -z \"${LOCALPID}\" ] && kill ${LOCALPID};" 15 - wait "${LOCALPID}" - LOCALRET="$?" - if [ "${LOCALRET}" != "0" ] && [ "${LOCALRET}" != "143" ] ; then - # Houston, we'v got a problem... - echo "Failed to launch a gnutls-serv server !" - kill -10 ${PARENT} - fi + PARENT="$1" + shift + PROVIDER="$1" + shift + + wait_for_free_port ${PORT} + + ${VALGRIND} ${SERV} ${PROVIDER} ${DEBUG} -p "${PORT}" $* & } launch_bare_server() { - PARENT="$1" - shift - ${SERV} $* >/dev/null 2>&1 & - LOCALPID="$!" - trap "[ ! -z \"${LOCALPID}\" ] && kill ${LOCALPID};" 15 - wait "${LOCALPID}" - LOCALRET="$?" - if [ "${LOCALRET}" != "0" ] && [ "${LOCALRET}" != "143" ] ; then - # Houston, we'v got a problem... - echo "Failed to launch server !" - kill -10 ${PARENT} - fi + PARENT="$1" + shift + + wait_for_free_port ${PORT} + ${SERV} $* >/dev/null 2>&1 & } wait_server() { - trap "kill $1" 1 15 2 + local PID=$1 + trap "test -n \"${PID}\" && kill ${PID};exit 1" 1 15 2 + wait_for_port $PORT + if test $? != 0;then + echo "Server $PORT did not come up" + kill $PID + exit 1 + fi +} + +wait_udp_server() { + local PID=$1 + trap "test -n \"${PID}\" && kill ${PID};exit 1" 1 15 2 sleep 4 } -trap "fail '' 'Failed to launch a gnutls-serv server, aborting test... '" 10 |