Browse code

Updated openvpn/t_cltsrv.sh (used by "make check") to conform to new --script-security rules. Also adds retrying if the addresses are in use (Matthias Andree).

git-svn-id: http://svn.openvpn.net/projects/openvpn/branches/BETA21/openvpn@3217 e7ae566f-a301-0410-adde-c780ea21d3b5

james authored on 2008/08/11 03:49:28
Showing 2 changed files
1 1
new file mode 100755
... ...
@@ -0,0 +1,2 @@
0
+#! /bin/sh
1
+echo "${role}:${signal}" >&3
... ...
@@ -1,7 +1,7 @@
1 1
 #! /bin/sh
2 2
 #
3 3
 # t_cltsrv.sh - script to test OpenVPN's crypto loopback
4
-# Copyright (C) 2005,2006  Matthias Andree
4
+# Copyright (C) 2005, 2006, 2008  Matthias Andree
5 5
 #
6 6
 # This program is free software; you can redistribute it and/or
7 7
 # modify it under the terms of the GNU General Public License
... ...
@@ -38,22 +38,50 @@ case `uname -s` in
38 38
     fi
39 39
     ;;
40 40
 esac
41
-echo "the following test will take about two minutes..." >&2
42
-set +e
43
-(
44
-./openvpn --cd "${srcdir}" ${addopts} --down 'echo "srv:${signal}" >&3 ; : #' --tls-exit --ping-exit 180 --config sample-config-files/loopback-server &
45
-./openvpn --cd "${srcdir}" ${addopts} --down 'echo "clt:${signal}" >&3 ; : #' --tls-exit --ping-exit 180 --config sample-config-files/loopback-client
46
-) 3>log.$$.signal >log.$$ 2>&1
47
-e1=$?
48
-wait $!
49
-e2=$?
50
-grep -v ":inactive$" log.$$.signal >/dev/null && { cat log.$$.signal ; echo ; cat log.$$ ; exit 1 ; }
41
+
42
+# make sure that the --down script is executable -- fail (rather than
43
+# skip) test if it isn't.
44
+downscript="t_cltsrv-down.sh"
45
+test -x "${srcdir}"/$downscript || chmod +x "${srcdir}"/$downscript || { echo >&2 "$downscript is not executable, failing." ; exit 1 ; }
46
+echo "The following test will take about two minutes." >&2
47
+echo "If the addresses are in use, this test will retry up to two times." >&2
48
+
49
+# go
50
+success=0
51
+for i in 1 2 3 ; do
52
+  set +e
53
+  (
54
+  ./openvpn --script-security 2 --cd "${srcdir}" ${addopts} --setenv role srv --down "$downscript" --tls-exit --ping-exit 180 --config sample-config-files/loopback-server &
55
+  ./openvpn --script-security 2 --cd "${srcdir}" ${addopts} --setenv role clt --down "$downscript" --tls-exit --ping-exit 180 --config sample-config-files/loopback-client
56
+  ) 3>log.$$.signal >log.$$ 2>&1
57
+  e1=$?
58
+  wait $!
59
+  e2=$?
60
+  grep 'TCP/UDP: Socket bind failed on local address.*in use' log.$$ >/dev/null && {
61
+    echo 'address in use, retrying in 150 s'
62
+    sleep 150
63
+    continue
64
+  }
65
+  grep -v ':inactive$' log.$$.signal >/dev/null && { cat log.$$.signal ; echo ; cat log.$$ ; exit 1 ; }
66
+  success=1
67
+  break
68
+done
51 69
 
52 70
 set -e
53 71
 
54
-if [ $e1 != 0 ] || [ $e2 != 0 ] ; then
55
-    cat log.$$
56
-    exit 1
72
+# exit code - defaults to 0, PASS
73
+ec=0
74
+
75
+if [ $success != 1 ] ; then
76
+  # couldn't run test -- addresses in use, skip test
77
+  cat log.$$
78
+  ec=77
79
+elif [ $e1 != 0 ] || [ $e2 != 0 ] ; then
80
+  # failure -- fail test
81
+  cat log.$$
82
+  ec=1
57 83
 fi
84
+
58 85
 rm log.$$ log.$$.signal
59 86
 trap 0
87
+exit $ec