xfstests: some refinements on "make depend"
[xfstests-dev.git] / 009
1 #! /bin/bash
2 # FS QA Test No. 009
3 #
4 # XFS allocator test (preallocation - allocp, resvsp ,etc)
5 #
6 #-----------------------------------------------------------------------
7 # Copyright (c) 2000-2002 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=1        # failure is the default!
33 trap "_cleanup; exit \$status" 0 1 2 3 15
34 # This isn't really related to fs block size, it's just what
35 # alloc uses for the "block" unit in it's input parameters...
36 bsize=4096
37
38 _cleanup()
39 {
40     echo "*** unmount"
41     umount $SCRATCH_MNT
42 }
43
44 _block_filter()
45 {
46    sed \
47         -e 's/[0-9][0-9]*\.\.[0-9][0-9]*/BLOCKRANGE/g' \
48         -e "s/blocksize $bsize/blocksize BSIZE/g"
49 }
50
51 _init()
52 {
53     echo "*** mkfs"
54     if ! _scratch_mkfs_xfs >$tmp.out 2>&1
55     then
56         cat $tmp.out
57         echo "failed to mkfs $SCRATCH_DEV"
58         exit 1
59     fi
60
61     echo "*** mount"
62     if ! _scratch_mount
63     then
64         echo "failed to mount $SCRATCH_DEV"
65         exit 1
66     fi
67 }
68
69 _filesize()
70 {
71     ls -l $1 | $AWK_PROG '{print "filesize = " $5}'
72 }
73
74 # get standard environment, filters and checks
75 . ./common.rc
76 . ./common.filter
77
78 # real QA test starts here
79 _supported_fs xfs
80 _supported_os IRIX Linux
81
82 _require_scratch
83
84 _init
85 out=$SCRATCH_MNT/$$.tmp
86
87 # since we're using a clean FS here, we make some assumptions
88 # about availability of contiguous blocks
89
90 # also interesting to note is that ALLOC == FREE. seriously.
91 # the _length is ignored_ in irix. the file is allocated up
92 # to the specified offset, and zero filled if previously
93 # unallocated. the file is truncated at the specified point.
94
95 echo "*** test 1 - reservations cleared on O_TRUNC"
96 rm -f $out
97 cat <<EOF | src/alloc -n -b $bsize -f $out | _block_filter
98 r 0 1000b
99 m
100 EOF
101 _filesize $out
102
103 cat <<EOF | src/alloc -n -b $bsize -f $out -t | _block_filter
104 m
105 EOF
106 _filesize $out
107
108 echo "*** test 2 - reserve & filesize"
109 rm -f $out
110 cat <<EOF | src/alloc -n -b $bsize -f $out | _block_filter
111 r 0 1000b
112 EOF
113
114 _filesize $out
115
116 echo "*** test 3 - alloc & filesize"
117 rm -f $out
118 cat <<EOF | src/alloc -n -b $bsize -f $out | _block_filter
119 a 1000b
120 EOF
121
122 _filesize $out
123
124 echo "*** test 4 - allocations cleared on O_TRUNC"
125 rm -f $out
126 cat <<EOF | src/alloc -n -b $bsize -f $out | _block_filter
127 a 1000b
128 EOF
129 _filesize $out
130
131 cat <<EOF | src/alloc -n -b $bsize -f $out -t | _block_filter
132 m
133 EOF
134 _filesize $out
135
136 echo "*** test 5 - reserve / unreserve"
137 rm -f $out
138 cat <<EOF | src/alloc -n -b $bsize -f $out | _block_filter
139 r 0 100b
140 u 100b 500b
141 m
142 u 900b 200b
143 m
144 EOF
145
146 echo "*** test 6 - reserve adjacent"
147 rm -f $out
148 cat <<EOF | src/alloc -t -n -b $bsize -f $out | _block_filter
149 r 0 100b
150 r 100b 100b
151 m
152 EOF
153
154 echo "*** test 7 - alloc"
155 rm -f $out
156 cat <<EOF | src/alloc -n -b $bsize -f $out | _block_filter
157 a 1000b
158 m
159 a 2000b
160 m
161 EOF
162
163 _filesize $out
164
165 echo "*** test 8 - alloc & truncate"
166 rm -f $out
167 cat <<EOF | src/alloc -n -b $bsize -f $out | _block_filter
168 a 1000b
169 m
170 t 500b
171 m
172 EOF
173
174 _filesize $out
175
176 echo "*** test 9 - reserve & truncate"
177 rm -f $out
178 cat <<EOF | src/alloc -n -b $bsize -f $out | _block_filter
179 r 0 1000b
180 m
181 t 500b
182 m
183 EOF
184
185 _filesize $out
186
187
188 status=0
189 exit