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