Go to the documentation of this file.00001 #! /bin/bash
00002 ##############################################################################
00003 # @file basistest-cron.sh
00004 # @brief Script intended to be run as cron job to perform automated testing.
00005 #
00006 # This script sets up the environment for the actual master script which
00007 # handles the automated testing. Further, it uses qsub to submit testing jobs
00008 # to the configured SGE queue, with the SGE options as set in this script.
00009 #
00010 # Edit this script to change the settings of the automated testing.
00011 # The default settings are the ones used for the cron job running on the
00012 # cluster of our lab as the 'swtest' user.
00013 #
00014 # The configuration of automated tests is done in the configuration file
00015 # for the basistest-master.sh. See value of conf variable below.
00016 #
00017 # Copyright (c) 2011 University of Pennsylvania. All rights reserved.<br />
00018 # See https://www.cbica.upenn.edu/sbia/software/license.html or COPYING file.
00019 #
00020 # Contact: SBIA Group <sbia-software at uphs.upenn.edu>
00021 #
00022 # @ingroup Tools
00023 ##############################################################################
00024
00025
00026 # constants used by the shflags.sh module
00027 HELP_COMMAND='basistest-cron (BASIS)'
00028 HELP_CONTACT='SBIA Group <sbia-software at uphs.upenn.edu>'
00029 HELP_VERSION='version 1.2.3 (revision 2104)'
00030 HELP_COPYRIGHT='Copyright (c) University of Pennsylvania. All rights reserved.
00031 See https://www.rad.upenn.edu/sbia/software/license.html or COPYING file.'
00032
00033
00034 # ----------------------------------------------------------------------------
00035 ## @brief Get real path of given file or directory.
00036 #
00037 # @note This function was substituted by BASIS either for the string
00038 # \@BASIS_BASH_UTILITIES\@ or \@BASIS_BASH_FUNCTION_realpath\@.
00039 #
00040 # Example:
00041 # @code
00042 # exec_dir=`realpath $0`
00043 # @endcode
00044 #
00045 # @param [in] path File or directory path.
00046 #
00047 # @returns Canonical path.
00048 #
00049 # @sa http://stackoverflow.com/questions/7665/how-to-resolve-symbolic-links-in-a-shell-script
00050 function realpath
00051 {
00052 local path=$1
00053
00054 local linkdir=''
00055 local symlink=''
00056
00057 while [ -h ${path} ]; do
00058 # 1) change to directory of the symbolic link
00059 # 2) change to directory where the symbolic link points to
00060 # 3) get the current working directory
00061 # 4) append the basename
00062 linkdir=$(dirname -- "${path}")
00063 symlink=$(readlink ${path})
00064 path=$(cd "${linkdir}" && cd $(dirname -- "${symlink}") && pwd)/$(basename -- "${symlink}")
00065 done
00066
00067 echo -n "$(cd -P -- "$(dirname "${path}")" && pwd -P)/$(basename -- "${path}")"
00068 }
00069
00070 readonly _SBIA_BASIS_BASISTEST_CRON_DIR="$(dirname -- "$(realpath "$(cd -P -- "$(dirname -- "${BASH_SOURCE}")" && pwd -P)/$(basename -- "$BASH_SOURCE")")")"
00071 source "${_SBIA_BASIS_BASISTEST_CRON_DIR}/../lib/basis.sh" || exit 1
00072
00073
00074 # ============================================================================
00075 # constants
00076 # ============================================================================
00077
00078 get_executable_directory _EXEC_DIR && readonly _EXEC_DIR
00079 get_executable_name _EXEC_NAME && readonly _EXEC_NAME
00080
00081 # ============================================================================
00082 # settings
00083 # ============================================================================
00084
00085 ## @brief Whether to use SGE or not.
00086 sge=1
00087
00088 ## @brief SGE queue; set to '' to not specify any.
00089 queue='centos5'
00090
00091 ## @brief Mail address for SGE notifications; set to '' to disable notifications.
00092 mail=''
00093
00094 ## @brief Output file for test log; used for -o and -e option of qsub.
00095 log='/sbia/home/swtest/var/log/basistest-$JOB_ID.log'
00096
00097 ## @brief Maximum number of days for which log files should be kept.
00098 max_log_mtime=7
00099
00100 ## @brief Configuration file; configure the automated tests here, see <tt>basistestd -h</td>.
00101 conf='/sbia/home/swtest/etc/basistest.conf'
00102
00103 ## @brief Schedule file; note that this file is created/updated by the testing daemon.
00104 schedule='/sbia/home/swtest/var/run/basistest.schedule'
00105
00106 ## @brief CTest script.
00107 #
00108 # Has to be given with full path because SGE copies the slave script which
00109 # looks for the CTest script relative to its own location.
00110 ctest="${_EXEC_DIR}/../share/cmake/basistest.ctest"
00111
00112 ## @brief Testing master script.
00113 master="${_EXEC_DIR}/basistest-master"
00114
00115 ## @brief Test execution command.
00116 #
00117 # Note: We use a fixed site name for the tests. This allows the test job to be
00118 # run on any compute node with the same system installation without
00119 # having CDash list submissions from these different notes as separate.
00120 # In particular, the numbers of how many tests are now succeeding compared
00121 # to previous runs, or how many are now failing would otherwise be confusing
00122 # when the tests are not regularly run at one and the same site, but
00123 # different sites which represent the same operating system and configuration.
00124 slave="${_EXEC_DIR}/basistest-slave -v -S ${ctest} --args site=sbia-cluster-centos5,shared-source,shared-build"
00125
00126 # ============================================================================
00127 # main
00128 # ============================================================================
00129
00130 dry='false'
00131
00132 while [ $# -gt 0 ]; do
00133 case "$1" in
00134 -h|--help)
00135 echo "Usage:"
00136 echo " ${_EXEC_NAME}"
00137 echo
00138 echo "Description:"
00139 echo " This command should be run regularly by a cron job. It contains"
00140 echo " all the fixed settings for the execution of the basistest master"
00141 echo " command, which is simply executed by this command."
00142 echo
00143 echo "Optional arguments:"
00144 echo " --dry Dry run, i.e., do not actually invoke the test execution command."
00145 echo
00146 print_contact
00147 exit 0
00148 ;;
00149
00150 --helpshort)
00151 echo "Usage:"
00152 echo " ${_EXEC_NAME}"
00153 echo
00154 print_contact
00155 exit 0
00156 ;;
00157
00158 --version)
00159 print_version 'basistest-cron'
00160 exit 0
00161 ;;
00162
00163 --dry)
00164 dry='true';
00165 ;;
00166
00167 *)
00168 echo "Invalid argument $1! See ${_EXEC_NAME} --help." 1>&2
00169 exit 1
00170 ;;
00171 esac
00172 shift
00173 done
00174
00175 # source environment settings of test user
00176 source /sbia/home/swtest/.bashrc || exit 1
00177
00178 # prepend test command by qsub command
00179 if [ ${sge} -ne 0 ]; then
00180 tmpslave=$(mktemp -t 'basistest-XXXXXX')
00181 echo "#! /usr/bin/env bash" >> "${tmpslave}"
00182 echo "# temporarily generated by basistest-cron for submission to SGE" >> "${tmpslave}"
00183 echo "${slave} \"\$@\"" >> "${tmpslave}"
00184 submit='qsub -cwd'
00185 if [ ! -z "${queue}" ]; then submit="${submit} -l ${queue}"; fi
00186 if [ ! -z "${mail}" ]; then submit="${submit} -M ${mail} -m b -m e -m a"; fi
00187 if [ ! -z "${log}" ]; then submit="${submit} -o ${log} -j y"; fi
00188 slave="${submit} ${tmpslave}"
00189 fi
00190
00191 # remove log files that are older than max_log_mtime (days)
00192 if [ ! -z "${log}" ]; then
00193 log_dir=${log
00194 log_dir_ok=0
00195 if [[ $(uname) == 'Darwin' ]]; then
00196 if [[ "${log_dir}" =~ ^/sbia/home/swtest/var/ ]]; then
00197 log_dir_ok=1
00198 fi
00199 else
00200 if [[ "${log_dir}" =~ '^/sbia/home/swtest/var/' ]]; then
00201 log_dir_ok=1
00202 fi
00203 fi
00204 if [ ${log_dir_ok} -eq 1 ]; then
00205 find ${log_dir} -mtime "+${max_log_mtime}" -exec rm -f '{}' ';' 2> /dev/null
00206 else
00207 echo "WARNING: Attempting to delete old log files from directory other than /sbia/home/swtest/var/." 1>&2
00208 echo "WARNING: Skipping removal of any files. Update basistest-cron.sh to account for changed location of log files!" 1>&2
00209 fi
00210 fi
00211
00212 # run actual testing master
00213 if [ "$dry" == 'true' ]; then
00214 ${master} '--dry' -c "${conf}" -s "${schedule}" -t "${slave}"
00215 else
00216 ${master} -c "${conf}" -s "${schedule}" -t "${slave}"
00217 fi
00218
00219 # remove SGE submission script (SGE copied it already)
00220 [ -n "${tmpslave}" ] && rm -f "${tmpslave}"