summaryrefslogtreecommitdiff
path: root/tests/scripts
diff options
context:
space:
mode:
authorNikos Mavrogiannopoulos <nmav@redhat.com>2016-05-13 13:41:53 +0200
committerNikos Mavrogiannopoulos <nmav@redhat.com>2016-05-13 20:15:19 +0200
commit74edce5051e1ae4e35c058a1776671338bcf3a49 (patch)
tree5fa7ae496036003bf8aac4fb81612f501451cd9d /tests/scripts
parent5b1d751f23e87b332b3cb3e86e488fb450abbe1c (diff)
downloadgnutls-74edce5051e1ae4e35c058a1776671338bcf3a49.tar.gz
tests: simplified server launching process
Also attempt to use a new port on every started server and added a waiting period for the port to become re-usable.
Diffstat (limited to 'tests/scripts')
-rw-r--r--tests/scripts/common.sh119
1 files changed, 72 insertions, 47 deletions
diff --git a/tests/scripts/common.sh b/tests/scripts/common.sh
index b338201cb2..ec8c7c3c4f 100644
--- a/tests/scripts/common.sh
+++ b/tests/scripts/common.sh
@@ -18,13 +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.
-rc=0
-while test $rc = 0
-do
- RPORT="$(((($$<<15)|RANDOM) % 63001 + 2000))"
- netstat -anlt|grep "\:$RPORT"
- rc=$?
-done
+
+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"
@@ -34,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