blob: 70ad134a4cd28f683fca18b6158a9dab9ebbdbd7 [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
Christopher Faulet2a7cf922018-12-19 10:22:01 +010022 --debug to show test logs on standard ouput (implies --v)
23 run-regtests.sh --debug
24
Christopher Faulet9c6df5e2018-12-19 10:25:07 +010025 --keep-logs to keep all log directories (by default kept if test fails)
26 run-regtests.sh --keep-logs
27
PiBa-NL72504042018-11-27 22:26:38 +010028 --varnishtestparams <ARGS>, passes custom ARGS to varnishtest
29 run-regtests.sh --varnishtestparams "-n 10"
30
Christopher Faulet8d0fdf52018-12-19 10:18:40 +010031 --clean to cleanup previous reg-tests log directories and exit
32 run-regtests.sh --clean
33
PiBa-NL72504042018-11-27 22:26:38 +010034 Including text below into a .vtc file will check for its requirements
35 related to haproxy's target and compilation options
36 # Below targets are not capable of completing this test succesfully
37 #EXCLUDE_TARGET=freebsd, abns sockets are not available on freebsd
38
39 #EXCLUDE_TARGETS=dos,freebsd,windows
40
41 # Below option is required to complete this test succesfully
42 #REQUIRE_OPTION=OPENSSL, this test needs OPENSSL compiled in.
43
44 #REQUIRE_OPTIONS=ZLIB,OPENSSL,LUA
45
46 # To define a range of versions that a test can run with:
47 #REQUIRE_VERSION=0.0
48 #REQUIRE_VERSION_BELOW=99.9
49
50 Configure environment variables to set the haproxy and varnishtest binaries to use
51 setenv HAPROXY_PROGRAM /usr/local/sbin/haproxy
52 setenv VARNISHTEST_PROGRAM /usr/local/bin/varnishtest
Frederic Lecailled4f36e32018-12-13 22:15:05 +010053 or
54 export HAPROXY_PROGRAM=/usr/local/sbin/haproxy
55 export VARNISHTEST_PROGRAM=/usr/local/bin/varnishtest
PiBa-NL72504042018-11-27 22:26:38 +010056EOF
Christopher Faulet8d67cf82018-12-18 22:41:20 +010057 exit 0
58}
PiBa-NL72504042018-11-27 22:26:38 +010059
Frederic Lecailled4f36e32018-12-13 22:15:05 +010060add_range_to_test_list()
61{
62 level0="*.vtc"
63 level1="h*.vtc"
64 level2="s*.vtc"
65 level3="l*.vtc"
66 level4="b*.vtc"
67 level5="k*.vtc"
68 level6="e*.vtc"
69
70 new_range=$(echo $1 | tr '-' ' ')
71 non_digit=$(echo $new_range | grep '[^0-9 ]')
72 if [ -n "$non_digit" ] ; then
73 return
74 fi
75 if [ "$new_range" = "$1" ] ; then
76 if [ $1 -gt 6 ] ; then
77 return
78 fi
79 eval echo '$'level$1
80 return
81 fi
82 if [ -z "$new_range" ] ; then
83 return
84 fi
85 list=
86 for l in $(seq $new_range) ; do
87 if [ -n "l" ] ; then
88 if [ -z "$list" ] ; then
89 list="$(eval echo '$'level${l})"
90 else
91 list="$list $(eval echo '$'level${l})"
92 fi
93 fi
94 done
95
96 echo $list
97}
98
99
100build_test_list()
101{
102 # Remove any spacing character
103 LEVEL="$(echo $LEVEL | tr -d ' ')"
104 # Replave any comma character by a space character
105 LEVEL="$(echo $LEVEL | tr ',' ' ')"
106 list=
107 for range in $LEVEL ; do
108 if [ -z "$list" ] ; then
109 list=$(add_range_to_test_list $range)
110 else
111 list="$list $(add_range_to_test_list $range)"
112 fi
113 done
114
115 echo $list
116}
117
118build_find_expr()
119{
120 expr=
121 for i in $@; do
122 if [ -z "$expr" ] ; then
123 expr="-name \"$i\""
124 else
125 expr="$expr -o -name \"$i\""
126 fi
127 done
128
129 echo $expr
130}
131
PiBa-NL72504042018-11-27 22:26:38 +0100132_startswith() {
133 _str="$1"
134 _sub="$2"
135 echo "$_str" | grep "^$_sub" >/dev/null 2>&1
136}
137
138_findtests() {
139 set -f
140 LEVEL=${LEVEL:-0};
Frederic Lecailled4f36e32018-12-13 22:15:05 +0100141 list=$(build_test_list "$LEVEL")
142 if [ -z "$list" ] ; then
143 echo "Invalid level specification '"$LEVEL"' or no file was found."
144 exit 1
PiBa-NL72504042018-11-27 22:26:38 +0100145 fi
Frederic Lecailled4f36e32018-12-13 22:15:05 +0100146 EXPR=$(build_find_expr $list)
PiBa-NL72504042018-11-27 22:26:38 +0100147
Frederic Lecailled4f36e32018-12-13 22:15:05 +0100148 for i in $( find "$1" $(eval echo $EXPR) ); do
PiBa-NL72504042018-11-27 22:26:38 +0100149 skiptest=
Willy Tarreau939193a2018-12-06 15:49:27 +0100150 require_version="$(sed -ne 's/^#REQUIRE_VERSION=//p' "$i")"
151 require_version_below="$(sed -ne 's/^#REQUIRE_VERSION_BELOW=//p' "$i")"
152 require_options="$(sed -ne 's/^#REQUIRE_OPTIONS=//p' "$i")"
153 exclude_targets=",$(sed -ne 's/^#EXCLUDE_TARGETS=//p' "$i"),"
PiBa-NL72504042018-11-27 22:26:38 +0100154
155 if [ -n "$require_version" ]; then
156 if [ $(_version "$HAPROXY_VERSION") -lt $(_version "$require_version") ]; then
157 echo " Skip $i because option haproxy is version: $HAPROXY_VERSION"
158 echo " REASON: this test requires at least version: $require_version"
159 skiptest=1
160 fi
161 fi
162 if [ -n "$require_version_below" ]; then
163 if [ $(_version "$HAPROXY_VERSION") -ge $(_version "$require_version_below") ]; then
164 echo " Skip $i because option haproxy is version: $HAPROXY_VERSION"
165 echo " REASON: this test requires a version below: $require_version_below"
166 skiptest=1
167 fi
168 fi
169
170 if [ -n "$( echo "$exclude_targets" | grep ",$TARGET," )" ]; then
171 echo " Skip $i because exclude_targets"
172 echo " REASON: exclude_targets '$exclude_targets' contains '$TARGET'"
173 skiptest=1
174 fi
175
176 #echo "REQUIRE_OPTIONS : $require_options"
177 for requiredoption in $(echo $require_options | tr "," "\012" ); do
178 if [ -z "$( echo "$OPTIONS" | grep "USE_$requiredoption=1" )" ]
179 then
180 echo " Skip $i because option $requiredoption not found"
181 echo -n " REASON: "
182 echo -n "$required" | sed -e 's/.*,//' -e 's/^[[:space:]]//'
183 echo
184 skiptest=1
185 fi
186 done
187 for required in "$(grep "#REQUIRE_OPTION=" "$i")";
188 do
189 if [ -z "$required" ]
190 then
191 continue
192 fi
193 requiredoption=$(echo "$required" | sed -e 's/.*=//' -e 's/,.*//')
194 if [ -z "$( echo "$OPTIONS" | grep "USE_$requiredoption=1" )" ]
195 then
196 echo " Skip $i because option $requiredoption not found"
197 echo -n " REASON: "
198 echo "$required" | sed -e 's/.*,//' -e 's/^[[:space:]]//'
199 skiptest=1
200 fi
201 done
202 testtarget=$(grep "#EXCLUDE_TARGET=" "$i")
203 if [ "$( echo "$testtarget" | grep "#EXCLUDE_TARGET=$TARGET," )" ]
204 then
205 echo " Skip $i because: TARGET = $TARGET"
206 echo -n " REASON: "
207 echo "$testtarget" | sed -e 's/.*,//' -e 's/^[[:space:]]//'
208 skiptest=1
209 fi
210
211 if [ -z $skiptest ]; then
212 echo " Add test: $i"
213 testlist="$testlist $i"
214 fi
215 done
216}
217
Christopher Faulet8d0fdf52018-12-19 10:18:40 +0100218_cleanup()
219{
220 DIRS=$(find "${TESTDIR}" -maxdepth 1 -type d -name "haregtests-*" -exec basename {} \; 2>/dev/null)
221 if [ -z "${DIRS}" ]; then
222 echo "No reg-tests log directory found"
223 else
224 echo "Cleanup following reg-tests log directories:"
225 for d in ${DIRS}; do
226 echo " o ${TESTDIR}/$d"
227 done
228 read -p "Continue (y/n)?" reply
229 case "$reply" in
230 y|Y)
231 for d in ${DIRS}; do
232 rm -r "${TESTDIR}/$d"
233 done
234 echo "done"
235 exit 0
236 ;;
237 *)
238 echo "aborted"
239 exit 1
240 ;;
241 esac
242 fi
243}
244
245
PiBa-NL72504042018-11-27 22:26:38 +0100246_process() {
PiBa-NL72504042018-11-27 22:26:38 +0100247 while [ ${#} -gt 0 ]; do
248 if _startswith "$1" "-"; then
249 case "${1}" in
250 --j)
251 jobcount="$2"
252 shift
253 ;;
254 --varnishtestparams)
255 varnishtestparams="$2"
256 shift
257 ;;
258 --v)
259 verbose=""
Christopher Faulet2a7cf922018-12-19 10:22:01 +0100260 ;;
261 --debug)
262 verbose=""
263 debug="-v"
PiBa-NL72504042018-11-27 22:26:38 +0100264 ;;
Christopher Faulet9c6df5e2018-12-19 10:25:07 +0100265 --keep-logs)
266 keep_logs="-L"
267 ;;
PiBa-NL72504042018-11-27 22:26:38 +0100268 --LEVEL)
269 LEVEL="$2"
270 shift
271 ;;
Christopher Faulet8d0fdf52018-12-19 10:18:40 +0100272 --clean)
273 _cleanup
274 exit 0
275 ;;
Christopher Faulet8d67cf82018-12-18 22:41:20 +0100276 --help)
277 _help
278 ;;
PiBa-NL72504042018-11-27 22:26:38 +0100279 *)
280 echo "Unknown parameter : $1"
Christopher Faulet8d67cf82018-12-18 22:41:20 +0100281 exit 1
PiBa-NL72504042018-11-27 22:26:38 +0100282 ;;
283 esac
284 else
Christopher Faulet8d67cf82018-12-18 22:41:20 +0100285 REGTESTS="${REGTESTS} $1"
PiBa-NL72504042018-11-27 22:26:38 +0100286 fi
287 shift 1
288 done
PiBa-NL72504042018-11-27 22:26:38 +0100289}
290
291_version() {
292 echo "$@" | awk -F. '{ printf("%d%03d%03d%03d\012", $1,$2,$3,$4); }';
293}
294
PiBa-NL72504042018-11-27 22:26:38 +0100295
Frédéric Lécaille51e01b52018-11-29 21:41:42 +0100296HAPROXY_PROGRAM="${HAPROXY_PROGRAM:-${PWD}/haproxy}"
297VARNISHTEST_PROGRAM="${VARNISHTEST_PROGRAM:-varnishtest}"
Christopher Faulet8d0fdf52018-12-19 10:18:40 +0100298TESTDIR="${TMPDIR:-/tmp}"
Christopher Faulet8d67cf82018-12-18 22:41:20 +0100299REGTESTS=""
300
301jobcount=""
302verbose="-q"
Christopher Faulet2a7cf922018-12-19 10:22:01 +0100303debug=""
Christopher Faulet9c6df5e2018-12-19 10:25:07 +0100304keep_logs="-l"
Christopher Faulet8d67cf82018-12-18 22:41:20 +0100305testlist=""
306
307_process "$@";
308
309echo ""
310echo "########################## Preparing to run tests ##########################"
PiBa-NL72504042018-11-27 22:26:38 +0100311
312preparefailed=
313if ! [ -x "$(command -v $HAPROXY_PROGRAM)" ]; then
314 echo "haproxy not found in path, please specify HAPROXY_PROGRAM environment variable"
315 preparefailed=1
316fi
317if ! [ -x "$(command -v $VARNISHTEST_PROGRAM)" ]; then
318 echo "varnishtest not found in path, please specify VARNISHTEST_PROGRAM environment variable"
319 preparefailed=1
320fi
321if [ $preparefailed ]; then
322 exit 1
323fi
324
325{ read HAPROXY_VERSION; read TARGET; read OPTIONS; } << EOF
326$($HAPROXY_PROGRAM -vv |grep 'HA-Proxy version\|TARGET\|OPTIONS' | sed 's/.* = //')
327EOF
328
329HAPROXY_VERSION=$(echo $HAPROXY_VERSION | cut -d " " -f 3)
330echo "Testing with haproxy version: $HAPROXY_VERSION"
331
332TESTRUNDATETIME="$(date '+%Y-%m-%d_%H-%M-%S')"
333
Frédéric Lécaille51e01b52018-11-29 21:41:42 +0100334mkdir -p "$TESTDIR" || exit 1
Christopher Faulet8d0fdf52018-12-19 10:18:40 +0100335TESTDIR=$(mktemp -d "$TESTDIR/haregtests-$TESTRUNDATETIME.XXXXXX") || exit 1
PiBa-NL72504042018-11-27 22:26:38 +0100336
Frédéric Lécaille51e01b52018-11-29 21:41:42 +0100337export TMPDIR="$TESTDIR"
338export HAPROXY_PROGRAM="$HAPROXY_PROGRAM"
PiBa-NL72504042018-11-27 22:26:38 +0100339
340# Mimic implicit build options from haproxy MakeFile that are present for each target:
341
342if [ $TARGET = generic ] ; then
343 #generic system target has nothing specific
344 OPTIONS="$OPTIONS USE_POLL=1 USE_TPROXY=1"
345fi
346if [ $TARGET = haiku ] ; then
347 #For Haiku
348 OPTIONS="$OPTIONS USE_POLL=1 USE_TPROXY=1"
349fi
350if [ $TARGET = linux22 ] ; then
351 #This is for Linux 2.2
352 OPTIONS="$OPTIONS USE_POLL=1 USE_TPROXY=1 USE_LIBCRYPT=1 USE_DL=1 USE_RT=1"
353fi
354if [ $TARGET = linux24 ] ; then
355 #This is for standard Linux 2.4 with netfilter but without epoll()
356 OPTIONS="$OPTIONS USE_NETFILTER=1 USE_POLL=1 USE_TPROXY=1 USE_CRYPT_H=1 USE_LIBCRYPT=1 USE_DL=1 USE_RT=1"
357fi
358if [ $TARGET = linux24e ] ; then
359 #This is for enhanced Linux 2.4 with netfilter and epoll() patch>0.21
360 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"
361fi
362if [ $TARGET = linux26 ] ; then
363 #This is for standard Linux 2.6 with netfilter and standard epoll()
364 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"
365fi
366if [ $TARGET = linux2628 ] ; then
367 #This is for standard Linux >= 2.6.28 with netfilter, epoll, tproxy and splice
368 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"
369fi
370if [ $TARGET = solaris ] ; then
371 #This is for Solaris8
372 OPTIONS="$OPTIONS USE_POLL=1 USE_TPROXY=1 USE_LIBCRYPT=1 USE_CRYPT_H=1 USE_GETADDRINFO=1 USE_THREAD=1"
373fi
374if [ $TARGET = freebsd ] ; then
375 #This is for FreeBSD
376 OPTIONS="$OPTIONS USE_POLL=1 USE_KQUEUE=1 USE_TPROXY=1 USE_LIBCRYPT=1 USE_THREAD=1 USE_CPU_AFFINITY=1"
377fi
378if [ $TARGET = osx ] ; then
379 #This is for MacOS/X
380 OPTIONS="$OPTIONS USE_POLL=1 USE_KQUEUE=1 USE_TPROXY=1"
381fi
382if [ $TARGET = openbsd ] ; then
383 #This is for OpenBSD >= 5.7
384 OPTIONS="$OPTIONS USE_POLL=1 USE_KQUEUE=1 USE_TPROXY=1 USE_ACCEPT4=1 USE_THREAD=1"
385fi
386if [ $TARGET = netbsd ] ; then
387 #This is for NetBSD
388 OPTIONS="$OPTIONS USE_POLL=1 USE_KQUEUE=1 USE_TPROXY=1"
389fi
390if [ $TARGET = aix51 ] ; then
391 #This is for AIX 5.1
392 OPTIONS="$OPTIONS USE_POLL=1 USE_LIBCRYPT=1"
393fi
394if [ $TARGET = aix52 ] ; then
395 #This is for AIX 5.2 and later
396 OPTIONS="$OPTIONS USE_POLL=1 USE_LIBCRYPT=1"
397fi
398if [ $TARGET = cygwin ] ; then
399 #This is for Cygwin
400 OPTIONS="$OPTIONS USE_POLL=1 USE_TPROXY=1"
401fi
402
403echo "Target : $TARGET"
404echo "Options : $OPTIONS"
405
406echo "########################## Gathering tests to run ##########################"
Christopher Faulet8d67cf82018-12-18 22:41:20 +0100407if [ -z "$REGTESTS" ]; then
408 _findtests ./
409else
410 for t in $REGTESTS; do
411 _findtests $t
412 done
413fi
PiBa-NL72504042018-11-27 22:26:38 +0100414
415echo "########################## Starting varnishtest ##########################"
416echo "Testing with haproxy version: $HAPROXY_VERSION"
417_vtresult=0
418if [ -n "$testlist" ]; then
419 if [ -n "$jobcount" ]; then
420 jobcount="-j $jobcount"
421 fi
Christopher Faulet9c6df5e2018-12-19 10:25:07 +0100422 cmd="$VARNISHTEST_PROGRAM -k -t 10 $keep_logs $verbose $debug $jobcount $varnishtestparams $testlist"
Christopher Faulet1ecf0ea2018-12-18 22:47:23 +0100423 eval $cmd
PiBa-NL72504042018-11-27 22:26:38 +0100424 _vtresult=$?
425else
426 echo "No tests found that meet the required criteria"
427fi
Christopher Faulet9c6df5e2018-12-19 10:25:07 +0100428
429
430if [ $_vtresult -eq 0 ]; then
431 # all tests were succesfull, removing tempdir (the last part.)
432 # ignore errors is the directory is not empty or if it does not exist
433 rmdir "$TESTDIR" 2>/dev/null
434fi
435
436if [ -d "${TESTDIR}" ]; then
437 echo "########################## Gathering results ##########################"
Frédéric Lécaille51e01b52018-11-29 21:41:42 +0100438 export TESTDIR
439 find "$TESTDIR" -type d -name "vtc.*" -exec sh -c 'for i; do
440 if [ ! -e "$i/LOG" ] ; then continue; fi
Christopher Faulet9c6df5e2018-12-19 10:25:07 +0100441
Frédéric Lécaille51e01b52018-11-29 21:41:42 +0100442 cat <<- EOF | tee -a "$TESTDIR/failedtests.log"
443$(echo "###### $(cat "$i/INFO") ######")
444$(echo "## test results in: \"$i\"")
445$(grep -- ---- "$i/LOG")
PiBa-NL72504042018-11-27 22:26:38 +0100446EOF
Frédéric Lécaille51e01b52018-11-29 21:41:42 +0100447 done' sh {} +
PiBa-NL72504042018-11-27 22:26:38 +0100448fi
Christopher Faulet9c6df5e2018-12-19 10:25:07 +0100449
450exit $_vtresult