-
Notifications
You must be signed in to change notification settings - Fork 54
Expand file tree
/
Copy pathflint
More file actions
executable file
·232 lines (207 loc) · 7.58 KB
/
flint
File metadata and controls
executable file
·232 lines (207 loc) · 7.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
#!/usr/bin/env bash
# This script checks the Fortran code of the solver corresponding to this directory.
# Usage: flint [--compiler_name [--all]] or flint --clean
# Parse inputs.
if [[ $# -gt 2 ]] ; then
printf "Usage: flint [--compiler_name [--all]] or flint --clean\n"
exit 2
fi
TEST_ALL="N"
CLEAN="N"
# Decide the list of tests to make.
# N.B.: () defines an array
# sunf95 is case sensitive. Put it as the first.
COMPILER_LIST=(sunf95 gfortran amdflang nagfor g95 ifort nvfortran ifx)
CLIST=(s g m n 9 i v x)
COMP_LIST=""
for i in "${!COMPILER_LIST[@]}"; do
if type "${COMPILER_LIST[$i]}" &> /dev/null ; then
COMP_LIST="$COMP_LIST ${CLIST[$i]}"
fi
done
# Do not make ftest if flang is provided by ARM, AMD, or AOMP; rtest, dtest, or mtest should be made instead.
if type flang &> /dev/null && ! type "${COMPILER_LIST[$i]}" | grep -iq '\/opt\/arm\|\/opt\/AMD\|aomp' ; then
COMP_LIST="$COMP_LIST f"
fi
# Make dtest if AOCC flang is installed.
if [[ -n "$(find -L /opt/AMD -type f -name flang -exec test -x {} \; -print 2>/dev/null)" ]] ; then
COMP_LIST="$COMP_LIST d"
fi
# Parse the arguments
while [[ -n "$1" ]]; do
case "$1" in
--all)
TEST_ALL="Y"
;;
--clean)
CLEAN="Y"
;;
-g|--gfortran)
COMP_LIST=" g"
;;
-i|--ifort)
COMP_LIST=" i"
;;
-m|--amdflang)
COMP_LIST=" m"
;;
-n|--nagfor)
COMP_LIST=" n"
;;
-9|--g95)
COMP_LIST=" 9"
;;
-s|--sunf95)
COMP_LIST=" s"
;;
-v|--nvfortran)
COMP_LIST=" v"
;;
-f|--flang)
COMP_LIST=" f"
;;
-d|--aoccflang)
COMP_LIST=" d"
;;
-x|--ifx)
COMP_LIST=" x"
;;
*)
printf "Usage: flint [--compiler_name [--all]] or flint -c|--clean\n"
exit 2
;;
esac
shift
done
# The directory where this script resides. It is the solver's directory.
SOLVER_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
# The solver's name.
SOLVER=$(basename "$SOLVER_DIR")
# The log directory in the solver's directory.
SOLVER_LOG_DIR="$SOLVER_DIR"/flog
# Root directory of this project.
ROOT_DIR=../..
# The testing directory.
TIME=$(date +%s)
RANDNUM="$((RANDOM*RANDOM))"
TEST_DIR=/tmp/"$(basename -- "$0")"_"$TIME"_"$RANDNUM"
printf "Test directory:\n\n%s\n\n" "$TEST_DIR"
# We export TEST_DIR, which will be referred to by the Makefiles.
export TEST_DIR
TEST_ROOT="$TEST_DIR"/prima
FTEST_DIR="$TEST_ROOT"/fortran/tests
FTEST_SOLVER_DIR="$FTEST_DIR"/test."$SOLVER"
# The log directory in the testing directory.
TEST_LOG_DIR="$FTEST_SOLVER_DIR"/log
printf "Test log directory:\n\n%s\n\n" "$TEST_LOG_DIR"
printf "Solver log directory:\n\n%s\n\n" "$SOLVER_LOG_DIR"
# The checktest script
CHCKTST="$FTEST_DIR"/tools/checktest
# Remove the old logs.
mkdir -p "$SOLVER_LOG_DIR"
rm -f "$SOLVER_LOG_DIR"/*test*.log
# Conduct the test.
cd "$ROOT_DIR"/fortran/tests || exit 1
# Make clean (old logs in $SOLVER_LOG_DIR have been cleaned up in the above).
printf "\nCleaning up ... "
make cleanall."$SOLVER" > /dev/null
printf "Done.\n\n"
if [[ "$CLEAN" == "Y" ]] ; then
exit 0
fi
# Check whether this is a 32-bit ARM machine (e.g., Raspberry Pi with 32-bit OS).
if [[ "$(uname -m)" = "aarch" || "$(uname -m)" = armv7* ]] ; then
ARM32='Y'
else
ARM32='N'
fi
printf "Tests to make:%s\n\n" "$COMP_LIST"
if [[ $TEST_ALL == 'Y' ]] ; then
FLG_LIST="-g -O1 -O2 -O3 -fast"
else
FLG_LIST="-g -O2 -fast"
fi
printf "Flags to test: %s\n\n" "$FLG_LIST"
for COMP in $COMP_LIST; do
if [[ $TEST_ALL == 'Y' && $ARM32 != 'Y' ]] ; then
for FLG in $FLG_LIST ; do
printf "%s\t" "$FLG"
export FFLAGS=$FLG && make "$COMP"test_c."$SOLVER"
done
else
if [[ $COMP == 'f' || $COMP == 'v' || $COMP == 'd' || $ARM32 == 'Y' ]] ; then
TESTS="i2_r4_d1 i8_r4_d0"
else
TESTS="i2_r16_d1 i8_r4_d0"
fi
for TEST in $TESTS ; do
for FLG in $FLG_LIST ; do
printf "%s\t" "$FLG"
export FFLAGS=$FLG
make clean
INFO="$(make "$COMP"test_"$TEST"_tst_c."$SOLVER" 2>&1 \
| grep -v "grep -v" \
| grep -v "binary file matches\|info, callback_fcn" \
| grep -i "starts\|warning\|error\|info\|abort\|invalid\|violation\|fault\|illegal\|fail\|questionable\|remark\|attention\|Could not resolve\|not defined\|not public entity" \
| grep -vi "[0-9]\s*warning\|[0-9]\s*error\|[0-9]\s*info\|infos.f90\|information\|xhist, info)\|zmat, info)\|--warning\|--error" \
| grep -vi "pedantic-errors\|Werror\|warn errors\|diag-error-limit\|colour=error\|rounding error\|constraint violation\|default" \
| grep -vi "warning: future releases of the clang compiler will prefer GCC installations containing libstdc" \
| grep -vi "is DOING NOTHING" \
| grep -v "^\s*- \|^\s*| \|^\s*\* \|^\s*+ \|^\s*X \|\# " \
)"
echo "$INFO" | grep -i --color "starts\|warning\|error\|info\|abort\|invalid\|violation\|fault\|illegal\|fail\|questionable\|remark\|attention\|Could not resolve\|not defined\|not public entity"
if echo "$INFO" | grep -iq "error\|abort\|invalid\|violation\|fault\|illegal\|fail\|Could not resolve\|not defined\|not public entity" ; then
if [[ -f "$TEST_LOG_DIR"/"$COMP"test_"$TEST"_tst_c.log ]] ; then
LOGFILE="$COMP"test_"$TEST"_tst_c.log
else
LOGFILE="$COMP"test_c.log
fi
mv "$TEST_LOG_DIR"/"$LOGFILE" "$SOLVER_LOG_DIR"
cat "$SOLVER_LOG_DIR"/"$LOGFILE"
exit 2
fi
done
done
fi
mv "$TEST_LOG_DIR"/"$COMP"test*.log "$SOLVER_LOG_DIR" 2>/dev/null || true
done
# Check the logfiles
LOGFILES=("$SOLVER_LOG_DIR"/*test*.log) # An array
if [[ "$TEST_ALL" == "Y" ]] ; then
for LOGFILE in "${LOGFILES[@]::${#LOGFILES[@]}}" ; do
printf "\nChecking %s ...\n" "$LOGFILE"
INFO="$(bash "$CHCKTST" --warnerror "$LOGFILE")"
printf "%s" "$INFO"
printf "\nDone!\n"
if [[ -n "$INFO" ]] ; then
printf "\nWarning or error found in log file.\n"
exit 1
fi
done
else
for LOGFILE in "${LOGFILES[@]::${#LOGFILES[@]}-1}" ; do
printf "\nChecking %s ...\n" "$LOGFILE"
bash "$CHCKTST" --error "$LOGFILE" # Will lead to failure in case of error logged
INFO="$(bash "$CHCKTST" --warning "$LOGFILE")"
printf "%s" "$INFO"
printf "\nDone!\n"
if [[ -n "$INFO" ]] ; then
read -n1 -s -r -p $'Continue? [Y/n] ' KEY
printf "\n"
if ! [[ "$KEY" == 'Y' || "$KEY" == 'y' || "$KEY" == "" ]]; then
exit 0
fi
fi
done
# No pause needed for the last logfile.
LOGFILE="${LOGFILES[-1]}" # The last logfile; it needs Bash 4.x.
printf "\nChecking %s ...\n" "$LOGFILE"
bash "$CHCKTST" --error "$LOGFILE" # Will lead to failure in case of error logged
INFO="$(bash "$CHCKTST" --warning "$LOGFILE")"
printf "%s" "$INFO"
printf "\nDone!\n\n"
fi
rm -rf "$TEST_DIR"
export -n TEST_DIR && unset TEST_DIR # De-export and unset TEST_DIR
export -n FFLAGS && unset FFLAGS # De-export and unset FFLAGS
exit 0