forked from jgressier/typhon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck.sh
executable file
·275 lines (253 loc) · 6.21 KB
/
check.sh
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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
#!/bin/bash -u
#
# Check non-regression of all NRG cases containing nrgconf.sh
#
bar=$(printf "%79s" | tr ' ' =)
# --- print usage ---
#
function usage() {
if [ $1 = 1 ] ; then
echo "$bar"
echo "ERROR"
echo "$bar"
fi
echo
echo "Usage: $SCRIPTNAME [-h] [-d|--diff-cmd <diff-command>]"
echo " $SCRIPTSPCE [-l] [--] [<pattern> ...]"
echo
echo " -h: prints this help"
echo " -exe <typhon-exe>:"
echo " uses <typhon-exe> (default is given by CASE/$REFCONF)"
echo " -d|--diff-cmd <diff-command>:"
echo " uses <diff-command>"
echo " -l: prints list of cases"
echo " -k: keep (do not delete) TMPDIR and cases"
echo " --: end of options"
echo
echo " <pattern>: selects cases with name matching <pattern>"
echo
echo " default: runs cases"
echo
exit $1
}
echo "$bar"
echo "TYPHON non regression check"
echo "$bar"
# --- directory initialization ---
#
ORIGDIR=$PWD
SCRIPTNAME=$(basename $0)
SCRIPTSPCE=${SCRIPTNAME//?/ }
export HOMEDIR=$(cd $(dirname $0) ; pwd)
export EXEDIR=$HOMEDIR/SOURCE
export BINDIR=$HOMEDIR/bin
export NRGDIR=$HOMEDIR/NRG
export MESHDIR=$HOMEDIR/NRG/COMMON
export TMPDIR=$(mktemp -d /tmp/typhon.${SCRIPTNAME%.sh}.XXXXXXXX)
if [ $? -ne 0 ] ; then
echo "could not create temporary directory"
exit 1
fi
export REFCONF=nrgconf.sh
# --- directory check ---
#
if [ ! -d $MESHDIR ] ; then
echo "directory $MESHDIR not found"
echo "$HOMEDIR/$SCRIPTNAME is not in a valid typhon directory"
exit 1
fi
# --- get options ---
#
#OPTS=$(getopt -o hd:lk -l diff-cmd: -n "$SCRIPTNAME" -- "$@")
#[[ $? != 0 ]] && usage 1
#eval set -- "$OPTS"
# --- parse options ---
#
typhonexe=
diffcmd=
list=0
keeptmpdir=0
patlist=()
while [ ${#} -gt 0 ] ; do
case "$1" in
-h) usage 0 ;;
-d|--diff-cmd) shift
if [ $# -gt 0 ] ; then
diffcmd=$1
else
echo "ERROR: no diff command:"
usage 1
fi ;;
-l) list=1 ;;
-k) keeptmpdir=1 ;;
-exe) shift
if [ $# -gt 0 ] ; then
typhonexe=$1
echo "force run with $typhonexe"
else
echo "ERROR: no typhon executable:"
usage 1
fi ;;
--) shift ; break ;;
*) break ;;
esac
shift
done
# --- check patterns ---
#
if [ ${#} -gt 0 ] ; then
for pat in "$@" ; do
if [ -n "$pat" ] ; then
patlist+=("-e" "$pat")
fi
done
shift ${#}
fi
# --- initialization ---
#
cd $HOMEDIR
. bin/shconf.sh
if [ -n "$diffcmd" ] ; then
{ cat $0 ;} | $diffcmd - $0 >/dev/null 2>&1 ; r=$?
{ echo a ; cat $0 ;} | $diffcmd - $0 >/dev/null 2>&1 ; r=$?$r
if [ $r != 10 ] ; then
echo "ERROR: check diff command:"
echo "$diffcmd"
usage 1
fi
export DIFF="$diffcmd"
fi
#
export DIFFCOM=$DIFF
export LD_LIBRARY_PATH=$EXEDIR/Lib:$LD_LIBRARY_PATH
if [ $keeptmpdir -eq 0 ] ; then
trap "rm -Rf $TMPDIR" 0 2
fi
logfiles=( diff.log check.log )
ok=1
for f in "${logfiles[@]}" ; do
if [ -e $f ] && [ ! -f $f ] ; then
echo "$f is not a regular file" ; ok=0
fi
done
test $ok = 0 && exit 1
rm -f "${logfiles[@]}"
# --- get list of cases ---
#
cd $NRGDIR
LISTCASES=( $(find * -name $REFCONF | xargs -n 1 dirname | grep "${patlist[@]:-.}") )
if [ ${#LISTCASES[@]} = 0 ] ; then
echo "NO CASE FOUND"
echo "$bar"
exit 0
fi
# --- print list of cases ---
#
if [ $list -eq 1 ] ; then
echo LISTCASES =
for CASE in "${LISTCASES[@]}" ; do
echo " ${CASE}"
done
exit 0
fi
# --- print parameter ---
#
scol0=
for CASE in "${LISTCASES[@]}" ; do
scol0=$(printf "%${#scol0}s" "${CASE//?/ }")
done
scol1=$scol0$(printf "%15s")
ncol2=24
# --- tests ---
#
echo diffing with DIFF : $DIFF
echo "$bar"
function iferror() {
test $? -ne 0
}
function next_case() {
if [ $# -gt 0 ] && [ "$1" = -n ] ; then
echo ; remain= ; shift
fi
if [ $# -gt 0 ] ; then
printf "$remain%s\n" "$@"
fi
if [ $keeptmpdir -eq 0 ] ; then
rm -f $TMPDIR/$CASE/*
fi
continue
}
function next_fic() {
test $# -gt 0 && printf "$remain%-${ncol2}s %s\n" "$@"
continue
}
echo diff-command : $DIFFCOM >> $HOMEDIR/diff.log
for CASE in "${LISTCASES[@]}" ; do
# init
CASEDIR=$NRGDIR/$CASE
# print
string="checking $CASE ..."
printf "$string" ; repl=${string//?/?} ; remain=${scol1/$repl/}
# configure
. $CASEDIR/$REFCONF
iferror && next_case -n "source NRG/$CASE/$REFCONF: command failed"
# create dir
mkdir -p $TMPDIR/$CASE
iferror && next_case -n "mkdir -p $TMPDIR/$CASE: command failed"
cd $TMPDIR/$CASE
# copy files
cp $MESHDIR/$MESHFILE $TMPDIR/$CASE
cp $CASEDIR/$INPUTFILE $TMPDIR/$CASE
# create hostfile
hostname > hostfile
# write headers
echo "$bar" >> $HOMEDIR/check.log
echo "$CASE" >> $HOMEDIR/check.log
echo '#' "$bar" >> $HOMEDIR/diff.log
echo '#' "$CASE" >> $HOMEDIR/diff.log
# check executable type
case $TYPE_EXE in
seq) exehead="" ;;
mpi) exehead="mpirun -np ${MPIPROCS:-2} -machinefile hostfile" ;;
*) next_case "'$TYPE_EXE': unknown typhon executable type" ;;
esac
# check executable
EXE=${typhonexe:-$EXEDIR/typhon-$TYPE_EXE}
#test -f $EXE || next_case -n "'$EXE': no such file"
#test -x $EXE || next_case -n "'$EXE': execute permission denied"
# execute
echo run: $exehead $EXE >> $HOMEDIR/check.log
$exehead $EXE >> $HOMEDIR/check.log 2>&1
iferror && next_case "?? computation failed"
for fic in $TO_CHECK ; do
test -f "$fic" || next_fic "'$fic': file missing"
fics=( $fic $CASEDIR/$fic )
$DIFFCOM ${fics[@]} >> diff.log 2>&1
case $? in
0) diff ${fics[@]} >/dev/null 2>&1
case $? in
0) printf "$remain%-${ncol2}s %s\n" "$fic" "identical" ;;
*) printf "$remain%-${ncol2}s %s\n" "$fic" "equal" ;;
esac ;;
1) printf "$remain%-${ncol2}s %s\n" "$fic" "changed"
echo diff ${fics[@]} >> $HOMEDIR/diff.log
cat diff.log >> $HOMEDIR/diff.log ;;
*) printf "$remain%-${ncol2}s %s\n" "$fic" "comparison failed" ;;
esac
rm -f diff.log
remain=$scol1
done
next_case
done
echo "$bar"
if [ $HOMEDIR = $ORIGDIR ] ; then
echo check.log diff.log
else
echo $HOMEDIR/check.log
echo $HOMEDIR/diff.log
fi
echo "$bar"
if [ $keeptmpdir -eq 1 ] ; then
echo "files kept in : $TMPDIR"
echo "$bar"
fi