-
Notifications
You must be signed in to change notification settings - Fork 4
/
Alltest
executable file
·235 lines (219 loc) · 6.84 KB
/
Alltest
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
233
234
235
#!/usr/bin/bash
# ShellChecked on every push - Always ShellCheck your scripts!
# First some configs
# Assumes it's running from the root dir. of the repository
if [ -z "${FOAM_LIBBIN}" ]; then
echo "Please source an OpenFOAM version. Aborting..."
echo "USAGE: ./Alltest [--no-serial|--no-parallel] [--report] [--html]"
exit 1
fi
# If tests folder is supplied through an env. var.
# do the symlinking
if [ -n "${FOAM_FOAMUT_TESTS}" ]; then
find "${FOAM_FOAMUT_TESTS}" -type d -name "Make" | while read -r make_dir; do
parent_dir=$(basename "$(dirname "$make_dir")")
target_dir="$PWD/tests/$parent_dir"
ln -f -s "$(dirname "$make_dir")" "$target_dir"
echo "picked up $parent_dir tests"
done
fi
doSerial=true
doParallel=true
doReport=false
for i in "$@"; do
case $i in
--no-serial)
doSerial=false
;;
--no-parallel)
doParallel=false
;;
--report)
doReport=true
;;
*)
;;
esac
done
set -e
root=$PWD
export FOAM_FOAMUT="$root"
foamV=$(echo "${WM_PROJECT}$(test ! -z "${WM_FORK}" && echo '-'"${WM_FORK}")-${WM_PROJECT_VERSION}")
args_array=("$@")
# If there is no lib${libName}.so, create a dummy one
dummyLibChecks="Pstream dynamicFvMesh"
for dummy in $dummyLibChecks; do
if [ ! -f "${FOAM_LIBBIN}/lib${dummy}.so" ] &&
[ ! -f "${FOAM_USER_LIBBIN}/lib${dummy}.so" ] &&
[ ! -f "${FOAM_LIBBIN}/${FOAM_MPI}/lib${dummy}.so" ]; then
echo '!<arch>' > "${FOAM_USER_LIBBIN}/lib${dummy}.so"
fi
done
# libraries to test
libs=$(find -L tests/ -maxdepth 1 -mindepth 1 -type d)
libs_array=($libs)
# where to run OpenFOAM cases
caseRun=/tmp/foamUtCases
mkdir -p "$caseRun"
# a timeout to prevent hanging processes (be CI friendly)
timeOut="${CATCH_TIMEOUT:-60}"
serialTests() {
local fargs=("$@")
local params=()
for ((i = 4; i <= $#; i++)); do
arg="${fargs[i]}"
case "$arg" in
--no-parallel|--no-serial|--report)
;;
*)
params+=("$arg")
;;
esac
done
for ((i = 0; i < ${#libs_array[@]}; i++)); do
lib="${libs_array[i]}"
printf "\n\nRunning tests for lib %s, on %s case in serial...\n" "$lib" "${2}" >&2
libName=$(basename "$lib")
report=""
case $doReport in
(true) report="-s -r json::out=${root}/reports/${libName}_${2}_serial.json -d yes"
echo "Report: ${root}/reports/${libName}_${2}_serial.json" >&2
;;
esac
timeout "$timeOut" "$root"/"$lib"/testDriver --allow-running-no-tests \
-n "$(basename "$lib")" $report "[serial][${2}]" "${params[@]}" \
--- -case "${3}"
locErr=$?
err=$((err+locErr))
# separator in case json reporter is used
for element in "${params[@]}"; do
if [ "$element" == "json" ]; then
if ((i != ${#libs_array[@]})); then
printf ","
fi
fi
done
done
}
parallelTests(){
if ! test -f "${3}/system/decomposeParDict" ; then
rm -rf "${3}/processor*"
echo "decomposeParDict not found, not running parallel tests on this case..." >&2
return 0
fi
local fargs=("$@")
local params=()
for ((i = 4; i <= $#; i++)); do
arg="${fargs[i]}"
case "$arg" in
--no-parallel|--no-serial|--report)
;;
*)
params+=("$arg")
;;
esac
done
nProcs=$(grep -oP "numberOfSubdomains\s+\K\d+" "${3}"/system/decomposeParDict)
decomposePar -force -case "${3}" > "${3}/log.decomposePar"
err=$((err + $?))
# run the case in parallel mode
report=""
case $doReport in
(true) report="-s -r json -d yes";;
esac
for ((i = 0; i < ${#libs_array[@]}; i++)); do
lib="${libs_array[i]}"
printf "\n\nRunning tests for lib %s, on %s case in parallel...\n" "$lib" "${2}" >&2
libName=$(basename "$lib")
logdir="reports/${libName}_${2}_parallel"
logparams=""
direct=""
case $doReport in
(true) logparams="-output-filename $logdir"
direct="> /dev/null"
echo "Parallel Reports (${nProcs}): ${logdir}" >&2
esac
timeout "$timeOut" mpirun $logparams -np "$nProcs" \
"$root"/"$lib"/testDriver \
--allow-running-no-tests \
-n "$(basename "$lib")" $report \
--rng-seed time "[parallel][${2}]" ${params[@]} --- -parallel -case "${3}" $direct
set +x
# separator in case json reporter is used
for element in "${params[@]}"; do
if [ "$element" == "json" ]; then
if ((i != ${#libs_array[@]} - 1)); then
printf ","
fi
fi
done
err=$((err + lerr))
done
}
# Compile catch
echo "Compiling Catch2 v3..." >&2
if [ ! -f "$FOAM_USER_LIBBIN/catch2/lib/libCatch2.a" ]; then
cd catch2
mkdir -p build
cd build
cmake -DCMAKE_INSTALL_PREFIX="$FOAM_USER_LIBBIN"/catch2 .. > log.cmake 2>&1
make -j"$(nproc)" > log.makeBuild 2>&1
make install > log.makeInstall 2>&1
cd - > /dev/null
rm -rf build
cd ..
fi
# 1st: compile tests
for lib in $libs; do
cd "$lib"
echo "Compiling $lib test driver..." >&2
if ! wmake > log.wmake 2>&1; then
echo "Errors compiling $lib test driver, see $PWD/log.wmake for more information"
exit 1
else
echo "Test driver for $lib has been compiled." >&2
fi
cd - > /dev/null
done
# go back to the root of the repository
cd "$root"
# get setup to run tests
mapfile -t cases_array < <(find -L cases/ -maxdepth 1 -mindepth 1 -type d)
if [ ${#cases_array[@]} -eq 0 ]; then
echo "No cases found to run tests"
exit 1
fi
mkdir -p "$root"/reports
# run the tests, but do not exit until attempting everything
set +e
err=0
for ((k = 0; k < ${#cases_array[@]}; k++)); do
ofCase="${cases_array[k]}"
caseName=$(basename "$ofCase")
casePath=$caseRun/$caseName
cp -rL "$ofCase" "$casePath"
case $doSerial in
(true) serialTests "$err" "$caseName" "$casePath" "$libs" "$@";;
esac
case $doParallel in
(true) parallelTests "$err" "$caseName" "$casePath" "$libs" "$@";;
esac
# separator in case json reporter is used
for element in "${args_array[@]}"; do
if [ "$element" == "json" ]; then
if ((k != ${#cases_array[@]} - 1)); then
printf ","
fi
fi
done
rm -rf "$casePath"
done
# Cleanup
for dummy in $dummyLibChecks; do
if [ -f "${FOAM_USER_LIBBIN}/lib${dummy}.so" ] &&
tr '\n' ' ' < "${FOAM_USER_LIBBIN}/lib${dummy}.so" | grep -q '^!<arch> $'; then
rm -rf "${FOAM_USER_LIBBIN}/lib${dummy}.so"
fi
done
rm -rf "$caseRun"
exit $err