Skip to content

Commit d2bcb7c

Browse files
committed
260128.221019.CST 1. Revise Makefile.common to handle the exit code of gdb correctly; 2. Revise checktest so that it detects "bound out of range" error
1 parent 8d10ee2 commit d2bcb7c

File tree

3 files changed

+28
-11
lines changed

3 files changed

+28
-11
lines changed

fortran/tests/makefiles/Makefile.common

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -285,16 +285,18 @@ else
285285
endif
286286
endif
287287

288-
# Invoke the binary by gdb in the batch mode, so that we get necessary information if it crashes.
289-
# N.B.: -return-child-return asks gdb to return with the exit code of the binary that it invokes,
290-
# unless gdb itself terminates with an error. In our situation, it is better not to use this flag,
291-
# Otherwise, when the binary crashes, `checktest` will not be called due to the error returned by gdb.
292-
# On GitHub Actions, gdb does not work out of the box due to security restrictions.
288+
# Invoke the binary by gdb using $(TOOLS_DIR)/run_gdb, which is a wrapper script. It does two
289+
# things: 1) It runs the binary under gdb in the batch mode and the -return-child-result mode, so
290+
# that the exit code of the binary is returned as the exit code of gdb. 2) If gdb fails (e.g., the
291+
# binary crashes), it records the exit code of gdb in a specified file and exits successfully.
292+
# In this way, the Makefile receipt can continue to call `checktest` to check the log file regardless
293+
# of the failure. The exit code will be checked after the test by reading the aforementioned file.
294+
# For more details, see $(TOOLS_DIR)/run_gdb.
293295
ifeq ($(OSTYPE), MAC)
296+
# On GitHub Actions, gdb does not work out of the box due to security restrictions.
294297
GDB :=
295298
else
296-
#GDB := gdb -return-child-result -batch -ex run -ex where -ex quit
297-
GDB := gdb -batch -ex run -ex where -ex quit
299+
GDB := bash $(TOOLS_DIR)/run_gdb
298300
endif
299301

300302
# Define SEDI.
@@ -890,7 +892,7 @@ $(TESTS_C) $(TESTS_INT_C):
890892
fi ; \
891893
export NVCOMPILER_TERM=trace && set -eu -o pipefail && \
892894
printf "\n$@_$(SUFFIXO) starts.\n\n" | tee -a "$(LOG_DIR)/$@.log" && \
893-
$(GDB) ./$@_c_$(SUFFIXO) 2>&1 \
895+
$(GDB) ./$@_c_$(SUFFIXO) $(LOG_DIR)/GDB_EXIT_CODE 2>&1 \
894896
| grep -v "Processor does not support trapping of floating-point exceptions" \
895897
| grep -v "libthread_db" \
896898
| tee -a "$(LOG_DIR)/$@.log" ; \
@@ -909,7 +911,7 @@ $(TESTS_C) $(TESTS_INT_C):
909911
fi ; \
910912
export NVCOMPILER_TERM=trace && set -eu -o pipefail && \
911913
printf "\n$@_$(SUFFIXG) starts.\n\n" | tee -a "$(LOG_DIR)/$@.log" && \
912-
$(GDB) ./$@_c_$(SUFFIXG) 2>&1 \
914+
$(GDB) ./$@_c_$(SUFFIXG) $(LOG_DIR)/GDB_EXIT_CODE 2>&1 \
913915
| grep -v "Processor does not support trapping of floating-point exceptions" \
914916
| grep -v "libthread_db" \
915917
| tee -a "$(LOG_DIR)/$@.log" ; \
@@ -922,9 +924,11 @@ $(TESTS_C) $(TESTS_INT_C):
922924
@set +o pipefail # Restore the original pipe setting
923925
@bash $(CHCKTST) --error "$(LOG_DIR)/$@.log"
924926
@bash $(CHCKTST) --warning "$(LOG_DIR)/$@.log"
927+
@echo "gdb exit code was: " && cat "$(LOG_DIR)/GDB_EXIT_CODE" && exit $$(cat "$(LOG_DIR)/GDB_EXIT_CODE")
925928
@printf "$@ ends at $(shell date +%Y.%m.%d_%H.%M.%S).\n" | tee -a "$(LOG_DIR)/$@.log"
926929
@cat "$(LOG_DIR)/$@.log" >> "$(LOG_DIR)/$(shell echo $@ | sed "s/_.*//").log"
927-
@rm "$(LOG_DIR)/$@.log" || :
930+
@ls "$(LOG_DIR)"
931+
@rm -r "$(LOG_DIR)" || :
928932
@$(MAKE) cleanmisc
929933

930934
# Make the binary corresponding to %_tst_c, but do not execute it.

fortran/tests/tools/checktest

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ WARNINGS="$(grep -i "warning\|Remark\|Questionable\|attention\|F[0-9]*-W\|F[0-9]
2626
| grep -vi "Assertion fails: SUM(VLAG(1:NPT)) == 1" \
2727
| grep -vi "invalid maxfun\|invalid maxhist\|invalid npt\|invalid rhobeg\|invalid rhoend\|invalid ftarget\|invalid ctol\|invalid maxfilt\|errstop")"
2828

29-
ERRORS="$(grep -i "error\|fail\|violation\|exception\|invalid\|bad\|overflow\|segmentation\|fault\|illegal\|F[0-9]*-S\|F[0-9]*-F\|F[0-9]*-E\|Could\ not\ resolve\|not\ defined\|Cannot connect to licence server (error 113)" "$LOGFILE" \
29+
ERRORS="$(grep -i "error\|fail\|violation\|exception\|invalid\|bad\|overflow\|segmentation\|fault\|illegal\|Subscript out of range\|F[0-9]*-S\|F[0-9]*-F\|F[0-9]*-E\|Could\ not\ resolve\|not\ defined\|Cannot connect to licence server (error 113)" "$LOGFILE" \
3030
| grep -vi "default" \
3131
| grep -vi "[0-9]\s*error" \
3232
| grep -vi "[0-9a-z]bad\|bad[0-9a-z]" \

fortran/tests/tools/run_gdb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/usr/bin/env bash
2+
# This script runs gdb on a given program ($1) and captures the exit code in a specified file ($2).
3+
# -return-child-result directs gdb to return the exit code of the program being debugged.
4+
#
5+
# N.B.: We record the exit code in the specified file rather than exiting with it directly, so that
6+
# the Makefile receipt continues to run subsequent tests. The exit code can be checked when needed
7+
# by reading the contents of the specified file.
8+
9+
echo 0 > "$2"
10+
11+
gdb -return-child-result -batch -ex run -ex where -ex quit "$1" 2>&1 || echo $? > "$2"
12+
13+
exit 0 # Exit successfully anyway.

0 commit comments

Comments
 (0)