sanitize the notrun messages.
[xfstests-dev.git] / check
1 #!/bin/sh
2 #
3 # Control script for QA
4 #
5 # Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.
6
7 # This program is free software; you can redistribute it and/or modify it
8 # under the terms of version 2 of the GNU General Public License as
9 # published by the Free Software Foundation.
10
11 # This program is distributed in the hope that it would be useful, but
12 # WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14
15 # Further, this software is distributed without any warranty that it is
16 # free of the rightful claim of any third person regarding infringement
17 # or the like.  Any license provided herein, whether implied or
18 # otherwise, applies only to this software file.  Patent licenses, if
19 # any, provided herein do not apply to combinations of this program with
20 # other software, or any other product whatsoever.
21
22 # You should have received a copy of the GNU General Public License along
23 # with this program; if not, write the Free Software Foundation, Inc., 59
24 # Temple Place - Suite 330, Boston MA 02111-1307, USA.
25
26 # Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
27 # Mountain View, CA  94043, or:
28
29 # http://www.sgi.com 
30
31 # For further information regarding this notice, see: 
32
33 # http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
34 #
35
36 export MKFS_OPTIONS=${MKFS_OPTIONS:=-bsize=4096}
37 export MOUNT_OPTIONS=${MOUNT_OPTIONS:=-ologbufs=2}
38
39 tmp=/tmp/$$
40 status=0
41 needwrap=true
42 try=0
43 n_bad=0
44 bad=""
45 notrun=""
46 interrupt=true
47
48 # generic initialization
49 iam=check
50 if ! . ./common.rc
51 then
52     echo "check: failed to source common.rc"
53     exit 1
54 fi
55
56 if [ $UID -ne 0 ]
57 then
58     echo "check: QA must be run as root"
59     exit 1
60 fi
61
62 _wallclock()
63 {
64     date "+%H %M %S" | $AWK_PROG '{ print $1*3600 + $2*60 + $3 }'
65 }
66
67 _timestamp()
68 {
69     now=`date "+%D-%T"` 
70     echo -n " [$now]"
71 }
72
73 _wrapup()
74 {
75     # for hangcheck ...
76     # remove files that were used by hangcheck
77     #
78     [ -f /tmp/check.pid ] && rm -rf /tmp/check.pid
79     [ -f /tmp/check.sts ] && rm -rf /tmp/check.sts
80
81     if $showme
82     then
83         :
84     elif $needwrap
85     then
86         if [ -f check.time -a -f $tmp.time ]
87         then
88             cat check.time $tmp.time \
89             | $AWK_PROG '
90         { t[$1] = $2 }
91 END     { if (NR > 0) {
92             for (i in t) print i " " t[i]
93           }
94         }' \
95             | sort -n >$tmp.out
96             mv $tmp.out check.time
97         fi
98
99         if [ -f $tmp.expunged ]
100         then
101             notrun=`wc -l <$tmp.expunged | sed -e 's/  *//g'`
102             try=`expr $try - $notrun`
103             list=`echo "$list" | sed -f $tmp.expunged`
104         fi
105
106         echo "" >>check.log
107         date >>check.log
108         echo $list | fmt | sed -e 's/^/    /' >>check.log
109         $interrupt && echo "Interrupted!" >>check.log
110         
111         if [ ! -z "$notrun" ]
112         then
113             echo "Not run:$notrun"
114             echo "Not run:$notrun" >>check.log
115         fi
116         if [ ! -z "$n_bad" -a $n_bad != 0 ]
117         then
118             echo "Failures:$bad"
119             echo "Failed $n_bad of $try tests"
120             echo "Failures:$bad" | fmt >>check.log
121             echo "Failed $n_bad of $try tests" >>check.log
122         else
123             echo "Passed all $try tests"
124             echo "Passed all $try tests" >>check.log
125         fi
126         needwrap=false
127     fi
128
129     rm -f $tmp.*
130 }
131
132 trap "_wrapup; exit \$status" 0 1 2 3 15
133
134 # for hangcheck ...
135 # Save pid of check in a well known place, so that hangcheck can be sure it
136 # has the right pid (getting the pid from ps output is not reliable enough).
137 #
138 rm -rf /tmp/check.pid
139 echo $$ >/tmp/check.pid
140
141 # for hangcheck ...
142 # Save the status of check in a well known place, so that hangcheck can be
143 # sure to know where check is up to (getting test number from ps output is
144 # not reliable enough since the trace stuff has been introduced).
145 #
146 rm -rf /tmp/check.sts
147 echo "preamble" >/tmp/check.sts
148
149 # don't leave old full output behind on a clean run
150 rm -f check.full
151
152 # by default don't output timestamps
153 timestamp=false
154
155 . ./common
156
157 [ -f check.time ] || touch check.time
158
159 if [ ! -z "$MKFS_OPTIONS" ]
160 then
161     echo "check: \$MKFS_OPTIONS specified -- \"$MKFS_OPTIONS\""
162     umount $SCRATCH_DEV 2>/dev/null
163     # call the overridden mkfs.xfs - make sure the FS is built
164     # the same as we'll create it later.
165     if ! mkfs_xfs -f $SCRATCH_DEV >$tmp.err 2>&1
166     then
167         echo "our local mkfs_xfs routine ..."
168         cat $tmp.err
169         echo "check: failed to mkfs.xfs \$SCRATCH_DEV using specified options"
170         exit 1
171     fi
172 fi
173
174 if [ ! -z "$MOUNT_OPTIONS" ]
175 then
176     echo "check: \$MOUNT_OPTIONS specified -- \"$MOUNT_OPTIONS\""
177     umount $TEST_DEV
178     # call the overridden mount - make sure the FS starts as
179     # the same as we'll set it later.
180     if ! mount -t xfs $TEST_DEV $TEST_DIR >$tmp.err 2>&1
181     then
182         echo "our local mount routine ..."
183         cat $tmp.err
184         # call the normal mount
185         echo "normal mount ..."
186         /bin/mount -t xfs $TEST_DEV $TEST_DIR
187         echo "check: failed to mount \$TEST_DEV using specified mount options"
188         exit 1
189     fi
190 fi
191
192 seq="check"
193 _check_fs $TEST_DEV
194
195 for seq in $list
196 do
197     err=false
198     echo -n "$seq"
199     if $showme
200     then
201         echo
202         continue
203     elif [ -f expunged ] && $expunge && egrep "^$seq([  ]|\$)" expunged >/dev/null
204     then
205         echo " - expunged"
206         rm -f $seq.out.bad
207         echo "/^$seq\$/d" >>$tmp.expunged
208     elif [ ! -f $seq ]
209     then
210         echo " - no such test?"
211         echo "/^$seq\$/d" >>$tmp.expunged
212     else
213         # really going to try and run this one
214         #
215         rm -f $seq.out.bad
216         lasttime=`sed -n -e "/^$seq /s/.* //p" <check.time`
217         [ "X$lasttime" != X ] && echo -n " ${lasttime}s ..."
218         rm -f core $seq.notrun
219
220         # for hangcheck ...
221         echo "$seq" >/tmp/check.sts
222
223         start=`_wallclock`
224         $timestamp && _timestamp
225         sh $seq >$tmp.rawout 2>&1
226         sts=$?
227         $timestamp && _timestamp
228         stop=`_wallclock`
229
230         _fix_malloc <$tmp.rawout >$tmp.out
231         rm -f $tmp.rawout
232
233         if [ -f core ]
234         then
235             echo -n " [dumped core]"
236             mv core $seq.core
237             err=true
238         fi
239
240         if [ -f $seq.notrun ]
241         then
242             echo -n " [not run] "
243             cat $seq.notrun
244             notrun="$notrun $seq"
245         else
246             if [ $sts -ne 0 ]
247             then
248                 echo -n " [failed, exit status $sts]"
249                 err=true
250             fi
251             if [ ! -f $seq.out ]
252             then
253                 echo " - no qualified output"
254                 err=true
255             else
256                 if diff $seq.out $tmp.out >/dev/null 2>&1
257                 then
258                     echo ""
259                     if $err
260                     then
261                         :
262                     else
263                         echo "$seq `expr $stop - $start`" >>$tmp.time
264                     fi
265                 else
266                     echo " - output mismatch (see $seq.out.bad)"
267                     mv $tmp.out $seq.out.bad
268                     $diff $seq.out $seq.out.bad
269                     err=true
270                 fi
271             fi
272         fi
273
274     fi
275
276     # come here for each test, except when $showme is true
277     #
278     if $err
279     then
280         bad="$bad $seq"
281         n_bad=`expr $n_bad + 1`
282         quick=false
283     fi
284     [ -f $seq.notrun ] || try=`expr $try + 1`
285     
286     seq="after_$seq"
287     _check_fs $TEST_DEV
288     
289 done
290
291 interrupt=false
292 status=`expr $n_bad`
293 exit