blob: be53e97cfd5069bb82e63f8d085232eddfe70c0a [file] [log] [blame]
Frédéric Lécaille51e01b52018-11-29 21:41:42 +01001#!/bin/sh
PiBa-NL72504042018-11-27 22:26:38 +01002
Christopher Faulet8d67cf82018-12-18 22:41:20 +01003_help()
4{
PiBa-NL72504042018-11-27 22:26:38 +01005 cat << EOF
6### run-regtests.sh ###
7 Running run-regtests.sh --help shows this information about how to use it
8
9 Run without parameters to run all tests in the current folder (including subfolders)
10 run-regtests.sh
11
12 Provide paths to run tests from (including subfolders):
13 run-regtests.sh ./tests1 ./tests2
14
15 Parameters:
16 --j <NUM>, To run varnishtest with multiple jobs / threads for a faster overall result
17 run-regtests.sh ./fasttest --j 16
18
19 --v, to run verbose
20 run-regtests.sh --v, disables the default varnishtest 'quiet' parameter
21
22 --varnishtestparams <ARGS>, passes custom ARGS to varnishtest
23 run-regtests.sh --varnishtestparams "-n 10"
24
25 Including text below into a .vtc file will check for its requirements
26 related to haproxy's target and compilation options
27 # Below targets are not capable of completing this test succesfully
28 #EXCLUDE_TARGET=freebsd, abns sockets are not available on freebsd
29
30 #EXCLUDE_TARGETS=dos,freebsd,windows
31
32 # Below option is required to complete this test succesfully
33 #REQUIRE_OPTION=OPENSSL, this test needs OPENSSL compiled in.
34
35 #REQUIRE_OPTIONS=ZLIB,OPENSSL,LUA
36
37 # To define a range of versions that a test can run with:
38 #REQUIRE_VERSION=0.0
39 #REQUIRE_VERSION_BELOW=99.9
40
41 Configure environment variables to set the haproxy and varnishtest binaries to use
42 setenv HAPROXY_PROGRAM /usr/local/sbin/haproxy
43 setenv VARNISHTEST_PROGRAM /usr/local/bin/varnishtest
Frederic Lecailled4f36e32018-12-13 22:15:05 +010044 or
45 export HAPROXY_PROGRAM=/usr/local/sbin/haproxy
46 export VARNISHTEST_PROGRAM=/usr/local/bin/varnishtest
PiBa-NL72504042018-11-27 22:26:38 +010047EOF
Christopher Faulet8d67cf82018-12-18 22:41:20 +010048 exit 0
49}
PiBa-NL72504042018-11-27 22:26:38 +010050
Frederic Lecailled4f36e32018-12-13 22:15:05 +010051add_range_to_test_list()
52{
53 level0="*.vtc"
54 level1="h*.vtc"
55 level2="s*.vtc"
56 level3="l*.vtc"
57 level4="b*.vtc"
58 level5="k*.vtc"
59 level6="e*.vtc"
60
61 new_range=$(echo $1 | tr '-' ' ')
62 non_digit=$(echo $new_range | grep '[^0-9 ]')
63 if [ -n "$non_digit" ] ; then
64 return
65 fi
66 if [ "$new_range" = "$1" ] ; then
67 if [ $1 -gt 6 ] ; then
68 return
69 fi
70 eval echo '$'level$1
71 return
72 fi
73 if [ -z "$new_range" ] ; then
74 return
75 fi
76 list=
77 for l in $(seq $new_range) ; do
78 if [ -n "l" ] ; then
79 if [ -z "$list" ] ; then
80 list="$(eval echo '$'level${l})"
81 else
82 list="$list $(eval echo '$'level${l})"
83 fi
84 fi
85 done
86
87 echo $list
88}
89
90
91build_test_list()
92{
93 # Remove any spacing character
94 LEVEL="$(echo $LEVEL | tr -d ' ')"
95 # Replave any comma character by a space character
96 LEVEL="$(echo $LEVEL | tr ',' ' ')"
97 list=
98 for range in $LEVEL ; do
99 if [ -z "$list" ] ; then
100 list=$(add_range_to_test_list $range)
101 else
102 list="$list $(add_range_to_test_list $range)"
103 fi
104 done
105
106 echo $list
107}
108
109build_find_expr()
110{
111 expr=
112 for i in $@; do
113 if [ -z "$expr" ] ; then
114 expr="-name \"$i\""
115 else
116 expr="$expr -o -name \"$i\""
117 fi
118 done
119
120 echo $expr
121}
122
PiBa-NL72504042018-11-27 22:26:38 +0100123_startswith() {
124 _str="$1"
125 _sub="$2"
126 echo "$_str" | grep "^$_sub" >/dev/null 2>&1
127}
128
129_findtests() {
130 set -f
131 LEVEL=${LEVEL:-0};
Frederic Lecailled4f36e32018-12-13 22:15:05 +0100132 list=$(build_test_list "$LEVEL")
133 if [ -z "$list" ] ; then
134 echo "Invalid level specification '"$LEVEL"' or no file was found."
135 exit 1
PiBa-NL72504042018-11-27 22:26:38 +0100136 fi
Frederic Lecailled4f36e32018-12-13 22:15:05 +0100137 EXPR=$(build_find_expr $list)
PiBa-NL72504042018-11-27 22:26:38 +0100138
Frederic Lecailled4f36e32018-12-13 22:15:05 +0100139 for i in $( find "$1" $(eval echo $EXPR) ); do
PiBa-NL72504042018-11-27 22:26:38 +0100140 skiptest=
Willy Tarreau939193a2018-12-06 15:49:27 +0100141 require_version="$(sed -ne 's/^#REQUIRE_VERSION=//p' "$i")"
142 require_version_below="$(sed -ne 's/^#REQUIRE_VERSION_BELOW=//p' "$i")"
143 require_options="$(sed -ne 's/^#REQUIRE_OPTIONS=//p' "$i")"
144 exclude_targets=",$(sed -ne 's/^#EXCLUDE_TARGETS=//p' "$i"),"
PiBa-NL72504042018-11-27 22:26:38 +0100145
146 if [ -n "$require_version" ]; then
147 if [ $(_version "$HAPROXY_VERSION") -lt $(_version "$require_version") ]; then
148 echo " Skip $i because option haproxy is version: $HAPROXY_VERSION"
149 echo " REASON: this test requires at least version: $require_version"
150 skiptest=1
151 fi
152 fi
153 if [ -n "$require_version_below" ]; then
154 if [ $(_version "$HAPROXY_VERSION") -ge $(_version "$require_version_below") ]; then
155 echo " Skip $i because option haproxy is version: $HAPROXY_VERSION"
156 echo " REASON: this test requires a version below: $require_version_below"
157 skiptest=1
158 fi
159 fi
160
161 if [ -n "$( echo "$exclude_targets" | grep ",$TARGET," )" ]; then
162 echo " Skip $i because exclude_targets"
163 echo " REASON: exclude_targets '$exclude_targets' contains '$TARGET'"
164 skiptest=1
165 fi
166
167 #echo "REQUIRE_OPTIONS : $require_options"
168 for requiredoption in $(echo $require_options | tr "," "\012" ); do
169 if [ -z "$( echo "$OPTIONS" | grep "USE_$requiredoption=1" )" ]
170 then
171 echo " Skip $i because option $requiredoption not found"
172 echo -n " REASON: "
173 echo -n "$required" | sed -e 's/.*,//' -e 's/^[[:space:]]//'
174 echo
175 skiptest=1
176 fi
177 done
178 for required in "$(grep "#REQUIRE_OPTION=" "$i")";
179 do
180 if [ -z "$required" ]
181 then
182 continue
183 fi
184 requiredoption=$(echo "$required" | sed -e 's/.*=//' -e 's/,.*//')
185 if [ -z "$( echo "$OPTIONS" | grep "USE_$requiredoption=1" )" ]
186 then
187 echo " Skip $i because option $requiredoption not found"
188 echo -n " REASON: "
189 echo "$required" | sed -e 's/.*,//' -e 's/^[[:space:]]//'
190 skiptest=1
191 fi
192 done
193 testtarget=$(grep "#EXCLUDE_TARGET=" "$i")
194 if [ "$( echo "$testtarget" | grep "#EXCLUDE_TARGET=$TARGET," )" ]
195 then
196 echo " Skip $i because: TARGET = $TARGET"
197 echo -n " REASON: "
198 echo "$testtarget" | sed -e 's/.*,//' -e 's/^[[:space:]]//'
199 skiptest=1
200 fi
201
202 if [ -z $skiptest ]; then
203 echo " Add test: $i"
204 testlist="$testlist $i"
205 fi
206 done
207}
208
209_process() {
PiBa-NL72504042018-11-27 22:26:38 +0100210 while [ ${#} -gt 0 ]; do
211 if _startswith "$1" "-"; then
212 case "${1}" in
213 --j)
214 jobcount="$2"
215 shift
216 ;;
217 --varnishtestparams)
218 varnishtestparams="$2"
219 shift
220 ;;
221 --v)
222 verbose=""
223 ;;
224 --LEVEL)
225 LEVEL="$2"
226 shift
227 ;;
Christopher Faulet8d67cf82018-12-18 22:41:20 +0100228 --help)
229 _help
230 ;;
PiBa-NL72504042018-11-27 22:26:38 +0100231 *)
232 echo "Unknown parameter : $1"
Christopher Faulet8d67cf82018-12-18 22:41:20 +0100233 exit 1
PiBa-NL72504042018-11-27 22:26:38 +0100234 ;;
235 esac
236 else
Christopher Faulet8d67cf82018-12-18 22:41:20 +0100237 REGTESTS="${REGTESTS} $1"
PiBa-NL72504042018-11-27 22:26:38 +0100238 fi
239 shift 1
240 done
PiBa-NL72504042018-11-27 22:26:38 +0100241}
242
243_version() {
244 echo "$@" | awk -F. '{ printf("%d%03d%03d%03d\012", $1,$2,$3,$4); }';
245}
246
PiBa-NL72504042018-11-27 22:26:38 +0100247
Frédéric Lécaille51e01b52018-11-29 21:41:42 +0100248HAPROXY_PROGRAM="${HAPROXY_PROGRAM:-${PWD}/haproxy}"
249VARNISHTEST_PROGRAM="${VARNISHTEST_PROGRAM:-varnishtest}"
Christopher Faulet8d67cf82018-12-18 22:41:20 +0100250REGTESTS=""
251
252jobcount=""
253verbose="-q"
254testlist=""
255
256_process "$@";
257
258echo ""
259echo "########################## Preparing to run tests ##########################"
PiBa-NL72504042018-11-27 22:26:38 +0100260
261preparefailed=
262if ! [ -x "$(command -v $HAPROXY_PROGRAM)" ]; then
263 echo "haproxy not found in path, please specify HAPROXY_PROGRAM environment variable"
264 preparefailed=1
265fi
266if ! [ -x "$(command -v $VARNISHTEST_PROGRAM)" ]; then
267 echo "varnishtest not found in path, please specify VARNISHTEST_PROGRAM environment variable"
268 preparefailed=1
269fi
270if [ $preparefailed ]; then
271 exit 1
272fi
273
274{ read HAPROXY_VERSION; read TARGET; read OPTIONS; } << EOF
275$($HAPROXY_PROGRAM -vv |grep 'HA-Proxy version\|TARGET\|OPTIONS' | sed 's/.* = //')
276EOF
277
278HAPROXY_VERSION=$(echo $HAPROXY_VERSION | cut -d " " -f 3)
279echo "Testing with haproxy version: $HAPROXY_VERSION"
280
281TESTRUNDATETIME="$(date '+%Y-%m-%d_%H-%M-%S')"
282
Frédéric Lécaille51e01b52018-11-29 21:41:42 +0100283TESTDIR="${TMPDIR:-/tmp}"
284mkdir -p "$TESTDIR" || exit 1
285TESTDIR=$(mktemp -d "$TESTDIR/$TESTRUNDATETIME.XXXXXX") || exit 1
PiBa-NL72504042018-11-27 22:26:38 +0100286
Frédéric Lécaille51e01b52018-11-29 21:41:42 +0100287export TMPDIR="$TESTDIR"
288export HAPROXY_PROGRAM="$HAPROXY_PROGRAM"
PiBa-NL72504042018-11-27 22:26:38 +0100289
290# Mimic implicit build options from haproxy MakeFile that are present for each target:
291
292if [ $TARGET = generic ] ; then
293 #generic system target has nothing specific
294 OPTIONS="$OPTIONS USE_POLL=1 USE_TPROXY=1"
295fi
296if [ $TARGET = haiku ] ; then
297 #For Haiku
298 OPTIONS="$OPTIONS USE_POLL=1 USE_TPROXY=1"
299fi
300if [ $TARGET = linux22 ] ; then
301 #This is for Linux 2.2
302 OPTIONS="$OPTIONS USE_POLL=1 USE_TPROXY=1 USE_LIBCRYPT=1 USE_DL=1 USE_RT=1"
303fi
304if [ $TARGET = linux24 ] ; then
305 #This is for standard Linux 2.4 with netfilter but without epoll()
306 OPTIONS="$OPTIONS USE_NETFILTER=1 USE_POLL=1 USE_TPROXY=1 USE_CRYPT_H=1 USE_LIBCRYPT=1 USE_DL=1 USE_RT=1"
307fi
308if [ $TARGET = linux24e ] ; then
309 #This is for enhanced Linux 2.4 with netfilter and epoll() patch>0.21
310 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"
311fi
312if [ $TARGET = linux26 ] ; then
313 #This is for standard Linux 2.6 with netfilter and standard epoll()
314 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"
315fi
316if [ $TARGET = linux2628 ] ; then
317 #This is for standard Linux >= 2.6.28 with netfilter, epoll, tproxy and splice
318 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"
319fi
320if [ $TARGET = solaris ] ; then
321 #This is for Solaris8
322 OPTIONS="$OPTIONS USE_POLL=1 USE_TPROXY=1 USE_LIBCRYPT=1 USE_CRYPT_H=1 USE_GETADDRINFO=1 USE_THREAD=1"
323fi
324if [ $TARGET = freebsd ] ; then
325 #This is for FreeBSD
326 OPTIONS="$OPTIONS USE_POLL=1 USE_KQUEUE=1 USE_TPROXY=1 USE_LIBCRYPT=1 USE_THREAD=1 USE_CPU_AFFINITY=1"
327fi
328if [ $TARGET = osx ] ; then
329 #This is for MacOS/X
330 OPTIONS="$OPTIONS USE_POLL=1 USE_KQUEUE=1 USE_TPROXY=1"
331fi
332if [ $TARGET = openbsd ] ; then
333 #This is for OpenBSD >= 5.7
334 OPTIONS="$OPTIONS USE_POLL=1 USE_KQUEUE=1 USE_TPROXY=1 USE_ACCEPT4=1 USE_THREAD=1"
335fi
336if [ $TARGET = netbsd ] ; then
337 #This is for NetBSD
338 OPTIONS="$OPTIONS USE_POLL=1 USE_KQUEUE=1 USE_TPROXY=1"
339fi
340if [ $TARGET = aix51 ] ; then
341 #This is for AIX 5.1
342 OPTIONS="$OPTIONS USE_POLL=1 USE_LIBCRYPT=1"
343fi
344if [ $TARGET = aix52 ] ; then
345 #This is for AIX 5.2 and later
346 OPTIONS="$OPTIONS USE_POLL=1 USE_LIBCRYPT=1"
347fi
348if [ $TARGET = cygwin ] ; then
349 #This is for Cygwin
350 OPTIONS="$OPTIONS USE_POLL=1 USE_TPROXY=1"
351fi
352
353echo "Target : $TARGET"
354echo "Options : $OPTIONS"
355
356echo "########################## Gathering tests to run ##########################"
Christopher Faulet8d67cf82018-12-18 22:41:20 +0100357if [ -z "$REGTESTS" ]; then
358 _findtests ./
359else
360 for t in $REGTESTS; do
361 _findtests $t
362 done
363fi
PiBa-NL72504042018-11-27 22:26:38 +0100364
365echo "########################## Starting varnishtest ##########################"
366echo "Testing with haproxy version: $HAPROXY_VERSION"
367_vtresult=0
368if [ -n "$testlist" ]; then
369 if [ -n "$jobcount" ]; then
370 jobcount="-j $jobcount"
371 fi
Christopher Faulet1ecf0ea2018-12-18 22:47:23 +0100372 cmd="$VARNISHTEST_PROGRAM -l -k -t 10 $verbose $jobcount $varnishtestparams $testlist"
373 eval $cmd
PiBa-NL72504042018-11-27 22:26:38 +0100374 _vtresult=$?
375else
376 echo "No tests found that meet the required criteria"
377fi
378if [ $_vtresult != 0 ]
379then
380 echo "########################## Gathering failed results ##########################"
Frédéric Lécaille51e01b52018-11-29 21:41:42 +0100381 export TESTDIR
382 find "$TESTDIR" -type d -name "vtc.*" -exec sh -c 'for i; do
383 if [ ! -e "$i/LOG" ] ; then continue; fi
384 cat <<- EOF | tee -a "$TESTDIR/failedtests.log"
385$(echo "###### $(cat "$i/INFO") ######")
386$(echo "## test results in: \"$i\"")
387$(grep -- ---- "$i/LOG")
PiBa-NL72504042018-11-27 22:26:38 +0100388EOF
Frédéric Lécaille51e01b52018-11-29 21:41:42 +0100389 done' sh {} +
PiBa-NL72504042018-11-27 22:26:38 +0100390 exit 1
391else
392 # all tests were succesfull, removing tempdir (the last part.)
Frédéric Lécaille51e01b52018-11-29 21:41:42 +0100393 rmdir "$TESTDIR"
PiBa-NL72504042018-11-27 22:26:38 +0100394fi
395exit 0