Skip to content

Commit 963a77f

Browse files
committed
Use timeout command in TEST.sh
The Github Actions CI pipeline fails on MacOS because `ulimit -t "10s"` unexpectedly causes the error `Cputime limit exceeded: 24`. This is likely because of breaking changes with the upgraded MacOS image `12.7.3 -> 14.4.1`. The `timeout` command is used instead to ensure the timeout applies to each test case separately. This does increase the reported test runtime since extra sub-processes have to be spawned specifically for that `timeout` command to work. `coreutils` is now required on MacOS to run `TEST.sh`. It can be installed using `brew install coreutils`.
1 parent 0e99faf commit 963a77f

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

.github/workflows/build-and-test.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,5 +78,9 @@ jobs:
7878
- name: Build
7979
run: opam exec -- make
8080

81+
- name: Install coreutils on MacOS
82+
if: runner.os == 'macOS'
83+
run: brew install coreutils
84+
8185
- name: Test
8286
run: opam exec -- make test

TEST.sh

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ declare -r EXAMPLEDIR=${EXAMPLEDIR:-"./examples"}
3434
declare -r INTERACTIVE_TESTDIR=${INTERACTIVE_TESTDIR:-"${TESTROOTDIR}/interactive"}
3535
declare -r HARPOON_TESTDIR=${HARPOON_TESTDIR:-"${TESTROOTDIR}/harpoon"}
3636

37-
declare -i TIMEOUT=${TIMEOUT:-10}
37+
declare -r TIMEOUT=${TIMEOUT:-"10s"}
3838

3939
function rsync_test_artifacts {
4040
rsync -ak "${ROOTDIR}/.admissible-fail" "${TEMPDIR}/.admissible-fail"
@@ -123,8 +123,6 @@ function parse_opts {
123123

124124
function do_testing {
125125
local is_failed=0 file_path
126-
# Limit runtime of each test case, in seconds.
127-
ulimit -t "${TIMEOUT}"
128126

129127
if [[ -n "${RUN_CASE_STUDIES}" ]]; then
130128
echo "===== CASE STUDIES ====="
@@ -204,10 +202,10 @@ function check_example_test_case {
204202
# ${...[@]+${...[@]}} is a workaround for bash < 4.4
205203
# In bash < 4.4, array without an item is considered as an undefined variable.
206204
output_file="$(mktemp)"
207-
"${BELUGA}" +test "${BELUGA_FLAGS[@]+${BELUGA_FLAGS[@]}}" "${file_path}" >>"${output_file}" 2>&1
205+
timeout --foreground "${TIMEOUT}" "${BELUGA}" +test "${BELUGA_FLAGS[@]+${BELUGA_FLAGS[@]}}" "${file_path}" >>"${output_file}" 2>&1
208206
exit_code=$?
209207

210-
if [ "${exit_code}" -eq 152 ]; then
208+
if [ "${exit_code}" -eq 124 ]; then
211209
if grep -q "${file_path}" .admissible-fail; then
212210
echo -e "${C_ADMISSIBLE}ADMISSIBLE TIMEOUT${C_END}"
213211
(( TEST_RESULT_ADMISSIBLE+=1 ))
@@ -242,10 +240,10 @@ function check_compiler_test_case {
242240
# ${...[@]+${...[@]}} is a workaround for bash < 4.4
243241
# In bash < 4.4, array without an item is considered as an undefined variable.
244242
output_file="$(mktemp)"
245-
"${BELUGA}" +test "${BELUGA_FLAGS[@]+${BELUGA_FLAGS[@]}}" "${file_path}" >>"${output_file}" 2>&1
243+
timeout --foreground "${TIMEOUT}" "${BELUGA}" +test "${BELUGA_FLAGS[@]+${BELUGA_FLAGS[@]}}" "${file_path}" >>"${output_file}" 2>&1
246244
exit_code=$?
247245

248-
if [ "${exit_code}" -eq 152 ]; then
246+
if [ "${exit_code}" -eq 124 ]; then
249247
if grep -q "${file_path}" .admissible-fail; then
250248
echo -e "${C_ADMISSIBLE}ADMISSIBLE TIMEOUT${C_END}"
251249
(( TEST_RESULT_ADMISSIBLE+=1 ))
@@ -318,10 +316,10 @@ function check_interactive {
318316

319317
local output exit_code
320318

321-
output=$("${REPLAY}" "${BELUGA}" "${file_path}" 2>&1)
319+
output=$(timeout --foreground "${TIMEOUT}" "${REPLAY}" "${BELUGA}" "${file_path}" 2>&1)
322320
exit_code=$?
323321

324-
if [ "${exit_code}" -eq 152 ]; then
322+
if [ "${exit_code}" -eq 124 ]; then
325323
if grep -q "${file_path}" .admissible-fail; then
326324
echo -e "${C_ADMISSIBLE}ADMISSIBLE TIMEOUT${C_END}"
327325
(( TEST_RESULT_ADMISSIBLE+=1 ))
@@ -355,10 +353,10 @@ function check_harpoon {
355353
# Read the first line in the file at "${file_path}"
356354
sig=$(sed -n '1p' "${file_path}")
357355

358-
output=$("${HARPOON}" --sig "${sig}" --test "${file_path}" --test-start 2 --no-save-back --stop 2>&1)
356+
output=$(timeout --foreground "${TIMEOUT}" "${HARPOON}" --sig "${sig}" --test "${file_path}" --test-start 2 --no-save-back --stop 2>&1)
359357
exit_code=$?
360358

361-
if [ "${exit_code}" -eq 152 ]; then
359+
if [ "${exit_code}" -eq 124 ]; then
362360
if grep -q "${file_path}" .admissible-fail; then
363361
echo -e "${C_ADMISSIBLE}ADMISSIBLE TIMEOUT${C_END}"
364362
(( TEST_RESULT_ADMISSIBLE+=1 ))
@@ -448,7 +446,7 @@ function print_paths {
448446
echo -e "\t TESTDIR: ${TESTDIR}"
449447
echo -e "\t INTERACTIVE_TESTDIR: ${INTERACTIVE_TESTDIR}"
450448
echo -e "\t EXAMPLEDIR: ${EXAMPLEDIR}"
451-
echo -e "\t TIMEOUT: ${TIMEOUT}" seconds
449+
echo -e "\t TIMEOUT: ${TIMEOUT}"
452450
echo
453451
}
454452

0 commit comments

Comments
 (0)