Use `timeout` if available, instead of a system of sleep/kill

The GNU coreutils software
[timeout](https://man7.org/linux/man-pages/man1/timeout.1.html) is
a perfect replacement for our buggy function `wait_for_process`.

This patch uses it when available. On Linux, brew, Cygwin, it is
available in the `coreutils` package.
This commit is contained in:
Laurent Rineau 2020-06-17 12:31:36 +02:00
parent 4dba18fe9d
commit 3468c7bf32
1 changed files with 39 additions and 13 deletions

View File

@ -21,6 +21,11 @@ if [ -n "$CGAL_TEST_PLATFORM" ]; then
else else
PLATFORM=no-platform PLATFORM=no-platform
fi fi
if [ -n "${CGAL_TIMEOUT_PROG+x}" ]; then
TIMEOUT=$CGAL_TIMEOUT_PROG
else
TIMEOUT=`which timeout`
fi
#clear the error file #clear the error file
rm -f "$ERRORFILE" rm -f "$ERRORFILE"
@ -111,12 +116,17 @@ run_local_cgal_test()
MAKEFLAGS= MAKEFLAGS=
export MAKEFLAGS export MAKEFLAGS
eval ./cgal_test_with_cmake > current_compiler_output 2>&1 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=$? exit_value=$?
if [ $exit_value -ne 0 ] if [ $exit_value -ne 0 ]
then then
printf "%s\n" "$exit_value" > test_failure printf "%s\n" "$exit_value" > test_failure
fi fi
return $exit_value
} }
#test_directory <directory> <already_here> #test_directory <directory> <already_here>
@ -152,12 +162,27 @@ test_directory()
export PLATFORM TESTSUITE_CXXFLAGS TESTSUITE_LDFLAGS export PLATFORM TESTSUITE_CXXFLAGS TESTSUITE_LDFLAGS
rm -f error.txt rm -f error.txt
START=`date +%s` START=`date +%s`
run_local_cgal_test &
TIME_PERIOD=1200 TIME_PERIOD=1200
if [ "$1" = "Polyhedron_Demo" ]; then if [ "$1" = "Polyhedron_Demo" ]; then
TIME_PERIOD=2400 TIME_PERIOD=2400
fi 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" if wait_for_process "$!" "$TIME_PERIOD" "5"
then then
if [ -f test_failure ] ; then if [ -f test_failure ] ; then
@ -170,6 +195,7 @@ test_directory()
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" >> "$ERRORFILE"
echo "ERROR: cgal_test_with_cmake did not finish within the time bound set" >> "$ERROR_OUTPUT" echo "ERROR: cgal_test_with_cmake did not finish within the time bound set" >> "$ERROR_OUTPUT"
fi fi
fi
STOP=`date +%s` STOP=`date +%s`
DURATION=`expr "$STOP" - "$START"` DURATION=`expr "$STOP" - "$START"`
printf " # Running time: %s (seconds)\n\n" "$DURATION" >> "$ERRORFILE" printf " # Running time: %s (seconds)\n\n" "$DURATION" >> "$ERRORFILE"