1 |
jmc |
1.2 |
#! /usr/bin/env bash |
2 |
jmc |
1.1 |
|
3 |
jmc |
1.2 |
# $Header: /u/gcmpack/MITgcm/tools/do_tst_2+2,v 1.1 2007/12/25 22:10:51 jmc Exp $ |
4 |
jmc |
1.1 |
# $Name: $ |
5 |
|
|
|
6 |
|
|
usage() |
7 |
|
|
{ |
8 |
|
|
echo "Usage: `basename $0` [OPTIONS]" |
9 |
|
|
echo " -> perform test 2+2=4 for several experiments" |
10 |
|
|
echo "" |
11 |
|
|
echo "where possible OPTIONS are:" |
12 |
|
|
echo " -help : print usage" |
13 |
|
|
echo " -t LIST_EXP : only check experiments in LIST_EXP" |
14 |
|
|
echo " -skd LIST_EXP : skip experiments in LIST_EXP" |
15 |
jmc |
1.2 |
echo " -o STRING : used to build output directory name" |
16 |
jmc |
1.1 |
echo " (DEF=\"hostname\")" |
17 |
jmc |
1.2 |
echo " -a,-A STRING : email address to send output to" |
18 |
jmc |
1.1 |
echo " (DEF=\"\" no email is sent)" |
19 |
jmc |
1.2 |
echo " (-A: + save each log file)" |
20 |
jmc |
1.1 |
echo " -clean : clean output & reset" |
21 |
|
|
exit |
22 |
|
|
} |
23 |
|
|
|
24 |
|
|
CLEAN=0 |
25 |
|
|
TESTDIRS= |
26 |
|
|
SKIPDIRS= |
27 |
|
|
OUTDIR=`hostname` |
28 |
jmc |
1.2 |
SAVELOG=0 |
29 |
jmc |
1.1 |
ADDRESS= |
30 |
|
|
SCRIPT='../tools/tst_2+2' |
31 |
|
|
MPACK="../tools/mpack-1.6/mpack" |
32 |
|
|
here=`pwd` |
33 |
|
|
yy= |
34 |
|
|
for xx |
35 |
|
|
do |
36 |
|
|
if test -n "$yy"; then |
37 |
|
|
eval "$yy=\$xx" |
38 |
|
|
yy= |
39 |
|
|
else |
40 |
|
|
case $xx in |
41 |
|
|
-help ) usage ;; |
42 |
|
|
-clean) CLEAN=1 ;; |
43 |
|
|
-t ) yy=TESTDIRS ;; |
44 |
|
|
-skd ) yy=SKIPDIRS ;; |
45 |
|
|
-a ) yy=ADDRESS ;; |
46 |
jmc |
1.2 |
-A ) yy=ADDRESS ; SAVELOG=1 ;; |
47 |
jmc |
1.1 |
-o ) yy=OUTDIR ;; |
48 |
|
|
*) echo "Error: unrecognized option: "$xx ; usage ; exit ;; |
49 |
|
|
esac |
50 |
|
|
fi |
51 |
|
|
done |
52 |
|
|
#------------------------ |
53 |
|
|
|
54 |
jmc |
1.2 |
if test "x$TESTDIRS" = x ; then TESTDIRS=`ls ` ; fi |
55 |
jmc |
1.1 |
LIST="" |
56 |
|
|
for xx in $TESTDIRS |
57 |
|
|
do |
58 |
|
|
yy=`echo $SKIPDIRS | grep -c $xx` |
59 |
|
|
if test $yy = 0 ; then |
60 |
jmc |
1.2 |
if test -f $xx/results/output.txt ; then |
61 |
jmc |
1.1 |
LIST=${LIST}" "$xx |
62 |
|
|
# else |
63 |
|
|
# echo ""; echo -n " -- skip \"$xx\" (not a directory !)" |
64 |
|
|
fi |
65 |
|
|
# else |
66 |
|
|
# echo ""; echo -n " -- skip \"$xx\" (excluded)" |
67 |
|
|
fi |
68 |
|
|
done |
69 |
|
|
|
70 |
|
|
if test -x $SCRIPT ; then |
71 |
|
|
echo "run script '$SCRIPT' for experiment in:" |
72 |
|
|
echo " $LIST" |
73 |
jmc |
1.2 |
yy=`echo $SCRIPT | grep -c '^\/'` |
74 |
jmc |
1.1 |
if test $yy = 0 ; then SCRIPT="../../$SCRIPT" ; fi |
75 |
|
|
else |
76 |
|
|
echo "ERROR: script '$SCRIPT' not found or not executable" |
77 |
|
|
exit |
78 |
|
|
fi |
79 |
|
|
echo "" |
80 |
|
|
#------------------------ |
81 |
|
|
|
82 |
|
|
if test $CLEAN = 1 ; then |
83 |
|
|
for xx in $LIST |
84 |
|
|
do |
85 |
|
|
listD='run '`(cd $xx/results ; ls output.*.txt 2> /dev/null | sed 's/^output\./tr_run./g' | sed 's/\.txt$//g' )` |
86 |
|
|
for yy in $listD |
87 |
|
|
do |
88 |
jmc |
1.2 |
if test -r $xx/$yy/data.tst ; then |
89 |
jmc |
1.1 |
echo "clean dir:" $xx/$yy |
90 |
jmc |
1.2 |
cd $xx/$yy |
91 |
jmc |
1.1 |
echo ' ' >> outp.tst_2+2.log |
92 |
|
|
echo $SCRIPT 4 >> outp.tst_2+2.log |
93 |
|
|
$SCRIPT 4 >> outp.tst_2+2.log 2>&1 |
94 |
|
|
cd $here |
95 |
|
|
fi |
96 |
|
|
done |
97 |
|
|
done |
98 |
|
|
exit |
99 |
|
|
fi |
100 |
|
|
#------------------------ |
101 |
|
|
# Create a uniquely named directory to store results |
102 |
|
|
DATE=`date +%Y%m%d` |
103 |
|
|
BASE="rs_"$OUTDIR"_"$DATE"_" |
104 |
|
|
xx=0 |
105 |
|
|
DRESULTS="$BASE$xx" |
106 |
|
|
while test -e $DRESULTS ; do |
107 |
|
|
xx=$(( $xx + 1 )) |
108 |
|
|
DRESULTS="$BASE$xx" |
109 |
|
|
done |
110 |
|
|
mkdir $DRESULTS |
111 |
|
|
out=$? |
112 |
|
|
if test "x$out" != x0 ; then |
113 |
|
|
echo "ERROR: Can't create results directory \"./$DRESULTS\"" |
114 |
|
|
exit 1 |
115 |
|
|
fi |
116 |
|
|
SUMMARY="$DRESULTS/summary.txt" |
117 |
|
|
OPTFILE= |
118 |
|
|
|
119 |
|
|
printf "Start time: " > $SUMMARY |
120 |
|
|
date >> $SUMMARY |
121 |
|
|
if test -f tr_out.txt ; then |
122 |
|
|
echo ' using output from:' >> $SUMMARY |
123 |
|
|
sed -n '2,/OPTFILE/ p' tr_out.txt >> $SUMMARY |
124 |
|
|
echo >> $SUMMARY |
125 |
|
|
fi |
126 |
|
|
echo 'test 2+2=4 summary :' >> $SUMMARY |
127 |
|
|
echo >> $SUMMARY |
128 |
|
|
echo 'P. Run Result experiment' >> $SUMMARY |
129 |
|
|
echo ' 1 2 3' >> $SUMMARY |
130 |
|
|
|
131 |
|
|
for xx in $LIST |
132 |
|
|
do |
133 |
|
|
echo ============================================================================== |
134 |
|
|
listD='run '`(cd $xx/results ; ls output.*.txt 2> /dev/null | sed 's/^output\./tr_run./g' | sed 's/\.txt$//g' )` |
135 |
|
|
for yy in $listD |
136 |
|
|
do |
137 |
jmc |
1.2 |
if test -f $xx/$yy/output.txt ; then |
138 |
jmc |
1.1 |
if test "x$OPTFILE" = x -a -f $xx/build/Makefile ; then |
139 |
|
|
comm=`grep '^# OPTFILE=' $xx/build/Makefile 2>/dev/null | head -1 | sed 's/^# //'` |
140 |
|
|
echo "from '$xx/build/Makefile', extract:" > $DRESULTS/genmake_state |
141 |
|
|
echo $comm >> $DRESULTS/genmake_state |
142 |
|
|
eval $comm |
143 |
|
|
fi |
144 |
jmc |
1.2 |
if test $yy = 'run' ; then nam=$xx |
145 |
jmc |
1.1 |
else nam=$xx`echo $yy | sed 's/tr_run//'` ; fi |
146 |
|
|
echo -n "Entering $xx/$yy :" |
147 |
|
|
cd $xx/$yy |
148 |
jmc |
1.2 |
pwd > outp.tst_2+2.log |
149 |
|
|
echo $SCRIPT All >> outp.tst_2+2.log ; echo ' ' >> outp.tst_2+2.log |
150 |
jmc |
1.1 |
$SCRIPT All >> outp.tst_2+2.log 2>&1 |
151 |
|
|
out=$? |
152 |
|
|
case $out in |
153 |
|
|
0 ) echo ' pass test 2+2=4' |
154 |
|
|
echo "Y Y Y Y pass <- $nam" >> ../../$SUMMARY ;; |
155 |
|
|
4|5) echo "Y Y Y Y FAIL ($out) - $nam" >> ../../$SUMMARY ;; |
156 |
|
|
3 ) echo "Y Y Y N FAIL ($out) - $nam" >> ../../$SUMMARY ;; |
157 |
|
|
2 ) echo "Y Y N N FAIL ($out) - $nam" >> ../../$SUMMARY ;; |
158 |
|
|
1 ) echo "Y N N N FAIL ($out) - $nam" >> ../../$SUMMARY ;; |
159 |
|
|
* ) echo "N N N N FAIL ($out) - $nam" >> ../../$SUMMARY ;; |
160 |
|
|
esac |
161 |
jmc |
1.2 |
if test $out != '0' ; then |
162 |
jmc |
1.1 |
echo " test 2+2=4 FAIL (exit $out)" |
163 |
|
|
echo " " |
164 |
|
|
tail -5 outp.tst_2+2.log |
165 |
|
|
echo " " |
166 |
jmc |
1.2 |
cp -p outp.tst_2+2.log ../../$DRESULTS/$nam.log |
167 |
|
|
elif test $SAVELOG = 1 ; then |
168 |
|
|
cp -p outp.tst_2+2.log ../../$DRESULTS/$nam.log |
169 |
jmc |
1.1 |
fi |
170 |
|
|
cd $here |
171 |
|
|
fi |
172 |
|
|
done |
173 |
|
|
done |
174 |
|
|
printf "End time: " >> $SUMMARY |
175 |
|
|
date >> $SUMMARY |
176 |
|
|
|
177 |
|
|
# If address was supplied and mpack exist, then send email using mpack. |
178 |
|
|
if test "x$ADDRESS" != xNONE -a "x$ADDRESS" != x ; then |
179 |
|
|
if test -x $MPACK ; then |
180 |
|
|
tar -cf $DRESULTS".tar" $DRESULTS > /dev/null 2>&1 \ |
181 |
|
|
&& gzip $DRESULTS".tar" \ |
182 |
|
|
&& $MPACK -s MITgcm-test -m 3555000 $DRESULTS".tar.gz" $ADDRESS |
183 |
|
|
out=$? |
184 |
|
|
if test "x$out" != x0 ; then |
185 |
|
|
echo |
186 |
|
|
echo "Warning: The tar, gzip, & mpack step failed. Please send email" |
187 |
|
|
echo " to <MITgcm-support@mitgcm.org> for help. You may copy the " |
188 |
|
|
echo " summary of results from the directory \"$DRESULTS\"." |
189 |
|
|
echo |
190 |
|
|
else |
191 |
|
|
echo |
192 |
|
|
echo "An email containing results was sent to the following address:" |
193 |
|
|
echo " \"$ADDRESS\"" |
194 |
|
|
echo |
195 |
|
|
fi |
196 |
|
|
test -f $DRESULTS".tar" && rm -f $DRESULTS".tar" |
197 |
|
|
test -f $DRESULTS".tar.gz" && rm -f $DRESULTS".tar.gz" |
198 |
|
|
else |
199 |
|
|
echo "Warning: $MPACK is not executable => no email was sent" |
200 |
|
|
echo |
201 |
|
|
fi |
202 |
|
|
fi |
203 |
|
|
|
204 |
|
|
# save output and remove output Dir (if no address was provided) |
205 |
|
|
# note: to keep the output Dir without sending email, use option "-a NONE" |
206 |
|
|
if test -f tst_2+2_out.txt ; then mv -f tst_2+2_out.txt tst_2+2_out.old ; fi |
207 |
|
|
cp -p $SUMMARY tst_2+2_out.txt |
208 |
|
|
if test "x$ADDRESS" = x ; then |
209 |
|
|
rm -rf $DRESULTS |
210 |
|
|
fi |
211 |
|
|
|