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