More merge conflicts
[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 tmp=/tmp/$$
37 status=0
38 needwrap=true
39 try=0
40 n_bad=0
41 bad=""
42 notrun=""
43 interrupt=true
44
45 export QA_CHECK_FS=${QA_CHECK_FS:=true}
46
47 # generic initialization
48 iam=check
49 if ! . ./common.rc
50 then
51     echo "check: failed to source common.rc"
52     exit 1
53 fi
54
55 if [ `id -u` -ne 0 ]
56 then
57     echo "check: QA must be run as root"
58     exit 1
59 fi
60
61 _wallclock()
62 {
63     date "+%H %M %S" | $AWK_PROG '{ print $1*3600 + $2*60 + $3 }'
64 }
65
66 _timestamp()
67 {
68     now=`date "+%D-%T"`
69     echo -n " [$now]"
70 }
71
72 _wrapup()
73 {
74     # for hangcheck ...
75     # remove files that were used by hangcheck
76     #
77     [ -f /tmp/check.pid ] && rm -rf /tmp/check.pid
78     [ -f /tmp/check.sts ] && rm -rf /tmp/check.sts
79
80     if $showme
81     then
82         :
83     elif $needwrap
84     then
85         if [ -f check.time -a -f $tmp.time ]
86         then
87             cat check.time $tmp.time \
88             | $AWK_PROG '
89         { t[$1] = $2 }
90 END     { if (NR > 0) {
91             for (i in t) print i " " t[i]
92           }
93         }' \
94             | sort -n >$tmp.out
95             mv $tmp.out check.time
96         fi
97
98         if [ -f $tmp.expunged ]
99         then
100             notrun=`wc -l <$tmp.expunged | sed -e 's/  *//g'`
101             try=`expr $try - $notrun`
102             list=`echo "$list" | sed -f $tmp.expunged`
103         fi
104
105         echo "" >>check.log
106         date >>check.log
107         echo $list | fmt | sed -e 's/^/    /' >>check.log
108         $interrupt && echo "Interrupted!" >>check.log
109         
110         if [ ! -z "$notrun" ]
111         then
112             echo "Not run:$notrun"
113             echo "Not run:$notrun" >>check.log
114         fi
115         if [ ! -z "$n_bad" -a $n_bad != 0 ]
116         then
117             echo "Failures:$bad"
118             echo "Failed $n_bad of $try tests"
119             echo "Failures:$bad" | fmt >>check.log
120             echo "Failed $n_bad of $try tests" >>check.log
121         else
122             echo "Passed all $try tests"
123             echo "Passed all $try tests" >>check.log
124         fi
125         needwrap=false
126     fi
127
128     rm -f /tmp/*.rawout /tmp/*.out /tmp/*.err /tmp/*.time
129     rm -f /tmp/check.pid /tmp/check.sts
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=${TIMESTAMP:=false}
155
156 . ./common
157
158 [ -f check.time ] || touch check.time
159
160 _get_os
161 if [ $os == "linux" ]; then
162
163 FULL_FSTYP_DETAILS=`_full_fstyp_details`
164 FULL_HOST_DETAILS=`_full_platform_details`
165
166 FULL_MKFS_OPTIONS=`_scratch_mkfs_options`
167
168 FULL_MOUNT_OPTIONS=`_scratch_mount_options`
169
170 cat <<EOF
171 FSTYP         -- $FULL_FSTYP_DETAILS
172 PLATFORM      -- $FULL_HOST_DETAILS
173 MKFS_OPTIONS  -- $FULL_MKFS_OPTIONS
174 MOUNT_OPTIONS -- $FULL_MOUNT_OPTIONS
175
176 EOF
177 fi
178
179 #Linux specific flag '-f'
180 if [ $os == "linux" ]; then
181    flag='-f'
182 fi
183
184 echo "MKFS_OPTIONS  -- $FULL_MKFS_OPTIONS"
185 FULL_MOUNT_OPTIONS=`_scratch_mount_options`
186
187 cat <<EOF
188 FSTYP         -- $FULL_FSTYP_DETAILS
189 PLATFORM      -- $FULL_HOST_DETAILS
190 MKFS_OPTIONS  -- $FULL_MKFS_OPTIONS
191 MOUNT_OPTIONS -- $FULL_MOUNT_OPTIONS
192
193 EOF
194
195 umount $SCRATCH_DEV 2>/dev/null
196 # call the overridden mkfs.xfs - make sure the FS is built
197 # the same as we'll create it later.
198
199 if ! _scratch_mkfs_xfs $flag >$tmp.err 2>&1
200 then
201     echo "our local _scratch_mkfs_xfs routine ..."
202     cat $tmp.err
203     echo "check: failed to mkfs.xfs \$SCRATCH_DEV using specified options"
204     exit 1
205 fi
206
207 # call the overridden mount - make sure the FS mounts with
208 # the same options that we'll mount with later.
209 if ! _scratch_mount >$tmp.err 2>&1
210 then
211     echo "our local mount routine ..."
212     cat $tmp.err
213     echo "check: failed to mount \$SCRATCH_DEV using specified options"
214     exit 1
215 fi
216
217 seq="check"
218 _check_test_fs
219
220 for seq in $list
221 do
222     err=false
223     echo -n "$seq"
224     if $showme
225     then
226         echo
227         continue
228     elif [ -f expunged ] && $expunge && egrep "^$seq([  ]|\$)" expunged >/dev/null
229     then
230         echo " - expunged"
231         rm -f $seq.out.bad
232         echo "/^$seq\$/d" >>$tmp.expunged
233     elif [ ! -f $seq ]
234     then
235         echo " - no such test?"
236         echo "/^$seq\$/d" >>$tmp.expunged
237     else
238         # really going to try and run this one
239         #
240         rm -f $seq.out.bad
241         lasttime=`sed -n -e "/^$seq /s/.* //p" <check.time`
242         if [ "X$lasttime" != X ]; then
243                 echo -n " ${lasttime}s ..."
244         else
245                 echo -n "       "       # prettier output with timestamps.
246         fi
247         rm -f core $seq.notrun
248
249         # for hangcheck ...
250         echo "$seq" >/tmp/check.sts
251
252         start=`_wallclock`
253         $timestamp && echo -n " ["`date "+%T"`"]"
254         sh $seq >$tmp.rawout 2>&1
255         $timestamp && echo -n " ["`date "+%T"`"]"
256         [ ! -x $seq ] && chmod u+x $seq # ensure we can run it
257         ./$seq >$tmp.rawout 2>&1
258         sts=$?
259         $timestamp && _timestamp
260         stop=`_wallclock`
261
262         _fix_malloc <$tmp.rawout >$tmp.out
263         rm -f $tmp.rawout
264
265         if [ -f core ]
266         then
267             echo -n " [dumped core]"
268             mv core $seq.core
269             err=true
270         fi
271
272         if [ -f $seq.notrun ]
273         then
274             $timestamp || echo -n " [not run] "
275             $timestamp && echo " [not run]" && echo -n "        $seq -- "
276             cat $seq.notrun
277             notrun="$notrun $seq"
278         else
279             if [ $sts -ne 0 ]
280             then
281                 echo -n " [failed, exit status $sts]"
282                 err=true
283             fi
284             if [ ! -f $seq.out ]
285             then
286                 echo " - no qualified output"
287                 err=true
288             else
289                 if diff $seq.out $tmp.out >/dev/null 2>&1
290                 then
291                     echo ""
292                     if $err
293                     then
294                         :
295                     else
296                         echo "$seq `expr $stop - $start`" >>$tmp.time
297                     fi
298                 else
299                     echo " - output mismatch (see $seq.out.bad)"
300                     mv $tmp.out $seq.out.bad
301                     $diff $seq.out $seq.out.bad
302                     err=true
303                 fi
304             fi
305         fi
306
307     fi
308
309     # come here for each test, except when $showme is true
310     #
311     if $err
312     then
313         bad="$bad $seq"
314         n_bad=`expr $n_bad + 1`
315         quick=false
316     fi
317     [ -f $seq.notrun ] || try=`expr $try + 1`
318     
319     seq="after_$seq"
320     _check_test_fs
321 done
322
323 interrupt=false
324 status=`expr $n_bad`
325 exit