From d9e5977b08259580deccad2e0eed3a106094820a Mon Sep 17 00:00:00 2001 From: Raghavendra Talur Date: Mon, 1 Feb 2016 12:29:40 +0530 Subject: tests: refactor option parsing into a function Creating a separate function to parse options. This is required for subsequent patches where we add more options to run-tests.sh. Created a variable tests to hold the tests list or pattern as passing around $@ is not informative. Change-Id: I032639c07419f5136c604531c5719c13ac4f9fe3 BUG: 1251592 Signed-off-by: Raghavendra Talur Reviewed-on: http://review.gluster.org/13328 CentOS-regression: Gluster Build System Smoke: Gluster Build System NetBSD-regression: NetBSD Build System Reviewed-by: Rajesh Joseph Reviewed-by: Ravishankar N --- run-tests.sh | 45 +++++++++++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/run-tests.sh b/run-tests.sh index f9000a1d918..aaaa1faa63d 100755 --- a/run-tests.sh +++ b/run-tests.sh @@ -3,6 +3,10 @@ # export TZ=UTC +force="no" +retry="no" +tests="" + function check_dependencies() { ## Check all dependencies are present @@ -165,7 +169,7 @@ function run_tests() } RES=0 for t in $(find ${regression_testsdir}/tests | LC_COLLATE=C sort) ; do - if match $t "$@" ; then + if match $t "$tests" ; then if [ -d $t ] ; then echo "Running tests in directory $t" prove -rf --timer $t @@ -257,19 +261,19 @@ function run_all () function main() { - if [ $# -lt 1 ]; then + if [ "x$tests" = "x" ]; then echo "Running all the regression test cases (new way)" #prove -rf --timer ${regression_testsdir}/tests; run_all else - run_tests "$@" + run_tests "$tests" fi } function main_and_retry() { RESFILE=`mktemp /tmp/${0##*/}.XXXXXX` || exit 1 - main "$@" | tee ${RESFILE} + main "$tests" | tee ${RESFILE} RET=$? FAILED=$( awk '/Failed: /{print $1}' ${RESFILE} ) @@ -289,22 +293,27 @@ function main_and_retry() return ${RET} } +function parse_args () { + args=`getopt fr $*` + set -- $args + while [ $# -gt 0 ]; do + case "$1" in + -f) force="yes" ;; + -r) retry="yes" ;; + --) shift; break;; + esac + shift + done + tests="$@" +} + + echo echo ... GlusterFS Test Framework ... echo -force="no" -retry="no" -args=`getopt fr $*` -set -- $args -while [ $# -gt 0 ]; do - case "$1" in - -f) force="yes" ;; - -r) retry="yes" ;; - --) shift; break;; - esac - shift -done +# Get user options +parse_args $@ # Make sure we're running as the root user check_user @@ -317,7 +326,7 @@ check_location # Run the tests if [ "x${retry}" = "xyes" ] ; then - main_and_retry $@ + main_and_retry "$tests" else - main "$@" + main "$tests" fi -- cgit