BASIS  r3148
basistest-slave.sh
Go to the documentation of this file.
00001 #! /bin/bash
00002 __FILE__="$(cd -P -- "$(dirname -- "$BASH_SOURCE")" && pwd -P)/$(basename -- "$BASH_SOURCE")"; if [[ -n "$SGE_ROOT" ]] && [[ $__FILE__ =~ $SGE_ROOT/.* ]] && [[ -n "${BASIS_DIR}" ]] && [[ -f "${BASIS_DIR}/bin/basistest-slave.sh" ]]; then __FILE__="${BASIS_DIR}/bin/basistest-slave.sh"; fi; i=0; lnk="$__FILE__"; while [[ -h "$lnk" ]] && [[ $i -lt 100 ]]; do dir=`dirname -- "$lnk"`; lnk=`readlink -- "$lnk"`; lnk=`cd "$dir" && cd $(dirname -- "$lnk") && pwd`/`basename -- "$lnk"`; let i++; done; [[ $i -lt 100 ]] && __FILE__="$lnk"; unset -v i dir lnk; __DIR__="$(dirname -- "$__FILE__")"; BASIS_BASH_UTILITIES="$__DIR__/bash/basis/basis.sh"; BASHPATH="$__DIR__/.:$__DIR__/bash:$BASHPATH" # <-- added by BASIS
00003 ##############################################################################
00004 # @file  basistest-slave.sh
00005 # @brief Test execution command.
00006 #
00007 # This shell script runs the tests of a BASIS project. It is a wrapper for
00008 # a CTest script. In particular, the testing master basistest-master.sh uses
00009 # this script by default in order to run a test.
00010 #
00011 # Copyright (c) 2011, 2012 University of Pennsylvania. All rights reserved.<br />
00012 # See https://www.cbica.upenn.edu/sbia/software/license.html or COPYING file.
00013 #
00014 # Contact: SBIA Group <sbia-software at uphs.upenn.edu>
00015 #
00016 # @ingroup Tools
00017 ##############################################################################
00018 
00019 . ${BASIS_BASH_UTILITIES} || exit 1
00020 
00021 # ============================================================================
00022 # constants
00023 # ============================================================================
00024 
00025 exedir  _EXEC_DIR  && readonly _EXEC_DIR
00026 exename _EXEC_NAME && readonly _EXEC_NAME
00027 
00028 # ============================================================================
00029 # help/version
00030 # ============================================================================
00031 
00032 # ----------------------------------------------------------------------------
00033 ## @brief Print documentation of options.
00034 #
00035 # @returns Nothing.
00036 function print_options
00037 {
00038     cat - << EOF-OPTIONS
00039 Optional arguments:
00040   --project, -p   The name of the project to be tested.
00041   --branch, -b    The branch to be tested, e.g., "tags/1.0.0".
00042                   Default: "trunk".
00043   --model, -m     The name of the dashboard model, i.e., either "Nightly",
00044                   "Continuous", or "Experimental".
00045                   Default: "Experimental".
00046   --script, -S    CTest script which performs the testing.
00047                   Default: basistest.ctest script of BASIS.
00048   --args, -a      Additional arguments for the CTest script. See below.
00049                   Instead of using the --args option, the additional arguments
00050                   can be given directly with only two dashes (--) prefixed.
00051 
00052 Standard arguments:
00053   --verbose, -v   Increases verbosity of output messages. Can be given multiple times.
00054   --help, -h      Print help and exit.
00055   --helpshort     Print short help and exit.
00056   --version       Print version information and exit.
00057 
00058 All other arguments are passed on as additional arguments to the CTest script
00059 without the leading two dashes (--). For example, the optional argument
00060 --coverage corresponds to supplying the option --args with the value 'coverage'.
00061 Both result in the argument 'coverage' being passed on to the CTest script.
00062 See below for a list of valid arguments of the CTest script.
00063 EOF-OPTIONS
00064 }
00065 
00066 # ----------------------------------------------------------------------------
00067 ## @brief Print help.
00068 #
00069 # @returns Nothing.
00070 function print_help
00071 {
00072     echo "Usage:"
00073     echo "  ${_EXEC_NAME} [options]"
00074     echo
00075     cat - << EOF-DESCRIPTION
00076 Description:
00077   This program performs the testing of a BASIS project.
00078 EOF-DESCRIPTION
00079     echo
00080     print_options
00081     echo
00082     echo "Arguments of CTest script:"
00083     which ctest &> /dev/null
00084     if [ $? -ne 0 ]; then
00085         echo "  Missing ctest command!" 1>&2
00086     else
00087         if [ ! -f "${ctest_script}" ]; then
00088             echo "  Missing CTest script ${ctest_script}" 1>&2
00089         else
00090             helpstr=`ctest -S "${ctest_script},helpoptions"`
00091             helpstr="${helpstr%CMake Error*}"
00092             echo -n "${helpstr}"
00093         fi
00094     fi
00095     echo
00096     cat - << EOF-EXAMPLES
00097 Examples:
00098   ${_EXEC_NAME}
00099 
00100     Run this command in the build tree of your BASIS project to run the tests
00101     with submission of the test results to the Experimental dashboard.
00102 
00103   ${_EXEC_NAME} --memcheck
00104 
00105     Run this command in the build tree of your BASIS project to run the memory
00106     checks with the submission of the results to the Experimental dashboard.
00107 
00108   ${_EXEC_NAME} --project BASIS --coverage
00109 
00110     Performs the testing of the project BASIS. The project source files are
00111     first download into the source directory, then the build tree is configured
00112     and the project is build. When these steps were successful, the tests are run,
00113     including coverage analysis.
00114 EOF-EXAMPLES
00115     echo
00116     print_contact
00117 }
00118 
00119 # ----------------------------------------------------------------------------
00120 ## @brief Print usage (i.e., only usage and options).
00121 #
00122 # @returns Nothing.
00123 function print_helpshort
00124 {
00125     echo "Usage:"
00126     echo "  ${_EXEC_NAME} [options]"
00127     echo
00128     print_options
00129     echo
00130     print_contact
00131 }
00132 
00133 # ============================================================================
00134 # options
00135 # ============================================================================
00136 
00137 # CTest script
00138 ctest_script="${_EXEC_DIR}/../share/cmake-modules/basistest.ctest"
00139 
00140 project=''           # name of the BASIS project
00141 branch='trunk'       # the branch to test
00142 model='Experimental' # the dashboard model
00143 args=''              # additional CTest script arguments
00144 verbosity=0          # verbosity of output messages
00145 
00146 function add_arg
00147 {
00148     if [ -n "${args}" ]; then
00149         args="${args},$1"
00150     else
00151         args="$1"
00152     fi
00153 }
00154 
00155 while [ $# -gt 0 ]; do
00156     case "$1" in
00157         -p|--project)
00158             shift
00159             if [ $# -gt 0 ]; then
00160                 project=$1
00161             else
00162                 echo "Option --project requires an argument!" 1>&2
00163                 exit 1
00164             fi
00165             ;;
00166         -b|--branch)
00167             shift
00168             if [ $# -gt 0 ]; then
00169                 branch=$1
00170             else
00171                 echo "Option --branch requires an argument!" 1>&2
00172                 exit 1
00173             fi
00174             ;;
00175         -m|--model)
00176             shift
00177             if [ $# -gt 0 ]; then
00178                 model=$1
00179             else
00180                 echo "Option --model requires an argument!" 1>&2
00181                 exit 1
00182             fi
00183             ;;
00184         -S|--script)
00185             shift
00186             if [ $# -gt 0 ]; then
00187                 ctest_script=$1
00188             else
00189                 echo "Option --script requires an argument!" 1>&2
00190                 exit 1
00191             fi
00192             ;;
00193         -a|--args)
00194             shift
00195             if [ $# -gt 0 ]; then
00196                 add_arg "$1"
00197             else
00198                 echo "Option --args requires an argument!" 1>&2
00199                 exit 1
00200             fi
00201             ;;
00202 
00203         # standard options
00204         -h|--help)    print_help; exit 0; ;;
00205         --helpshort)  print_helpshort; exit 0; ;;
00206         --version)    print_version ""; exit 0; ;;
00207         -v|--verbose) ((verbosity++)); ;;
00208         -vv)          verbosity=$((${verbosity} + 2));;
00209 
00210         # pass all unknown options as arguments to the CTest script
00211         *)
00212             if [ "${1:0:2}" != '--' ]; then
00213                 if [ "${1:0:1}" == '-' ]; then
00214                     echo "Invalid option: $1" 1>&2
00215                 else
00216                     echo "Invalid argument: $1" 1>&2
00217                     echo "Did you mean --$1 instead?" 1>&2
00218                 fi
00219                 exit 1
00220             fi
00221             add_arg "${1:2}"
00222             ;;
00223     esac
00224     shift
00225 done
00226 
00227 # ============================================================================
00228 # main
00229 # ============================================================================
00230 
00231 if [ ${verbosity} -gt 0 ]; then
00232     echo "${_EXEC_NAME} running on host $(hostname)"
00233     echo
00234 fi
00235 
00236 # see if ctest can be found
00237 which ctest &> /dev/null
00238 if [ $? -ne 0 ]; then
00239     echo "Could not find the ctest command" 1>&2
00240     exit 1
00241 fi
00242 
00243 # check existence of CTest script
00244 if [ ! -f "${ctest_script}" ]; then
00245     echo "Missing CTest script ${ctest_script}" 1>&2
00246     exit 1
00247 fi
00248 
00249 # compose command
00250 cmd='ctest'
00251 if [ ${verbosity} -gt 1 ]; then
00252     cmd="${cmd} -VV"
00253 else
00254     cmd="${cmd} -V"
00255 fi
00256 cmd="${cmd} -S ${ctest_script}"
00257 if [ -n "${project}" ]; then cmd="${cmd},project=${project}"; fi
00258 if [ -n "${branch}"  ]; then cmd="${cmd},branch=${branch}"; fi
00259 if [ -n "${model}"   ]; then cmd="${cmd},model=${model}"; fi
00260 if [ ! -z "${args}"  ]; then cmd="${cmd},${args}"; fi
00261 cmd="${cmd}"
00262 
00263 # run test
00264 if [ ${verbosity} -gt 1 ]; then
00265     echo "Exec ${cmd}"
00266 fi
00267 exec ${cmd}