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