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