2019-03-21 23:31:21 +08:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
# This script verifies expression folding.
|
2019-03-21 23:49:38 +08:00
|
|
|
# It compiles a source file with '-fdebug-dump-symbols' and looks for
|
|
|
|
# parameter declarations to check they have been folded as expected.
|
2019-03-21 23:31:21 +08:00
|
|
|
# To check folding of an expression EXPR, the fortran program passed to this script
|
|
|
|
# must contain the following:
|
2019-03-21 23:49:38 +08:00
|
|
|
# logical, parameter :: test_x = <compare EXPR to expected value>
|
2021-01-27 00:20:57 +08:00
|
|
|
# This script will test that all parameter with a name starting with "test_"
|
|
|
|
# have been folded to .true.
|
2019-03-21 23:31:21 +08:00
|
|
|
# For instance, acos folding can be tested with:
|
|
|
|
#
|
|
|
|
# real(4), parameter :: res_acos = acos(0.5_4)
|
|
|
|
# real(4), parameter :: exp_acos = 1.047
|
|
|
|
# logical, parameter :: test_acos = abs(res_acos - exp_acos).LE.(0.001_4)
|
|
|
|
#
|
2019-03-21 23:49:38 +08:00
|
|
|
# There are two kinds of failure:
|
|
|
|
# - test_x is folded to .false.. This means the expression was folded
|
2019-03-21 23:31:21 +08:00
|
|
|
# but the value is not as expected.
|
|
|
|
# - test_x is not folded (it is neither .true. nor .false.). This means the
|
|
|
|
# compiler could not fold the expression.
|
|
|
|
|
2020-03-06 19:21:36 +08:00
|
|
|
if [[ $# < 3 ]]; then
|
2020-05-12 02:38:53 +08:00
|
|
|
echo "Usage: $0 <fortran-source> <temp test dir> <f18-executable>"
|
2019-03-21 23:31:21 +08:00
|
|
|
exit 1
|
|
|
|
fi
|
2019-06-06 19:24:42 +08:00
|
|
|
|
2020-03-06 19:21:36 +08:00
|
|
|
src=$1
|
2019-03-21 23:31:21 +08:00
|
|
|
[[ ! -f $src ]] && echo "File not found: $src" && exit 1
|
2020-05-12 02:38:53 +08:00
|
|
|
shift
|
2019-03-21 23:31:21 +08:00
|
|
|
|
2020-05-12 02:38:53 +08:00
|
|
|
temp=$1
|
2020-03-06 19:21:36 +08:00
|
|
|
mkdir -p $temp
|
2020-05-12 02:38:53 +08:00
|
|
|
shift
|
|
|
|
|
2021-02-12 02:28:25 +08:00
|
|
|
CMD="$* -fdebug-dump-symbols"
|
2019-03-21 23:31:21 +08:00
|
|
|
|
2019-06-06 19:24:42 +08:00
|
|
|
# Check if tests should assume folding is using libpgmath
|
2020-03-06 19:21:36 +08:00
|
|
|
if [[ $LIBPGMATH ]]; then
|
2019-06-06 19:24:42 +08:00
|
|
|
CMD="$CMD -DTEST_LIBPGMATH"
|
|
|
|
echo "Assuming libpgmath support"
|
2020-03-06 19:21:36 +08:00
|
|
|
else
|
|
|
|
echo "Not assuming libpgmath support"
|
2019-06-06 19:24:42 +08:00
|
|
|
fi
|
|
|
|
|
2019-03-21 23:49:38 +08:00
|
|
|
src1=$temp/symbols.log
|
|
|
|
src2=$temp/all_parameters.log
|
|
|
|
src3=$temp/tested_parameters.log
|
|
|
|
src4=$temp/failures.log
|
2019-05-22 15:56:35 +08:00
|
|
|
messages=$temp/messages.log
|
|
|
|
actual_warnings=$temp/actwarnings.log
|
|
|
|
expected_warnings=$temp/expwarnings.log
|
|
|
|
warning_diffs=$temp/warnings.diff
|
2019-03-21 23:31:21 +08:00
|
|
|
|
2019-06-20 04:18:17 +08:00
|
|
|
if ! ( cd $temp; $CMD $src ) > $src1 2> $messages # compile, dumping symbols
|
|
|
|
then
|
|
|
|
cat $messages
|
|
|
|
echo FAIL compilation
|
|
|
|
exit 1
|
2019-03-12 06:39:11 +08:00
|
|
|
fi
|
2019-03-21 23:31:21 +08:00
|
|
|
|
2019-03-21 23:49:38 +08:00
|
|
|
# Get all PARAMETER declarations
|
2019-03-21 23:31:21 +08:00
|
|
|
sed -e '/, PARAMETER/!d' -e 's/, PARAMETER.*init:/ /' \
|
|
|
|
-e 's/^ *//' $src1 > $src2
|
|
|
|
|
2019-03-21 23:49:38 +08:00
|
|
|
# Collect test results
|
2019-03-21 23:31:21 +08:00
|
|
|
sed -e '/^test_/!d' $src2 > $src3
|
|
|
|
|
2019-03-21 23:49:38 +08:00
|
|
|
# Check all tests results (keep tests that do not resolve to true)
|
2019-03-21 23:31:21 +08:00
|
|
|
sed -e '/\.true\._.$/d' $src3 > $src4
|
|
|
|
|
2019-05-22 15:56:35 +08:00
|
|
|
|
|
|
|
#Check warnings
|
2019-07-03 05:00:44 +08:00
|
|
|
sed -n 's=^[^:]*:\([0-9]*\):[0-9]*: =\1: =p' $messages > $actual_warnings
|
2019-05-22 15:56:35 +08:00
|
|
|
|
|
|
|
awk '
|
|
|
|
BEGIN { FS = "!WARN: "; }
|
|
|
|
/^ *!WARN: / { warnings[nwarnings++] = $2; next; }
|
|
|
|
{ for (i = 0; i < nwarnings; ++i) printf "%d: %s\n", NR, warnings[i]; nwarnings = 0; }
|
|
|
|
' $src > $expected_warnings
|
|
|
|
|
|
|
|
diff -U0 $actual_warnings $expected_warnings > $warning_diffs
|
|
|
|
|
|
|
|
if [ -s $src4 ] || [ -s $warning_diffs ]; then
|
2019-03-21 23:31:21 +08:00
|
|
|
echo "folding test failed:"
|
2019-03-21 23:49:38 +08:00
|
|
|
# Print failed tests (It will actually print all parameters
|
2019-03-21 23:31:21 +08:00
|
|
|
# that have the same suffix as the failed test so that one can get more info
|
|
|
|
# by declaring expected_x and result_x for instance)
|
2019-05-22 15:56:35 +08:00
|
|
|
if [[ -s $src4 ]]; then
|
|
|
|
sed -e 's/test_/_/' -e 's/ .*//' $src4 | grep -f - $src2
|
|
|
|
fi
|
|
|
|
if [[ -s $warning_diffs ]]; then
|
|
|
|
echo "$cmd"
|
|
|
|
< $warning_diffs \
|
|
|
|
sed -n -e 's/^-\([0-9]\)/actual at \1/p' -e 's/^+\([0-9]\)/expect at \1/p' \
|
|
|
|
| sort -n -k 2
|
|
|
|
fi
|
2019-03-21 23:31:21 +08:00
|
|
|
echo FAIL
|
|
|
|
exit 1
|
|
|
|
else
|
2019-06-04 04:21:35 +08:00
|
|
|
passed_results=$(wc -l < $src3)
|
|
|
|
passed_warnings=$(wc -l < $expected_warnings)
|
|
|
|
passed=$(($passed_warnings + $passed_results))
|
2019-03-21 23:31:21 +08:00
|
|
|
echo all $passed tests passed
|
|
|
|
echo PASS
|
|
|
|
fi
|