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 |
| 43 | EOF |
| 44 | return |
| 45 | fi |
| 46 | |
| 47 | _startswith() { |
| 48 | _str="$1" |
| 49 | _sub="$2" |
| 50 | echo "$_str" | grep "^$_sub" >/dev/null 2>&1 |
| 51 | } |
| 52 | |
| 53 | _findtests() { |
| 54 | set -f |
| 55 | LEVEL=${LEVEL:-0}; |
| 56 | EXPR='*.vtc' |
| 57 | if [ $LEVEL = 1 ] ; then |
| 58 | EXPR='h*.vtc'; |
| 59 | elif [ $LEVEL = 2 ] ; then |
| 60 | EXPR='s*.vtc'; |
| 61 | elif [ $LEVEL = 3 ] ; then |
| 62 | EXPR='l*.vtc'; |
| 63 | elif [ $LEVEL = 4 ] ; then |
| 64 | EXPR='b*.vtc'; |
| 65 | fi |
| 66 | |
| 67 | for i in $( find "$1" -name "$EXPR" ); do |
| 68 | skiptest= |
Willy Tarreau | 939193a | 2018-12-06 15:49:27 +0100 | [diff] [blame] | 69 | require_version="$(sed -ne 's/^#REQUIRE_VERSION=//p' "$i")" |
| 70 | require_version_below="$(sed -ne 's/^#REQUIRE_VERSION_BELOW=//p' "$i")" |
| 71 | require_options="$(sed -ne 's/^#REQUIRE_OPTIONS=//p' "$i")" |
| 72 | exclude_targets=",$(sed -ne 's/^#EXCLUDE_TARGETS=//p' "$i")," |
PiBa-NL | 7250404 | 2018-11-27 22:26:38 +0100 | [diff] [blame] | 73 | |
| 74 | if [ -n "$require_version" ]; then |
| 75 | if [ $(_version "$HAPROXY_VERSION") -lt $(_version "$require_version") ]; then |
| 76 | echo " Skip $i because option haproxy is version: $HAPROXY_VERSION" |
| 77 | echo " REASON: this test requires at least version: $require_version" |
| 78 | skiptest=1 |
| 79 | fi |
| 80 | fi |
| 81 | if [ -n "$require_version_below" ]; then |
| 82 | if [ $(_version "$HAPROXY_VERSION") -ge $(_version "$require_version_below") ]; then |
| 83 | echo " Skip $i because option haproxy is version: $HAPROXY_VERSION" |
| 84 | echo " REASON: this test requires a version below: $require_version_below" |
| 85 | skiptest=1 |
| 86 | fi |
| 87 | fi |
| 88 | |
| 89 | if [ -n "$( echo "$exclude_targets" | grep ",$TARGET," )" ]; then |
| 90 | echo " Skip $i because exclude_targets" |
| 91 | echo " REASON: exclude_targets '$exclude_targets' contains '$TARGET'" |
| 92 | skiptest=1 |
| 93 | fi |
| 94 | |
| 95 | #echo "REQUIRE_OPTIONS : $require_options" |
| 96 | for requiredoption in $(echo $require_options | tr "," "\012" ); do |
| 97 | if [ -z "$( echo "$OPTIONS" | grep "USE_$requiredoption=1" )" ] |
| 98 | then |
| 99 | echo " Skip $i because option $requiredoption not found" |
| 100 | echo -n " REASON: " |
| 101 | echo -n "$required" | sed -e 's/.*,//' -e 's/^[[:space:]]//' |
| 102 | echo |
| 103 | skiptest=1 |
| 104 | fi |
| 105 | done |
| 106 | for required in "$(grep "#REQUIRE_OPTION=" "$i")"; |
| 107 | do |
| 108 | if [ -z "$required" ] |
| 109 | then |
| 110 | continue |
| 111 | fi |
| 112 | requiredoption=$(echo "$required" | sed -e 's/.*=//' -e 's/,.*//') |
| 113 | if [ -z "$( echo "$OPTIONS" | grep "USE_$requiredoption=1" )" ] |
| 114 | then |
| 115 | echo " Skip $i because option $requiredoption not found" |
| 116 | echo -n " REASON: " |
| 117 | echo "$required" | sed -e 's/.*,//' -e 's/^[[:space:]]//' |
| 118 | skiptest=1 |
| 119 | fi |
| 120 | done |
| 121 | testtarget=$(grep "#EXCLUDE_TARGET=" "$i") |
| 122 | if [ "$( echo "$testtarget" | grep "#EXCLUDE_TARGET=$TARGET," )" ] |
| 123 | then |
| 124 | echo " Skip $i because: TARGET = $TARGET" |
| 125 | echo -n " REASON: " |
| 126 | echo "$testtarget" | sed -e 's/.*,//' -e 's/^[[:space:]]//' |
| 127 | skiptest=1 |
| 128 | fi |
| 129 | |
| 130 | if [ -z $skiptest ]; then |
| 131 | echo " Add test: $i" |
| 132 | testlist="$testlist $i" |
| 133 | fi |
| 134 | done |
| 135 | } |
| 136 | |
| 137 | _process() { |
| 138 | jobcount="" |
| 139 | verbose="-q" |
| 140 | |
| 141 | while [ ${#} -gt 0 ]; do |
| 142 | if _startswith "$1" "-"; then |
| 143 | case "${1}" in |
| 144 | --j) |
| 145 | jobcount="$2" |
| 146 | shift |
| 147 | ;; |
| 148 | --varnishtestparams) |
| 149 | varnishtestparams="$2" |
| 150 | shift |
| 151 | ;; |
| 152 | --v) |
| 153 | verbose="" |
| 154 | ;; |
| 155 | --LEVEL) |
| 156 | LEVEL="$2" |
| 157 | shift |
| 158 | ;; |
| 159 | *) |
| 160 | echo "Unknown parameter : $1" |
| 161 | return 1 |
| 162 | ;; |
| 163 | esac |
| 164 | else |
| 165 | _findtests "$1" |
| 166 | pathwasset=1 |
| 167 | fi |
| 168 | shift 1 |
| 169 | done |
| 170 | if [ -z $pathwasset ]; then |
| 171 | # no path was given, find all tests under current path |
| 172 | _findtests ./ |
| 173 | fi |
| 174 | } |
| 175 | |
| 176 | _version() { |
| 177 | echo "$@" | awk -F. '{ printf("%d%03d%03d%03d\012", $1,$2,$3,$4); }'; |
| 178 | } |
| 179 | |
| 180 | echo "" |
| 181 | echo "########################## Preparing to run tests ##########################" |
| 182 | |
Frédéric Lécaille | 51e01b5 | 2018-11-29 21:41:42 +0100 | [diff] [blame] | 183 | HAPROXY_PROGRAM="${HAPROXY_PROGRAM:-${PWD}/haproxy}" |
| 184 | VARNISHTEST_PROGRAM="${VARNISHTEST_PROGRAM:-varnishtest}" |
PiBa-NL | 7250404 | 2018-11-27 22:26:38 +0100 | [diff] [blame] | 185 | |
| 186 | preparefailed= |
| 187 | if ! [ -x "$(command -v $HAPROXY_PROGRAM)" ]; then |
| 188 | echo "haproxy not found in path, please specify HAPROXY_PROGRAM environment variable" |
| 189 | preparefailed=1 |
| 190 | fi |
| 191 | if ! [ -x "$(command -v $VARNISHTEST_PROGRAM)" ]; then |
| 192 | echo "varnishtest not found in path, please specify VARNISHTEST_PROGRAM environment variable" |
| 193 | preparefailed=1 |
| 194 | fi |
| 195 | if [ $preparefailed ]; then |
| 196 | exit 1 |
| 197 | fi |
| 198 | |
| 199 | { read HAPROXY_VERSION; read TARGET; read OPTIONS; } << EOF |
| 200 | $($HAPROXY_PROGRAM -vv |grep 'HA-Proxy version\|TARGET\|OPTIONS' | sed 's/.* = //') |
| 201 | EOF |
| 202 | |
| 203 | HAPROXY_VERSION=$(echo $HAPROXY_VERSION | cut -d " " -f 3) |
| 204 | echo "Testing with haproxy version: $HAPROXY_VERSION" |
| 205 | |
| 206 | TESTRUNDATETIME="$(date '+%Y-%m-%d_%H-%M-%S')" |
| 207 | |
Frédéric Lécaille | 51e01b5 | 2018-11-29 21:41:42 +0100 | [diff] [blame] | 208 | TESTDIR="${TMPDIR:-/tmp}" |
| 209 | mkdir -p "$TESTDIR" || exit 1 |
| 210 | TESTDIR=$(mktemp -d "$TESTDIR/$TESTRUNDATETIME.XXXXXX") || exit 1 |
PiBa-NL | 7250404 | 2018-11-27 22:26:38 +0100 | [diff] [blame] | 211 | |
Frédéric Lécaille | 51e01b5 | 2018-11-29 21:41:42 +0100 | [diff] [blame] | 212 | export TMPDIR="$TESTDIR" |
| 213 | export HAPROXY_PROGRAM="$HAPROXY_PROGRAM" |
PiBa-NL | 7250404 | 2018-11-27 22:26:38 +0100 | [diff] [blame] | 214 | |
| 215 | # Mimic implicit build options from haproxy MakeFile that are present for each target: |
| 216 | |
| 217 | if [ $TARGET = generic ] ; then |
| 218 | #generic system target has nothing specific |
| 219 | OPTIONS="$OPTIONS USE_POLL=1 USE_TPROXY=1" |
| 220 | fi |
| 221 | if [ $TARGET = haiku ] ; then |
| 222 | #For Haiku |
| 223 | OPTIONS="$OPTIONS USE_POLL=1 USE_TPROXY=1" |
| 224 | fi |
| 225 | if [ $TARGET = linux22 ] ; then |
| 226 | #This is for Linux 2.2 |
| 227 | OPTIONS="$OPTIONS USE_POLL=1 USE_TPROXY=1 USE_LIBCRYPT=1 USE_DL=1 USE_RT=1" |
| 228 | fi |
| 229 | if [ $TARGET = linux24 ] ; then |
| 230 | #This is for standard Linux 2.4 with netfilter but without epoll() |
| 231 | OPTIONS="$OPTIONS USE_NETFILTER=1 USE_POLL=1 USE_TPROXY=1 USE_CRYPT_H=1 USE_LIBCRYPT=1 USE_DL=1 USE_RT=1" |
| 232 | fi |
| 233 | if [ $TARGET = linux24e ] ; then |
| 234 | #This is for enhanced Linux 2.4 with netfilter and epoll() patch>0.21 |
| 235 | 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" |
| 236 | fi |
| 237 | if [ $TARGET = linux26 ] ; then |
| 238 | #This is for standard Linux 2.6 with netfilter and standard epoll() |
| 239 | 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" |
| 240 | fi |
| 241 | if [ $TARGET = linux2628 ] ; then |
| 242 | #This is for standard Linux >= 2.6.28 with netfilter, epoll, tproxy and splice |
| 243 | 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" |
| 244 | fi |
| 245 | if [ $TARGET = solaris ] ; then |
| 246 | #This is for Solaris8 |
| 247 | OPTIONS="$OPTIONS USE_POLL=1 USE_TPROXY=1 USE_LIBCRYPT=1 USE_CRYPT_H=1 USE_GETADDRINFO=1 USE_THREAD=1" |
| 248 | fi |
| 249 | if [ $TARGET = freebsd ] ; then |
| 250 | #This is for FreeBSD |
| 251 | OPTIONS="$OPTIONS USE_POLL=1 USE_KQUEUE=1 USE_TPROXY=1 USE_LIBCRYPT=1 USE_THREAD=1 USE_CPU_AFFINITY=1" |
| 252 | fi |
| 253 | if [ $TARGET = osx ] ; then |
| 254 | #This is for MacOS/X |
| 255 | OPTIONS="$OPTIONS USE_POLL=1 USE_KQUEUE=1 USE_TPROXY=1" |
| 256 | fi |
| 257 | if [ $TARGET = openbsd ] ; then |
| 258 | #This is for OpenBSD >= 5.7 |
| 259 | OPTIONS="$OPTIONS USE_POLL=1 USE_KQUEUE=1 USE_TPROXY=1 USE_ACCEPT4=1 USE_THREAD=1" |
| 260 | fi |
| 261 | if [ $TARGET = netbsd ] ; then |
| 262 | #This is for NetBSD |
| 263 | OPTIONS="$OPTIONS USE_POLL=1 USE_KQUEUE=1 USE_TPROXY=1" |
| 264 | fi |
| 265 | if [ $TARGET = aix51 ] ; then |
| 266 | #This is for AIX 5.1 |
| 267 | OPTIONS="$OPTIONS USE_POLL=1 USE_LIBCRYPT=1" |
| 268 | fi |
| 269 | if [ $TARGET = aix52 ] ; then |
| 270 | #This is for AIX 5.2 and later |
| 271 | OPTIONS="$OPTIONS USE_POLL=1 USE_LIBCRYPT=1" |
| 272 | fi |
| 273 | if [ $TARGET = cygwin ] ; then |
| 274 | #This is for Cygwin |
| 275 | OPTIONS="$OPTIONS USE_POLL=1 USE_TPROXY=1" |
| 276 | fi |
| 277 | |
| 278 | echo "Target : $TARGET" |
| 279 | echo "Options : $OPTIONS" |
| 280 | |
| 281 | echo "########################## Gathering tests to run ##########################" |
| 282 | |
| 283 | testlist="" |
| 284 | pathwasset= |
| 285 | |
| 286 | _process "$@"; |
| 287 | |
| 288 | echo "########################## Starting varnishtest ##########################" |
| 289 | echo "Testing with haproxy version: $HAPROXY_VERSION" |
| 290 | _vtresult=0 |
| 291 | if [ -n "$testlist" ]; then |
| 292 | if [ -n "$jobcount" ]; then |
| 293 | jobcount="-j $jobcount" |
| 294 | fi |
| 295 | $VARNISHTEST_PROGRAM $varnishtestparams $verbose $jobcount -l -k -t 10 $testlist |
| 296 | _vtresult=$? |
| 297 | else |
| 298 | echo "No tests found that meet the required criteria" |
| 299 | fi |
| 300 | if [ $_vtresult != 0 ] |
| 301 | then |
| 302 | echo "########################## Gathering failed results ##########################" |
Frédéric Lécaille | 51e01b5 | 2018-11-29 21:41:42 +0100 | [diff] [blame] | 303 | export TESTDIR |
| 304 | find "$TESTDIR" -type d -name "vtc.*" -exec sh -c 'for i; do |
| 305 | if [ ! -e "$i/LOG" ] ; then continue; fi |
| 306 | cat <<- EOF | tee -a "$TESTDIR/failedtests.log" |
| 307 | $(echo "###### $(cat "$i/INFO") ######") |
| 308 | $(echo "## test results in: \"$i\"") |
| 309 | $(grep -- ---- "$i/LOG") |
PiBa-NL | 7250404 | 2018-11-27 22:26:38 +0100 | [diff] [blame] | 310 | EOF |
Frédéric Lécaille | 51e01b5 | 2018-11-29 21:41:42 +0100 | [diff] [blame] | 311 | done' sh {} + |
PiBa-NL | 7250404 | 2018-11-27 22:26:38 +0100 | [diff] [blame] | 312 | exit 1 |
| 313 | else |
| 314 | # all tests were succesfull, removing tempdir (the last part.) |
Frédéric Lécaille | 51e01b5 | 2018-11-29 21:41:42 +0100 | [diff] [blame] | 315 | rmdir "$TESTDIR" |
PiBa-NL | 7250404 | 2018-11-27 22:26:38 +0100 | [diff] [blame] | 316 | fi |
| 317 | exit 0 |