cgal/Testsuite/test/run_testsuite_with_cmake

264 lines
8.1 KiB
Bash
Executable File

#! /bin/sh
#
# This is the test script for the CGAL-library.
#
# Usage:
# run_testsuite for running the test suite in all subdirectories
# run_testsuite <directory-list> for running the test suite in the listed
# subdirectories
#
# To use this script you have to do two things:
#
# 2) set some additional compiler and or linker flags
TESTSUITE_CXXFLAGS=""
TESTSUITE_LDFLAGS=""
CURRENTDIR=`pwd`
ERRORFILE=${CURRENTDIR}/error.txt
if [ -n "$CGAL_TEST_PLATFORM" ]; then
PLATFORM=$CGAL_TEST_PLATFORM
else
PLATFORM=no-platform
fi
if [ -n "${CGAL_TIMEOUT_PROG+x}" ]; then
TIMEOUT=$CGAL_TIMEOUT_PROG
else
TIMEOUT=`which timeout`
[ -z "$TIMEOUT" ] && TIMEOUT=`which gtimeout`
fi
#clear the error file
rm -f "$ERRORFILE"
touch "$ERRORFILE"
# On Cygwin, killing bash does not kill jobs it has spawned. This
# function takes a PID as argument and prints the list of children
# processes of this process, including itself.
process_tree()
{
local pid=$1
local result=
echo $pid
ps -a | awk '!/^ +PID/ {print $1 " " $2}' | {
while read apid appid; do
if [ "$appid" = "$pid" ]; then
process_tree $apid
fi
done
}
}
# Wait for process with pid $1.
# Wait for $2 periods of $3 seconds, checking after every period
# if the watched process has finished.
wait_for_process()
{
pid=$1;
cycles=$2
period=$3
while [ $cycles -ne 0 ]
do
cycles=`expr $cycles - 1`
# send SIGCONT to the process and check the exit value of kill.
# If the process still exists, the call to kill succeeds (and the signal is
# ignored).
kill -CONT $pid 2>kill_output 1>/dev/null; terminated=$?
# But under CYGWIN the exit status is not to be trusted.
if [ $terminated -eq 0 ]; then
if grep -i 'no such process' kill_output; then
terminated=1;
fi
fi
rm -f kill_output
if [ $terminated -eq 0 ]
then
sleep $period
else
cycles=0
running=0
fi
done
if [ $terminated -eq 0 ]
then
if false; then
# Send signal Terminate (SIGTERM) to the whole process group.
# First disable the default action (quit) for the current process.
trap true TERM
kill -TERM 0
trap TERM
else
# $pid is the PID of the forked shell that launched the command
# in background, in run_local_cgal_test(). If the shell is
# Bash, the Bash manual states that it ignores SIGTERM.
# However, it does not catch SIGHUP. That is why the first
# signal send is SIGHUP.
case "`uname`" in
CYGWIN*)
pids=`process_tree $pid`;;
*) pids=$pid;;
esac
for p in $pids; do kill -HUP $p; done
sleep 10
# If SIGHUP was not enough, SIGKILL will finish the job, 10s after.
for p in $pids; do kill -KILL $p 2>/dev/null; done
fi
return 1
fi
return 0
}
run_local_cgal_test()
{
# Workaround an issue on Windows when GNU Make is used for "make -f
# makefile2" but nmake is used after.
MAKEFLAGS=
export MAKEFLAGS
if [ -n "$TIMEOUT" ]; then
"$TIMEOUT" $(( $TIME_PERIOD * 5 )) ./cgal_test_with_cmake > current_compiler_output 2>&1
else
./cgal_test_with_cmake > current_compiler_output 2>&1
fi
exit_value=$?
if [ $exit_value -ne 0 ]
then
printf "%s\n" "$exit_value" > test_failure
fi
return $exit_value
}
#test_directory <directory> <already_here>
# test_directory() may call itself once: the second parameter avoids that
# it calls itself infinitely.
test_directory()
{
cd "$CURRENTDIR"
if [ -d $1 ] ; then
echo "DIRECTORY $1:"
echo
echo "DIRECTORY $1:" >> "$ERRORFILE"
echo >> "$ERRORFILE"
cd "$1"
COMPILER_OUTPUT=CompilerOutput_$PLATFORM
rm -f "$COMPILER_OUTPUT"
ERROR_OUTPUT=ErrorOutput_$PLATFORM
rm -f "$ERROR_OUTPUT"
echo "------------------------------------------------------------------" >> "$COMPILER_OUTPUT"
echo "- Compiler output from platform $PLATFORM" >> "$COMPILER_OUTPUT"
echo "------------------------------------------------------------------" >> "$COMPILER_OUTPUT"
echo >> "$COMPILER_OUTPUT"
echo "------------------------------------------------------------------" >> "$ERROR_OUTPUT"
echo "- Error output from platform $PLATFORM" >> "$ERROR_OUTPUT"
echo "------------------------------------------------------------------" >> "$ERROR_OUTPUT"
echo >> "$ERROR_OUTPUT"
if [ -f cgal_test_with_cmake -a -x cgal_test_with_cmake ] ; then
export PLATFORM TESTSUITE_CXXFLAGS TESTSUITE_LDFLAGS
rm -f error.txt
START=`date +%s`
TIME_PERIOD=1200
if [ "$1" = "Polyhedron_Demo" ]; then
TIME_PERIOD=2400
fi
if [ -n "$TIMEOUT" ]; then
run_local_cgal_test
return_code=$?
if [ $return_code -eq 124 ]; then
echo "ERROR: cgal_test_with_cmake did not finish within the time bound set" >> "$ERRORFILE"
echo "ERROR: cgal_test_with_cmake did not finish within the time bound set" >> "$ERROR_OUTPUT"
else
if [ -f test_failure ] ; then
exit_failure=`cat test_failure`
rm -f test_failure
echo "ERROR: cgal_test_with_cmake exited with error condition $exit_value" >> "$ERRORFILE"
echo "ERROR: cgal_test_with_cmake exited with error condition $exit_value" >> "$ERROR_OUTPUT"
fi
fi
else
run_local_cgal_test &
if wait_for_process "$!" "$TIME_PERIOD" "5"
then
if [ -f test_failure ] ; then
exit_failure=`cat test_failure`
rm -f test_failure
echo "ERROR: cgal_test_with_cmake exited with error condition $exit_value" >> "$ERRORFILE"
echo "ERROR: cgal_test_with_cmake exited with error condition $exit_value" >> "$ERROR_OUTPUT"
fi
else
echo "ERROR: cgal_test_with_cmake did not finish within the time bound set" >> "$ERRORFILE"
echo "ERROR: cgal_test_with_cmake did not finish within the time bound set" >> "$ERROR_OUTPUT"
fi
fi
STOP=`date +%s`
DURATION=`expr "$STOP" - "$START"`
printf " # Running time: %s (seconds)\n\n" "$DURATION" >> "$ERRORFILE"
printf " # Running time: %s (seconds)\n\n" "$DURATION" >> "$ERROR_OUTPUT"
cat current_compiler_output >> "$COMPILER_OUTPUT"
cat current_compiler_output
rm -f current_compiler_output
if [ -f error.txt ] ; then
cat error.txt >> "$ERRORFILE"
cat error.txt >> "$ERROR_OUTPUT"
else
echo "ERROR: the script cgal_test_with_cmake failed to generate output" >> "$ERRORFILE"
fi
else
if [ -z "$2" ]; then
create_cgal_test
test_directory "$1" "second_time"
else
echo " Could not execute the script cgal_test_with_cmake in directory $1"
echo "ERROR: could not execute the script $1/cgal_test_with_cmake" >> $ERRORFILE
fi
fi
echo >> "$ERRORFILE"
echo >> "$ERROR_OUTPUT"
fi
echo
}
run_testsuite()
{
echo "---------------------------------------------------------------"
echo "- Testing platform $PLATFORM"
echo "---------------------------------------------------------------"
echo
echo "---------------------------------------------------------------" >> "$ERRORFILE"
echo "- TEST RESULTS FROM PLATFORM $PLATFORM" >> "$ERRORFILE"
echo "---------------------------------------------------------------" >> "$ERRORFILE"
echo >> "$ERRORFILE"
case "`uname`" in
CYGWIN*)
PATH=`cygpath "$CGAL_DIR"`/bin:`cygpath "$CGAL_DIR"`/lib:$PATH
export PATH
esac
for DIR in $TEST_DIRECTORIES ; do
if [ ! -f $DIR/skipped ]; then
test_directory "$DIR"
fi
done
}
[ x"$1" = x"icons" -o x"$1" = x"resources" ] && exit 0
if [ -z "$1" ] ; then
TEST_DIRECTORIES=`ls | grep -E -v 'icons|resources'`
else
TEST_DIRECTORIES="$*"
fi
run_testsuite