xfstests: randholes: use posix_memalign()
[xfstests-dev.git] / check
1 #!/bin/bash
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 # print out our test configuration
165 echo "FSTYP         -- `_full_fstyp_details`"
166 echo "PLATFORM      -- `_full_platform_details`"
167 if [ ! -z "$SCRATCH_DEV" ]; then
168   echo "MKFS_OPTIONS  -- `_scratch_mkfs_options`"
169   echo "MOUNT_OPTIONS -- `_scratch_mount_options`"
170 fi
171 echo
172
173
174 if [ ! -z "$SCRATCH_DEV" ]; then
175   umount $SCRATCH_DEV 2>/dev/null
176   # call the overridden mkfs - make sure the FS is built
177   # the same as we'll create it later.
178
179   if ! _scratch_mkfs $flag >$tmp.err 2>&1
180   then
181       echo "our local _scratch_mkfs routine ..."
182       cat $tmp.err
183       echo "check: failed to mkfs \$SCRATCH_DEV using specified options"
184       exit 1
185   fi
186
187   # call the overridden mount - make sure the FS mounts with
188   # the same options that we'll mount with later.
189   if ! _scratch_mount >$tmp.err 2>&1
190   then
191       echo "our local mount routine ..."
192       cat $tmp.err
193       echo "check: failed to mount \$SCRATCH_DEV using specified options"
194       exit 1
195   fi
196 fi
197
198 seq="check"
199 _check_test_fs
200
201 [ -n "$TESTS_REMAINING_LOG" ] && echo $list > $TESTS_REMAINING_LOG
202
203 for seq in $list
204 do
205     err=false
206     echo -n "$seq"
207     if [ -n "$TESTS_REMAINING_LOG" ] ; then
208         sed -e "s/$seq//" -e 's/  / /' -e 's/^ *//' $TESTS_REMAINING_LOG > $TESTS_REMAINING_LOG.tmp
209         mv $TESTS_REMAINING_LOG.tmp $TESTS_REMAINING_LOG
210         sync
211     fi
212
213     if $showme
214     then
215         echo
216         continue
217     elif [ -f expunged ] && $expunge && egrep "^$seq([  ]|\$)" expunged >/dev/null
218     then
219         echo " - expunged"
220         rm -f $seq.out.bad
221         echo "/^$seq\$/d" >>$tmp.expunged
222     elif [ ! -f $seq ]
223     then
224         echo " - no such test?"
225         echo "/^$seq\$/d" >>$tmp.expunged
226     else
227         # really going to try and run this one
228         #
229         rm -f $seq.out.bad
230         lasttime=`sed -n -e "/^$seq /s/.* //p" <check.time`
231         if [ "X$lasttime" != X ]; then
232                 echo -n " ${lasttime}s ..."
233         else
234                 echo -n "       "       # prettier output with timestamps.
235         fi
236         rm -f core $seq.notrun
237
238         # for hangcheck ...
239         echo "$seq" >/tmp/check.sts
240
241         start=`_wallclock`
242         $timestamp && echo -n " ["`date "+%T"`"]"
243         [ ! -x $seq ] && chmod u+x $seq # ensure we can run it
244         ./$seq >$tmp.rawout 2>&1
245         sts=$?
246         $timestamp && _timestamp
247         stop=`_wallclock`
248
249         _fix_malloc <$tmp.rawout >$tmp.out
250         rm -f $tmp.rawout
251
252         if [ -f core ]
253         then
254             echo -n " [dumped core]"
255             mv core $seq.core
256             err=true
257         fi
258
259         if [ -f $seq.notrun ]
260         then
261             $timestamp || echo -n " [not run] "
262             $timestamp && echo " [not run]" && echo -n "        $seq -- "
263             cat $seq.notrun
264             notrun="$notrun $seq"
265         else
266             if [ $sts -ne 0 ]
267             then
268                 echo -n " [failed, exit status $sts]"
269                 err=true
270             fi
271             if [ ! -f $seq.out ]
272             then
273                 echo " - no qualified output"
274                 err=true
275             else
276                 if diff $seq.out $tmp.out >/dev/null 2>&1
277                 then
278                     if $err
279                     then
280                         :
281                     else
282                         echo "$seq `expr $stop - $start`" >>$tmp.time
283                         echo -n " `expr $stop - $start`s"
284                     fi
285                     echo ""
286                 else
287                     echo " - output mismatch (see $seq.out.bad)"
288                     mv $tmp.out $seq.out.bad
289                     $diff $seq.out $seq.out.bad
290                     err=true
291                 fi
292             fi
293         fi
294
295     fi
296
297     # come here for each test, except when $showme is true
298     #
299     if $err
300     then
301         bad="$bad $seq"
302         n_bad=`expr $n_bad + 1`
303         quick=false
304     fi
305     if [ ! -f $seq.notrun ]
306     then
307         try="$try $seq"
308         n_try=`expr $n_try + 1`
309         _check_test_fs
310     fi
311     
312     seq="after_$seq"
313 done
314
315 interrupt=false
316 status=`expr $n_bad`
317 exit