#!/bin/sh # ---------------------------------------------------- # ---------------------------------------------------- # autotest_cgal: a script to automagically install and # test internal CGAL releases # $Id$ # ---------------------------------------------------- # You will need # * GNU wget and ftp # * or alternatively curl # # Furthermore you have to edit .autocgalrc in order to # cutomize it for your environment. # In particular you have to change the BUILHOSTS # variable to contain the names of your hosts and # set the COMPILERS_ variables to the # os-compilers descriptions on which you want to run # the testsuite. # ---------------------------------------------------- # ---------------------------------------------------- #sets the umask to 022 & 0777 umask 022 WGET="wget" CURL="curl" CURL_OPTS="--remote-name --silent --location-trusted" CGAL_URL="http://cgal.inria.fr/CGAL/Members/Releases" LATEST_LOCATION="${CGAL_URL}/LATEST" TAR="tar" GZIP="gzip" GUNZIP="gunzip" COMPRESSOR="${GZIP}" SENDMAIL="mail" CGAL_TESTER=`whoami` CGAL_TESTER_NAME="${CGAL_TESTER}" CGAL_TESTER_ADDRESS="${CGAL_TESTER}" CONSOLE_OUTPUT="y" CGAL_ROOT=`pwd` FTP_SERVER="ftp-sop.inria.fr" FTP_STORE_DIR="geometrica/Incoming" BUILD_HOSTS="must_be_set_in_.autocgalrc" MAIL_ADDRESS="must_be_set_in_.autocgalrc" MYSHELL="must_be_set_in_.autocgalrc" ACTUAL_DIR=`pwd` FTP="ftp" LOGS_DIR="${CGAL_ROOT}/AUTOTEST_LOGS" RSH="rsh" LOCK_FILE="${CGAL_ROOT}/autotest_cgal.lock" NICE_OPTIONS="-19" # Now loading autocgalrc. if [ -f $HOME/.autocgalrc ]; then . $HOME/.autocgalrc else echo "CONFIGURATION FILE .autocgalrc NOT FOUND"; fi # # write to logfile # # $1 = logfile log() { LOGFILE=${1} shift if [ -n "${CONSOLE_OUTPUT}" ]; then printf "${*} ..." fi printf "\n-------------------------------------------------------\n" \ >> ${LOGFILE} printf " ${*} ...\n" \ >> ${LOGFILE} printf "\n-------------------------------------------------------\n" \ >> ${LOGFILE} } # $1 = logfile log_done() { if [ -n "${CONSOLE_OUTPUT}" ]; then printf \ " done\n-------------------------------------------------------\n" fi printf "\n-------------------------------------------------------\n" \ >> ${1} printf " **DONE**\n" \ >> ${1} printf "\n-------------------------------------------------------\n" \ >> ${1} } # # produce a string containing the actual date/time # (used to identify files) # datestr() { date +%d%m%Y%H%M } # # function to put result files on the web # # $1 = source filename (full path) # $2 = target filename (basename only) put_on_web() { if [ -n "${USE_CURL}" ]; then $CURL --upload-file ${1} --user anonymous:${MAIL_ADDRESS} \ ftp://${FTP_SERVER}/${FTP_STORE_DIR}/${2} >> ${ACTUAL_LOGFILE} 2>&1 else $FTP -n $FTP_SERVER <> ${ACTUAL_LOGFILE} ${COMPRESSOR} -9f ${ACTUAL_LOGFILE} FILENAME="${CGAL_RELEASE_ID}-log`datestr`.gz" mv ${ACTUAL_LOGFILE}.gz ${LOGS_DIR}/${FILENAME} if [ ! "${MAIL_ADDRESS}" = "must_be_set_in_.autocgalrc" ]; then for i in ${MAIL_ADDRESS}; do printf "ERROR\n${LOGS_DIR}/${FILENAME}\n" | \ ${SENDMAIL} -s "completed autotest" ${i} done fi rm -rf $LOCK_FILE; exit 1 } # # function to print the value of variable $1 # value_of() { _value=`eval "printf '$'${1}"` eval "printf \"${_value}\"" } # # function for executing a command remotely # # $1 = HOST # $2 = COMMAND remote_command() { if [ "${1}" = "localhost" ]; then eval $2 else printf "** Logging into host ${1} **\n" ${RSH} ${1} ${MYSHELL} \"${2}\" fi } # # function for building the CGAL libs # # $1 = HOST build_cgal_libs() { remote_command ${1} \ "cd ${CGAL_DIR}; ${CGAL_DIR}/install_cgal --CGAL_DIR ${CGAL_DIR} --rebuild-all; rm ${OLD_CGAL_DIR}; ln -s `basename ${CGAL_DIR}` ${OLD_CGAL_DIR}" \ >> ${ACTUAL_LOGFILE} 2>&1 } #----------------------------------------------- # testsuite script parallel #----------------------------------------------- # $1 = HOST # $2 = COMPILERS run_testsuite() { for i in ${2}; do test_script ${1} ${i} done } # --------------------------------------------------- # test script NEW # create additional directories to test in parallel # on multiple platforms # the variable PROCESSORS_electra, where electra is the # name of the machine, is used to specify the number of # processors to use # --------------------------------------------------- # $1 = HOST # $2 = COMPILER test_script() { NUMBER_OF_PROCESSORS="`value_of PROCESSORS_${1}`" cd ${CGAL_TEST_DIR} TEST_DIR_ROOT=${TEST_DIR_ROOT:-${CGAL_DIR}} LOCAL_TEST_DIR=${TEST_DIR_ROOT}/test_${2} log ${ACTUAL_LOGFILE}.${1} "Testing on ${1} with ${2}" if [ "${NUMBER_OF_PROCESSORS}" = "1" ] ; then MAKE_OPTS="" else MAKE_OPTS="-j ${NUMBER_OF_PROCESSORS}" fi remote_command ${1} \ "CGAL_MAKEFILE=${CGAL_MAKE_DIR}/makefile_${2}; CGAL_TESTER=${CGAL_TESTER}; CGAL_TESTER_NAME='${CGAL_TESTER_NAME}'; CGAL_TESTER_ADDRESS='${CGAL_TESTER_ADDRESS}'; export CGAL_MAKEFILE; export CGAL_TESTER CGAL_TESTER_NAME CGAL_TESTER_ADDRESS; rm -rf ${LOCAL_TEST_DIR}; cp -r ${CGAL_TEST_DIR} ${LOCAL_TEST_DIR}; cd ${LOCAL_TEST_DIR}; nice ${NICE_OPTIONS} make ${MAKE_OPTS}; echo 'COLLECTING RESULTS'; ./collect_cgal_testresults; echo 'COPYING RESULTS'; cp results_${CGAL_TESTER}_${2}.tar.gz results_${CGAL_TESTER}_${2}.txt ${CGAL_TEST_DIR}; echo 'REMOVING LOCAL_TEST_DIR'; cd ..; rm -rf ${LOCAL_TEST_DIR} " >> ${ACTUAL_LOGFILE}.${1} 2>&1 log_done ${ACTUAL_LOGFILE}.${1} #PLATFORM=`basename $CGAL_MAKEFILE | sed -e "s/makefile_//g"` # # collect results and put them on the web # cd ${CGAL_TEST_DIR} log ${ACTUAL_LOGFILE}.${1} "PUTTING RESULTS ON THE WEB" log ${ACTUAL_LOGFILE}.${1} "RESULTS COLLECTED "${2}"-"${1} ${TAR} cf test_results-${1}.tar "results_"$CGAL_TESTER"_"${2}".tar.gz" "results_"$CGAL_TESTER"_"${2}".txt" ${COMPRESSOR} -9f test_results-${1}.tar FILENAME=${CGAL_RELEASE_ID}-test`datestr`-${2}.tar.gz LOGFILENAME="${CGAL_RELEASE_ID}-log`datestr`-${1}.gz" ${COMPRESSOR} -9f ${ACTUAL_LOGFILE}.${1} mv ${ACTUAL_LOGFILE}.${1}.gz ${LOGS_DIR}/${LOGFILENAME} put_on_web \ test_results-${1}.tar.gz \ ${FILENAME} # # notify the CGAL world # if [ ! "${MAIL_ADDRESS}" = "must_be_set_in_.autocgalrc" ]; then for i in ${MAIL_ADDRESS}; do printf "result collection::\n${FILENAME}\n" | ${SENDMAIL} -s "autohandle" ${i} done fi } # ---------------------------------------------------- # get CGAL # get_cgal() { log ${ACTUAL_LOGFILE} "getting CGAL" rm -f ${CGAL_ZIPFILE} if [ -n "${USE_CURL}" ]; then ${CURL} ${CURL_OPTS} ${CGAL_LOCATION} >> ${ACTUAL_LOGFILE} 2>&1 else ${WGET} ${CGAL_LOCATION} >> ${ACTUAL_LOGFILE} 2>&1 fi if [ ${?} != 0 ]; then error "Could not get CGAL" fi log_done ${ACTUAL_LOGFILE} } # ---------------------------------------------------- # unzip/untar CGAL # unzip_cgal() { cd ${CGAL_ROOT} log ${ACTUAL_LOGFILE} "unzipping CGAL" if [ "${USE_TARGZ}" = "y" ]; then DECOMPRESSOR="${GUNZIP}" log_done ${ACTUAL_LOGFILE} fi if [ "${USE_TARBZ}" = "y" ]; then DECOMPRESSOR="bunzip2" fi log ${ACTUAL_LOGFILE} "untarring CGAL" ${DECOMPRESSOR} -c ${CGAL_ZIPFILE} | ${TAR} xvf - >> ${ACTUAL_LOGFILE} 2>&1 if [ ${?} != 0 ]; then error "Could not untar CGAL" fi log_done ${ACTUAL_LOGFILE} } # ---------------------------------------------------- # copy stuff from old CGAL installation # copy_old_stuff() { # copy config install files cd ${CGAL_DIR} ./install_cgal --upgrade ${OLD_CGAL_DIR} >> ${ACTUAL_LOGFILE} log_done ${ACTUAL_LOGFILE} } # ---------------------------------------------------- # build cgal # build_cgal() { log ${ACTUAL_LOGFILE} "building cgal libs" for i in ${BUILD_HOSTS}; do build_cgal_libs ${i} done log_done ${ACTUAL_LOGFILE} ${COMPRESSOR} -9f ${ACTUAL_LOGFILE} mv ${ACTUAL_LOGFILE}.gz \ ${LOGS_DIR}/${CGAL_RELEASE_ID}-log`datestr`.gz } # ---------------------------------------------------- # run the testsuites # run_test() { log ${ACTUAL_LOGFILE} "running the testsuites" if [ -n "${CONSOLE_OUTPUT}" ]; then printf "\n-------------------------------------------------------\n" fi for i in ${BUILD_HOSTS}; do run_testsuite ${i} "`value_of COMPILERS_${i}`" & done } # ---------------------------------------------------- # START OF MAIN BODY # ---------------------------------------------------- USE_TARGZ="n" USE_TARBZ="n" # logfile ACTUAL_LOGFILE="${CGAL_ROOT}/`basename ${0}`.log" cd $CGAL_ROOT CRITICAL="n" if [ "${MYSHELL}" = "must_be_set_in_.autocgalrc" ]; then log ${ACTUAL_LOGFILE} "MYSHELL must be set in .autocgalrc" CRITICAL="y" fi if [ "${CRITICAL}" = "y" ]; then error "COULD NOT DETERMINE MYSHELL!" fi lockfile -r 5 $LOCK_FILE; if [ ${?} != 0 ]; then echo "COULD NOT AQUIRE LOCK!"; exit 1; fi if [ -r "LATEST" ]; then rm -rf LATEST fi log ${ACTUAL_LOGFILE} "getting LATEST" if [ -n "${USE_CURL}" ]; then ${CURL} ${CURL_OPTS} ${LATEST_LOCATION} >> ${ACTUAL_LOGFILE} 2>&1 else ${WGET} ${LATEST_LOCATION} >> ${ACTUAL_LOGFILE} 2>&1 fi if [ ! -f "LATEST" ]; then error "COULD NOT DOWNLOAD LATEST!" fi if [ -r "RELEASE_NR" ]; then cmp LATEST RELEASE_NR > ${ACTUAL_LOGFILE} if [ ! ${?} != 0 ]; then rm -f $LOCK_FILE; exit 1; fi fi for i in `cat LATEST` do CGAL_LOCATION="${CGAL_URL}/${i}"; CGAL_ZIPFILE="${i}"; done CGAL_RELEASE_ID=`echo $CGAL_ZIPFILE | sed "s/.tar.gz//"` if [ ! "${CGAL_RELEASE_ID}" = "${CGAL_ZIPFILE}" ]; then USE_TARGZ="y" else CGAL_RELEASE_ID=`echo $CGAL_ZIPFILE | sed "s/.tar.bz2//"` if [ ! "${CGAL_RELEASE_ID}" = "${CGAL_ZIPFILE}" ]; then USE_TARBZ="y" fi fi # dir for the actual release CGAL_DIR=${CGAL_ROOT}/${CGAL_RELEASE_ID} # dir of the previous release # HAS TO exist ! # (used to copy config/install files and evt. gmp stuff) OLD_CGAL_DIR=${CGAL_ROOT}/CGAL-I # you will guess it :) CGAL_INCL_DIR=${CGAL_DIR}/include OLD_CGAL_INCL_DIR=${OLD_CGAL_DIR}/include CGAL_LIB_DIR=${CGAL_DIR}/lib OLD_CGAL_LIB_DIR=${OLD_CGAL_DIR}/lib CGAL_MAKE_DIR=${CGAL_DIR}/make CGAL_TEST_DIR=${CGAL_DIR}/test CGAL_RUN_TEST=${CGAL_TEST_DIR}/run_testsuite CGAL_COLLECT_TEST=${CGAL_TEST_DIR}/collect_cgal_testresults # ---------------------------------------------------- # some sanity checks # # remove old logfile rm -f ${ACTUAL_LOGFILE} # check, if OLD_CGAL_DIR exists and is a symbolic link if [ ! -r ${OLD_CGAL_DIR} -o ! -d ${OLD_CGAL_DIR} ]; then error "directory ${OLD_CGAL_DIR} does not exist" fi if [ ! -h ${OLD_CGAL_DIR} ]; then error "${OLD_CGAL_DIR} has to be a symbolic link" fi if [ ! -r ${LOGS_DIR} ]; then mkdir $LOGS_DIR fi if [ ! "${MAIL_ADDRESS}" = "must_be_set_in_.autocgalrc" ]; then for i in ${MAIL_ADDRESS}; do printf "subject says it all\n" | \ ${SENDMAIL} -s "Started autotest" ${i} done fi # do the job main_procedure() { if [ "${BUILD_HOSTS}" = "must_be_set_in_.autocgalrc" ]; then error "BUILD_HOSTS must be set in .autocgalrc" else for i in ${BUILD_HOSTS}; do TEXT="`value_of COMPILERS_${i}`" if [ -z "${TEXT}" ]; then error "COMPILERS_${i} must be defined in .autocgalrc" else TEXT="`value_of PROCESSORS_${i}`" TEMPVAR="PROCESSORS_${i}" if [ -z "${TEXT}" ]; then log ${ACTUAL_LOGFILE} "\ngiving default 1 values TO PROCESSORS_${i} ..."; eval $TEMPVAR="1"; fi fi done fi get_cgal unzip_cgal copy_old_stuff build_cgal run_test } if [ "${BUILD_HOSTS}" = "localhost" ]; then TEXT="`value_of COMPILERS_localhost`" if [ -z "${TEXT}" ]; then # printf "\nWARNING: Only installing on localhost\n"; get_cgal unzip_cgal copy_old_stuff build_cgal; else main_procedure; fi else main_procedure; fi # restore settings: cd ${CGAL_ROOT} mv LATEST RELEASE_NR rm -f $LOCK_FILE; # EOF