02fcfd762e8cad5de696465414b6b4a84c8dcdb7
[xfstests-dev.git] / check
1 #!/bin/sh
2 #
3 # Control script for QA
4 #
5 # Copyright (c) 2000-2002,2006 Silicon Graphics, Inc.  All Rights Reserved.
6 #
7
8 tmp=/tmp/$$
9 status=0
10 needwrap=true
11 n_try=0
12 try=""
13 n_bad=0
14 bad=""
15 notrun=""
16 interrupt=true
17
18 export QA_CHECK_FS=${QA_CHECK_FS:=true}
19
20 # by default don't output timestamps
21 timestamp=${TIMESTAMP:=false}
22
23 # generic initialization
24 iam=check
25
26 # we need common.config
27 if ! . ./common.config
28 then
29     echo "$iam: failed to source common.config"
30     exit 1
31 fi
32
33 # we need common
34 . ./common
35
36
37 # we need common.rc
38 if ! . ./common.rc
39 then
40     echo "check: failed to source common.rc"
41     exit 1
42 fi
43
44 if [ `id -u` -ne 0 ]
45 then
46     echo "check: QA must be run as root"
47     exit 1
48 fi
49
50 _wallclock()
51 {
52     date "+%H %M %S" | $AWK_PROG '{ print $1*3600 + $2*60 + $3 }'
53 }
54
55 _timestamp()
56 {
57     now=`date "+%T"`
58     echo -n " [$now]"
59 }
60
61 _wrapup()
62 {
63     # for hangcheck ...
64     # remove files that were used by hangcheck
65     #
66     [ -f /tmp/check.pid ] && rm -rf /tmp/check.pid
67     [ -f /tmp/check.sts ] && rm -rf /tmp/check.sts
68
69     if $showme
70     then
71         :
72     elif $needwrap
73     then
74         if [ -f check.time -a -f $tmp.time ]
75         then
76             cat check.time $tmp.time \
77             | $AWK_PROG '
78         { t[$1] = $2 }
79 END     { if (NR > 0) {
80             for (i in t) print i " " t[i]
81           }
82         }' \
83             | sort -n >$tmp.out
84             mv $tmp.out check.time
85         fi
86
87         if [ -f $tmp.expunged ]
88         then
89             notrun=`wc -l <$tmp.expunged | sed -e 's/  *//g'`
90             n_try=`expr $n_try - $notrun`
91             list=`echo "$list" | sed -f $tmp.expunged`
92         fi
93
94         echo "" >>check.log
95         date >>check.log
96         echo $list | fmt | sed -e 's/^/    /' >>check.log
97         $interrupt && echo "Interrupted!" >>check.log
98         
99         if [ ! -z "$n_try" -a $n_try != 0 ]
100         then
101             echo "Ran:$try"
102         fi
103
104         if [ ! -z "$notrun" ]
105         then
106             echo "Not run:$notrun"
107             echo "Not run:$notrun" >>check.log
108         fi
109
110         if [ ! -z "$n_bad" -a $n_bad != 0 ]
111         then
112             echo "Failures:$bad"
113             echo "Failed $n_bad of $n_try tests"
114             echo "Failures:$bad" | fmt >>check.log
115             echo "Failed $n_bad of $n_try tests" >>check.log
116         else
117             echo "Passed all $n_try tests"
118             echo "Passed all $n_try tests" >>check.log
119         fi
120         needwrap=false
121     fi
122
123     rm -f /tmp/*.rawout /tmp/*.out /tmp/*.err /tmp/*.time
124     rm -f /tmp/check.pid /tmp/check.sts
125     rm -f $tmp.*
126 }
127
128 trap "_wrapup; exit \$status" 0 1 2 3 15
129
130 # for hangcheck ...
131 # Save pid of check in a well known place, so that hangcheck can be sure it
132 # has the right pid (getting the pid from ps output is not reliable enough).
133 #
134 rm -rf /tmp/check.pid
135 echo $$ >/tmp/check.pid
136
137 # for hangcheck ...
138 # Save the status of check in a well known place, so that hangcheck can be
139 # sure to know where check is up to (getting test number from ps output is
140 # not reliable enough since the trace stuff has been introduced).
141 #
142 rm -rf /tmp/check.sts
143 echo "preamble" >/tmp/check.sts
144
145 # don't leave old full output behind on a clean run
146 rm -f check.full
147
148 [ -f check.time ] || touch check.time
149
150 FULL_FSTYP_DETAILS=`_full_fstyp_details`
151 FULL_HOST_DETAILS=`_full_platform_details`
152 FULL_MKFS_OPTIONS=`_scratch_mkfs_options`
153 FULL_MOUNT_OPTIONS=`_scratch_mount_options`
154
155 cat <<EOF
156 FSTYP         -- $FULL_FSTYP_DETAILS
157 PLATFORM      -- $FULL_HOST_DETAILS
158 MKFS_OPTIONS  -- $FULL_MKFS_OPTIONS
159 MOUNT_OPTIONS -- $FULL_MOUNT_OPTIONS
160
161 EOF
162
163 if [ ! -z "$SCRATCH_DEV" ]; then
164   umount $SCRATCH_DEV 2>/dev/null
165   # call the overridden mkfs - make sure the FS is built
166   # the same as we'll create it later.
167
168   if ! _scratch_mkfs $flag >$tmp.err 2>&1
169   then
170       echo "our local _scratch_mkfs routine ..."
171       cat $tmp.err
172       echo "check: failed to mkfs \$SCRATCH_DEV using specified options"
173       exit 1
174   fi
175
176   # call the overridden mount - make sure the FS mounts with
177   # the same options that we'll mount with later.
178   if ! _scratch_mount >$tmp.err 2>&1
179   then
180       echo "our local mount routine ..."
181       cat $tmp.err
182       echo "check: failed to mount \$SCRATCH_DEV using specified options"
183       exit 1
184   fi
185 fi
186
187 seq="check"
188 _check_test_fs
189
190 [ -n "$TESTS_REMAINING_LOG" ] && echo $list > $TESTS_REMAINING_LOG
191
192 for seq in $list
193 do
194     err=false
195     echo -n "$seq"
196     if [ -n "$TESTS_REMAINING_LOG" ] ; then
197         sed -e "s/$seq//" -e 's/  / /' -e 's/^ *//' $TESTS_REMAINING_LOG > $TESTS_REMAINING_LOG.tmp
198         mv $TESTS_REMAINING_LOG.tmp $TESTS_REMAINING_LOG
199         sync
200     fi
201
202     if $showme
203     then
204         echo
205         continue
206     elif [ -f expunged ] && $expunge && egrep "^$seq([  ]|\$)" expunged >/dev/null
207     then
208         echo " - expunged"
209         rm -f $seq.out.bad
210         echo "/^$seq\$/d" >>$tmp.expunged
211     elif [ ! -f $seq ]
212     then
213         echo " - no such test?"
214         echo "/^$seq\$/d" >>$tmp.expunged
215     else
216         # really going to try and run this one
217         #
218         rm -f $seq.out.bad
219         lasttime=`sed -n -e "/^$seq /s/.* //p" <check.time`
220         if [ "X$lasttime" != X ]; then
221                 echo -n " ${lasttime}s ..."
222         else
223                 echo -n "       "       # prettier output with timestamps.
224         fi
225         rm -f core $seq.notrun
226
227         # for hangcheck ...
228         echo "$seq" >/tmp/check.sts
229
230         start=`_wallclock`
231         $timestamp && echo -n " ["`date "+%T"`"]"
232         [ ! -x $seq ] && chmod u+x $seq # ensure we can run it
233         ./$seq >$tmp.rawout 2>&1
234         sts=$?
235         $timestamp && _timestamp
236         stop=`_wallclock`
237
238         _fix_malloc <$tmp.rawout >$tmp.out
239         rm -f $tmp.rawout
240
241         if [ -f core ]
242         then
243             echo -n " [dumped core]"
244             mv core $seq.core
245             err=true
246         fi
247
248         if [ -f $seq.notrun ]
249         then
250             $timestamp || echo -n " [not run] "
251             $timestamp && echo " [not run]" && echo -n "        $seq -- "
252             cat $seq.notrun
253             notrun="$notrun $seq"
254         else
255             if [ $sts -ne 0 ]
256             then
257                 echo -n " [failed, exit status $sts]"
258                 err=true
259             fi
260             if [ ! -f $seq.out ]
261             then
262                 echo " - no qualified output"
263                 err=true
264             else
265                 if diff $seq.out $tmp.out >/dev/null 2>&1
266                 then
267                     echo ""
268                     if $err
269                     then
270                         :
271                     else
272                         echo "$seq `expr $stop - $start`" >>$tmp.time
273                     fi
274                 else
275                     echo " - output mismatch (see $seq.out.bad)"
276                     mv $tmp.out $seq.out.bad
277                     $diff $seq.out $seq.out.bad
278                     err=true
279                 fi
280             fi
281         fi
282
283     fi
284
285     # come here for each test, except when $showme is true
286     #
287     if $err
288     then
289         bad="$bad $seq"
290         n_bad=`expr $n_bad + 1`
291         quick=false
292     fi
293     if [ ! -f $seq.notrun ]
294     then
295         try="$try $seq"
296         n_try=`expr $n_try + 1`
297     fi
298     
299     seq="after_$seq"
300     _check_test_fs
301 done
302
303 interrupt=false
304 status=`expr $n_bad`
305 exit