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