blob: 5126efb3f29999ae31ecc8a3c003f199563bd386 [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:
Frédéric Lécaille43361232019-01-11 10:10:21 +010016 --j <NUM>, To run vtest with multiple jobs / threads for a faster overall result
PiBa-NL72504042018-11-27 22:26:38 +010017 run-regtests.sh ./fasttest --j 16
18
19 --v, to run verbose
Frédéric Lécaille43361232019-01-11 10:10:21 +010020 run-regtests.sh --v, disables the default vtest 'quiet' parameter
PiBa-NL72504042018-11-27 22:26:38 +010021
Ilya Shipitsin856aabc2020-04-16 23:51:34 +050022 --debug to show test logs on standard output (implies --v)
Christopher Faulet2a7cf922018-12-19 10:22:01 +010023 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
Frédéric Lécaille43361232019-01-11 10:10:21 +010028 --vtestparams <ARGS>, passes custom ARGS to vtest
29 run-regtests.sh --vtestparams "-n 10"
PiBa-NL72504042018-11-27 22:26:38 +010030
Frédéric Lécailledc1a3bd2019-03-29 15:07:24 +010031 --type <reg tests types> filter the types of the tests to be run, depending on
32 the commented REGTESTS_TYPE variable value in each VTC file.
Christopher Faulet1eee6ca2019-12-11 16:26:11 +010033 The value of REGTESTS_TYPE supported are: default, slow, bug, broken, devel
34 and experimental. When not specified, it is set to 'default' as default value.
Frédéric Lécailledc1a3bd2019-03-29 15:07:24 +010035
36 run-regtest.sh --type slow,default
37
Christopher Faulet8d0fdf52018-12-19 10:18:40 +010038 --clean to cleanup previous reg-tests log directories and exit
39 run-regtests.sh --clean
40
PiBa-NL72504042018-11-27 22:26:38 +010041 Including text below into a .vtc file will check for its requirements
42 related to haproxy's target and compilation options
Bertrand Jacquin7e30b502019-05-16 22:15:31 +010043 # Below targets are not capable of completing this test successfully
PiBa-NL72504042018-11-27 22:26:38 +010044 #EXCLUDE_TARGET=freebsd, abns sockets are not available on freebsd
45
46 #EXCLUDE_TARGETS=dos,freebsd,windows
47
Bertrand Jacquin7e30b502019-05-16 22:15:31 +010048 # Below option is required to complete this test successfully
PiBa-NL72504042018-11-27 22:26:38 +010049 #REQUIRE_OPTION=OPENSSL, this test needs OPENSSL compiled in.
Christopher Faulet7e245df2018-12-21 15:18:02 +010050 #REQUIRE_OPTIONS=ZLIB|SLZ,OPENSSL,LUA
PiBa-NL72504042018-11-27 22:26:38 +010051
William Dauchyaabde712021-01-09 17:26:20 +010052 #REQUIRE_SERVICE=prometheus-exporter
53 #REQUIRE_SERVICES=prometheus-exporter,foo
54
PiBa-NL72504042018-11-27 22:26:38 +010055 # To define a range of versions that a test can run with:
56 #REQUIRE_VERSION=0.0
57 #REQUIRE_VERSION_BELOW=99.9
58
Frédéric Lécaille43361232019-01-11 10:10:21 +010059 Configure environment variables to set the haproxy and vtest binaries to use
PiBa-NL72504042018-11-27 22:26:38 +010060 setenv HAPROXY_PROGRAM /usr/local/sbin/haproxy
Frédéric Lécaille43361232019-01-11 10:10:21 +010061 setenv VTEST_PROGRAM /usr/local/bin/vtest
Willy Tarreaua4009cd2020-12-16 10:39:20 +010062 setenv HAPROXY_ARGS "-dM -de -m 50"
Frederic Lecailled4f36e32018-12-13 22:15:05 +010063 or
64 export HAPROXY_PROGRAM=/usr/local/sbin/haproxy
Frédéric Lécaille43361232019-01-11 10:10:21 +010065 export VTEST_PROGRAM=/usr/local/bin/vtest
Willy Tarreaua4009cd2020-12-16 10:39:20 +010066 export HAPROXY_ARGS="-dM -de -m 50"
PiBa-NL72504042018-11-27 22:26:38 +010067EOF
Christopher Faulet8d67cf82018-12-18 22:41:20 +010068 exit 0
69}
PiBa-NL72504042018-11-27 22:26:38 +010070
Frederic Lecailled4f36e32018-12-13 22:15:05 +010071add_range_to_test_list()
72{
73 level0="*.vtc"
74 level1="h*.vtc"
75 level2="s*.vtc"
76 level3="l*.vtc"
77 level4="b*.vtc"
78 level5="k*.vtc"
79 level6="e*.vtc"
80
81 new_range=$(echo $1 | tr '-' ' ')
82 non_digit=$(echo $new_range | grep '[^0-9 ]')
83 if [ -n "$non_digit" ] ; then
84 return
85 fi
86 if [ "$new_range" = "$1" ] ; then
87 if [ $1 -gt 6 ] ; then
88 return
89 fi
90 eval echo '$'level$1
91 return
92 fi
93 if [ -z "$new_range" ] ; then
94 return
95 fi
96 list=
97 for l in $(seq $new_range) ; do
98 if [ -n "l" ] ; then
99 if [ -z "$list" ] ; then
100 list="$(eval echo '$'level${l})"
101 else
102 list="$list $(eval echo '$'level${l})"
103 fi
104 fi
105 done
106
107 echo $list
108}
109
PiBa-NL72504042018-11-27 22:26:38 +0100110_startswith() {
111 _str="$1"
112 _sub="$2"
113 echo "$_str" | grep "^$_sub" >/dev/null 2>&1
114}
115
116_findtests() {
117 set -f
PiBa-NL72504042018-11-27 22:26:38 +0100118
William Lallemandc1ddcaf2021-02-05 11:27:54 +0100119 REGTESTS_TYPES="${REGTESTS_TYPES:-default,bug,devel,slow}"
Frédéric Lécailledc1a3bd2019-03-29 15:07:24 +0100120 any_test=$(echo $REGTESTS_TYPES | grep -cw "any")
121 for i in $( find "$1" -name *.vtc ); do
PiBa-NL72504042018-11-27 22:26:38 +0100122 skiptest=
Willy Tarreau969e7af2021-11-18 13:49:01 +0100123 OLDIFS="$IFS"; IFS="$LINEFEED"
124 set -- $(grep '^#[0-9A-Z_]*=' "$i")
125 IFS="$OLDIFS"
126
127 require_version=""; require_version_below=""; require_options="";
128 require_services=""; exclude_targets=""; regtest_type=""
129 requiredoption=""; requiredservice=""; excludedtarget="";
130
131 while [ $# -gt 0 ]; do
132 v="$1"; v="${v#*=}"
133 case "$1" in
134 "#REQUIRE_VERSION="*) require_version="$v" ;;
135 "#REQUIRE_VERSION_BELOW="*) require_version_below="$v" ;;
136 "#REQUIRE_OPTIONS="*) require_options="$v" ;;
137 "#REQUIRE_SERVICES="*) require_services="$v" ;;
138 "#EXCLUDE_TARGETS="*) exclude_targets="$v" ;;
139 "#REGTEST_TYPE="*) regtest_type="$v" ;;
140 "#REQUIRE_OPTION="*) requiredoption="${v%,*}" ;;
141 "#REQUIRE_SERVICE="*) required_service="${v%,*}" ;;
142 "#EXCLUDE_TARGET="*) excludedtarget="${v%,*}" ;;
143 # Note: any new variable declared here must be initialized above.
144 esac
145 shift
146 done
147
Frédéric Lécailledc1a3bd2019-03-29 15:07:24 +0100148 if [ $any_test -ne 1 ] ; then
Frédéric Lécailledc1a3bd2019-03-29 15:07:24 +0100149 if [ -z $regtest_type ] ; then
150 regtest_type=default
151 fi
152 if ! $(echo $REGTESTS_TYPES | grep -wq $regtest_type) ; then
153 echo " Skip $i because its type '"$regtest_type"' is excluded"
154 skiptest=1
155 fi
156 fi
Christopher Faulet7e245df2018-12-21 15:18:02 +0100157
Christopher Faulet7e245df2018-12-21 15:18:02 +0100158 if [ -n "$requiredoption" ]; then
Willy Tarreau969e7af2021-11-18 13:49:01 +0100159 require_options="$require_options,$requiredoption"
Christopher Faulet7e245df2018-12-21 15:18:02 +0100160 fi
161
William Dauchyaabde712021-01-09 17:26:20 +0100162 if [ -n "$requiredservice" ]; then
Willy Tarreau969e7af2021-11-18 13:49:01 +0100163 require_services="$require_services,$requiredservice"
William Dauchyaabde712021-01-09 17:26:20 +0100164 fi
165
Christopher Faulet7e245df2018-12-21 15:18:02 +0100166 if [ -n "$excludedtarget" ]; then
Willy Tarreau969e7af2021-11-18 13:49:01 +0100167 exclude_targets="$exclude_targets,$excludedtarget"
Christopher Faulet7e245df2018-12-21 15:18:02 +0100168 fi
PiBa-NL72504042018-11-27 22:26:38 +0100169
Willy Tarreau969e7af2021-11-18 13:49:01 +0100170 IFS=","; set -- $require_options; IFS=$OLDIFS; require_options="$*"
171 IFS=","; set -- $require_services; IFS=$OLDIFS; require_services="$*"
172 IFS=","; set -- $exclude_targets; IFS=$OLDIFS; exclude_targets="$*"
173
PiBa-NL72504042018-11-27 22:26:38 +0100174 if [ -n "$require_version" ]; then
175 if [ $(_version "$HAPROXY_VERSION") -lt $(_version "$require_version") ]; then
176 echo " Skip $i because option haproxy is version: $HAPROXY_VERSION"
177 echo " REASON: this test requires at least version: $require_version"
178 skiptest=1
179 fi
180 fi
181 if [ -n "$require_version_below" ]; then
182 if [ $(_version "$HAPROXY_VERSION") -ge $(_version "$require_version_below") ]; then
183 echo " Skip $i because option haproxy is version: $HAPROXY_VERSION"
184 echo " REASON: this test requires a version below: $require_version_below"
185 skiptest=1
186 fi
187 fi
188
Christopher Faulet7e245df2018-12-21 15:18:02 +0100189 for excludedtarget in $exclude_targets; do
190 if [ "$excludedtarget" = "$TARGET" ]; then
191 echo " Skip $i because haproxy is compiled for the excluded target $TARGET"
PiBa-NL72504042018-11-27 22:26:38 +0100192 skiptest=1
193 fi
194 done
Christopher Faulet7e245df2018-12-21 15:18:02 +0100195
196 for requiredoption in $require_options; do
Willy Tarreau969e7af2021-11-18 13:49:01 +0100197 IFS="|"; set -- $requiredoption; IFS=$OLDIFS; alternatives="$*"
Christopher Faulet7e245df2018-12-21 15:18:02 +0100198 found=
199 for alt in $alternatives; do
Willy Tarreau0b3eb812021-11-18 15:05:45 +0100200 if [ -z "${FEATURES_PATTERN##* +$alt *}" ]; then
Christopher Faulet7e245df2018-12-21 15:18:02 +0100201 found=1;
202 fi
203 done
204 if [ -z $found ]; then
205 echo " Skip $i because haproxy is not compiled with the required option $requiredoption"
PiBa-NL72504042018-11-27 22:26:38 +0100206 skiptest=1
207 fi
208 done
PiBa-NL72504042018-11-27 22:26:38 +0100209
William Dauchyaabde712021-01-09 17:26:20 +0100210 for requiredservice in $require_services; do
Willy Tarreau969e7af2021-11-18 13:49:01 +0100211 IFS="|"; set -- $requiredservice; IFS=$OLDIFS; alternatives="$*"
William Dauchyaabde712021-01-09 17:26:20 +0100212 found=
213 for alt in $alternatives; do
Willy Tarreau0b3eb812021-11-18 15:05:45 +0100214 if [ -z "${SERVICES_PATTERN##* $alt *}" ]; then
William Dauchyaabde712021-01-09 17:26:20 +0100215 found=1;
216 fi
217 done
218 if [ -z $found ]; then
219 echo " Skip $i because haproxy is not compiled with the required service $requiredservice"
220 skiptest=1
221 fi
222 done
223
PiBa-NL72504042018-11-27 22:26:38 +0100224 if [ -z $skiptest ]; then
225 echo " Add test: $i"
226 testlist="$testlist $i"
227 fi
228 done
229}
230
Christopher Faulet8d0fdf52018-12-19 10:18:40 +0100231_cleanup()
232{
233 DIRS=$(find "${TESTDIR}" -maxdepth 1 -type d -name "haregtests-*" -exec basename {} \; 2>/dev/null)
234 if [ -z "${DIRS}" ]; then
235 echo "No reg-tests log directory found"
236 else
237 echo "Cleanup following reg-tests log directories:"
238 for d in ${DIRS}; do
239 echo " o ${TESTDIR}/$d"
240 done
241 read -p "Continue (y/n)?" reply
242 case "$reply" in
243 y|Y)
244 for d in ${DIRS}; do
245 rm -r "${TESTDIR}/$d"
246 done
247 echo "done"
248 exit 0
249 ;;
250 *)
251 echo "aborted"
252 exit 1
253 ;;
254 esac
255 fi
256}
257
258
PiBa-NL72504042018-11-27 22:26:38 +0100259_process() {
PiBa-NL72504042018-11-27 22:26:38 +0100260 while [ ${#} -gt 0 ]; do
261 if _startswith "$1" "-"; then
262 case "${1}" in
263 --j)
264 jobcount="$2"
265 shift
266 ;;
Frédéric Lécaille43361232019-01-11 10:10:21 +0100267 --vtestparams)
268 vtestparams="$2"
PiBa-NL72504042018-11-27 22:26:38 +0100269 shift
270 ;;
271 --v)
272 verbose=""
Christopher Faulet2a7cf922018-12-19 10:22:01 +0100273 ;;
274 --debug)
275 verbose=""
276 debug="-v"
PiBa-NL72504042018-11-27 22:26:38 +0100277 ;;
Christopher Faulet9c6df5e2018-12-19 10:25:07 +0100278 --keep-logs)
279 keep_logs="-L"
280 ;;
Frédéric Lécailledc1a3bd2019-03-29 15:07:24 +0100281 --type)
282 REGTESTS_TYPES="$2"
283 shift
284 ;;
Christopher Faulet8d0fdf52018-12-19 10:18:40 +0100285 --clean)
286 _cleanup
287 exit 0
288 ;;
Christopher Faulet8d67cf82018-12-18 22:41:20 +0100289 --help)
290 _help
291 ;;
PiBa-NL72504042018-11-27 22:26:38 +0100292 *)
293 echo "Unknown parameter : $1"
Christopher Faulet8d67cf82018-12-18 22:41:20 +0100294 exit 1
PiBa-NL72504042018-11-27 22:26:38 +0100295 ;;
296 esac
297 else
Christopher Faulet8d67cf82018-12-18 22:41:20 +0100298 REGTESTS="${REGTESTS} $1"
PiBa-NL72504042018-11-27 22:26:38 +0100299 fi
300 shift 1
301 done
PiBa-NL72504042018-11-27 22:26:38 +0100302}
303
Willy Tarreaub7a28e72021-11-18 15:32:16 +0100304# compute a version from up to 4 sub-version components, each multiplied
305# by a power of 1000, and padded left with 0, 1 or 2 zeroes.
PiBa-NL72504042018-11-27 22:26:38 +0100306_version() {
Willy Tarreaub7a28e72021-11-18 15:32:16 +0100307 OLDIFS="$IFS"; IFS="."; set -- $*; IFS="$OLDIFS"
308 set -- ${1%%[!0-9]*} 000${2%%[!0-9]*} 000${3%%[!0-9]*} 000${4%%[!0-9]*}
309 prf2=${2%???}; prf3=${3%???}; prf4=${4%???}
310 echo ${1}${2#$prf2}${3#$prf3}${4#$prf4}
PiBa-NL72504042018-11-27 22:26:38 +0100311}
312
PiBa-NL72504042018-11-27 22:26:38 +0100313
Frédéric Lécaille51e01b52018-11-29 21:41:42 +0100314HAPROXY_PROGRAM="${HAPROXY_PROGRAM:-${PWD}/haproxy}"
Willy Tarreaua4009cd2020-12-16 10:39:20 +0100315HAPROXY_ARGS="${HAPROXY_ARGS--dM}"
Frédéric Lécaille43361232019-01-11 10:10:21 +0100316VTEST_PROGRAM="${VTEST_PROGRAM:-vtest}"
Christopher Faulet8d0fdf52018-12-19 10:18:40 +0100317TESTDIR="${TMPDIR:-/tmp}"
Christopher Faulet8d67cf82018-12-18 22:41:20 +0100318REGTESTS=""
Willy Tarreau969e7af2021-11-18 13:49:01 +0100319LINEFEED="
320"
Christopher Faulet8d67cf82018-12-18 22:41:20 +0100321
322jobcount=""
323verbose="-q"
Christopher Faulet2a7cf922018-12-19 10:22:01 +0100324debug=""
Christopher Faulet9c6df5e2018-12-19 10:25:07 +0100325keep_logs="-l"
Christopher Faulet8d67cf82018-12-18 22:41:20 +0100326testlist=""
327
328_process "$@";
329
330echo ""
331echo "########################## Preparing to run tests ##########################"
PiBa-NL72504042018-11-27 22:26:38 +0100332
333preparefailed=
334if ! [ -x "$(command -v $HAPROXY_PROGRAM)" ]; then
335 echo "haproxy not found in path, please specify HAPROXY_PROGRAM environment variable"
336 preparefailed=1
337fi
Frédéric Lécaille43361232019-01-11 10:10:21 +0100338if ! [ -x "$(command -v $VTEST_PROGRAM)" ]; then
339 echo "vtest not found in path, please specify VTEST_PROGRAM environment variable"
PiBa-NL72504042018-11-27 22:26:38 +0100340 preparefailed=1
341fi
342if [ $preparefailed ]; then
343 exit 1
344fi
345
William Dauchyaabde712021-01-09 17:26:20 +0100346{ read HAPROXY_VERSION; read TARGET; read FEATURES; read SERVICES; } << EOF
Willy Tarreau5f3448f2021-05-09 06:12:41 +0200347$($HAPROXY_PROGRAM $HAPROXY_ARGS -vv | grep 'HA-\?Proxy version\|TARGET.*=\|^Feature\|^Available services' | sed 's/.* [:=] //')
PiBa-NL72504042018-11-27 22:26:38 +0100348EOF
349
350HAPROXY_VERSION=$(echo $HAPROXY_VERSION | cut -d " " -f 3)
351echo "Testing with haproxy version: $HAPROXY_VERSION"
352
Willy Tarreau0b3eb812021-11-18 15:05:45 +0100353FEATURES_PATTERN=" $FEATURES "
354SERVICES_PATTERN=" $SERVICES "
355
PiBa-NL72504042018-11-27 22:26:38 +0100356TESTRUNDATETIME="$(date '+%Y-%m-%d_%H-%M-%S')"
357
Frédéric Lécaille51e01b52018-11-29 21:41:42 +0100358mkdir -p "$TESTDIR" || exit 1
Christopher Faulet8d0fdf52018-12-19 10:18:40 +0100359TESTDIR=$(mktemp -d "$TESTDIR/haregtests-$TESTRUNDATETIME.XXXXXX") || exit 1
PiBa-NL72504042018-11-27 22:26:38 +0100360
Frédéric Lécaille51e01b52018-11-29 21:41:42 +0100361export TMPDIR="$TESTDIR"
362export HAPROXY_PROGRAM="$HAPROXY_PROGRAM"
Willy Tarreaua4009cd2020-12-16 10:39:20 +0100363if [ -n "$HAPROXY_ARGS" ]; then
364 export HAPROXY_ARGS
365fi
PiBa-NL72504042018-11-27 22:26:38 +0100366
PiBa-NL72504042018-11-27 22:26:38 +0100367echo "Target : $TARGET"
Willy Tarreau87586e12019-03-27 13:52:39 +0100368echo "Options : $FEATURES"
William Dauchyaabde712021-01-09 17:26:20 +0100369echo "Services : $SERVICES"
PiBa-NL72504042018-11-27 22:26:38 +0100370
371echo "########################## Gathering tests to run ##########################"
Christopher Fauletfa6798f2018-12-19 11:22:04 +0100372
Christopher Faulet8d67cf82018-12-18 22:41:20 +0100373if [ -z "$REGTESTS" ]; then
Willy Tarreauca8df4c2019-04-23 16:09:50 +0200374 _findtests reg-tests/
Christopher Faulet8d67cf82018-12-18 22:41:20 +0100375else
376 for t in $REGTESTS; do
377 _findtests $t
378 done
379fi
PiBa-NL72504042018-11-27 22:26:38 +0100380
Frédéric Lécaille43361232019-01-11 10:10:21 +0100381echo "########################## Starting vtest ##########################"
PiBa-NL72504042018-11-27 22:26:38 +0100382echo "Testing with haproxy version: $HAPROXY_VERSION"
383_vtresult=0
384if [ -n "$testlist" ]; then
385 if [ -n "$jobcount" ]; then
386 jobcount="-j $jobcount"
387 fi
Tim Duesterhusa9334df2021-05-31 23:07:29 +0200388 cmd="$VTEST_PROGRAM -b $((2<<20)) -k -t 10 $keep_logs $verbose $debug $jobcount $vtestparams $testlist"
Christopher Faulet1ecf0ea2018-12-18 22:47:23 +0100389 eval $cmd
PiBa-NL72504042018-11-27 22:26:38 +0100390 _vtresult=$?
391else
392 echo "No tests found that meet the required criteria"
393fi
Christopher Faulet9c6df5e2018-12-19 10:25:07 +0100394
395
396if [ $_vtresult -eq 0 ]; then
Bertrand Jacquin7e30b502019-05-16 22:15:31 +0100397 # all tests were successful, removing tempdir (the last part.)
Christopher Faulet9c6df5e2018-12-19 10:25:07 +0100398 # ignore errors is the directory is not empty or if it does not exist
399 rmdir "$TESTDIR" 2>/dev/null
400fi
401
402if [ -d "${TESTDIR}" ]; then
403 echo "########################## Gathering results ##########################"
Frédéric Lécaille51e01b52018-11-29 21:41:42 +0100404 export TESTDIR
405 find "$TESTDIR" -type d -name "vtc.*" -exec sh -c 'for i; do
406 if [ ! -e "$i/LOG" ] ; then continue; fi
Christopher Faulet9c6df5e2018-12-19 10:25:07 +0100407
Frédéric Lécaille51e01b52018-11-29 21:41:42 +0100408 cat <<- EOF | tee -a "$TESTDIR/failedtests.log"
409$(echo "###### $(cat "$i/INFO") ######")
410$(echo "## test results in: \"$i\"")
Frédéric Lécaillef9a48ef2019-01-08 11:30:28 +0100411$(grep -E -- "^(----|\* diag)" "$i/LOG")
PiBa-NL72504042018-11-27 22:26:38 +0100412EOF
Frédéric Lécaille51e01b52018-11-29 21:41:42 +0100413 done' sh {} +
PiBa-NL72504042018-11-27 22:26:38 +0100414fi
Christopher Faulet9c6df5e2018-12-19 10:25:07 +0100415
416exit $_vtresult