2018-11-29 21:41:42 +01:00
#!/bin/sh
2018-11-27 22:26:38 +01:00
2018-12-18 22:41:20 +01:00
_help( )
{
2018-11-27 22:26:38 +01: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 10:10:21 +01:00
--j <NUM>, To run vtest with multiple jobs / threads for a faster overall result
2018-11-27 22:26:38 +01:00
run-regtests.sh ./fasttest --j 16
--v, to run verbose
2019-01-11 10:10:21 +01:00
run-regtests.sh --v, disables the default vtest 'quiet' parameter
2018-11-27 22:26:38 +01:00
2018-12-19 10:22:01 +01:00
--debug to show test logs on standard ouput ( implies --v)
run-regtests.sh --debug
2018-12-19 10:25:07 +01:00
--keep-logs to keep all log directories ( by default kept if test fails)
run-regtests.sh --keep-logs
2019-01-11 10:10:21 +01:00
--vtestparams <ARGS>, passes custom ARGS to vtest
run-regtests.sh --vtestparams "-n 10"
2018-11-27 22:26:38 +01:00
2018-12-19 10:18:40 +01:00
--clean to cleanup previous reg-tests log directories and exit
run-regtests.sh --clean
2019-04-12 16:53:41 +02: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 11:22:04 +01: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 22:26:38 +01:00
Including text below into a .vtc file will check for its requirements
related to haproxy' s target and compilation options
# Below targets are not capable of completing this test succesfully
#EXCLUDE_TARGET=freebsd, abns sockets are not available on freebsd
#EXCLUDE_TARGETS=dos,freebsd,windows
# Below option is required to complete this test succesfully
#REQUIRE_OPTION=OPENSSL, this test needs OPENSSL compiled in.
2018-12-21 15:18:02 +01:00
#REQUIRE_OPTIONS=ZLIB|SLZ,OPENSSL,LUA
2018-11-27 22:26:38 +01:00
# To define a range of versions that a test can run with:
#REQUIRE_VERSION=0.0
#REQUIRE_VERSION_BELOW=99.9
2019-01-11 10:10:21 +01:00
Configure environment variables to set the haproxy and vtest binaries to use
2018-11-27 22:26:38 +01:00
setenv HAPROXY_PROGRAM /usr/local/sbin/haproxy
2019-01-11 10:10:21 +01:00
setenv VTEST_PROGRAM /usr/local/bin/vtest
2018-12-13 22:15:05 +01:00
or
export HAPROXY_PROGRAM = /usr/local/sbin/haproxy
2019-01-11 10:10:21 +01:00
export VTEST_PROGRAM = /usr/local/bin/vtest
2018-11-27 22:26:38 +01:00
EOF
2018-12-18 22:41:20 +01:00
exit 0
}
2018-11-27 22:26:38 +01:00
2018-12-13 22:15:05 +01: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
}
build_test_list( )
{
# Remove any spacing character
LEVEL = " $( echo $LEVEL | tr -d ' ' ) "
# Replave any comma character by a space character
LEVEL = " $( echo $LEVEL | tr ',' ' ' ) "
list =
for range in $LEVEL ; do
if [ -z " $list " ] ; then
list = $( add_range_to_test_list $range )
else
list = " $list $( add_range_to_test_list $range ) "
fi
done
echo $list
}
build_find_expr( )
{
expr =
for i in $@ ; do
if [ -z " $expr " ] ; then
expr = " -name \" $i \" "
else
expr = " $expr -o -name \" $i \" "
fi
done
echo $expr
}
2018-11-27 22:26:38 +01:00
_startswith( ) {
_str = " $1 "
_sub = " $2 "
echo " $_str " | grep " ^ $_sub " >/dev/null 2>& 1
}
_findtests( ) {
set -f
LEVEL = ${ LEVEL :- 0 } ;
2018-12-13 22:15:05 +01:00
list = $( build_test_list " $LEVEL " )
if [ -z " $list " ] ; then
echo "Invalid level specification '" $LEVEL "' or no file was found."
exit 1
2018-11-27 22:26:38 +01:00
fi
2018-12-13 22:15:05 +01:00
EXPR = $( build_find_expr $list )
2018-11-27 22:26:38 +01:00
2018-12-13 22:15:05 +01:00
for i in $( find " $1 " $( eval echo $EXPR ) ) ; do
2018-11-27 22:26:38 +01:00
skiptest =
2018-12-06 15:49:27 +01:00
require_version = " $( sed -ne 's/^#REQUIRE_VERSION=//p' " $i " ) "
require_version_below = " $( sed -ne 's/^#REQUIRE_VERSION_BELOW=//p' " $i " ) "
2018-12-21 15:18:02 +01: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' ) "
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 22:26:38 +01: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 15:18:02 +01: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 22:26:38 +01:00
skiptest = 1
fi
done
2018-12-21 15:18:02 +01:00
for requiredoption in $require_options ; do
alternatives = $( echo " $requiredoption " | sed -e 's/|/ /g' )
found =
for alt in $alternatives ; do
2019-03-27 13:52:39 +01:00
if echo " $FEATURES " | grep -qw " \+ $alt " ; then
2018-12-21 15:18:02 +01: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 22:26:38 +01:00
skiptest = 1
fi
done
if [ -z $skiptest ] ; then
echo " Add test: $i "
testlist = " $testlist $i "
fi
done
}
2018-12-19 10:18:40 +01: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 22:26:38 +01:00
_process( ) {
while [ ${# } -gt 0 ] ; do
if _startswith " $1 " "-" ; then
case " ${ 1 } " in
--j)
jobcount = " $2 "
shift
; ;
2019-01-11 10:10:21 +01:00
--vtestparams)
vtestparams = " $2 "
2018-11-27 22:26:38 +01:00
shift
; ;
--v)
verbose = ""
; ;
2018-12-19 10:22:01 +01:00
--debug)
verbose = ""
debug = "-v"
; ;
2018-12-19 10:25:07 +01:00
--keep-logs)
keep_logs = "-L"
; ;
2018-11-27 22:26:38 +01:00
--LEVEL)
LEVEL = " $2 "
shift
; ;
2018-12-19 11:22:04 +01:00
--use-htx)
no_htx = ""
; ;
2019-04-12 16:53:41 +02:00
--no-htx)
no_htx = "no "
; ;
2018-12-19 10:18:40 +01:00
--clean)
_cleanup
exit 0
; ;
2018-12-18 22:41:20 +01:00
--help)
_help
; ;
2018-11-27 22:26:38 +01:00
*)
echo " Unknown parameter : $1 "
2018-12-18 22:41:20 +01:00
exit 1
2018-11-27 22:26:38 +01:00
; ;
esac
else
2018-12-18 22:41:20 +01:00
REGTESTS = " ${ REGTESTS } $1 "
2018-11-27 22:26:38 +01:00
fi
shift 1
done
}
_version( ) {
echo " $@ " | awk -F. '{ printf("%d%03d%03d%03d\012", $1,$2,$3,$4); }' ;
}
2018-11-29 21:41:42 +01:00
HAPROXY_PROGRAM = " ${ HAPROXY_PROGRAM :- ${ PWD } /haproxy } "
2019-01-11 10:10:21 +01:00
VTEST_PROGRAM = " ${ VTEST_PROGRAM :- vtest } "
2018-12-19 10:18:40 +01:00
TESTDIR = " ${ TMPDIR :- /tmp } "
2018-12-18 22:41:20 +01:00
REGTESTS = ""
jobcount = ""
verbose = "-q"
2018-12-19 10:22:01 +01:00
debug = ""
2018-12-19 10:25:07 +01:00
keep_logs = "-l"
2019-04-12 16:53:41 +02:00
no_htx = ""
2018-12-18 22:41:20 +01:00
testlist = ""
_process " $@ " ;
echo ""
echo "########################## Preparing to run tests ##########################"
2018-11-27 22:26:38 +01: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 10:10:21 +01:00
if ! [ -x " $( command -v $VTEST_PROGRAM ) " ] ; then
echo "vtest not found in path, please specify VTEST_PROGRAM environment variable"
2018-11-27 22:26:38 +01:00
preparefailed = 1
fi
if [ $preparefailed ] ; then
exit 1
fi
2019-03-27 14:00:10 +01:00
{ read HAPROXY_VERSION; read TARGET; read FEATURES; } << EOF
$( $HAPROXY_PROGRAM -vv | grep 'HA-Proxy version\|TARGET.*=\|^Feature' | sed 's/.* [:=] //' )
2018-11-27 22:26:38 +01: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 21:41:42 +01:00
mkdir -p " $TESTDIR " || exit 1
2018-12-19 10:18:40 +01:00
TESTDIR = $( mktemp -d " $TESTDIR /haregtests- $TESTRUNDATETIME .XXXXXX " ) || exit 1
2018-11-27 22:26:38 +01:00
2018-11-29 21:41:42 +01:00
export TMPDIR = " $TESTDIR "
export HAPROXY_PROGRAM = " $HAPROXY_PROGRAM "
2018-11-27 22:26:38 +01:00
echo " Target : $TARGET "
2019-03-27 13:52:39 +01:00
echo " Options : $FEATURES "
2018-11-27 22:26:38 +01:00
echo "########################## Gathering tests to run ##########################"
2019-04-12 16:53:41 +02: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 11:22:04 +01:00
fi
2018-12-18 22:41:20 +01:00
if [ -z " $REGTESTS " ] ; then
_findtests ./
else
for t in $REGTESTS ; do
_findtests $t
done
fi
2018-11-27 22:26:38 +01:00
2019-01-11 10:10:21 +01:00
echo "########################## Starting vtest ##########################"
2018-11-27 22:26:38 +01:00
echo " Testing with haproxy version: $HAPROXY_VERSION "
_vtresult = 0
if [ -n " $testlist " ] ; then
if [ -n " $jobcount " ] ; then
jobcount = " -j $jobcount "
fi
2019-01-11 10:10:21 +01:00
cmd = " $VTEST_PROGRAM -k -t 10 -Dno-htx= ${ no_htx } $keep_logs $verbose $debug $jobcount $vtestparams $testlist "
2018-12-18 22:47:23 +01:00
eval $cmd
2018-11-27 22:26:38 +01:00
_vtresult = $?
else
echo "No tests found that meet the required criteria"
fi
2018-12-19 10:25:07 +01:00
if [ $_vtresult -eq 0 ] ; then
# all tests were succesfull, removing tempdir (the last part.)
# 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 21:41:42 +01: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 10:25:07 +01:00
2018-11-29 21:41:42 +01:00
cat <<- EOF | tee -a "$TE STDIR/failedtests.log"
$( echo " ###### $( cat " $i /INFO " ) ###### " )
$( echo " ## test results in: \" $i \" " )
2019-01-08 11:30:28 +01:00
$( grep -E -- "^(----|\* diag)" " $i /LOG " )
2018-11-27 22:26:38 +01:00
EOF
2018-11-29 21:41:42 +01:00
done ' sh { } +
2018-11-27 22:26:38 +01:00
fi
2018-12-19 10:25:07 +01:00
exit $_vtresult