5e1cc7a09bab946e9d3d464aed3f764e019ff688
[xfstests-dev.git] / tests / xfs / 012
1 #! /bin/bash
2 # FS QA Test No. 012
3 #
4 # holes
5 #
6 #-----------------------------------------------------------------------
7 # Copyright (c) 2000-2001 Silicon Graphics, Inc.  All Rights Reserved.
8 #
9 # This program is free software; you can redistribute it and/or
10 # modify it under the terms of the GNU General Public License as
11 # published by the Free Software Foundation.
12 #
13 # This program is distributed in the hope that it would be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write the Free Software Foundation,
20 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
21 #
22 #-----------------------------------------------------------------------
23 #
24
25 seq=`basename $0`
26 seqres=$RESULT_DIR/$seq
27 seqres=$RESULT_DIR/$seq
28 seqres=$RESULT_DIR/$seq
29 echo "QA output created by $seq"
30
31 here=`pwd`
32 tmp=/tmp/$$
33 status=0        # success is the default!
34 trap "_cleanup; exit \$status" 0 1 2 3 15
35
36 _cleanup()
37 {
38     cd /
39     rm -f $tmp.*
40     rm -rf $testdir/holes.$$.*
41     _cleanup_testdir
42 }
43
44 _filesize()
45 {
46     ls -l $1 | $AWK_PROG '{print "    filesize = " $5}'
47 }
48
49 # get standard environment, filters and checks
50 . ./common/rc
51 . ./common/filter
52
53 _do_test()
54 {
55     _n="$1"
56     _param="$2"
57     _count="$3"
58     
59     failed=0
60     
61     out=$testdir/holes.$$.$_n
62     echo ""
63     echo "holes.$_n : $_param"
64     echo "-----------------------------------------------"
65     if  ! $here/src/holes $_param $out >$tmp.out
66     then
67         echo "    holes returned $? - see $seqres.full"
68         failed=1
69         status=1
70     fi
71         
72
73     if [ $failed -eq 0 ]
74     then        
75         # quick check - how many holes did we get?
76         count=`xfs_bmap $out | egrep -c ': hole'`
77         echo "    $count hole(s) detected"
78         # and how big was the file?
79         _filesize $out
80         
81         if [ $count -ne $_count ]
82         then
83             echo "    unexpected number of holes - see $seqres.full"
84             status=1
85             failed=1
86         fi
87     fi
88         
89     if [ $failed -eq 1 ]
90     then
91         echo "--------------------------------------"       >>$seqres.full
92         echo "$_n - output from holes:"                     >>$seqres.full
93         echo "--------------------------------------"       >>$seqres.full
94         cat $tmp.out                                        >>$seqres.full
95         echo "--------------------------------------"       >>$seqres.full
96         echo "$_n - output from bmap:"                      >>$seqres.full
97         echo "--------------------------------------"       >>$seqres.full
98         xfs_bmap -vvv $out                                  >>$seqres.full
99         echo "--------------------------------------"       >>$seqres.full
100         echo "$_n - output from ls -li:"                    >>$seqres.full
101         echo "--------------------------------------"       >>$seqres.full
102         ls -li $out                                         >>$seqres.full
103         status=1
104     fi
105 }
106
107 # real QA test starts here
108 _supported_fs xfs
109 _supported_os IRIX Linux
110
111 _setup_testdir
112
113 rm -f $seqres.full
114
115 # small & fairly dense
116 _do_test 1 "-l 40960000 -b 40960 -i 10 -c 1" 100
117
118 # big & sparse
119 _do_test 2 "-l 409600000 -b 40960 -i 1000 -c 1" 10
120
121 # no holes, but a very nasty way to write a file (lots of extents)
122 _do_test 3 "-l 40960000 -b 40960 -i 10 -c 10" 0
123
124 exit