blob: 84a6c1c8ffb7efcae18c344246b12a304c1985b5 [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
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
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
Christopher Faulet8d0fdf52018-12-19 10:18:40 +010031 --clean to cleanup previous reg-tests log directories and exit
32 run-regtests.sh --clean
33
Christopher Faulet78f31bf2019-04-12 16:53:41 +020034 --use-htx to use the HTX in tests (deprecated, the default mode now)
35
36 --no-htx to use the legacy HTTP in tests
37 run-regtests.sh --no-htx, sets the macro \${no-htx}
Christopher Fauletfa6798f2018-12-19 11:22:04 +010038 In .vtc files, in HAProxy configuration, you should use the following line
39 to "templatize" your tests:
40
41 \${no-htx} option http-use-htx
42
PiBa-NL72504042018-11-27 22:26:38 +010043 Including text below into a .vtc file will check for its requirements
44 related to haproxy's target and compilation options
45 # Below targets are not capable of completing this test succesfully
46 #EXCLUDE_TARGET=freebsd, abns sockets are not available on freebsd
47
48 #EXCLUDE_TARGETS=dos,freebsd,windows
49
50 # Below option is required to complete this test succesfully
51 #REQUIRE_OPTION=OPENSSL, this test needs OPENSSL compiled in.
52
Christopher Faulet7e245df2018-12-21 15:18:02 +010053 #REQUIRE_OPTIONS=ZLIB|SLZ,OPENSSL,LUA
PiBa-NL72504042018-11-27 22:26:38 +010054
55 # 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
Frederic Lecailled4f36e32018-12-13 22:15:05 +010062 or
63 export HAPROXY_PROGRAM=/usr/local/sbin/haproxy
Frédéric Lécaille43361232019-01-11 10:10:21 +010064 export VTEST_PROGRAM=/usr/local/bin/vtest
PiBa-NL72504042018-11-27 22:26:38 +010065EOF
Christopher Faulet8d67cf82018-12-18 22:41:20 +010066 exit 0
67}
PiBa-NL72504042018-11-27 22:26:38 +010068
Frederic Lecailled4f36e32018-12-13 22:15:05 +010069add_range_to_test_list()
70{
71 level0="*.vtc"
72 level1="h*.vtc"
73 level2="s*.vtc"
74 level3="l*.vtc"
75 level4="b*.vtc"
76 level5="k*.vtc"
77 level6="e*.vtc"
78
79 new_range=$(echo $1 | tr '-' ' ')
80 non_digit=$(echo $new_range | grep '[^0-9 ]')
81 if [ -n "$non_digit" ] ; then
82 return
83 fi
84 if [ "$new_range" = "$1" ] ; then
85 if [ $1 -gt 6 ] ; then
86 return
87 fi
88 eval echo '$'level$1
89 return
90 fi
91 if [ -z "$new_range" ] ; then
92 return
93 fi
94 list=
95 for l in $(seq $new_range) ; do
96 if [ -n "l" ] ; then
97 if [ -z "$list" ] ; then
98 list="$(eval echo '$'level${l})"
99 else
100 list="$list $(eval echo '$'level${l})"
101 fi
102 fi
103 done
104
105 echo $list
106}
107
108
109build_test_list()
110{
111 # Remove any spacing character
112 LEVEL="$(echo $LEVEL | tr -d ' ')"
113 # Replave any comma character by a space character
114 LEVEL="$(echo $LEVEL | tr ',' ' ')"
115 list=
116 for range in $LEVEL ; do
117 if [ -z "$list" ] ; then
118 list=$(add_range_to_test_list $range)
119 else
120 list="$list $(add_range_to_test_list $range)"
121 fi
122 done
123
124 echo $list
125}
126
127build_find_expr()
128{
129 expr=
130 for i in $@; do
131 if [ -z "$expr" ] ; then
132 expr="-name \"$i\""
133 else
134 expr="$expr -o -name \"$i\""
135 fi
136 done
137
138 echo $expr
139}
140
PiBa-NL72504042018-11-27 22:26:38 +0100141_startswith() {
142 _str="$1"
143 _sub="$2"
144 echo "$_str" | grep "^$_sub" >/dev/null 2>&1
145}
146
147_findtests() {
148 set -f
149 LEVEL=${LEVEL:-0};
Frederic Lecailled4f36e32018-12-13 22:15:05 +0100150 list=$(build_test_list "$LEVEL")
151 if [ -z "$list" ] ; then
152 echo "Invalid level specification '"$LEVEL"' or no file was found."
153 exit 1
PiBa-NL72504042018-11-27 22:26:38 +0100154 fi
Frederic Lecailled4f36e32018-12-13 22:15:05 +0100155 EXPR=$(build_find_expr $list)
PiBa-NL72504042018-11-27 22:26:38 +0100156
Frederic Lecailled4f36e32018-12-13 22:15:05 +0100157 for i in $( find "$1" $(eval echo $EXPR) ); do
PiBa-NL72504042018-11-27 22:26:38 +0100158 skiptest=
Willy Tarreau939193a2018-12-06 15:49:27 +0100159 require_version="$(sed -ne 's/^#REQUIRE_VERSION=//p' "$i")"
160 require_version_below="$(sed -ne 's/^#REQUIRE_VERSION_BELOW=//p' "$i")"
Christopher Faulet7e245df2018-12-21 15:18:02 +0100161 require_options="$(sed -ne 's/^#REQUIRE_OPTIONS=//p' "$i" | sed -e 's/,/ /g')"
162 exclude_targets="$(sed -ne 's/^#EXCLUDE_TARGETS=//p' "$i" | sed -e 's/,/ /g')"
163
164 requiredoption="$(sed -ne 's/^#REQUIRE_OPTION=//p' "$i" | sed -e 's/,.*//')"
165 if [ -n "$requiredoption" ]; then
166 require_options="$require_options $requiredoption"
167 fi
168
169 excludedtarget="$(sed -ne 's/^#EXCLUDE_TARGET=//p' "$i" | sed -e 's/,.*//')"
170 if [ -n "$excludedtarget" ]; then
171 exclude_targets="$exclude_targets $excludedtarget"
172 fi
PiBa-NL72504042018-11-27 22:26:38 +0100173
174 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
197 alternatives=$(echo "$requiredoption" | sed -e 's/|/ /g')
198 found=
199 for alt in $alternatives; do
Willy Tarreau87586e12019-03-27 13:52:39 +0100200 if echo "$FEATURES" | grep -qw "\+$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
210 if [ -z $skiptest ]; then
211 echo " Add test: $i"
212 testlist="$testlist $i"
213 fi
214 done
215}
216
Christopher Faulet8d0fdf52018-12-19 10:18:40 +0100217_cleanup()
218{
219 DIRS=$(find "${TESTDIR}" -maxdepth 1 -type d -name "haregtests-*" -exec basename {} \; 2>/dev/null)
220 if [ -z "${DIRS}" ]; then
221 echo "No reg-tests log directory found"
222 else
223 echo "Cleanup following reg-tests log directories:"
224 for d in ${DIRS}; do
225 echo " o ${TESTDIR}/$d"
226 done
227 read -p "Continue (y/n)?" reply
228 case "$reply" in
229 y|Y)
230 for d in ${DIRS}; do
231 rm -r "${TESTDIR}/$d"
232 done
233 echo "done"
234 exit 0
235 ;;
236 *)
237 echo "aborted"
238 exit 1
239 ;;
240 esac
241 fi
242}
243
244
PiBa-NL72504042018-11-27 22:26:38 +0100245_process() {
PiBa-NL72504042018-11-27 22:26:38 +0100246 while [ ${#} -gt 0 ]; do
247 if _startswith "$1" "-"; then
248 case "${1}" in
249 --j)
250 jobcount="$2"
251 shift
252 ;;
Frédéric Lécaille43361232019-01-11 10:10:21 +0100253 --vtestparams)
254 vtestparams="$2"
PiBa-NL72504042018-11-27 22:26:38 +0100255 shift
256 ;;
257 --v)
258 verbose=""
Christopher Faulet2a7cf922018-12-19 10:22:01 +0100259 ;;
260 --debug)
261 verbose=""
262 debug="-v"
PiBa-NL72504042018-11-27 22:26:38 +0100263 ;;
Christopher Faulet9c6df5e2018-12-19 10:25:07 +0100264 --keep-logs)
265 keep_logs="-L"
266 ;;
PiBa-NL72504042018-11-27 22:26:38 +0100267 --LEVEL)
268 LEVEL="$2"
269 shift
270 ;;
Christopher Fauletfa6798f2018-12-19 11:22:04 +0100271 --use-htx)
272 no_htx=""
273 ;;
Christopher Faulet78f31bf2019-04-12 16:53:41 +0200274 --no-htx)
275 no_htx="no "
276 ;;
Christopher Faulet8d0fdf52018-12-19 10:18:40 +0100277 --clean)
278 _cleanup
279 exit 0
280 ;;
Christopher Faulet8d67cf82018-12-18 22:41:20 +0100281 --help)
282 _help
283 ;;
PiBa-NL72504042018-11-27 22:26:38 +0100284 *)
285 echo "Unknown parameter : $1"
Christopher Faulet8d67cf82018-12-18 22:41:20 +0100286 exit 1
PiBa-NL72504042018-11-27 22:26:38 +0100287 ;;
288 esac
289 else
Christopher Faulet8d67cf82018-12-18 22:41:20 +0100290 REGTESTS="${REGTESTS} $1"
PiBa-NL72504042018-11-27 22:26:38 +0100291 fi
292 shift 1
293 done
PiBa-NL72504042018-11-27 22:26:38 +0100294}
295
296_version() {
297 echo "$@" | awk -F. '{ printf("%d%03d%03d%03d\012", $1,$2,$3,$4); }';
298}
299
PiBa-NL72504042018-11-27 22:26:38 +0100300
Frédéric Lécaille51e01b52018-11-29 21:41:42 +0100301HAPROXY_PROGRAM="${HAPROXY_PROGRAM:-${PWD}/haproxy}"
Frédéric Lécaille43361232019-01-11 10:10:21 +0100302VTEST_PROGRAM="${VTEST_PROGRAM:-vtest}"
Christopher Faulet8d0fdf52018-12-19 10:18:40 +0100303TESTDIR="${TMPDIR:-/tmp}"
Christopher Faulet8d67cf82018-12-18 22:41:20 +0100304REGTESTS=""
305
306jobcount=""
307verbose="-q"
Christopher Faulet2a7cf922018-12-19 10:22:01 +0100308debug=""
Christopher Faulet9c6df5e2018-12-19 10:25:07 +0100309keep_logs="-l"
Christopher Faulet78f31bf2019-04-12 16:53:41 +0200310no_htx=""
Christopher Faulet8d67cf82018-12-18 22:41:20 +0100311testlist=""
312
313_process "$@";
314
315echo ""
316echo "########################## Preparing to run tests ##########################"
PiBa-NL72504042018-11-27 22:26:38 +0100317
318preparefailed=
319if ! [ -x "$(command -v $HAPROXY_PROGRAM)" ]; then
320 echo "haproxy not found in path, please specify HAPROXY_PROGRAM environment variable"
321 preparefailed=1
322fi
Frédéric Lécaille43361232019-01-11 10:10:21 +0100323if ! [ -x "$(command -v $VTEST_PROGRAM)" ]; then
324 echo "vtest not found in path, please specify VTEST_PROGRAM environment variable"
PiBa-NL72504042018-11-27 22:26:38 +0100325 preparefailed=1
326fi
327if [ $preparefailed ]; then
328 exit 1
329fi
330
Willy Tarreauad25c262019-03-27 14:00:10 +0100331{ read HAPROXY_VERSION; read TARGET; read FEATURES; } << EOF
332$($HAPROXY_PROGRAM -vv |grep 'HA-Proxy version\|TARGET.*=\|^Feature' | sed 's/.* [:=] //')
PiBa-NL72504042018-11-27 22:26:38 +0100333EOF
334
335HAPROXY_VERSION=$(echo $HAPROXY_VERSION | cut -d " " -f 3)
336echo "Testing with haproxy version: $HAPROXY_VERSION"
337
338TESTRUNDATETIME="$(date '+%Y-%m-%d_%H-%M-%S')"
339
Frédéric Lécaille51e01b52018-11-29 21:41:42 +0100340mkdir -p "$TESTDIR" || exit 1
Christopher Faulet8d0fdf52018-12-19 10:18:40 +0100341TESTDIR=$(mktemp -d "$TESTDIR/haregtests-$TESTRUNDATETIME.XXXXXX") || exit 1
PiBa-NL72504042018-11-27 22:26:38 +0100342
Frédéric Lécaille51e01b52018-11-29 21:41:42 +0100343export TMPDIR="$TESTDIR"
344export HAPROXY_PROGRAM="$HAPROXY_PROGRAM"
PiBa-NL72504042018-11-27 22:26:38 +0100345
PiBa-NL72504042018-11-27 22:26:38 +0100346echo "Target : $TARGET"
Willy Tarreau87586e12019-03-27 13:52:39 +0100347echo "Options : $FEATURES"
PiBa-NL72504042018-11-27 22:26:38 +0100348
349echo "########################## Gathering tests to run ##########################"
Christopher Faulet78f31bf2019-04-12 16:53:41 +0200350# if htx is enable, but HAProxy version is lower to 1.9, disable it
351if [ $(_version "$HAPROXY_VERSION") -lt $(_version "1.9") ]; then
352 no_htx="#"
Christopher Fauletfa6798f2018-12-19 11:22:04 +0100353fi
354
Christopher Faulet8d67cf82018-12-18 22:41:20 +0100355if [ -z "$REGTESTS" ]; then
356 _findtests ./
357else
358 for t in $REGTESTS; do
359 _findtests $t
360 done
361fi
PiBa-NL72504042018-11-27 22:26:38 +0100362
Frédéric Lécaille43361232019-01-11 10:10:21 +0100363echo "########################## Starting vtest ##########################"
PiBa-NL72504042018-11-27 22:26:38 +0100364echo "Testing with haproxy version: $HAPROXY_VERSION"
365_vtresult=0
366if [ -n "$testlist" ]; then
367 if [ -n "$jobcount" ]; then
368 jobcount="-j $jobcount"
369 fi
Frédéric Lécaille43361232019-01-11 10:10:21 +0100370 cmd="$VTEST_PROGRAM -k -t 10 -Dno-htx=${no_htx} $keep_logs $verbose $debug $jobcount $vtestparams $testlist"
Christopher Faulet1ecf0ea2018-12-18 22:47:23 +0100371 eval $cmd
PiBa-NL72504042018-11-27 22:26:38 +0100372 _vtresult=$?
373else
374 echo "No tests found that meet the required criteria"
375fi
Christopher Faulet9c6df5e2018-12-19 10:25:07 +0100376
377
378if [ $_vtresult -eq 0 ]; then
379 # all tests were succesfull, removing tempdir (the last part.)
380 # ignore errors is the directory is not empty or if it does not exist
381 rmdir "$TESTDIR" 2>/dev/null
382fi
383
384if [ -d "${TESTDIR}" ]; then
385 echo "########################## Gathering results ##########################"
Frédéric Lécaille51e01b52018-11-29 21:41:42 +0100386 export TESTDIR
387 find "$TESTDIR" -type d -name "vtc.*" -exec sh -c 'for i; do
388 if [ ! -e "$i/LOG" ] ; then continue; fi
Christopher Faulet9c6df5e2018-12-19 10:25:07 +0100389
Frédéric Lécaille51e01b52018-11-29 21:41:42 +0100390 cat <<- EOF | tee -a "$TESTDIR/failedtests.log"
391$(echo "###### $(cat "$i/INFO") ######")
392$(echo "## test results in: \"$i\"")
Frédéric Lécaillef9a48ef2019-01-08 11:30:28 +0100393$(grep -E -- "^(----|\* diag)" "$i/LOG")
PiBa-NL72504042018-11-27 22:26:38 +0100394EOF
Frédéric Lécaille51e01b52018-11-29 21:41:42 +0100395 done' sh {} +
PiBa-NL72504042018-11-27 22:26:38 +0100396fi
Christopher Faulet9c6df5e2018-12-19 10:25:07 +0100397
398exit $_vtresult