updates to match top of tree, grpquota support, fix output to match 3.01
[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 "$MOUNT_OPTIONS" ]
161 then
162     echo "check: \$MOUNT_OPTIONS specifed - \"$MOUNT_OPTIONS\""
163     umount $TEST_DEV
164     # call the overridden mount - make sure the FS starts as
165     # the same as we'll set it later.
166     if ! mount -t xfs $TEST_DEV $TEST_DIR >$tmp.err 2>&1
167     then
168         echo "our mount ..."
169         cat $tmp.err
170         # call the normal mount
171         echo "normal mount ..."
172         /bin/mount -t xfs $TEST_DEV $TEST_DIR
173         echo "check: failed to mount \$TEST_DEV using specified mount options"
174         exit 1
175     fi
176 fi
177
178 seq="check"
179 _check_fs $TEST_DEV
180
181 for seq in $list
182 do
183     err=false
184     echo -n "$seq"
185     if $showme
186     then
187         echo
188         continue
189     elif [ -f expunged ] && $expunge && egrep "^$seq([  ]|\$)" expunged >/dev/null
190     then
191         echo " - expunged"
192         rm -f $seq.out.bad
193         echo "/^$seq\$/d" >>$tmp.expunged
194     elif [ ! -f $seq ]
195     then
196         echo " - no such test?"
197         echo "/^$seq\$/d" >>$tmp.expunged
198     else
199         # really going to try and run this one
200         #
201         rm -f $seq.out.bad
202         lasttime=`sed -n -e "/^$seq /s/.* //p" <check.time`
203         [ "X$lasttime" != X ] && echo -n " ${lasttime}s ..."
204         rm -f core $seq.notrun
205
206         # for hangcheck ...
207         echo "$seq" >/tmp/check.sts
208
209         start=`_wallclock`
210         $timestamp && _timestamp
211         sh $seq >$tmp.rawout 2>&1
212         sts=$?
213         $timestamp && _timestamp
214         stop=`_wallclock`
215
216         _fix_malloc <$tmp.rawout >$tmp.out
217         rm -f $tmp.rawout
218
219         if [ -f core ]
220         then
221             echo -n " [dumped core]"
222             mv core $seq.core
223             err=true
224         fi
225
226         if [ -f $seq.notrun ]
227         then
228             echo -n " [not run] "
229             cat $seq.notrun
230             notrun="$notrun $seq"
231         else
232             if [ $sts -ne 0 ]
233             then
234                 echo -n " [failed, exit status $sts]"
235                 err=true
236             fi
237             if [ ! -f $seq.out ]
238             then
239                 echo " - no qualified output"
240                 err=true
241             else
242                 if diff $seq.out $tmp.out >/dev/null 2>&1
243                 then
244                     echo ""
245                     if $err
246                     then
247                         :
248                     else
249                         echo "$seq `expr $stop - $start`" >>$tmp.time
250                     fi
251                 else
252                     echo " - output mismatch (see $seq.out.bad)"
253                     mv $tmp.out $seq.out.bad
254                     $diff $seq.out $seq.out.bad
255                     err=true
256                 fi
257             fi
258         fi
259
260     fi
261
262     # come here for each test, except when $showme is true
263     #
264     if $err
265     then
266         bad="$bad $seq"
267         n_bad=`expr $n_bad + 1`
268         quick=false
269     fi
270     [ -f $seq.notrun ] || try=`expr $try + 1`
271     
272     seq="after_$seq"
273     _check_fs $TEST_DEV
274     
275 done
276
277 interrupt=false
278 status=`expr $n_bad`
279 exit