blob: d05d8deb3770c364417fb3cff80d1c4164a94da9 [file] [log] [blame]
Frédéric Lécaille51e01b52018-11-29 21:41:42 +01001#!/bin/sh
PiBa-NL72504042018-11-27 22:26:38 +01002
3if [ "$1" = "--help" ]; then
4 cat << EOF
5### run-regtests.sh ###
6 Running run-regtests.sh --help shows this information about how to use it
7
8 Run without parameters to run all tests in the current folder (including subfolders)
9 run-regtests.sh
10
11 Provide paths to run tests from (including subfolders):
12 run-regtests.sh ./tests1 ./tests2
13
14 Parameters:
15 --j <NUM>, To run varnishtest with multiple jobs / threads for a faster overall result
16 run-regtests.sh ./fasttest --j 16
17
18 --v, to run verbose
19 run-regtests.sh --v, disables the default varnishtest 'quiet' parameter
20
21 --varnishtestparams <ARGS>, passes custom ARGS to varnishtest
22 run-regtests.sh --varnishtestparams "-n 10"
23
24 Including text below into a .vtc file will check for its requirements
25 related to haproxy's target and compilation options
26 # Below targets are not capable of completing this test succesfully
27 #EXCLUDE_TARGET=freebsd, abns sockets are not available on freebsd
28
29 #EXCLUDE_TARGETS=dos,freebsd,windows
30
31 # Below option is required to complete this test succesfully
32 #REQUIRE_OPTION=OPENSSL, this test needs OPENSSL compiled in.
33
34 #REQUIRE_OPTIONS=ZLIB,OPENSSL,LUA
35
36 # To define a range of versions that a test can run with:
37 #REQUIRE_VERSION=0.0
38 #REQUIRE_VERSION_BELOW=99.9
39
40 Configure environment variables to set the haproxy and varnishtest binaries to use
41 setenv HAPROXY_PROGRAM /usr/local/sbin/haproxy
42 setenv VARNISHTEST_PROGRAM /usr/local/bin/varnishtest
43EOF
44 return
45fi
46
47_startswith() {
48 _str="$1"
49 _sub="$2"
50 echo "$_str" | grep "^$_sub" >/dev/null 2>&1
51}
52
53_findtests() {
54 set -f
55 LEVEL=${LEVEL:-0};
56 EXPR='*.vtc'
57 if [ $LEVEL = 1 ] ; then
58 EXPR='h*.vtc';
59 elif [ $LEVEL = 2 ] ; then
60 EXPR='s*.vtc';
61 elif [ $LEVEL = 3 ] ; then
62 EXPR='l*.vtc';
63 elif [ $LEVEL = 4 ] ; then
64 EXPR='b*.vtc';
65 fi
66
67 for i in $( find "$1" -name "$EXPR" ); do
68 skiptest=
69 require_version="$(grep "#REQUIRE_VERSION=" "$i" | sed -e 's/.*=//')"
70 require_version_below="$(grep "#REQUIRE_VERSION_BELOW=" "$i" | sed -e 's/.*=//')"
71 require_options="$(grep "#REQUIRE_OPTIONS=" "$i" | sed -e 's/.*=//')"
72 exclude_targets=",$(grep "#EXCLUDE_TARGETS=" "$i" | sed -e 's/.*=//'),"
73
74 if [ -n "$require_version" ]; then
75 if [ $(_version "$HAPROXY_VERSION") -lt $(_version "$require_version") ]; then
76 echo " Skip $i because option haproxy is version: $HAPROXY_VERSION"
77 echo " REASON: this test requires at least version: $require_version"
78 skiptest=1
79 fi
80 fi
81 if [ -n "$require_version_below" ]; then
82 if [ $(_version "$HAPROXY_VERSION") -ge $(_version "$require_version_below") ]; then
83 echo " Skip $i because option haproxy is version: $HAPROXY_VERSION"
84 echo " REASON: this test requires a version below: $require_version_below"
85 skiptest=1
86 fi
87 fi
88
89 if [ -n "$( echo "$exclude_targets" | grep ",$TARGET," )" ]; then
90 echo " Skip $i because exclude_targets"
91 echo " REASON: exclude_targets '$exclude_targets' contains '$TARGET'"
92 skiptest=1
93 fi
94
95 #echo "REQUIRE_OPTIONS : $require_options"
96 for requiredoption in $(echo $require_options | tr "," "\012" ); do
97 if [ -z "$( echo "$OPTIONS" | grep "USE_$requiredoption=1" )" ]
98 then
99 echo " Skip $i because option $requiredoption not found"
100 echo -n " REASON: "
101 echo -n "$required" | sed -e 's/.*,//' -e 's/^[[:space:]]//'
102 echo
103 skiptest=1
104 fi
105 done
106 for required in "$(grep "#REQUIRE_OPTION=" "$i")";
107 do
108 if [ -z "$required" ]
109 then
110 continue
111 fi
112 requiredoption=$(echo "$required" | sed -e 's/.*=//' -e 's/,.*//')
113 if [ -z "$( echo "$OPTIONS" | grep "USE_$requiredoption=1" )" ]
114 then
115 echo " Skip $i because option $requiredoption not found"
116 echo -n " REASON: "
117 echo "$required" | sed -e 's/.*,//' -e 's/^[[:space:]]//'
118 skiptest=1
119 fi
120 done
121 testtarget=$(grep "#EXCLUDE_TARGET=" "$i")
122 if [ "$( echo "$testtarget" | grep "#EXCLUDE_TARGET=$TARGET," )" ]
123 then
124 echo " Skip $i because: TARGET = $TARGET"
125 echo -n " REASON: "
126 echo "$testtarget" | sed -e 's/.*,//' -e 's/^[[:space:]]//'
127 skiptest=1
128 fi
129
130 if [ -z $skiptest ]; then
131 echo " Add test: $i"
132 testlist="$testlist $i"
133 fi
134 done
135}
136
137_process() {
138 jobcount=""
139 verbose="-q"
140
141 while [ ${#} -gt 0 ]; do
142 if _startswith "$1" "-"; then
143 case "${1}" in
144 --j)
145 jobcount="$2"
146 shift
147 ;;
148 --varnishtestparams)
149 varnishtestparams="$2"
150 shift
151 ;;
152 --v)
153 verbose=""
154 ;;
155 --LEVEL)
156 LEVEL="$2"
157 shift
158 ;;
159 *)
160 echo "Unknown parameter : $1"
161 return 1
162 ;;
163 esac
164 else
165 _findtests "$1"
166 pathwasset=1
167 fi
168 shift 1
169 done
170 if [ -z $pathwasset ]; then
171 # no path was given, find all tests under current path
172 _findtests ./
173 fi
174}
175
176_version() {
177 echo "$@" | awk -F. '{ printf("%d%03d%03d%03d\012", $1,$2,$3,$4); }';
178}
179
180echo ""
181echo "########################## Preparing to run tests ##########################"
182
Frédéric Lécaille51e01b52018-11-29 21:41:42 +0100183HAPROXY_PROGRAM="${HAPROXY_PROGRAM:-${PWD}/haproxy}"
184VARNISHTEST_PROGRAM="${VARNISHTEST_PROGRAM:-varnishtest}"
PiBa-NL72504042018-11-27 22:26:38 +0100185
186preparefailed=
187if ! [ -x "$(command -v $HAPROXY_PROGRAM)" ]; then
188 echo "haproxy not found in path, please specify HAPROXY_PROGRAM environment variable"
189 preparefailed=1
190fi
191if ! [ -x "$(command -v $VARNISHTEST_PROGRAM)" ]; then
192 echo "varnishtest not found in path, please specify VARNISHTEST_PROGRAM environment variable"
193 preparefailed=1
194fi
195if [ $preparefailed ]; then
196 exit 1
197fi
198
199{ read HAPROXY_VERSION; read TARGET; read OPTIONS; } << EOF
200$($HAPROXY_PROGRAM -vv |grep 'HA-Proxy version\|TARGET\|OPTIONS' | sed 's/.* = //')
201EOF
202
203HAPROXY_VERSION=$(echo $HAPROXY_VERSION | cut -d " " -f 3)
204echo "Testing with haproxy version: $HAPROXY_VERSION"
205
206TESTRUNDATETIME="$(date '+%Y-%m-%d_%H-%M-%S')"
207
Frédéric Lécaille51e01b52018-11-29 21:41:42 +0100208TESTDIR="${TMPDIR:-/tmp}"
209mkdir -p "$TESTDIR" || exit 1
210TESTDIR=$(mktemp -d "$TESTDIR/$TESTRUNDATETIME.XXXXXX") || exit 1
PiBa-NL72504042018-11-27 22:26:38 +0100211
Frédéric Lécaille51e01b52018-11-29 21:41:42 +0100212export TMPDIR="$TESTDIR"
213export HAPROXY_PROGRAM="$HAPROXY_PROGRAM"
PiBa-NL72504042018-11-27 22:26:38 +0100214
215# Mimic implicit build options from haproxy MakeFile that are present for each target:
216
217if [ $TARGET = generic ] ; then
218 #generic system target has nothing specific
219 OPTIONS="$OPTIONS USE_POLL=1 USE_TPROXY=1"
220fi
221if [ $TARGET = haiku ] ; then
222 #For Haiku
223 OPTIONS="$OPTIONS USE_POLL=1 USE_TPROXY=1"
224fi
225if [ $TARGET = linux22 ] ; then
226 #This is for Linux 2.2
227 OPTIONS="$OPTIONS USE_POLL=1 USE_TPROXY=1 USE_LIBCRYPT=1 USE_DL=1 USE_RT=1"
228fi
229if [ $TARGET = linux24 ] ; then
230 #This is for standard Linux 2.4 with netfilter but without epoll()
231 OPTIONS="$OPTIONS USE_NETFILTER=1 USE_POLL=1 USE_TPROXY=1 USE_CRYPT_H=1 USE_LIBCRYPT=1 USE_DL=1 USE_RT=1"
232fi
233if [ $TARGET = linux24e ] ; then
234 #This is for enhanced Linux 2.4 with netfilter and epoll() patch>0.21
235 OPTIONS="$OPTIONS USE_NETFILTER=1 USE_POLL=1 USE_EPOLL=1 USE_MY_EPOLL=1 USE_TPROXY=1 USE_CRYPT_H=1 USE_LIBCRYPT=1 USE_DL=1 USE_RT=1"
236fi
237if [ $TARGET = linux26 ] ; then
238 #This is for standard Linux 2.6 with netfilter and standard epoll()
239 OPTIONS="$OPTIONS USE_NETFILTER=1 USE_POLL=1 USE_EPOLL=1 USE_TPROXY=1 USE_CRYPT_H=1 USE_LIBCRYPT=1 USE_FUTEX=1 USE_DL=1 USE_RT=1"
240fi
241if [ $TARGET = linux2628 ] ; then
242 #This is for standard Linux >= 2.6.28 with netfilter, epoll, tproxy and splice
243 OPTIONS="$OPTIONS USE_NETFILTER=1 USE_POLL=1 USE_EPOLL=1 USE_TPROXY=1 USE_CRYPT_H=1 USE_LIBCRYPT=1 USE_LINUX_SPLICE=1 USE_LINUX_TPROXY=1 USE_ACCEPT4=1 USE_FUTEX=1 USE_CPU_AFFINITY=1 ASSUME_SPLICE_WORKS=1 USE_DL=1 USE_RT=1 USE_THREAD=1"
244fi
245if [ $TARGET = solaris ] ; then
246 #This is for Solaris8
247 OPTIONS="$OPTIONS USE_POLL=1 USE_TPROXY=1 USE_LIBCRYPT=1 USE_CRYPT_H=1 USE_GETADDRINFO=1 USE_THREAD=1"
248fi
249if [ $TARGET = freebsd ] ; then
250 #This is for FreeBSD
251 OPTIONS="$OPTIONS USE_POLL=1 USE_KQUEUE=1 USE_TPROXY=1 USE_LIBCRYPT=1 USE_THREAD=1 USE_CPU_AFFINITY=1"
252fi
253if [ $TARGET = osx ] ; then
254 #This is for MacOS/X
255 OPTIONS="$OPTIONS USE_POLL=1 USE_KQUEUE=1 USE_TPROXY=1"
256fi
257if [ $TARGET = openbsd ] ; then
258 #This is for OpenBSD >= 5.7
259 OPTIONS="$OPTIONS USE_POLL=1 USE_KQUEUE=1 USE_TPROXY=1 USE_ACCEPT4=1 USE_THREAD=1"
260fi
261if [ $TARGET = netbsd ] ; then
262 #This is for NetBSD
263 OPTIONS="$OPTIONS USE_POLL=1 USE_KQUEUE=1 USE_TPROXY=1"
264fi
265if [ $TARGET = aix51 ] ; then
266 #This is for AIX 5.1
267 OPTIONS="$OPTIONS USE_POLL=1 USE_LIBCRYPT=1"
268fi
269if [ $TARGET = aix52 ] ; then
270 #This is for AIX 5.2 and later
271 OPTIONS="$OPTIONS USE_POLL=1 USE_LIBCRYPT=1"
272fi
273if [ $TARGET = cygwin ] ; then
274 #This is for Cygwin
275 OPTIONS="$OPTIONS USE_POLL=1 USE_TPROXY=1"
276fi
277
278echo "Target : $TARGET"
279echo "Options : $OPTIONS"
280
281echo "########################## Gathering tests to run ##########################"
282
283testlist=""
284pathwasset=
285
286_process "$@";
287
288echo "########################## Starting varnishtest ##########################"
289echo "Testing with haproxy version: $HAPROXY_VERSION"
290_vtresult=0
291if [ -n "$testlist" ]; then
292 if [ -n "$jobcount" ]; then
293 jobcount="-j $jobcount"
294 fi
295 $VARNISHTEST_PROGRAM $varnishtestparams $verbose $jobcount -l -k -t 10 $testlist
296 _vtresult=$?
297else
298 echo "No tests found that meet the required criteria"
299fi
300if [ $_vtresult != 0 ]
301then
302 echo "########################## Gathering failed results ##########################"
Frédéric Lécaille51e01b52018-11-29 21:41:42 +0100303 export TESTDIR
304 find "$TESTDIR" -type d -name "vtc.*" -exec sh -c 'for i; do
305 if [ ! -e "$i/LOG" ] ; then continue; fi
306 cat <<- EOF | tee -a "$TESTDIR/failedtests.log"
307$(echo "###### $(cat "$i/INFO") ######")
308$(echo "## test results in: \"$i\"")
309$(grep -- ---- "$i/LOG")
PiBa-NL72504042018-11-27 22:26:38 +0100310EOF
Frédéric Lécaille51e01b52018-11-29 21:41:42 +0100311 done' sh {} +
PiBa-NL72504042018-11-27 22:26:38 +0100312 exit 1
313else
314 # all tests were succesfull, removing tempdir (the last part.)
Frédéric Lécaille51e01b52018-11-29 21:41:42 +0100315 rmdir "$TESTDIR"
PiBa-NL72504042018-11-27 22:26:38 +0100316fi
317exit 0