123c7a3b956aa26ba340e43f1d1fb81484917ca2
[xfstests-dev.git] / 012
1 #! /bin/sh
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 # creator
25 owner=dxm@sgi.com
26
27 seq=`basename $0`
28 echo "QA output created by $seq"
29
30 here=`pwd`
31 tmp=/tmp/$$
32 status=0        # success is the default!
33 trap "_cleanup; exit \$status" 0 1 2 3 15
34
35 _cleanup()
36 {
37     cd /
38     rm -f $tmp.*
39     rm -rf $testdir/holes.$$.*
40     _cleanup_testdir
41 }
42
43 _filesize()
44 {
45     ls -l $1 | $AWK_PROG '{print "    filesize = " $5}'
46 }
47
48 # get standard environment, filters and checks
49 . ./common.rc
50 . ./common.filter
51
52 _do_test()
53 {
54     _n="$1"
55     _param="$2"
56     _count="$3"
57     
58     failed=0
59     
60     out=$testdir/holes.$$.$_n
61     echo ""
62     echo "holes.$_n : $_param"
63     echo "-----------------------------------------------"
64     if  ! $here/src/holes $_param $out >$tmp.out
65     then
66         echo "    holes returned $? - see $seq.out.full"
67         failed=1
68         status=1
69     fi
70         
71
72     if [ $failed -eq 0 ]
73     then        
74         # quick check - how many holes did we get?
75         count=`xfs_bmap $out | egrep -c ': hole'`
76         echo "    $count hole(s) detected"
77         # and how big was the file?
78         _filesize $out
79         
80         if [ $count -ne $_count ]
81         then
82             echo "    unexpected number of holes - see $seq.out.full"
83             status=1
84             failed=1
85         fi
86     fi
87         
88     if [ $failed -eq 1 ]
89     then
90         echo "--------------------------------------"       >>$here/$seq.out.full
91         echo "$_n - output from holes:"                     >>$here/$seq.out.full
92         echo "--------------------------------------"       >>$here/$seq.out.full
93         cat $tmp.out                                        >>$here/$seq.out.full
94         echo "--------------------------------------"       >>$here/$seq.out.full
95         echo "$_n - output from bmap:"                      >>$here/$seq.out.full
96         echo "--------------------------------------"       >>$here/$seq.out.full
97         xfs_bmap -vvv $out                                  >>$here/$seq.out.full
98         echo "--------------------------------------"       >>$here/$seq.out.full
99         echo "$_n - output from ls -li:"                    >>$here/$seq.out.full
100         echo "--------------------------------------"       >>$here/$seq.out.full
101         ls -li $out                                         >>$here/$seq.out.full
102         status=1
103     fi
104 }
105
106 # real QA test starts here
107 _supported_fs xfs
108 _supported_os IRIX Linux
109
110 _setup_testdir
111
112 rm -f $here/$seq.out.full
113
114 # small & fairly dense
115 _do_test 1 "-l 40960000 -b 40960 -i 10 -c 1" 100
116
117 # big & sparse
118 _do_test 2 "-l 409600000 -b 40960 -i 1000 -c 1" 10
119
120 # no holes, but a very nasty way to write a file (lots of extents)
121 _do_test 3 "-l 40960000 -b 40960 -i 10 -c 10" 0
122
123 exit