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