fsstress: translate flags in fiemap_f
[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 diff="diff -u"
32 showme=false
33 have_test_arg=false
34 randomize=false
35 export here=`pwd`
36 xfile=""
37
38 # start the initialisation work now
39 iam=check
40
41 export MSGVERB="text:action"
42 export QA_CHECK_FS=${QA_CHECK_FS:=true}
43
44 # number of diff lines from a failed test, 0 for whole output
45 export DIFF_LENGTH=${DIFF_LENGTH:=10}
46
47 # by default don't output timestamps
48 timestamp=${TIMESTAMP:=false}
49
50 rm -f $tmp.list $tmp.tmp $tmp.grep $here/$iam.out $tmp.xlist
51
52 # we need common/config
53 if ! . ./common/config
54 then
55     echo "$iam: failed to source common/config"
56     exit 1
57 fi
58
59 # Autodetect fs type based on what's on $TEST_DEV unless it's been set
60 # externally
61 if [ -z "$FSTYP" -a "$HOSTOS" == "Linux" ]; then
62     FSTYP=`blkid -c /dev/null -s TYPE -o value $TEST_DEV`
63 fi
64 FSTYP=${FSTYP:=xfs}
65 export FSTYP
66
67 SUPPORTED_TESTS="[0-9][0-9][0-9] [0-9][0-9][0-9][0-9]"
68 SRC_GROUPS="generic shared"
69 export SRC_DIR="tests"
70
71 usage()
72 {
73     echo "Usage: $0 [options] [testlist]"'
74
75 check options
76     -nfs                test NFS
77     -tmpfs              test TMPFS
78     -l                  line mode diff
79     -udiff              show unified diff (default)
80     -n                  show me, do not run tests
81     -T                  output timestamps
82     -r                  randomize test order
83     --large-fs          optimise scratch device for large filesystems
84
85 testlist options
86     -g group[,group...] include tests from these groups
87     -x group[,group...] exclude tests from these groups
88     -X file             exclude individual tests
89     [testlist]          include tests matching names in testlist
90 '
91             exit 0
92 }
93
94 get_group_list()
95 {
96         grp=$1
97
98         for d in $SRC_GROUPS $FSTYP; do
99                 l=$(sed -n < $SRC_DIR/$d/group \
100                         -e 's/#.*//' \
101                         -e 's/$/ /' \
102                         -e "s;\(^[0-9][0-9][0-9]\).* $grp .*;$SRC_DIR/$d/\1;p")
103                 grpl="$grpl $l"
104         done
105         echo $grpl
106 }
107
108 # find all tests, excluding files that are test metadata such as group files.
109 # This assumes that tests are defined purely by alphanumeric filenames with no
110 # ".xyz" extensions in the name.
111 get_all_tests()
112 {
113         touch $tmp.list
114         for d in $SRC_GROUPS $FSTYP; do
115                 ls $SRC_DIR/$d/* | \
116                         grep -v "\..*" | \
117                         grep -v "group\|Makefile" >> $tmp.list 2>/dev/null
118         done
119 }
120
121 # takes the list of tests to run in $tmp.list, and removes the tests passed to
122 # the function from that list.
123 trim_test_list()
124 {
125         test_list="$*"
126
127         rm -f $tmp.grep
128         numsed=0
129         for t in $test_list
130         do
131             if [ $numsed -gt 100 ]; then
132                 grep -v -f $tmp.grep <$tmp.list >$tmp.tmp
133                 mv $tmp.tmp $tmp.list
134                 numsed=0
135                 rm -f $tmp.grep
136             fi
137             echo "^$t\$" >>$tmp.grep
138             numsed=`expr $numsed + 1`
139         done
140         grep -v -f $tmp.grep <$tmp.list >$tmp.tmp
141         mv $tmp.tmp $tmp.list
142 }
143
144
145 _wallclock()
146 {
147     date "+%H %M %S" | $AWK_PROG '{ print $1*3600 + $2*60 + $3 }'
148 }
149
150 _timestamp()
151 {
152     now=`date "+%T"`
153     echo -n " [$now]"
154 }
155
156 _prepare_test_list()
157 {
158         unset list
159         # Tests specified on the command line
160         if [ -s $tmp.arglist ]; then
161                 cat $tmp.arglist > $tmp.list
162         else
163                 touch $tmp.list
164         fi
165
166         # Specified groups to include
167         for group in $GROUP_LIST; do
168                 list=$(get_group_list $group)
169                 if [ -z "$list" ]; then
170                         echo "Group \"$group\" is empty or not defined?"
171                         exit 1
172                 fi
173
174                 for t in $list; do
175                         grep -s "^$t\$" $tmp.list >/dev/null || \
176                                                         echo "$t" >>$tmp.list
177                 done
178         done
179
180         if ! $have_test_arg && [ -z "$GROUP_LIST" ]; then
181                 # no test numbers, do everything
182                 get_all_tests
183         fi
184
185         # Specified groups to exclude
186         for xgroup in $XGROUP_LIST; do
187                 list=$(get_group_list $xgroup)
188                 if [ -z "$list" ]; then
189                         echo "Group \"$xgroup\" is empty or not defined?"
190                         exit 1
191                 fi
192
193                 trim_test_list $list
194         done
195
196         # sort the list of tests into numeric order
197         list=`sort -n $tmp.list | uniq`
198         rm -f $tmp.list $tmp.tmp $tmp.grep
199
200         if $randomize
201         then
202                 list=`echo $list | awk -f randomize.awk`
203         fi
204 }
205
206 # Process command arguments first.
207 while [ $# -gt 0 ]; do
208         case "$1" in
209         -\? | -h | --help) usage ;;
210
211         -nfs)   FSTYP=nfs ;;
212         -tmpfs) FSTYP=tmpfs ;;
213
214         -g)     group=$2 ; shift ;
215                 GROUP_LIST="$GROUP_LIST $group"
216                 ;;
217
218         -x)     xgroup=$2 ; shift ;
219                 XGROUP_LIST="$XGROUP_LIST $xgroup"
220                 ;;
221
222         -X)     xfile=$2; shift ;
223                 for d in $SRC_GROUPS $FSTYP; do
224                         [ -f $SRC_DIR/$d/$xfile ] || continue
225                         for f in `cat $SRC_DIR/$d/$xfile`; do
226                                 echo $d/$f >> $tmp.xlist
227                         done
228                 done
229                 ;;
230
231         -l)     diff="diff" ;;
232         -udiff) diff="$diff -u" ;;
233
234         -n)     showme=true ;;
235         -r)     randomize=true ;;
236
237         -T)     timestamp=true ;;
238
239         --large-fs) export LARGE_SCRATCH_DEV=yes ;;
240         --extra-space=*) export SCRATCH_DEV_EMPTY_SPACE=${r#*=} ;;
241
242         -*)     usage ;;
243         *)      # not an argument, we've got tests now.
244                 have_test_arg=true ;;
245         esac
246
247         # if we've found a test specification, the break out of the processing
248         # loop before we shift the arguments so that this is the first argument
249         # that we process in the test arg loop below.
250         if $have_test_arg; then
251                 break;
252         fi
253
254         shift
255 done
256
257 # Process tests from command line now.
258 if $have_test_arg; then
259         while [ $# -gt 0 ]; do
260                 case "$1" in
261                 -*)     echo "Argments before tests, please!"
262                         status=1
263                         exit $status
264                         ;;
265                 *)      test_dir=`dirname $1`
266                         test_dir=${test_dir#$SRC_DIR/*}
267                         test_name=`basename $1`
268                         group_file=$SRC_DIR/$test_dir/group
269
270                         if egrep "^$test_name" $group_file >/dev/null ; then
271                                 # in group file ... OK
272                                 echo $SRC_DIR/$test_dir/$test_name >>$tmp.arglist
273                         else
274                                 # oops
275                                 echo "$1 - unknown test, ignored"
276                         fi
277                         ;;
278                 esac
279
280                 shift
281         done
282 fi
283
284 _prepare_test_list
285
286 # we need common/rc
287 if ! . ./common/rc
288 then
289     echo "check: failed to source common/rc"
290     exit 1
291 fi
292
293 if [ `id -u` -ne 0 ]
294 then
295     echo "check: QA must be run as root"
296     exit 1
297 fi
298
299 # Ok, time to start running...
300
301 _wrapup()
302 {
303     seq="check"
304     check="$RESULT_BASE/check"
305
306     if $showme
307     then
308         :
309     elif $needwrap
310     then
311         if [ -f $check.time -a -f $tmp.time ]
312         then
313             cat $check.time $tmp.time \
314             | $AWK_PROG '
315         { t[$1] = $2 }
316 END     { if (NR > 0) {
317             for (i in t) print i " " t[i]
318           }
319         }' \
320             | sort -n >$tmp.out
321             mv $tmp.out $check.time
322         fi
323
324         echo "" >>$check.log
325         date >>$check.log
326         echo $list | fmt | sed -e 's/^/    /' -e "s;$SRC_DIR/;;g" >>$check.log
327         $interrupt && echo "Interrupted!" >>$check.log
328         
329         if [ ! -z "$n_try" -a $n_try != 0 ]
330         then
331             echo "Ran:$try"
332         fi
333
334         if [ ! -z "$notrun" ]
335         then
336             echo "Not run:$notrun"
337             echo "Not run:$notrun" >>$check.log
338         fi
339
340         if [ ! -z "$n_bad" -a $n_bad != 0 ]
341         then
342             echo "Failures:$bad"
343             echo "Failed $n_bad of $n_try tests"
344             echo "Failures:$bad" | fmt >>$check.log
345             echo "Failed $n_bad of $n_try tests" >>$check.log
346         else
347             echo "Passed all $n_try tests"
348             echo "Passed all $n_try tests" >>$check.log
349         fi
350         needwrap=false
351     fi
352
353     rm -f /tmp/*.rawout /tmp/*.out /tmp/*.err /tmp/*.time
354     rm -f $tmp.*
355 }
356
357 trap "_wrapup; exit \$status" 0 1 2 3 15
358
359 mkdir -p $RESULT_BASE
360 if [ ! -d $RESULT_BASE ]; then
361         echo "failed to create results directory $RESULTS_BASE"
362         exit 1;
363 fi
364
365 seq="check"
366 check="$RESULT_BASE/check"
367
368 # don't leave old full output behind on a clean run
369 rm -f $check.full
370
371 [ -f $check.time ] || touch $check.time
372
373 # print out our test configuration
374 echo "FSTYP         -- `_full_fstyp_details`"
375 echo "PLATFORM      -- `_full_platform_details`"
376 if [ ! -z "$SCRATCH_DEV" ]; then
377   echo "MKFS_OPTIONS  -- `_scratch_mkfs_options`"
378   echo "MOUNT_OPTIONS -- `_scratch_mount_options`"
379 fi
380 echo
381
382
383 if [ ! -z "$SCRATCH_DEV" ]; then
384   umount $SCRATCH_DEV 2>/dev/null
385   # call the overridden mkfs - make sure the FS is built
386   # the same as we'll create it later.
387
388   if ! _scratch_mkfs $flag >$tmp.err 2>&1
389   then
390       echo "our local _scratch_mkfs routine ..."
391       cat $tmp.err
392       echo "check: failed to mkfs \$SCRATCH_DEV using specified options"
393       exit 1
394   fi
395
396   # call the overridden mount - make sure the FS mounts with
397   # the same options that we'll mount with later.
398   if ! _scratch_mount >$tmp.err 2>&1
399   then
400       echo "our local mount routine ..."
401       cat $tmp.err
402       echo "check: failed to mount \$SCRATCH_DEV using specified options"
403       exit 1
404   fi
405 fi
406
407 seqres="$check"
408 _check_test_fs
409
410 for seq in $list
411 do
412     err=false
413
414     # the filename for the test and the name output are different.
415     # we don't include the tests/ directory in the name output.
416     seqnum=`echo $seq | sed -e "s;$SRC_DIR/;;"`
417
418     # Similarly, the result directory needs to replace the tests/
419     # part of the test location.
420     group=`dirname $seq`
421     export RESULT_DIR=`echo $group | sed -e "s;$SRC_DIR;$RESULT_BASE;"`
422     mkdir -p $RESULT_DIR
423     seqres="$RESULT_BASE/$seqnum"
424
425     echo -n "$seqnum"
426
427     if $showme
428     then
429         echo
430         continue
431     elif [ ! -f $seq ]
432     then
433         echo " - no such test?"
434     else
435         # really going to try and run this one
436         #
437         rm -f $seqres.out.bad
438
439         # check if we really should run it
440         if [ -s $tmp.xlist ]; then
441                 if grep $seqnum $tmp.xlist > /dev/null 2>&1 ; then
442                         echo "       [expunged]"
443                         continue
444                 fi
445         fi
446
447         # slashes now in names, sed barfs on them so use grep
448         lasttime=`grep -w ^$seqnum $check.time | awk '// {print $2}'`
449         if [ "X$lasttime" != X ]; then
450                 echo -n " ${lasttime}s ..."
451         else
452                 echo -n "       "       # prettier output with timestamps.
453         fi
454         rm -f core $seqres.notrun
455
456         start=`_wallclock`
457         $timestamp && echo -n " ["`date "+%T"`"]"
458         [ ! -x $seq ] && chmod u+x $seq # ensure we can run it
459         $LOGGER_PROG "run xfstest $seqnum"
460         ./$seq >$tmp.rawout 2>&1
461         sts=$?
462         $timestamp && _timestamp
463         stop=`_wallclock`
464
465         _fix_malloc <$tmp.rawout >$tmp.out
466         rm -f $tmp.rawout
467
468         if [ -f core ]
469         then
470             echo -n " [dumped core]"
471             mv core $RESULT_BASE/$seqnum.core
472             err=true
473         fi
474
475         if [ -f $seqres.notrun ]
476         then
477             $timestamp || echo -n " [not run] "
478             $timestamp && echo " [not run]" && echo -n "        $seqnum -- "
479             cat $seqres.notrun
480             notrun="$notrun $seqnum"
481         else
482             if [ $sts -ne 0 ]
483             then
484                 echo -n " [failed, exit status $sts]"
485                 err=true
486             fi
487             if [ ! -f $seq.out ]
488             then
489                 echo " - no qualified output"
490                 err=true
491             else
492
493                 # coreutils 8.16+ changed quote formats in error messages from
494                 # `foo' to 'foo'. Filter old versions to match the new version.
495                 sed -i "s/\`/\'/g" $tmp.out
496                 if diff $seq.out $tmp.out >/dev/null 2>&1
497                 then
498                     if $err
499                     then
500                         :
501                     else
502                         echo "$seqnum `expr $stop - $start`" >>$tmp.time
503                         echo -n " `expr $stop - $start`s"
504                     fi
505                     echo ""
506                 else
507                     echo " - output mismatch (see $seqres.out.bad)"
508                     mv $tmp.out $seqres.out.bad
509                     $diff $seq.out $seqres.out.bad | {
510                         if test "$DIFF_LENGTH" -le 0; then
511                                 cat
512                         else
513                                 head -n "$DIFF_LENGTH"
514                                 echo "..."
515                                 echo "(Run '$diff $seq.out $seqres.out.bad'" \
516                                         " to see the entire diff)"
517                         fi; } | \
518                         sed -e 's/^\(.\)/    \1/'
519                     err=true
520                 fi
521             fi
522         fi
523
524     fi
525
526     # come here for each test, except when $showme is true
527     #
528     if $err
529     then
530         bad="$bad $seqnum"
531         n_bad=`expr $n_bad + 1`
532         quick=false
533     fi
534     if [ ! -f $seqres.notrun ]
535     then
536         try="$try $seqnum"
537         n_try=`expr $n_try + 1`
538         _check_test_fs
539     fi
540
541     seq="after_$seqnum"
542 done
543
544 interrupt=false
545 status=`expr $n_bad`
546 exit