2018-11-29 20:41:42 +00:00
|
|
|
#!/bin/sh
|
2018-11-27 21:26:38 +00:00
|
|
|
|
2018-12-18 21:41:20 +00:00
|
|
|
_help()
|
|
|
|
{
|
2018-11-27 21:26:38 +00:00
|
|
|
cat << EOF
|
|
|
|
### run-regtests.sh ###
|
|
|
|
Running run-regtests.sh --help shows this information about how to use it
|
|
|
|
|
|
|
|
Run without parameters to run all tests in the current folder (including subfolders)
|
|
|
|
run-regtests.sh
|
|
|
|
|
|
|
|
Provide paths to run tests from (including subfolders):
|
|
|
|
run-regtests.sh ./tests1 ./tests2
|
|
|
|
|
|
|
|
Parameters:
|
2019-01-11 09:10:21 +00:00
|
|
|
--j <NUM>, To run vtest with multiple jobs / threads for a faster overall result
|
2018-11-27 21:26:38 +00:00
|
|
|
run-regtests.sh ./fasttest --j 16
|
|
|
|
|
|
|
|
--v, to run verbose
|
2019-01-11 09:10:21 +00:00
|
|
|
run-regtests.sh --v, disables the default vtest 'quiet' parameter
|
2018-11-27 21:26:38 +00:00
|
|
|
|
2018-12-19 09:22:01 +00:00
|
|
|
--debug to show test logs on standard ouput (implies --v)
|
|
|
|
run-regtests.sh --debug
|
|
|
|
|
2018-12-19 09:25:07 +00:00
|
|
|
--keep-logs to keep all log directories (by default kept if test fails)
|
|
|
|
run-regtests.sh --keep-logs
|
|
|
|
|
2019-01-11 09:10:21 +00:00
|
|
|
--vtestparams <ARGS>, passes custom ARGS to vtest
|
|
|
|
run-regtests.sh --vtestparams "-n 10"
|
2018-11-27 21:26:38 +00:00
|
|
|
|
2019-03-29 14:07:24 +00:00
|
|
|
--type <reg tests types> filter the types of the tests to be run, depending on
|
|
|
|
the commented REGTESTS_TYPE variable value in each VTC file.
|
2019-12-11 15:26:11 +00:00
|
|
|
The value of REGTESTS_TYPE supported are: default, slow, bug, broken, devel
|
|
|
|
and experimental. When not specified, it is set to 'default' as default value.
|
2019-03-29 14:07:24 +00:00
|
|
|
|
|
|
|
run-regtest.sh --type slow,default
|
|
|
|
|
2018-12-19 09:18:40 +00:00
|
|
|
--clean to cleanup previous reg-tests log directories and exit
|
|
|
|
run-regtests.sh --clean
|
|
|
|
|
2019-04-12 14:53:41 +00:00
|
|
|
--use-htx to use the HTX in tests (deprecated, the default mode now)
|
|
|
|
|
|
|
|
--no-htx to use the legacy HTTP in tests
|
|
|
|
run-regtests.sh --no-htx, sets the macro \${no-htx}
|
2018-12-19 10:22:04 +00:00
|
|
|
In .vtc files, in HAProxy configuration, you should use the following line
|
|
|
|
to "templatize" your tests:
|
|
|
|
|
|
|
|
\${no-htx} option http-use-htx
|
|
|
|
|
2018-11-27 21:26:38 +00:00
|
|
|
Including text below into a .vtc file will check for its requirements
|
|
|
|
related to haproxy's target and compilation options
|
2019-05-16 21:15:31 +00:00
|
|
|
# Below targets are not capable of completing this test successfully
|
2018-11-27 21:26:38 +00:00
|
|
|
#EXCLUDE_TARGET=freebsd, abns sockets are not available on freebsd
|
|
|
|
|
|
|
|
#EXCLUDE_TARGETS=dos,freebsd,windows
|
|
|
|
|
2019-05-16 21:15:31 +00:00
|
|
|
# Below option is required to complete this test successfully
|
2018-11-27 21:26:38 +00:00
|
|
|
#REQUIRE_OPTION=OPENSSL, this test needs OPENSSL compiled in.
|
|
|
|
|
2018-12-21 14:18:02 +00:00
|
|
|
#REQUIRE_OPTIONS=ZLIB|SLZ,OPENSSL,LUA
|
2018-11-27 21:26:38 +00:00
|
|
|
|
|
|
|
# To define a range of versions that a test can run with:
|
|
|
|
#REQUIRE_VERSION=0.0
|
|
|
|
#REQUIRE_VERSION_BELOW=99.9
|
|
|
|
|
2019-12-19 13:30:00 +00:00
|
|
|
# To define required binaries for a test:
|
|
|
|
#REQUIRE_BINARIES=socat,curl
|
|
|
|
|
2019-01-11 09:10:21 +00:00
|
|
|
Configure environment variables to set the haproxy and vtest binaries to use
|
2018-11-27 21:26:38 +00:00
|
|
|
setenv HAPROXY_PROGRAM /usr/local/sbin/haproxy
|
2019-01-11 09:10:21 +00:00
|
|
|
setenv VTEST_PROGRAM /usr/local/bin/vtest
|
2018-12-13 21:15:05 +00:00
|
|
|
or
|
|
|
|
export HAPROXY_PROGRAM=/usr/local/sbin/haproxy
|
2019-01-11 09:10:21 +00:00
|
|
|
export VTEST_PROGRAM=/usr/local/bin/vtest
|
2018-11-27 21:26:38 +00:00
|
|
|
EOF
|
2018-12-18 21:41:20 +00:00
|
|
|
exit 0
|
|
|
|
}
|
2018-11-27 21:26:38 +00:00
|
|
|
|
2018-12-13 21:15:05 +00:00
|
|
|
add_range_to_test_list()
|
|
|
|
{
|
|
|
|
level0="*.vtc"
|
|
|
|
level1="h*.vtc"
|
|
|
|
level2="s*.vtc"
|
|
|
|
level3="l*.vtc"
|
|
|
|
level4="b*.vtc"
|
|
|
|
level5="k*.vtc"
|
|
|
|
level6="e*.vtc"
|
|
|
|
|
|
|
|
new_range=$(echo $1 | tr '-' ' ')
|
|
|
|
non_digit=$(echo $new_range | grep '[^0-9 ]')
|
|
|
|
if [ -n "$non_digit" ] ; then
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
if [ "$new_range" = "$1" ] ; then
|
|
|
|
if [ $1 -gt 6 ] ; then
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
eval echo '$'level$1
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
if [ -z "$new_range" ] ; then
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
list=
|
|
|
|
for l in $(seq $new_range) ; do
|
|
|
|
if [ -n "l" ] ; then
|
|
|
|
if [ -z "$list" ] ; then
|
|
|
|
list="$(eval echo '$'level${l})"
|
|
|
|
else
|
|
|
|
list="$list $(eval echo '$'level${l})"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
echo $list
|
|
|
|
}
|
|
|
|
|
2018-11-27 21:26:38 +00:00
|
|
|
_startswith() {
|
|
|
|
_str="$1"
|
|
|
|
_sub="$2"
|
|
|
|
echo "$_str" | grep "^$_sub" >/dev/null 2>&1
|
|
|
|
}
|
|
|
|
|
|
|
|
_findtests() {
|
|
|
|
set -f
|
|
|
|
|
2019-03-29 14:07:24 +00:00
|
|
|
REGTESTS_TYPES="${REGTESTS_TYPES:-any}"
|
|
|
|
any_test=$(echo $REGTESTS_TYPES | grep -cw "any")
|
|
|
|
for i in $( find "$1" -name *.vtc ); do
|
2018-11-27 21:26:38 +00:00
|
|
|
skiptest=
|
2018-12-06 14:49:27 +00:00
|
|
|
require_version="$(sed -ne 's/^#REQUIRE_VERSION=//p' "$i")"
|
|
|
|
require_version_below="$(sed -ne 's/^#REQUIRE_VERSION_BELOW=//p' "$i")"
|
2018-12-21 14:18:02 +00:00
|
|
|
require_options="$(sed -ne 's/^#REQUIRE_OPTIONS=//p' "$i" | sed -e 's/,/ /g')"
|
|
|
|
exclude_targets="$(sed -ne 's/^#EXCLUDE_TARGETS=//p' "$i" | sed -e 's/,/ /g')"
|
2019-12-19 13:30:00 +00:00
|
|
|
require_binaries="$(sed -ne 's/^#REQUIRE_BINARIES=//p' "$i" | sed -e 's/,/ /g')"
|
2019-03-29 14:07:24 +00:00
|
|
|
if [ $any_test -ne 1 ] ; then
|
|
|
|
regtest_type="$(sed -ne 's/^#REGTEST_TYPE=//p' "$i")"
|
|
|
|
if [ -z $regtest_type ] ; then
|
|
|
|
regtest_type=default
|
|
|
|
fi
|
|
|
|
if ! $(echo $REGTESTS_TYPES | grep -wq $regtest_type) ; then
|
|
|
|
echo " Skip $i because its type '"$regtest_type"' is excluded"
|
|
|
|
skiptest=1
|
|
|
|
fi
|
|
|
|
fi
|
2018-12-21 14:18:02 +00:00
|
|
|
|
|
|
|
requiredoption="$(sed -ne 's/^#REQUIRE_OPTION=//p' "$i" | sed -e 's/,.*//')"
|
|
|
|
if [ -n "$requiredoption" ]; then
|
|
|
|
require_options="$require_options $requiredoption"
|
|
|
|
fi
|
|
|
|
|
|
|
|
excludedtarget="$(sed -ne 's/^#EXCLUDE_TARGET=//p' "$i" | sed -e 's/,.*//')"
|
|
|
|
if [ -n "$excludedtarget" ]; then
|
|
|
|
exclude_targets="$exclude_targets $excludedtarget"
|
|
|
|
fi
|
2018-11-27 21:26:38 +00:00
|
|
|
|
|
|
|
if [ -n "$require_version" ]; then
|
|
|
|
if [ $(_version "$HAPROXY_VERSION") -lt $(_version "$require_version") ]; then
|
|
|
|
echo " Skip $i because option haproxy is version: $HAPROXY_VERSION"
|
|
|
|
echo " REASON: this test requires at least version: $require_version"
|
|
|
|
skiptest=1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
if [ -n "$require_version_below" ]; then
|
|
|
|
if [ $(_version "$HAPROXY_VERSION") -ge $(_version "$require_version_below") ]; then
|
|
|
|
echo " Skip $i because option haproxy is version: $HAPROXY_VERSION"
|
|
|
|
echo " REASON: this test requires a version below: $require_version_below"
|
|
|
|
skiptest=1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2018-12-21 14:18:02 +00:00
|
|
|
for excludedtarget in $exclude_targets; do
|
|
|
|
if [ "$excludedtarget" = "$TARGET" ]; then
|
|
|
|
echo " Skip $i because haproxy is compiled for the excluded target $TARGET"
|
2018-11-27 21:26:38 +00:00
|
|
|
skiptest=1
|
|
|
|
fi
|
|
|
|
done
|
2018-12-21 14:18:02 +00:00
|
|
|
|
|
|
|
for requiredoption in $require_options; do
|
|
|
|
alternatives=$(echo "$requiredoption" | sed -e 's/|/ /g')
|
|
|
|
found=
|
|
|
|
for alt in $alternatives; do
|
2019-03-27 12:52:39 +00:00
|
|
|
if echo "$FEATURES" | grep -qw "\+$alt"; then
|
2018-12-21 14:18:02 +00:00
|
|
|
found=1;
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
if [ -z $found ]; then
|
|
|
|
echo " Skip $i because haproxy is not compiled with the required option $requiredoption"
|
2018-11-27 21:26:38 +00:00
|
|
|
skiptest=1
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2019-12-19 13:30:00 +00:00
|
|
|
for requiredbin in $require_binaries; do
|
|
|
|
which $requiredbin >/dev/null 2>&1
|
|
|
|
if [ "$?" -eq "1" ]; then
|
|
|
|
echo " Skip $i because '"$requiredbin"' is not installed"
|
|
|
|
skiptest=1
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2018-11-27 21:26:38 +00:00
|
|
|
if [ -z $skiptest ]; then
|
|
|
|
echo " Add test: $i"
|
|
|
|
testlist="$testlist $i"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2018-12-19 09:18:40 +00:00
|
|
|
_cleanup()
|
|
|
|
{
|
|
|
|
DIRS=$(find "${TESTDIR}" -maxdepth 1 -type d -name "haregtests-*" -exec basename {} \; 2>/dev/null)
|
|
|
|
if [ -z "${DIRS}" ]; then
|
|
|
|
echo "No reg-tests log directory found"
|
|
|
|
else
|
|
|
|
echo "Cleanup following reg-tests log directories:"
|
|
|
|
for d in ${DIRS}; do
|
|
|
|
echo " o ${TESTDIR}/$d"
|
|
|
|
done
|
|
|
|
read -p "Continue (y/n)?" reply
|
|
|
|
case "$reply" in
|
|
|
|
y|Y)
|
|
|
|
for d in ${DIRS}; do
|
|
|
|
rm -r "${TESTDIR}/$d"
|
|
|
|
done
|
|
|
|
echo "done"
|
|
|
|
exit 0
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "aborted"
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-11-27 21:26:38 +00:00
|
|
|
_process() {
|
|
|
|
while [ ${#} -gt 0 ]; do
|
|
|
|
if _startswith "$1" "-"; then
|
|
|
|
case "${1}" in
|
|
|
|
--j)
|
|
|
|
jobcount="$2"
|
|
|
|
shift
|
|
|
|
;;
|
2019-01-11 09:10:21 +00:00
|
|
|
--vtestparams)
|
|
|
|
vtestparams="$2"
|
2018-11-27 21:26:38 +00:00
|
|
|
shift
|
|
|
|
;;
|
|
|
|
--v)
|
|
|
|
verbose=""
|
|
|
|
;;
|
2018-12-19 09:22:01 +00:00
|
|
|
--debug)
|
|
|
|
verbose=""
|
|
|
|
debug="-v"
|
|
|
|
;;
|
2018-12-19 09:25:07 +00:00
|
|
|
--keep-logs)
|
|
|
|
keep_logs="-L"
|
|
|
|
;;
|
2019-03-29 14:07:24 +00:00
|
|
|
--type)
|
|
|
|
REGTESTS_TYPES="$2"
|
|
|
|
shift
|
|
|
|
;;
|
2018-12-19 10:22:04 +00:00
|
|
|
--use-htx)
|
|
|
|
no_htx=""
|
|
|
|
;;
|
2019-04-12 14:53:41 +00:00
|
|
|
--no-htx)
|
|
|
|
no_htx="no "
|
|
|
|
;;
|
2018-12-19 09:18:40 +00:00
|
|
|
--clean)
|
|
|
|
_cleanup
|
|
|
|
exit 0
|
|
|
|
;;
|
2018-12-18 21:41:20 +00:00
|
|
|
--help)
|
|
|
|
_help
|
|
|
|
;;
|
2018-11-27 21:26:38 +00:00
|
|
|
*)
|
|
|
|
echo "Unknown parameter : $1"
|
2018-12-18 21:41:20 +00:00
|
|
|
exit 1
|
2018-11-27 21:26:38 +00:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
else
|
2018-12-18 21:41:20 +00:00
|
|
|
REGTESTS="${REGTESTS} $1"
|
2018-11-27 21:26:38 +00:00
|
|
|
fi
|
|
|
|
shift 1
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
_version() {
|
|
|
|
echo "$@" | awk -F. '{ printf("%d%03d%03d%03d\012", $1,$2,$3,$4); }';
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-11-29 20:41:42 +00:00
|
|
|
HAPROXY_PROGRAM="${HAPROXY_PROGRAM:-${PWD}/haproxy}"
|
2019-01-11 09:10:21 +00:00
|
|
|
VTEST_PROGRAM="${VTEST_PROGRAM:-vtest}"
|
2018-12-19 09:18:40 +00:00
|
|
|
TESTDIR="${TMPDIR:-/tmp}"
|
2018-12-18 21:41:20 +00:00
|
|
|
REGTESTS=""
|
|
|
|
|
|
|
|
jobcount=""
|
|
|
|
verbose="-q"
|
2018-12-19 09:22:01 +00:00
|
|
|
debug=""
|
2018-12-19 09:25:07 +00:00
|
|
|
keep_logs="-l"
|
2019-04-12 14:53:41 +00:00
|
|
|
no_htx=""
|
2018-12-18 21:41:20 +00:00
|
|
|
testlist=""
|
|
|
|
|
|
|
|
_process "$@";
|
|
|
|
|
|
|
|
echo ""
|
|
|
|
echo "########################## Preparing to run tests ##########################"
|
2018-11-27 21:26:38 +00:00
|
|
|
|
|
|
|
preparefailed=
|
|
|
|
if ! [ -x "$(command -v $HAPROXY_PROGRAM)" ]; then
|
|
|
|
echo "haproxy not found in path, please specify HAPROXY_PROGRAM environment variable"
|
|
|
|
preparefailed=1
|
|
|
|
fi
|
2019-01-11 09:10:21 +00:00
|
|
|
if ! [ -x "$(command -v $VTEST_PROGRAM)" ]; then
|
|
|
|
echo "vtest not found in path, please specify VTEST_PROGRAM environment variable"
|
2018-11-27 21:26:38 +00:00
|
|
|
preparefailed=1
|
|
|
|
fi
|
|
|
|
if [ $preparefailed ]; then
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2019-03-27 13:00:10 +00:00
|
|
|
{ read HAPROXY_VERSION; read TARGET; read FEATURES; } << EOF
|
|
|
|
$($HAPROXY_PROGRAM -vv |grep 'HA-Proxy version\|TARGET.*=\|^Feature' | sed 's/.* [:=] //')
|
2018-11-27 21:26:38 +00:00
|
|
|
EOF
|
|
|
|
|
|
|
|
HAPROXY_VERSION=$(echo $HAPROXY_VERSION | cut -d " " -f 3)
|
|
|
|
echo "Testing with haproxy version: $HAPROXY_VERSION"
|
|
|
|
|
|
|
|
TESTRUNDATETIME="$(date '+%Y-%m-%d_%H-%M-%S')"
|
|
|
|
|
2018-11-29 20:41:42 +00:00
|
|
|
mkdir -p "$TESTDIR" || exit 1
|
2018-12-19 09:18:40 +00:00
|
|
|
TESTDIR=$(mktemp -d "$TESTDIR/haregtests-$TESTRUNDATETIME.XXXXXX") || exit 1
|
2018-11-27 21:26:38 +00:00
|
|
|
|
2018-11-29 20:41:42 +00:00
|
|
|
export TMPDIR="$TESTDIR"
|
|
|
|
export HAPROXY_PROGRAM="$HAPROXY_PROGRAM"
|
2018-11-27 21:26:38 +00:00
|
|
|
|
|
|
|
echo "Target : $TARGET"
|
2019-03-27 12:52:39 +00:00
|
|
|
echo "Options : $FEATURES"
|
2018-11-27 21:26:38 +00:00
|
|
|
|
|
|
|
echo "########################## Gathering tests to run ##########################"
|
2019-04-12 14:53:41 +00:00
|
|
|
# if htx is enable, but HAProxy version is lower to 1.9, disable it
|
|
|
|
if [ $(_version "$HAPROXY_VERSION") -lt $(_version "1.9") ]; then
|
|
|
|
no_htx="#"
|
2018-12-19 10:22:04 +00:00
|
|
|
fi
|
|
|
|
|
2018-12-18 21:41:20 +00:00
|
|
|
if [ -z "$REGTESTS" ]; then
|
2019-04-23 14:09:50 +00:00
|
|
|
_findtests reg-tests/
|
2018-12-18 21:41:20 +00:00
|
|
|
else
|
|
|
|
for t in $REGTESTS; do
|
|
|
|
_findtests $t
|
|
|
|
done
|
|
|
|
fi
|
2018-11-27 21:26:38 +00:00
|
|
|
|
2019-01-11 09:10:21 +00:00
|
|
|
echo "########################## Starting vtest ##########################"
|
2018-11-27 21:26:38 +00:00
|
|
|
echo "Testing with haproxy version: $HAPROXY_VERSION"
|
|
|
|
_vtresult=0
|
|
|
|
if [ -n "$testlist" ]; then
|
|
|
|
if [ -n "$jobcount" ]; then
|
|
|
|
jobcount="-j $jobcount"
|
|
|
|
fi
|
2019-04-25 18:14:43 +00:00
|
|
|
cmd="$VTEST_PROGRAM -b $((2<<20)) -k -t 10 -Dno-htx=${no_htx} $keep_logs $verbose $debug $jobcount $vtestparams $testlist"
|
2018-12-18 21:47:23 +00:00
|
|
|
eval $cmd
|
2018-11-27 21:26:38 +00:00
|
|
|
_vtresult=$?
|
|
|
|
else
|
|
|
|
echo "No tests found that meet the required criteria"
|
|
|
|
fi
|
2018-12-19 09:25:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
if [ $_vtresult -eq 0 ]; then
|
2019-05-16 21:15:31 +00:00
|
|
|
# all tests were successful, removing tempdir (the last part.)
|
2018-12-19 09:25:07 +00:00
|
|
|
# ignore errors is the directory is not empty or if it does not exist
|
|
|
|
rmdir "$TESTDIR" 2>/dev/null
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -d "${TESTDIR}" ]; then
|
|
|
|
echo "########################## Gathering results ##########################"
|
2018-11-29 20:41:42 +00:00
|
|
|
export TESTDIR
|
|
|
|
find "$TESTDIR" -type d -name "vtc.*" -exec sh -c 'for i; do
|
|
|
|
if [ ! -e "$i/LOG" ] ; then continue; fi
|
2018-12-19 09:25:07 +00:00
|
|
|
|
2018-11-29 20:41:42 +00:00
|
|
|
cat <<- EOF | tee -a "$TESTDIR/failedtests.log"
|
|
|
|
$(echo "###### $(cat "$i/INFO") ######")
|
|
|
|
$(echo "## test results in: \"$i\"")
|
2019-01-08 10:30:28 +00:00
|
|
|
$(grep -E -- "^(----|\* diag)" "$i/LOG")
|
2018-11-27 21:26:38 +00:00
|
|
|
EOF
|
2018-11-29 20:41:42 +00:00
|
|
|
done' sh {} +
|
2018-11-27 21:26:38 +00:00
|
|
|
fi
|
2018-12-19 09:25:07 +00:00
|
|
|
|
|
|
|
exit $_vtresult
|