cgal/Packages/Scripts/developer_scripts/autotest_cgal

547 lines
13 KiB
Bash
Executable File

#!/bin/sh
# ----------------------------------------------------
# ----------------------------------------------------
# autotest_cgal: a script to automagically install and
# test internal CGAL releases
# $Revision$ $Date$
# ----------------------------------------------------
# You will need
# * GNU wget
# (see ftp://sunsite.auc.dk/pub/infosystems/wget/)
#
# 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_<hostname> variables to the
# os-compilers descriptions on which you want to run
# the testsuite.
# ----------------------------------------------------
# ----------------------------------------------------
#sets the umask to 022 & 0777
umask 022
WGET="wget"
CGAL_URL="https://www-sop.inria.fr/geometrica/CGAL/Members/Releases"
LATEST_LOCATION="${CGAL_URL}/LATEST"
TAR="tar"
GZIP="gzip"
GUNZIP="gunzip"
COMPRESSOR="${GZIP}"
SENDMAIL="mail"
CGAL_TESTER=`whoami`
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"
if [ -f $HOME/.autocgalrc ]; then
. $HOME/.autocgalrc
else
# if [ -f .autocgalrc ]; then
# . .autocgalrc
# else
echo "CONFIGURATION FILE .autocgalrc NOT FOUND";
# fi
fi
# ----------------------------------------------------
# You probably don't need to change anything beyond
# ----------------------------------------------------
#
# 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()
{
$FTP -n $FTP_SERVER <<EOF
quote USER anonymous
quote PASS ${MAIL_ADDRESS}
binary
put ${1} ${FTP_STORE_DIR}/${2}
quit
EOF
}
error()
{
if [ -n "${CONSOLE_OUTPUT}" ]; then
printf "\nERROR: ${*}, exiting.\n"
fi
printf "\nERROR: ${*}, exiting.\n" >> ${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
}
#----------------------------------------------
# create the global makefile to make it run
# on multiple processors
#---------------------------------------------
make_global_makefile()
{
log ${ACTUAL_LOGFILE} "create the global makefile"
MAKEFILE_NAME="Makefile"
MAKE_TEST_DIRECTORIES=`ls`
#clear the error file
rm -f $MAKEFILE_NAME
touch $MAKEFILE_NAME
printf "testsuite: " >> ${MAKEFILE_NAME}
for DIR in $MAKE_TEST_DIRECTORIES ; do
if [ -d $DIR ] ; then
printf "test_$DIR " >> ${MAKEFILE_NAME}
fi
done
printf "\n" >> ${MAKEFILE_NAME}
for DIR in $MAKE_TEST_DIRECTORIES ; do
if [ -d $DIR ] ; then
echo "test_$DIR:" >> ${MAKEFILE_NAME}
printf "\t+ ./run_testsuite $DIR\n" >> ${MAKEFILE_NAME}
fi
done
log_done ${ACTUAL_LOGFILE}
}
# ---------------------------------------------------
# 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}
mkdir ../test_${2}
cp -r * ../test_${2}
cd ../test_${2}
make_global_makefile
log ${ACTUAL_LOGFILE}.${1} "Testing on ${1} with ${2}"
remote_command ${1} \
"export CGAL_MAKEFILE=${CGAL_MAKE_DIR}/makefile_${2};
cd ${CGAL_DIR}/test_${2};
nice -19 make -j ${NUMBER_OF_PROCESSORS}" \
>> ${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
#
log ${ACTUAL_LOGFILE}.${1} "COLLECTING AND PUTTING RESULTS ON THE WEB"
cd ${CGAL_DIR}/test_${2}
./collect_cgal_testresults >> ${ACTUAL_LOGFILE}.${1} 2>&1
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}
${WGET} ${CGAL_LOCATION} >> ${ACTUAL_LOGFILE} 2>&1
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
log ${ACTUAL_LOGFILE} "copy config install files"
cp -r ${OLD_CGAL_DIR}/config/install ${CGAL_DIR}/config
log_done ${ACTUAL_LOGFILE}
# copy gmp header and libs
log ${ACTUAL_LOGFILE} "copy gmp header"
if [ -f ${OLD_CGAL_INCL_DIR}/gmp.h ]; then
cp ${OLD_CGAL_INCL_DIR}/gmp.h ${CGAL_INCL_DIR}
fi
log_done ${ACTUAL_LOGFILE}
log ${ACTUAL_LOGFILE} "copy gmp libs"
printf "\n" >> ${ACTUAL_LOGFILE}
for i in `find ${OLD_CGAL_LIB_DIR} -name "libgmp.a" -print`; do
printf "."
printf "copying ${i}\n" >> ${ACTUAL_LOGFILE}
newdir=`dirname ${i} | \
sed "s%${OLD_CGAL_LIB_DIR}%${CGAL_LIB_DIR}%g`
mkdir -p ${newdir}
if [ ${?} != 0 ]; then
error "Could not mkdir ${newdir}"
fi
cp ${i} ${newdir}
done
for i in `find ${OLD_CGAL_LIB_DIR} -name "gmp.lib" -print`; do
printf "."
printf "copying ${i}\n" >> ${ACTUAL_LOGFILE}
newdir=`dirname ${i} | \
sed "s%${OLD_CGAL_LIB_DIR}%${CGAL_LIB_DIR}%g`
echo $newdir
mkdir -p ${newdir}
if [ ${?} != 0 ]; then
error "Could not mkdir ${newdir}"
fi
cp ${i} ${newdir}
done
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"
${WGET} ${LATEST_LOCATION} >> ${ACTUAL_LOGFILE} 2>&1
if [ ! -f "LATEST" ]; then
error "COULD NOT DOWNLOAD LATEST!"
fi
if [ ! -r "RELEASE_NR" ]; then
touch "RELEASE_NR"
fi
cmp LATEST RELEASE_NR > ${ACTUAL_LOGFILE}
if [ ${?} != 0 ]; then
# echo "The diff is different!!"
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
get_cgal
unzip_cgal
copy_old_stuff
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
build_cgal
run_test
# restore settings:
cd ${CGAL_ROOT}
cp LATEST RELEASE_NR
fi
rm -rf $LOCK_FILE;
# EOF