/[MITgcm]/MITgcm/tools/do_tst_2+2
ViewVC logotype

Contents of /MITgcm/tools/do_tst_2+2

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.10 - (show annotations) (download)
Fri Jan 21 02:18:46 2011 UTC (13 years, 2 months ago) by jmc
Branch: MAIN
Changes since 1.9: +31 -7 lines
modifications similar to the one in testreport (MPI machine-file).

1 #! /usr/bin/env bash
2
3 # $Header: /u/gcmpack/MITgcm/tools/do_tst_2+2,v 1.9 2011/01/19 23:43:13 jmc Exp $
4 # $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 echo " -exe COMMAND : use COMMAND to run the tests"
16 echo " -mpi : run the tests using MPI"
17 echo " -mf STRING :(MPI) file with list of possible machines to run on"
18 echo " -o STRING : used to build output directory name"
19 echo " (DEF=\"hostname\")"
20 echo " -a,-A STRING : email address to send output to"
21 echo " (DEF=\"\" no email is sent)"
22 echo " (-A: + save each log file)"
23 echo " -clean : clean output & reset"
24 exit
25 }
26
27 CLEAN=0
28 TESTDIRS=
29 SKIPDIRS=
30 SCRIPT='../tools/tst_2+2'
31 scrArg='All'
32 COMMAND=
33 mpi=0
34 MPI_MFILE=
35 OUTDIR=`hostname | sed 's/\..*$//'`
36 SAVELOG=0
37 ADDRESS=
38 MPACK="../tools/mpack-1.6/mpack"
39 here=`pwd`
40 yy=
41 for xx
42 do
43 if test -n "$yy"; then
44 eval "$yy=\$xx"
45 yy=
46 else
47 case $xx in
48 -help ) usage ;;
49 -clean) CLEAN=1 ;;
50 -t ) yy=TESTDIRS ;;
51 -skd ) yy=SKIPDIRS ;;
52 -exe ) yy=COMMAND ;;
53 -mpi ) mpi=1 ;;
54 -mf ) yy=MPI_MFILE ;;
55 -a ) yy=ADDRESS ;;
56 -A ) yy=ADDRESS ; SAVELOG=1 ;;
57 -o ) yy=OUTDIR ;;
58 *) echo "Error: unrecognized option: "$xx ; usage ; exit ;;
59 esac
60 fi
61 done
62 #------------------------
63
64 if test "x$TESTDIRS" = x ; then TESTDIRS=`ls ` ; fi
65 LIST=""
66 for xx in $TESTDIRS
67 do
68 yy=`echo $SKIPDIRS | grep -c $xx`
69 if test $yy = 0 ; then
70 if test -f $xx/results/output.txt ; then
71 LIST=${LIST}" "$xx
72 # else
73 # echo ""; echo -n " -- skip \"$xx\" (not a directory !)"
74 fi
75 # else
76 # echo ""; echo -n " -- skip \"$xx\" (excluded)"
77 fi
78 done
79
80 if test -x $SCRIPT ; then
81 echo "run script '$SCRIPT' for experiment in:"
82 echo " $LIST"
83 yy=`echo $SCRIPT | grep -c '^\/'`
84 if test $yy = 0 ; then SCRIPT="../../$SCRIPT" ; fi
85 else
86 echo "ERROR: script '$SCRIPT' not found or not executable"
87 exit
88 fi
89 echo ""
90 #------------------------
91
92 if test $CLEAN = 1 ; then
93 for xx in $LIST
94 do
95 listD='run '`(cd $xx/results ; ls output.*.txt 2> /dev/null | sed 's/^output\./tr_run./g' | sed 's/\.txt$//g' )`
96 for yy in $listD
97 do
98 if test -r $xx/$yy/data.tst ; then
99 echo "clean dir:" $xx/$yy
100 cd $xx/$yy
101 echo ' ' >> outp.tst_2+2.log
102 echo $SCRIPT 4 >> outp.tst_2+2.log
103 $SCRIPT 4 >> outp.tst_2+2.log 2>&1
104 cd $here
105 fi
106 done
107 done
108 exit
109 fi
110 #------------------------
111 # Create a uniquely named directory to store results
112 CMDLINE=$0
113 for xx in "$@" ; do nw=`echo $xx | wc -w`
114 if test $nw = '1' ; then CMDLINE="$CMDLINE $xx"
115 else CMDLINE="$CMDLINE '$xx'" ; fi
116 done
117 #for xx in "$@" ; do CMDLINE="$CMDLINE '$xx'" ; done
118 DATE=`date +%Y%m%d`
119 BASE="rs_"$OUTDIR"_"$DATE"_"
120 xx=0
121 DRESULTS="$BASE$xx"
122 while test -e $DRESULTS ; do
123 xx=$(( $xx + 1 ))
124 DRESULTS="$BASE$xx"
125 done
126 mkdir $DRESULTS
127 out=$?
128 if test "x$out" != x0 ; then
129 echo "ERROR: Can't create results directory \"./$DRESULTS\""
130 exit 1
131 fi
132 SUMMARY="$DRESULTS/summary.txt"
133 OPTFILE=
134
135 printf "Start time: " > $SUMMARY
136 date >> $SUMMARY
137 echo 'run:' $CMDLINE >> $SUMMARY
138 if test -f tr_out.txt ; then
139 echo ' using output from:' >> $SUMMARY
140 sed -n '2,/OPTFILE/ p' tr_out.txt >> $SUMMARY
141 echo >> $SUMMARY
142 fi
143 echo 'test 2+2=4 summary :' >> $SUMMARY
144 echo >> $SUMMARY
145 echo 'P. Run Result experiment' >> $SUMMARY
146 echo ' 1 2 3' >> $SUMMARY
147
148 #-- For MPI test:
149 LOC_MFILE='tr_mpi_mfile'
150 RUNOUTP="output.txt"
151 if [ $mpi -ge 1 ] ; then
152 SCRIPT="$SCRIPT -mpi"
153 RUNOUTP="STDOUT.0000"
154 fi
155
156 for xx in $LIST
157 do
158 echo ==============================================================================
159 if [ $mpi -le 0 ] ; then
160 rCommand=$COMMAND
161 else
162 LOC_NPROC=2
163 mpi_size=$xx/build/SIZE.h.mpi
164 if test -f $mpi_size ; then
165 px=`grep '^ & *nPx *=' $mpi_size | sed 's/^ & *nPx *= *//' | sed 's/, *$//'`
166 py=`grep '^ & *nPy *=' $mpi_size | sed 's/^ & *nPy *= *//' | sed 's/, *$//'`
167 pp=`expr $px \* $py` > /dev/null 2>&1 ; out=$?
168 if test "x$out" = x0 ; then LOC_NPROC=$pp ; fi
169 fi
170 rCommand=`echo $COMMAND | sed "s/ TR_NPROC / $LOC_NPROC /"`
171 if test "x$MPI_MFILE" != x ; then
172 #- create new MPI machine-file with the right number of Procs
173 rm -f $LOC_MFILE
174 cat $MPI_MFILE | sort | uniq | head -$LOC_NPROC > $LOC_MFILE
175 nl=`wc -l $LOC_MFILE | awk '{print $1}'`
176 if [ $nl -lt $LOC_NPROC ] ; then
177 rm -f $LOC_MFILE
178 cat $MPI_MFILE | head -$LOC_NPROC > $LOC_MFILE
179 fi
180 rCommand=`echo $rCommand | sed "s/ TR_MFILE / ..\/..\/$LOC_MFILE /"`
181 fi
182 fi
183
184 listD='run '`(cd $xx/results ; ls output.*.txt 2> /dev/null | sed 's/^output\./tr_run./g' | sed 's/\.txt$//g' )`
185 for yy in $listD
186 do
187 if test -f $xx/$yy/$RUNOUTP ; then
188 if test "x$OPTFILE" = x -a -f $xx/build/Makefile ; then
189 comm=`grep '^# OPTFILE=' $xx/build/Makefile 2>/dev/null | head -1 | sed 's/^# //'`
190 echo "from '$xx/build/Makefile', extract:" > $DRESULTS/genmake_state
191 sed -n '/^# executed by:/,+1 p' $xx/build/Makefile >> $DRESULTS/genmake_state
192 echo " $comm" >> $DRESULTS/genmake_state
193 eval $comm
194 gmkLog=$xx/build/genmake.log
195 grep '^Get compiler version using:' $gmkLog > /dev/null 2>&1
196 out=$?
197 if test "x$out" = x0 ; then
198 echo "from '$gmkLog', extract compiler version:" >> $DRESULTS/genmake_state
199 sed -n '/Get compiler version/,/<-- compiler version/p' $gmkLog \
200 | grep -v '^... compiler version ' > tr_vers.tmp_log
201 sed -n '1,/^$/p' tr_vers.tmp_log | sed '/^$/d' | sed 's/^./ &/' \
202 >> $DRESULTS/genmake_state
203 rm -f tr_vers.tmp_log
204 fi
205 fi
206 if test $yy = 'run' ; then nam=$xx
207 else nam=$xx`echo $yy | sed 's/tr_run//'` ; fi
208 echo -n "Entering $xx/$yy :"
209 cd $xx/$yy
210 pwd > outp.tst_2+2.log
211 if test "x$COMMAND" = x ; then
212 echo $SCRIPT $scrArg >> outp.tst_2+2.log ; echo ' ' >> outp.tst_2+2.log
213 $SCRIPT $scrArg >> outp.tst_2+2.log 2>&1
214 out=$?
215 else
216 echo "$SCRIPT $scrArg -command \"$rCommand\"" >> outp.tst_2+2.log
217 echo ' ' >> outp.tst_2+2.log
218 $SCRIPT $scrArg -command "$rCommand" >> outp.tst_2+2.log 2>&1
219 out=$?
220 fi
221 case $out in
222 0 ) echo ' pass test 2+2=4'
223 echo "Y Y Y Y pass <- $nam" >> ../../$SUMMARY ;;
224 4|5) echo "Y Y Y Y FAIL ($out) - $nam" >> ../../$SUMMARY ;;
225 3 ) echo "Y Y Y N FAIL ($out) - $nam" >> ../../$SUMMARY ;;
226 2 ) echo "Y Y N N FAIL ($out) - $nam" >> ../../$SUMMARY ;;
227 1 ) echo "Y N N N FAIL ($out) - $nam" >> ../../$SUMMARY ;;
228 * ) echo "N N N N FAIL ($out) - $nam" >> ../../$SUMMARY ;;
229 esac
230 if test $out != '0' ; then
231 echo " test 2+2=4 FAIL (exit $out)"
232 echo " "
233 tail -5 outp.tst_2+2.log
234 echo " "
235 cp -p outp.tst_2+2.log ../../$DRESULTS/$nam.log
236 elif test $SAVELOG = 1 ; then
237 cp -p outp.tst_2+2.log ../../$DRESULTS/$nam.log
238 fi
239 cd $here
240 fi
241 done
242 if test "x$mpi" != x0 -a "x$MPI_MFILE" != x ; then rm -f $LOC_MFILE ; fi
243 done
244 printf "End time: " >> $SUMMARY
245 date >> $SUMMARY
246
247 # If address was supplied and mpack exist, then send email using mpack.
248 if test "x$ADDRESS" != xNONE -a "x$ADDRESS" != x ; then
249 if test -x $MPACK ; then
250 tar -cf $DRESULTS".tar" $DRESULTS > /dev/null 2>&1 \
251 && gzip $DRESULTS".tar" \
252 && $MPACK -s MITgcm-test -m 3555000 $DRESULTS".tar.gz" $ADDRESS
253 out=$?
254 if test "x$out" != x0 ; then
255 echo
256 echo "Warning: The tar, gzip, & mpack step failed. Please send email"
257 echo " to <MITgcm-support@mitgcm.org> for help. You may copy the "
258 echo " summary of results from the directory \"$DRESULTS\"."
259 echo
260 else
261 echo
262 echo "An email containing results was sent to the following address:"
263 echo " \"$ADDRESS\""
264 echo
265 fi
266 test -f $DRESULTS".tar" && rm -f $DRESULTS".tar"
267 test -f $DRESULTS".tar.gz" && rm -f $DRESULTS".tar.gz"
268 else
269 echo "Warning: $MPACK is not executable => no email was sent"
270 echo
271 fi
272 fi
273
274 # save output and remove output Dir (if no address was provided)
275 # note: to keep the output Dir without sending email, use option "-a NONE"
276 if test -f tst_2+2_out.txt ; then mv -f tst_2+2_out.txt tst_2+2_out.old ; fi
277 cp -p $SUMMARY tst_2+2_out.txt
278 if test "x$ADDRESS" = x ; then
279 rm -rf $DRESULTS
280 fi

  ViewVC Help
Powered by ViewVC 1.1.22