blob: 3ed38062aa166c992b86ff63484be357d020f016 [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
Frederic Lecailled4f36e32018-12-13 22:15:05 +010043 or
44 export HAPROXY_PROGRAM=/usr/local/sbin/haproxy
45 export VARNISHTEST_PROGRAM=/usr/local/bin/varnishtest
PiBa-NL72504042018-11-27 22:26:38 +010046EOF
47 return
48fi
49
Frederic Lecailled4f36e32018-12-13 22:15:05 +010050add_range_to_test_list()
51{
52 level0="*.vtc"
53 level1="h*.vtc"
54 level2="s*.vtc"
55 level3="l*.vtc"
56 level4="b*.vtc"
57 level5="k*.vtc"
58 level6="e*.vtc"
59
60 new_range=$(echo $1 | tr '-' ' ')
61 non_digit=$(echo $new_range | grep '[^0-9 ]')
62 if [ -n "$non_digit" ] ; then
63 return
64 fi
65 if [ "$new_range" = "$1" ] ; then
66 if [ $1 -gt 6 ] ; then
67 return
68 fi
69 eval echo '$'level$1
70 return
71 fi
72 if [ -z "$new_range" ] ; then
73 return
74 fi
75 list=
76 for l in $(seq $new_range) ; do
77 if [ -n "l" ] ; then
78 if [ -z "$list" ] ; then
79 list="$(eval echo '$'level${l})"
80 else
81 list="$list $(eval echo '$'level${l})"
82 fi
83 fi
84 done
85
86 echo $list
87}
88
89
90build_test_list()
91{
92 # Remove any spacing character
93 LEVEL="$(echo $LEVEL | tr -d ' ')"
94 # Replave any comma character by a space character
95 LEVEL="$(echo $LEVEL | tr ',' ' ')"
96 list=
97 for range in $LEVEL ; do
98 if [ -z "$list" ] ; then
99 list=$(add_range_to_test_list $range)
100 else
101 list="$list $(add_range_to_test_list $range)"
102 fi
103 done
104
105 echo $list
106}
107
108build_find_expr()
109{
110 expr=
111 for i in $@; do
112 if [ -z "$expr" ] ; then
113 expr="-name \"$i\""
114 else
115 expr="$expr -o -name \"$i\""
116 fi
117 done
118
119 echo $expr
120}
121
PiBa-NL72504042018-11-27 22:26:38 +0100122_startswith() {
123 _str="$1"
124 _sub="$2"
125 echo "$_str" | grep "^$_sub" >/dev/null 2>&1
126}
127
128_findtests() {
129 set -f
130 LEVEL=${LEVEL:-0};
Frederic Lecailled4f36e32018-12-13 22:15:05 +0100131 list=$(build_test_list "$LEVEL")
132 if [ -z "$list" ] ; then
133 echo "Invalid level specification '"$LEVEL"' or no file was found."
134 exit 1
PiBa-NL72504042018-11-27 22:26:38 +0100135 fi
Frederic Lecailled4f36e32018-12-13 22:15:05 +0100136 EXPR=$(build_find_expr $list)
PiBa-NL72504042018-11-27 22:26:38 +0100137
Frederic Lecailled4f36e32018-12-13 22:15:05 +0100138 for i in $( find "$1" $(eval echo $EXPR) ); do
PiBa-NL72504042018-11-27 22:26:38 +0100139 skiptest=
Willy Tarreau939193a2018-12-06 15:49:27 +0100140 require_version="$(sed -ne 's/^#REQUIRE_VERSION=//p' "$i")"
141 require_version_below="$(sed -ne 's/^#REQUIRE_VERSION_BELOW=//p' "$i")"
142 require_options="$(sed -ne 's/^#REQUIRE_OPTIONS=//p' "$i")"
143 exclude_targets=",$(sed -ne 's/^#EXCLUDE_TARGETS=//p' "$i"),"
PiBa-NL72504042018-11-27 22:26:38 +0100144
145 if [ -n "$require_version" ]; then
146 if [ $(_version "$HAPROXY_VERSION") -lt $(_version "$require_version") ]; then
147 echo " Skip $i because option haproxy is version: $HAPROXY_VERSION"
148 echo " REASON: this test requires at least version: $require_version"
149 skiptest=1
150 fi
151 fi
152 if [ -n "$require_version_below" ]; then
153 if [ $(_version "$HAPROXY_VERSION") -ge $(_version "$require_version_below") ]; then
154 echo " Skip $i because option haproxy is version: $HAPROXY_VERSION"
155 echo " REASON: this test requires a version below: $require_version_below"
156 skiptest=1
157 fi
158 fi
159
160 if [ -n "$( echo "$exclude_targets" | grep ",$TARGET," )" ]; then
161 echo " Skip $i because exclude_targets"
162 echo " REASON: exclude_targets '$exclude_targets' contains '$TARGET'"
163 skiptest=1
164 fi
165
166 #echo "REQUIRE_OPTIONS : $require_options"
167 for requiredoption in $(echo $require_options | tr "," "\012" ); do
168 if [ -z "$( echo "$OPTIONS" | grep "USE_$requiredoption=1" )" ]
169 then
170 echo " Skip $i because option $requiredoption not found"
171 echo -n " REASON: "
172 echo -n "$required" | sed -e 's/.*,//' -e 's/^[[:space:]]//'
173 echo
174 skiptest=1
175 fi
176 done
177 for required in "$(grep "#REQUIRE_OPTION=" "$i")";
178 do
179 if [ -z "$required" ]
180 then
181 continue
182 fi
183 requiredoption=$(echo "$required" | sed -e 's/.*=//' -e 's/,.*//')
184 if [ -z "$( echo "$OPTIONS" | grep "USE_$requiredoption=1" )" ]
185 then
186 echo " Skip $i because option $requiredoption not found"
187 echo -n " REASON: "
188 echo "$required" | sed -e 's/.*,//' -e 's/^[[:space:]]//'
189 skiptest=1
190 fi
191 done
192 testtarget=$(grep "#EXCLUDE_TARGET=" "$i")
193 if [ "$( echo "$testtarget" | grep "#EXCLUDE_TARGET=$TARGET," )" ]
194 then
195 echo " Skip $i because: TARGET = $TARGET"
196 echo -n " REASON: "
197 echo "$testtarget" | sed -e 's/.*,//' -e 's/^[[:space:]]//'
198 skiptest=1
199 fi
200
201 if [ -z $skiptest ]; then
202 echo " Add test: $i"
203 testlist="$testlist $i"
204 fi
205 done
206}
207
208_process() {
209 jobcount=""
210 verbose="-q"
211
212 while [ ${#} -gt 0 ]; do
213 if _startswith "$1" "-"; then
214 case "${1}" in
215 --j)
216 jobcount="$2"
217 shift
218 ;;
219 --varnishtestparams)
220 varnishtestparams="$2"
221 shift
222 ;;
223 --v)
224 verbose=""
225 ;;
226 --LEVEL)
227 LEVEL="$2"
228 shift
229 ;;
230 *)
231 echo "Unknown parameter : $1"
232 return 1
233 ;;
234 esac
235 else
236 _findtests "$1"
237 pathwasset=1
238 fi
239 shift 1
240 done
241 if [ -z $pathwasset ]; then
242 # no path was given, find all tests under current path
243 _findtests ./
244 fi
245}
246
247_version() {
248 echo "$@" | awk -F. '{ printf("%d%03d%03d%03d\012", $1,$2,$3,$4); }';
249}
250
251echo ""
252echo "########################## Preparing to run tests ##########################"
253
Frédéric Lécaille51e01b52018-11-29 21:41:42 +0100254HAPROXY_PROGRAM="${HAPROXY_PROGRAM:-${PWD}/haproxy}"
255VARNISHTEST_PROGRAM="${VARNISHTEST_PROGRAM:-varnishtest}"
PiBa-NL72504042018-11-27 22:26:38 +0100256
257preparefailed=
258if ! [ -x "$(command -v $HAPROXY_PROGRAM)" ]; then
259 echo "haproxy not found in path, please specify HAPROXY_PROGRAM environment variable"
260 preparefailed=1
261fi
262if ! [ -x "$(command -v $VARNISHTEST_PROGRAM)" ]; then
263 echo "varnishtest not found in path, please specify VARNISHTEST_PROGRAM environment variable"
264 preparefailed=1
265fi
266if [ $preparefailed ]; then
267 exit 1
268fi
269
270{ read HAPROXY_VERSION; read TARGET; read OPTIONS; } << EOF
271$($HAPROXY_PROGRAM -vv |grep 'HA-Proxy version\|TARGET\|OPTIONS' | sed 's/.* = //')
272EOF
273
274HAPROXY_VERSION=$(echo $HAPROXY_VERSION | cut -d " " -f 3)
275echo "Testing with haproxy version: $HAPROXY_VERSION"
276
277TESTRUNDATETIME="$(date '+%Y-%m-%d_%H-%M-%S')"
278
Frédéric Lécaille51e01b52018-11-29 21:41:42 +0100279TESTDIR="${TMPDIR:-/tmp}"
280mkdir -p "$TESTDIR" || exit 1
281TESTDIR=$(mktemp -d "$TESTDIR/$TESTRUNDATETIME.XXXXXX") || exit 1
PiBa-NL72504042018-11-27 22:26:38 +0100282
Frédéric Lécaille51e01b52018-11-29 21:41:42 +0100283export TMPDIR="$TESTDIR"
284export HAPROXY_PROGRAM="$HAPROXY_PROGRAM"
PiBa-NL72504042018-11-27 22:26:38 +0100285
286# Mimic implicit build options from haproxy MakeFile that are present for each target:
287
288if [ $TARGET = generic ] ; then
289 #generic system target has nothing specific
290 OPTIONS="$OPTIONS USE_POLL=1 USE_TPROXY=1"
291fi
292if [ $TARGET = haiku ] ; then
293 #For Haiku
294 OPTIONS="$OPTIONS USE_POLL=1 USE_TPROXY=1"
295fi
296if [ $TARGET = linux22 ] ; then
297 #This is for Linux 2.2
298 OPTIONS="$OPTIONS USE_POLL=1 USE_TPROXY=1 USE_LIBCRYPT=1 USE_DL=1 USE_RT=1"
299fi
300if [ $TARGET = linux24 ] ; then
301 #This is for standard Linux 2.4 with netfilter but without epoll()
302 OPTIONS="$OPTIONS USE_NETFILTER=1 USE_POLL=1 USE_TPROXY=1 USE_CRYPT_H=1 USE_LIBCRYPT=1 USE_DL=1 USE_RT=1"
303fi
304if [ $TARGET = linux24e ] ; then
305 #This is for enhanced Linux 2.4 with netfilter and epoll() patch>0.21
306 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"
307fi
308if [ $TARGET = linux26 ] ; then
309 #This is for standard Linux 2.6 with netfilter and standard epoll()
310 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"
311fi
312if [ $TARGET = linux2628 ] ; then
313 #This is for standard Linux >= 2.6.28 with netfilter, epoll, tproxy and splice
314 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"
315fi
316if [ $TARGET = solaris ] ; then
317 #This is for Solaris8
318 OPTIONS="$OPTIONS USE_POLL=1 USE_TPROXY=1 USE_LIBCRYPT=1 USE_CRYPT_H=1 USE_GETADDRINFO=1 USE_THREAD=1"
319fi
320if [ $TARGET = freebsd ] ; then
321 #This is for FreeBSD
322 OPTIONS="$OPTIONS USE_POLL=1 USE_KQUEUE=1 USE_TPROXY=1 USE_LIBCRYPT=1 USE_THREAD=1 USE_CPU_AFFINITY=1"
323fi
324if [ $TARGET = osx ] ; then
325 #This is for MacOS/X
326 OPTIONS="$OPTIONS USE_POLL=1 USE_KQUEUE=1 USE_TPROXY=1"
327fi
328if [ $TARGET = openbsd ] ; then
329 #This is for OpenBSD >= 5.7
330 OPTIONS="$OPTIONS USE_POLL=1 USE_KQUEUE=1 USE_TPROXY=1 USE_ACCEPT4=1 USE_THREAD=1"
331fi
332if [ $TARGET = netbsd ] ; then
333 #This is for NetBSD
334 OPTIONS="$OPTIONS USE_POLL=1 USE_KQUEUE=1 USE_TPROXY=1"
335fi
336if [ $TARGET = aix51 ] ; then
337 #This is for AIX 5.1
338 OPTIONS="$OPTIONS USE_POLL=1 USE_LIBCRYPT=1"
339fi
340if [ $TARGET = aix52 ] ; then
341 #This is for AIX 5.2 and later
342 OPTIONS="$OPTIONS USE_POLL=1 USE_LIBCRYPT=1"
343fi
344if [ $TARGET = cygwin ] ; then
345 #This is for Cygwin
346 OPTIONS="$OPTIONS USE_POLL=1 USE_TPROXY=1"
347fi
348
349echo "Target : $TARGET"
350echo "Options : $OPTIONS"
351
352echo "########################## Gathering tests to run ##########################"
353
354testlist=""
355pathwasset=
356
357_process "$@";
358
359echo "########################## Starting varnishtest ##########################"
360echo "Testing with haproxy version: $HAPROXY_VERSION"
361_vtresult=0
362if [ -n "$testlist" ]; then
363 if [ -n "$jobcount" ]; then
364 jobcount="-j $jobcount"
365 fi
366 $VARNISHTEST_PROGRAM $varnishtestparams $verbose $jobcount -l -k -t 10 $testlist
367 _vtresult=$?
368else
369 echo "No tests found that meet the required criteria"
370fi
371if [ $_vtresult != 0 ]
372then
373 echo "########################## Gathering failed results ##########################"
Frédéric Lécaille51e01b52018-11-29 21:41:42 +0100374 export TESTDIR
375 find "$TESTDIR" -type d -name "vtc.*" -exec sh -c 'for i; do
376 if [ ! -e "$i/LOG" ] ; then continue; fi
377 cat <<- EOF | tee -a "$TESTDIR/failedtests.log"
378$(echo "###### $(cat "$i/INFO") ######")
379$(echo "## test results in: \"$i\"")
380$(grep -- ---- "$i/LOG")
PiBa-NL72504042018-11-27 22:26:38 +0100381EOF
Frédéric Lécaille51e01b52018-11-29 21:41:42 +0100382 done' sh {} +
PiBa-NL72504042018-11-27 22:26:38 +0100383 exit 1
384else
385 # all tests were succesfull, removing tempdir (the last part.)
Frédéric Lécaille51e01b52018-11-29 21:41:42 +0100386 rmdir "$TESTDIR"
PiBa-NL72504042018-11-27 22:26:38 +0100387fi
388exit 0