Numerous changes to QA scripts allowing tests to run with external log/rt devices...
[xfstests-dev.git] / check
1 #!/bin/sh
2 #
3 # Control script for QA
4 #
5 # Copyright (c) 2000-2002 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 _wrapup()
68 {
69     # for hangcheck ...
70     # remove files that were used by hangcheck
71     #
72     [ -f /tmp/check.pid ] && rm -rf /tmp/check.pid
73     [ -f /tmp/check.sts ] && rm -rf /tmp/check.sts
74
75     if $showme
76     then
77         :
78     elif $needwrap
79     then
80         if [ -f check.time -a -f $tmp.time ]
81         then
82             cat check.time $tmp.time \
83             | $AWK_PROG '
84         { t[$1] = $2 }
85 END     { if (NR > 0) {
86             for (i in t) print i " " t[i]
87           }
88         }' \
89             | sort -n >$tmp.out
90             mv $tmp.out check.time
91         fi
92
93         if [ -f $tmp.expunged ]
94         then
95             notrun=`wc -l <$tmp.expunged | sed -e 's/  *//g'`
96             try=`expr $try - $notrun`
97             list=`echo "$list" | sed -f $tmp.expunged`
98         fi
99
100         echo "" >>check.log
101         date >>check.log
102         echo $list | fmt | sed -e 's/^/    /' >>check.log
103         $interrupt && echo "Interrupted!" >>check.log
104         
105         if [ ! -z "$notrun" ]
106         then
107             echo "Not run:$notrun"
108             echo "Not run:$notrun" >>check.log
109         fi
110         if [ ! -z "$n_bad" -a $n_bad != 0 ]
111         then
112             echo "Failures:$bad"
113             echo "Failed $n_bad of $try tests"
114             echo "Failures:$bad" | fmt >>check.log
115             echo "Failed $n_bad of $try tests" >>check.log
116         else
117             echo "Passed all $try tests"
118             echo "Passed all $try tests" >>check.log
119         fi
120         needwrap=false
121     fi
122
123     rm -f $tmp.*
124 }
125
126 trap "_wrapup; exit \$status" 0 1 2 3 15
127
128 # for hangcheck ...
129 # Save pid of check in a well known place, so that hangcheck can be sure it
130 # has the right pid (getting the pid from ps output is not reliable enough).
131 #
132 rm -rf /tmp/check.pid
133 echo $$ >/tmp/check.pid
134
135 # for hangcheck ...
136 # Save the status of check in a well known place, so that hangcheck can be
137 # sure to know where check is up to (getting test number from ps output is
138 # not reliable enough since the trace stuff has been introduced).
139 #
140 rm -rf /tmp/check.sts
141 echo "preamble" >/tmp/check.sts
142
143 # don't leave old full output behind on a clean run
144 rm -f check.full
145
146 # by default don't output timestamps
147 timestamp=${TIMESTAMP:=false}
148
149 . ./common
150
151 [ -f check.time ] || touch check.time
152
153 FULL_MKFS_OPTIONS=`_scratch_mkfs_options`
154 echo check: MKFS_OPTIONS  -- $FULL_MKFS_OPTIONS
155 umount $SCRATCH_DEV 2>/dev/null
156 # call the overridden mkfs.xfs - make sure the FS is built
157 # the same as we'll create it later.
158 if ! _scratch_mkfs_xfs -f >$tmp.err 2>&1
159 then
160     echo "our local _scratch_mkfs_xfs routine ..."
161     cat $tmp.err
162     echo "check: failed to mkfs.xfs \$SCRATCH_DEV using specified options"
163     exit 1
164 fi
165
166 FULL_MOUNT_OPTIONS=`_scratch_mount_options`
167 echo check: MOUNT_OPTIONS -- $FULL_MOUNT_OPTIONS
168 # call the overridden mount - make sure the FS mounts with
169 # the same options that we'll mount with later.
170 if ! _scratch_mount >$tmp.err 2>&1
171 then
172     echo "our local mount routine ..."
173     cat $tmp.err
174     echo "check: failed to mount \$SCRATCH_DEV using specified options"
175     exit 1
176 fi
177
178 seq="check"
179 _check_test_fs
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         if [ "X$lasttime" != X ]; then
204                 echo -n " ${lasttime}s ..."
205         else
206                 echo -n "       "       # prettier output with timestamps.
207         fi
208         rm -f core $seq.notrun
209
210         # for hangcheck ...
211         echo "$seq" >/tmp/check.sts
212
213         start=`_wallclock`
214         $timestamp && echo -n " ["`date "+%T"`"]"
215         sh $seq >$tmp.rawout 2>&1
216         sts=$?
217         $timestamp && echo -n " ["`date "+%T"`"]"
218         stop=`_wallclock`
219
220         _fix_malloc <$tmp.rawout >$tmp.out
221         rm -f $tmp.rawout
222
223         if [ -f core ]
224         then
225             echo -n " [dumped core]"
226             mv core $seq.core
227             err=true
228         fi
229
230         if [ -f $seq.notrun ]
231         then
232             $timestamp || echo -n " [not run] "
233             $timestamp && echo " [not run]" && echo -n "        $seq -- "
234             cat $seq.notrun
235             notrun="$notrun $seq"
236         else
237             if [ $sts -ne 0 ]
238             then
239                 echo -n " [failed, exit status $sts]"
240                 err=true
241             fi
242             if [ ! -f $seq.out ]
243             then
244                 echo " - no qualified output"
245                 err=true
246             else
247                 if diff $seq.out $tmp.out >/dev/null 2>&1
248                 then
249                     echo ""
250                     if $err
251                     then
252                         :
253                     else
254                         echo "$seq `expr $stop - $start`" >>$tmp.time
255                     fi
256                 else
257                     echo " - output mismatch (see $seq.out.bad)"
258                     mv $tmp.out $seq.out.bad
259                     $diff $seq.out $seq.out.bad
260                     err=true
261                 fi
262             fi
263         fi
264
265     fi
266
267     # come here for each test, except when $showme is true
268     #
269     if $err
270     then
271         bad="$bad $seq"
272         n_bad=`expr $n_bad + 1`
273         quick=false
274     fi
275     [ -f $seq.notrun ] || try=`expr $try + 1`
276     
277     seq="after_$seq"
278     _check_test_fs
279     
280 done
281
282 interrupt=false
283 status=`expr $n_bad`
284 exit