Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
cosmetics : indent
[simgrid.git] / teshsuite / smpi / mpich-test / runbase
1 #! /bin/sh
2 #
3 # This file contains support shell routines and steps common to all
4 # runtests scripts.
5 #
6 # Find MPIRUN
7 #
8 # Some people don't include "." in their path (! in case an ls trojan horse,
9 # I guess - if someone does that to you, you have bigger problems).  This
10 # code tests to see if you have a path to mpirun; if not, it tries ./mpirun.
11 #
12 # One particular problem is having multiple mpiruns in the path.  An
13 # absolute path for mpirun will fix many problems
14 FindMPIRUN () {
15     if [ -z "$MPICH_USE_LIB_MPIRUN" -a ! -x "$mpirun" ] ; then
16         IFS="${IFS=     }"; saveifs="$IFS"; IFS="${IFS}:"
17         for dir in $PATH ; do 
18             if [ -x $dir/mpirun ] ; then
19                 if [ -n "${MPICH_VERSION}" ] ; then
20                     # Test that we've found the correct mpirun
21                     if strings $dir/mpirun | grep "MPIRUN for MPICH" > /dev/null ; then
22                         :
23                     else
24                         # echo "$dir/mpirun isn't for MPICH"
25                         continue
26                     fi
27                 fi
28                 mpirun="mpirun"
29                 break
30              fi
31         done
32         IFS="$saveifs"
33     fi
34     if [ -z "$mpirun" -a -x "./mpirun" ] ; then
35         mpirun=./mpirun
36     fi
37     #
38     if [ -z "$mpirun" ] ; then
39         echo "No mpirun in path.  Testing can not proceed."
40         exit 1
41     fi
42 }
43
44 # MakeExe program-name
45 MakeExe() {
46     if [ -s $STOPFILE ] ; then 
47         echo "Found stopfile $STOPFILE; exiting"
48         exit 0
49     fi
50     if [ ! -x $1 ] ; then
51         $MAKE $1
52         if [ ! -x $1 ] ; then 
53             if [ "$MPITEST_CONTINUE" = "always" ] ; then
54                 echo "Could not build executable $1; skipping this test"
55             else 
56                 echo "Could not build executable $1; aborting tests"
57                 exit 1
58             fi
59         fi
60     fi
61 }
62
63 # CleanExe program-name
64 CleanExe() {
65     if [ $makeeach = 1 ] ; then
66         /bin/rm -f $1 $1.o
67     fi
68 }
69
70 # Output marker
71 OutTime() {
72     if [ $quiet = 0 ] ; then
73         if [ -z "$hostname" ] ; then
74             hostname=`hostname`
75         fi
76         d=`date`
77         echo "$hostname : $d"
78     fi
79 }
80
81 # Do an "on the fly" check for problems.
82 # Checkout testname difffile
83 # difffile may be empty, in which case stdout is used.
84 # If $writesummaryfile is yes, output the results to $summaryfile.
85 # Use XML-style output for the summary file:
86 # <MPITEST>
87 # <NAME NAME="" STATUS="PASS"|"FAIL">
88 # <WORKDIR>directory</WORKDIR>
89 # <TESTDIFF>
90 #    text from different
91 # </TESTDIFF>
92 # </MPITEST>
93 #
94 # We'd also like to support 
95 # <NP>$np</NP>
96 # but we don't have that information when this routine is called
97 CheckOutput() {
98     bfile=$1
99     difffile=$2
100     fileok="no"
101     if [ ! -s ${bfile}.out ] ; then
102         echo "No output file ${bfile}.out!"
103     else
104         cmpfile=""
105         # Handle Fortran systems that generate stop statements
106         rm -f ${bfile}.tout
107         grep -v 'FORTRAN STOP' ${bfile}.out > ${bfile}.tout
108         for stdfile in $srcdir/${bfile}.std $srcdir/${bfile}.std2 \
109                         $srcdir/std/${bfile}.std ${bfile}.stdo ; do
110             if [ -z "$cmpfile" -a -s "$stdfile" ] ; then
111                 cmpfile=$stdfile
112             fi
113             if test -s $stdfile && diff -b ${bfile}.tout $stdfile > /dev/null ; then
114                 fileok=yes
115                 break;
116             fi
117         done
118         if [ $fileok = "no" ] ; then
119             if [ -n "$difffile" ] ; then
120                 if [ -n "$cmpfile" ] ; then
121                     echo "Differences in ${bfile}.out" >> ${difffile}
122                     diff -b ${bfile}.tout $cmpfile >> ${difffile}
123                 else
124                     echo "Cannot find a file to compare against for test ${bfile}.out"
125                 fi
126             else
127                 if [ -n "$cmpfile" ] ; then
128                     echo "Differences in ${bfile}.out"
129                     diff -b ${bfile}.tout $cmpfile
130                 else
131                     echo "Cannot find a file to compare against for test ${bfile}.out"
132                 fi
133             fi
134             nodiff=0
135         fi
136         if [ "$writesummaryfile" = "yes" ] ; then
137             if [ $fileok = "yes" ] ; then 
138                 passed=pass
139             else
140                 passed=fail
141             fi
142             mydir=`pwd`
143             cat >>$summaryfile <<EOF
144 <MPITEST>
145 <NAME>$bfile</NAME>
146 <WORKDIR>$mydir</WORKDIR>
147 <STATUS>$passed</STATUS>
148 EOF
149             if [ -n "$np" ] ; then
150                 echo "<NP>$np</NP>" >> $summaryfile
151             fi
152             if [ $fileok = "no" ] ; then
153                 echo "<TESTDIFF>" >> $summaryfile
154                 if [ ! -s ${bfile}.out ] ; then
155                     echo "No output file" >>$summaryfile
156                 else
157                     if [ -z "$cmpfile" ] ; then 
158                         cmpfile="/dev/null"
159                     fi
160                     diff -b ${bfile}.tout $cmpfile | \
161                     sed -e 's/&/-AMP-amp;/g' -e 's/</-AMP-lt;/g' \
162                         -e 's/>/-AMP-gt;/g' | \
163                     sed -e 's/-AMP-/\&/g' >> $summaryfile
164                 fi
165                 echo "</TESTDIFF>" >> $summaryfile
166             fi
167             if [ -s "$bfile.tbk" ] ; then
168                 echo "<TRACEBACK>" >> $summaryfile
169                 echo "$bfile.tbk" >>$summaryfile
170                 echo "</TRACEBACK>" >> $summaryfile
171             fi
172             echo "</MPITEST>" >> $summaryfile
173         fi
174         rm -f ${bfile}.tout
175     fi
176 }
177
178 # Runtest pgm-name np marker-test args outfiles
179 # filename.tbk is a traceback file.  Use a tool like pardump $1 > $1.tbk
180 # to get such files
181 RunTest() {
182     OutTime
183     pgm=$1
184     np=$2
185     testfiles="$testfiles $pgm.out"
186     /bin/rm -f $pgm.out $pgm.tbk
187     MakeExe $1
188     if [ ! -x $pgm ] ; then
189         # If no executable, put the make data into $1.out
190         $MAKE $pgm > $pgm.out 2>&1 
191     else
192         mname=$3
193         if [ -z "$mname" ] ; then mname="*** $1 ***" ; fi
194         #echo "$mname" >> $pgm.out
195         echo "$mname"
196         mvarg=""
197         if [ -n "$5" ] ; then rm -f $5 ; 
198             if [ -n "$MPIRUNMVBACK" ] ; then mvarg="$MPIRUNMVBACK \"$5\"" ; fi 
199         fi
200         # The eval is necessary to ensure that the mvarg value is properly
201         # tokenized.  The ./$1 ensures that the program will be found,
202         # even if . is not in the PATH.
203         
204         eval $mpirun $args -np $np $mvarg ./$pgm $4 </dev/null >> $pgm.out 2>&1
205         if [ -n "$5" ] ; then 
206             for file in $5 ; do 
207                 if [ -s $file ] ; then 
208                     cat $file >> $pgm.out ; rm -f $file 
209                 fi
210             done
211         fi
212         #echo "$mname" >> $pgm.out
213         if [ ! -s $srcdir/$pgm.std -a ! -s $pgm.stdo ] ; then
214             # We don't need a special file if the output is just "No Errors"
215             cat >>$pgm.stdo <<EOF
216  No Errors
217 EOF
218         fi
219         if [ "$CheckOutputWhileRunning" = "yes" -o "$check_at_once" = 1 ] ; then
220             CheckOutput $pgm
221         fi
222        # CleanExe $pgm
223     #ipcs
224     fi
225     np=""
226 }
227
228 #
229 # Check the output of the programs against the "standard" output.  The 
230 # possible files are:
231 #   $srcdir/file.std
232 #   $srcdir/file.std2
233 #   file.stdo     
234 # The last one is an automatically generated file for those programs
235 # that simply produce a " No errors" output.
236 CheckAllOutput ()
237 {
238     difffile=$1
239     /bin/rm -f ${difffile}
240     nodiff=1
241     for file in $testfiles ; do
242         bfile=`basename $file .out`
243         CheckOutput $bfile ${difffile}
244     done
245     if [ -s ${difffile} ] ; then
246         cat ${difffile}
247     elif [ $nodiff = 1 ] ; then
248         echo "-- No differences found; test successful"
249     fi
250 }