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
PLATFORM=no-platform
fi
if [ -n "${CGAL_TIMEOUT_PROG+x}" ]; then
TIMEOUT=$CGAL_TIMEOUT_PROG
else
TIMEOUT=`which timeout`
fi
#clear the error file
rm -f "$ERRORFILE"
@ -111,12 +116,17 @@ run_local_cgal_test()
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=$?
if [ $exit_value -ne 0 ]
then
printf "%s\n" "$exit_value" > test_failure
fi
return $exit_value
}
#test_directory <directory> <already_here>
@ -152,23 +162,39 @@ test_directory()
export PLATFORM TESTSUITE_CXXFLAGS TESTSUITE_LDFLAGS
rm -f error.txt
START=`date +%s`
run_local_cgal_test &
TIME_PERIOD=1200
if [ "$1" = "Polyhedron_Demo" ]; then
TIME_PERIOD=2400
fi
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
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
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"
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"`