2013-08-21 00:50:41 -07:00
#!/bin/bash
2014-03-06 16:53:50 +00:00
# Copyright (c) 2013-2014 Red Hat, Inc. <http://www.redhat.com>
2013-08-21 00:50:41 -07:00
#
2014-05-20 19:18:31 +05:30
export TZ = UTC
2016-02-01 12:29:40 +05:30
force = "no"
retry = "no"
tests = ""
2016-02-04 14:32:12 +05:30
exit_on_failure = "yes"
2016-02-01 12:29:40 +05:30
2014-03-06 16:53:50 +00:00
function check_dependencies( )
{
## Check all dependencies are present
MISSING = ""
# Check for dbench
2014-08-08 01:56:23 -07:00
env dbench --usage > /dev/null 2>& 1
if [ $? -ne 0 ] ; then
2014-03-06 16:53:50 +00:00
MISSING = " $MISSING dbench "
fi
# Check for git
env git --version > /dev/null 2>& 1
if [ $? -ne 0 ] ; then
MISSING = " $MISSING git "
fi
2014-10-09 09:08:57 +02:00
# Check for nfs-utils (Linux-only: built-in NetBSD with different name)
if [ "x`uname -s`" = "xLinux" ] ; then
env mount.nfs -V > /dev/null 2>& 1
if [ $? -ne 0 ] ; then
MISSING = " $MISSING nfs-utils "
fi
2014-03-06 16:53:50 +00:00
fi
# Check for the Perl Test Harness
env prove --version > /dev/null 2>& 1
if [ $? -ne 0 ] ; then
MISSING = " $MISSING perl-Test-Harness "
fi
2014-08-08 01:56:23 -07:00
which json_verify > /dev/null
if [ $? -ne 0 ] ; then
MISSING = " $MISSING json_verify "
2014-06-13 03:33:51 +01:00
fi
2014-10-09 09:08:57 +02:00
# Check for XFS programs (Linux Only: NetBSD does without)
if [ "x`uname -s`" = "xLinux" ] ; then
env mkfs.xfs -V > /dev/null 2>& 1
if [ $? -ne 0 ] ; then
MISSING = " $MISSING xfsprogs "
fi
2014-03-06 16:53:50 +00:00
fi
# Check for attr
env getfattr --version > /dev/null 2>& 1
if [ $? -ne 0 ] ; then
MISSING = " $MISSING attr "
fi
2014-07-29 02:32:14 +02:00
# Check for pidof
2014-09-04 19:30:48 +05:30
pidof pidof > /dev/null 2>& 1
2014-07-29 02:32:14 +02:00
if [ $? -ne 0 ] ; then
MISSING = " $MISSING pidof "
fi
2014-08-19 16:14:03 -07:00
# check for psutil python package
test ` uname -s` = = "Darwin" || test ` uname -s` = = "FreeBSD" && {
pip show psutil | grep -q psutil >/dev/null 2>& 1
if [ $? -ne 0 ] ; then
MISSING = " $MISSING psutil "
fi
}
2014-03-06 16:53:50 +00:00
## If dependencies are missing, warn the user and abort
if [ " x $MISSING " != "x" ] ; then
2014-07-29 02:32:14 +02:00
test " x ${ force } " != "xyes" && echo "Aborting."
2014-03-06 16:53:50 +00:00
echo
echo "The following required tools are missing:"
echo
for pkg in $MISSING ; do
echo " * $pkg "
done
echo
2014-07-29 02:32:14 +02:00
test " x ${ force } " = "xyes" && return
2014-03-06 16:53:50 +00:00
echo "Please install them and try again."
echo
exit 2
fi
}
function check_location( )
2013-08-21 00:50:41 -07:00
{
2013-09-15 19:56:25 -07:00
regression_testsdir = $( dirname $0 ) ;
2013-08-21 00:50:41 -07:00
if [ ! -f ${ regression_testsdir } /tests/include.rc ] ; then
2014-03-06 16:53:50 +00:00
echo "Aborting."
echo
echo "The tests/ subdirectory seems to be missing."
echo
echo "Please correct the problem and try again."
echo
2013-08-21 00:50:41 -07:00
exit 1
fi
}
2014-03-06 16:53:50 +00:00
function check_user( )
{
# If we're not running as root, warn the user and abort
MYUID = ` /usr/bin/id -u`
if [ 0${ MYUID } -ne 0 ] ; then
echo "Aborting."
echo
echo "The GlusterFS Test Framework must be run as root."
echo
echo "Please change to the root user and try again."
echo
exit 3
fi
}
2016-02-02 18:14:24 +05:30
function match( )
2014-07-10 20:17:25 +02:00
{
# Patterns considered valid:
2016-02-02 18:14:24 +05:30
# 0. Empty means everything
# "" matches ** i.e all
2014-07-10 20:17:25 +02:00
# 1. full or partial file/directory names
# basic matches tests/basic
# basic/afr matches tests/basic/afr
# 2. globs
# basic/* matches all files and directories in basic
# basic/*/ matches subdirectories in basic (afr|ec)
# 3. numbered bug matching
# 884455 matches bugs/bug-884455.t
# 859927 matches bugs/859927, bugs/bug-859927.t
# 1015990 matches /bugs/bug-1015990-rep.t, bug-1015990.t
# ...lots of other cases accepted as well, since globbing is tricky.
local t = $1
shift
local a
local match = 1
2016-02-02 18:14:24 +05:30
if [ -z " $@ " ] ; then
match = 0
return $match
2014-07-10 20:17:25 +02:00
fi
2016-02-02 18:14:24 +05:30
for a in $@ ; do
case " $t " in
*$a *)
2014-07-10 20:17:25 +02:00
match = 0
; ;
esac
done
return $match
2016-02-02 18:14:24 +05:30
}
2015-04-15 22:58:59 -04:00
# If you're submitting a fix related to one of these tests and want its result
# to be considered, you'll need to remove it from the list as part of your
# patch.
function is_bad_test ( )
2015-04-07 15:32:18 -04:00
{
2015-04-15 22:58:59 -04:00
local name = $1
2015-05-27 16:40:52 +05:30
for bt in ./tests/basic/quota-anon-fd-nfs.t \
2015-11-06 13:17:26 +05:30
./tests/bugs/quota/bug-1235182.t \
2015-09-01 14:21:43 +05:30
./tests/basic/quota-nfs.t \
2015-07-29 16:24:37 +05:30
./tests/basic/tier/tier_lookup_heal.t \
2015-11-06 14:36:37 +05:30
./tests/basic/tier/bug-1214222-directories_missing_after_attach_tier.t \
2015-11-04 15:33:22 -05:00
./tests/basic/tier/fops-during-migration.t \
2015-12-02 17:13:00 -05:00
./tests/basic/tier/record-metadata-heat.t \
2015-12-22 08:50:26 +05:30
./tests/basic/tier/tier-snapshot.t \
2015-08-08 21:29:55 +05:30
./tests/bugs/snapshot/bug-1109889.t \
./tests/bugs/distribute/bug-1066798.t \
2015-08-28 10:46:11 +05:30
./tests/bugs/glusterd/bug-1238706-daemons-stop-on-peer-cleanup.t \
2015-09-14 15:43:31 +05:30
./tests/geo-rep/georep-basic-dr-rsync.t \
2015-09-29 12:31:22 +05:30
./tests/geo-rep/georep-basic-dr-tarssh.t \
2015-12-02 17:13:00 -05:00
./tests/bugs/fuse/bug-924726.t \
2015-12-10 01:27:53 +01:00
./tests/basic/afr/split-brain-healing.t \
./tests/basic/afr/replace-brick-self-heal.t \
./tests/bugs/snapshot/bug-1140162-file-snapshot-features-encrypt-opts-validation.t \
2015-12-15 12:05:25 +05:30
./tests/bugs/tier/bug-1286974.t \
2015-12-10 01:27:53 +01:00
./tests/features/weighted-rebalance.t \
2016-01-20 16:35:42 +05:30
./tests/performance/open-behind.t \
2016-02-03 15:14:13 +05:30
./tests/basic/afr/self-heald.t \
2015-08-24 16:20:06 +05:30
; do
2015-04-15 22:58:59 -04:00
[ x" $name " = x" $bt " ] && return 0 # bash: zero means true/success
done
return 1 # bash: non-zero means false/failure
}
2015-04-07 15:32:18 -04:00
2016-02-02 19:12:41 +05:30
function run_tests( )
2015-04-15 22:58:59 -04:00
{
2016-02-02 19:12:41 +05:30
RES = 0
FAILED = ''
GENERATED_CORE = ''
for t in $( find ${ regression_testsdir } /tests -name '*.t' \
| LC_COLLATE = C sort) ; do
2015-04-15 22:58:59 -04:00
old_cores = $( ls /core.* 2> /dev/null | wc -l)
2016-02-02 19:12:41 +05:30
if match $t " $@ " ; then
2016-02-04 18:18:15 +05:30
echo
echo "=================================================="
2015-04-15 22:58:59 -04:00
if is_bad_test $t ; then
2016-02-02 19:12:41 +05:30
echo " Skipping bad test file $t "
2016-02-04 18:18:15 +05:30
echo "=================================================="
echo
2016-02-02 19:12:41 +05:30
continue
fi
echo " Running tests in file $t "
prove -mf --timer $t
TMP_RES = $?
if [ ${ TMP_RES } -ne 0 ] && [ " x ${ retry } " = "xyes" ] ; then
echo " $t : bad status $TMP_RES "
echo ""
echo " *********************************"
echo " * REGRESSION FAILED *"
echo " * Retrying failed tests in case *"
echo " * we got some spurous failures *"
echo " *********************************"
echo ""
prove -mf --timer $t
TMP_RES = $?
fi
if [ ${ TMP_RES } -ne 0 ] ; then
RES = ${ TMP_RES }
FAILED = " ${ FAILED } ${ t } "
fi
new_cores = $( ls /core.* 2> /dev/null | wc -l)
if [ x" $new_cores " != x" $old_cores " ] ; then
core_diff = $(( new_cores-old_cores))
echo " $t : $core_diff new core files "
RES = 1
GENERATED_CORE = " ${ GENERATED_CORE } ${ t } "
fi
2016-02-04 18:18:15 +05:30
echo " End of test $t "
echo "=================================================="
echo
2016-02-04 14:32:12 +05:30
if [ $RES -ne 0 ] && [ x" $exit_on_failure " = "xyes" ] ; then
break;
fi
2015-04-07 15:32:18 -04:00
fi
done
2016-02-04 18:18:15 +05:30
echo
echo "Run complete"
2016-02-02 19:12:41 +05:30
if [ ${ RES } -ne 0 ] ; then
FAILED = $( echo ${ FAILED } | tr ' ' '\n' | sort -u )
FAILED_COUNT = $( echo -n " ${ FAILED } " | grep -c '^' )
echo -e " $FAILED_COUNT test(s) failed \n ${ FAILED } "
GENERATED_CORE = $( echo ${ GENERATED_CORE } | tr ' ' '\n' | sort -u )
GENERATED_CORE_COUNT = $( echo -n " ${ GENERATED_CORE } " | grep -c '^' )
echo -e " $GENERATED_CORE_COUNT test(s) generated core \n ${ GENERATED_CORE } "
fi
2016-02-04 18:18:15 +05:30
echo " Result is $RES "
2016-02-02 19:12:41 +05:30
return ${ RES }
2015-04-07 15:32:18 -04:00
}
2016-02-01 12:29:40 +05:30
function parse_args ( ) {
2016-02-04 14:32:12 +05:30
args = ` getopt frc " $@ " `
2016-02-01 12:29:40 +05:30
set -- $args
while [ $# -gt 0 ] ; do
case " $1 " in
-f) force = "yes" ; ;
-r) retry = "yes" ; ;
2016-02-04 14:32:12 +05:30
-c) exit_on_failure = "no" ; ;
2016-02-01 12:29:40 +05:30
--) shift; break; ;
esac
shift
done
tests = " $@ "
}
2014-03-06 16:53:50 +00:00
echo
echo ... GlusterFS Test Framework ...
echo
2016-02-01 12:29:40 +05:30
# Get user options
2016-02-02 19:24:07 +05:30
parse_args " $@ "
2014-07-29 02:32:14 +02:00
2014-03-06 16:53:50 +00:00
# Make sure we're running as the root user
check_user
# Make sure the needed programs are available
check_dependencies
# Check we're running from the right location
check_location
# Run the tests
2016-02-02 19:34:01 +05:30
run_tests " $tests "