Put the output of fsx into seq.full and output all of seq.full on failure.
[xfstests-dev.git] / 004
1 #! /bin/sh
2 # FS QA Test No. 004
3 #
4 # exercise xfs_db bug #789674 and other freesp functionality
5 #
6 #-----------------------------------------------------------------------
7 # Copyright (c) 2000-2002 Silicon Graphics, Inc.  All Rights Reserved.
8 #-----------------------------------------------------------------------
9 #
10 # creator
11 owner=nathans@sgi.com
12
13 seq=`basename $0`
14 echo "QA output created by $seq"
15
16 here=`pwd`
17 tmp=/tmp/$$
18 status=0
19
20 _cleanup()
21 {
22         umount $SCRATCH_MNT
23         rm -f $tmp.*
24         exit $status
25 }
26 trap "_cleanup" 0 1 2 3 15
27
28 _populate_scratch()
29 {
30         echo "=== mkfs output ===" >>$seq.full
31         _scratch_mkfs_xfs | tee -a $seq.full | _filter_mkfs 2>$tmp.mkfs
32         . $tmp.mkfs
33         _scratch_mount
34         dd if=/dev/zero of=$SCRATCH_MNT/foo count=200 bs=4096 >/dev/null 2>&1 &
35         dd if=/dev/zero of=$SCRATCH_MNT/goo count=400 bs=4096 >/dev/null 2>&1 &
36         dd if=/dev/zero of=$SCRATCH_MNT/moo count=800 bs=4096 >/dev/null 2>&1 &
37         wait
38         umount $SCRATCH_MNT                     # flush everything
39         _scratch_mount                          # and then remount
40 }
41
42
43 # get standard environment, filters and checks
44 . ./common.rc
45 . ./common.filter
46
47 # real QA test starts here
48 _supported_fs xfs
49 _supported_os IRIX Linux
50
51 _need_to_be_root
52 _require_scratch
53 _require_nobigloopfs
54
55 rm -f $seq.full
56
57 _populate_scratch
58
59 [ "$HOSTOS" = "Linux" ] && DF_PROG="$DF_PROG -P --block-size=512"
60
61 eval `$DF_PROG $SCRATCH_MNT 2>&1 \
62         | tail -1 | $AWK_PROG '{ printf "blocks=%u used=%u avail=%u\n", $3, $4, $5 }'`
63 echo "df gave: blocks=$blocks used=$used avail=$avail" >>$seq.full
64 echo "blocksize from mkfs is '$dbsize'" >>$seq.full
65
66 xfs_db -r -c "freesp -s" $SCRATCH_DEV >$tmp.xfs_db
67 echo "xfs_db for $SCRATCH_DEV" >>$seq.full
68 cat $tmp.xfs_db >>$seq.full
69
70 # check the 'blocks' field from freesp command is OK
71 # since 2.6.18, df does not report the 4 blocks per AG that cannot
72 # be allocated, hence we check for that exact mismatch.
73 perl -ne '
74             BEGIN       { $avail ='$avail' * 512;
75                           $answer="(no xfs_db free blocks line?)" }
76             /free blocks (\d+)$/        || next;
77             $freesp = $1 * '$dbsize';
78             if ($freesp == $avail)      { $answer = "yes"; }
79             else {
80                 $avail = $avail + (('$agcount' + 1) * '$dbsize' * 4);
81                 if ($freesp == $avail)  { $answer = "yes"; }
82                 else                    { $answer = "no ($freesp != $avail)"; }
83             }
84             END { print "$answer\n" }
85         ' <$tmp.xfs_db >$tmp.ans
86 ans="`cat $tmp.ans`"
87 echo "Checking blocks column same as df: $ans"
88 if [ "$ans" != yes ]
89 then
90         echo "Error: $SCRATCH_DEV: freesp mismatch: $ans"
91         echo "xfs_db output ..."
92         cat $tmp.xfs_db
93         status=1
94 fi
95
96 # check the 'pct' field from freesp command is good
97 perl -ne '
98             BEGIN       { $percent = 0; }
99             /free/      && next;        # skip over free extent size number
100             if (/\s+(\d+\.\d+)$/) {
101                 $percent += $1;
102             }
103             END { $percent += 0.5; print int($percent), "\n" }  # round up
104 ' <$tmp.xfs_db >$tmp.ans
105 ans="`cat $tmp.ans`"
106 echo "Checking percent column yields 100: $ans"
107 if [ "$ans" != 100 ]
108 then
109         echo "Error: $SCRATCH_DEV: pct mismatch: $ans (expected 100)"
110         echo "xfs_db output ..."
111         cat $tmp.xfs_db
112         status=1
113 fi
114
115 exit