Add GPL license plate to SGI's test files.
[xfstests-dev.git] / 009
1 #! /bin/sh
2 #
3 #-----------------------------------------------------------------------
4 # Copyright (c) 2000-2002 Silicon Graphics, Inc.  All Rights Reserved.
5 #
6 # This program is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License as
8 # published by the Free Software Foundation.
9 #
10 # This program is distributed in the hope that it would be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write the Free Software Foundation,
17 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18 #
19 #-----------------------------------------------------------------------
20 #
21 # FS QA Test No. 009
22 #
23 # XFS allocator test (preallocation - allocp, resvsp ,etc)
24 #
25 # creator
26 owner=dxm@sgi.com
27
28 seq=`basename $0`
29 echo "QA output created by $seq"
30
31 here=`pwd`
32 tmp=/tmp/$$
33 status=1        # failure is the default!
34 trap "_cleanup; exit \$status" 0 1 2 3 15
35 # This isn't really related to fs block size, it's just what
36 # alloc uses for the "block" unit in it's input parameters...
37 bsize=4096
38
39 _cleanup()
40 {
41     echo "*** unmount"
42     umount $SCRATCH_MNT
43 }
44
45 _block_filter()
46 {
47    sed \
48         -e 's/[0-9][0-9]*\.\.[0-9][0-9]*/BLOCKRANGE/g' \
49         -e "s/blocksize $bsize/blocksize BSIZE/g"
50 }
51
52 _init()
53 {
54     echo "*** mkfs"
55     if ! _scratch_mkfs_xfs >$tmp.out 2>&1
56     then
57         cat $tmp.out
58         echo "failed to mkfs $SCRATCH_DEV"
59         exit 1
60     fi
61
62     echo "*** mount"
63     if ! _scratch_mount
64     then
65         echo "failed to mount $SCRATCH_DEV"
66         exit 1
67     fi
68 }
69
70 _filesize()
71 {
72     ls -l $1 | $AWK_PROG '{print "filesize = " $5}'
73 }
74
75 # get standard environment, filters and checks
76 . ./common.rc
77 . ./common.filter
78
79 # real QA test starts here
80 _supported_fs xfs
81 _supported_os IRIX Linux
82
83 _require_scratch
84
85 _init
86 out=$SCRATCH_MNT/$$.tmp
87
88 # since we're using a clean FS here, we make some assumptions
89 # about availability of contiguous blocks
90
91 # also interesting to note is that ALLOC == FREE. seriously.
92 # the _length is ignored_ in irix. the file is allocated up
93 # to the specified offset, and zero filled if previously
94 # unallocated. the file is truncated at the specified point.
95
96 echo "*** test 1 - reservations cleared on O_TRUNC"
97 rm -f $out
98 cat <<EOF | src/alloc -n -b $bsize -f $out | _block_filter
99 r 0 1000b
100 m
101 EOF
102 _filesize $out
103
104 cat <<EOF | src/alloc -n -b $bsize -f $out -t | _block_filter
105 m
106 EOF
107 _filesize $out
108
109 echo "*** test 2 - reserve & filesize"
110 rm -f $out
111 cat <<EOF | src/alloc -n -b $bsize -f $out | _block_filter
112 r 0 1000b
113 EOF
114
115 _filesize $out
116
117 echo "*** test 3 - alloc & filesize"
118 rm -f $out
119 cat <<EOF | src/alloc -n -b $bsize -f $out | _block_filter
120 a 1000b
121 EOF
122
123 _filesize $out
124
125 echo "*** test 4 - allocations cleared on O_TRUNC"
126 rm -f $out
127 cat <<EOF | src/alloc -n -b $bsize -f $out | _block_filter
128 a 1000b
129 EOF
130 _filesize $out
131
132 cat <<EOF | src/alloc -n -b $bsize -f $out -t | _block_filter
133 m
134 EOF
135 _filesize $out
136
137 echo "*** test 5 - reserve / unreserve"
138 rm -f $out
139 cat <<EOF | src/alloc -n -b $bsize -f $out | _block_filter
140 r 0 100b
141 u 100b 500b
142 m
143 u 900b 200b
144 m
145 EOF
146
147 echo "*** test 6 - reserve adjacent"
148 rm -f $out
149 cat <<EOF | src/alloc -t -n -b $bsize -f $out | _block_filter
150 r 0 100b
151 r 100b 100b
152 m
153 EOF
154
155 echo "*** test 7 - alloc"
156 rm -f $out
157 cat <<EOF | src/alloc -n -b $bsize -f $out | _block_filter
158 a 1000b
159 m
160 a 2000b
161 m
162 EOF
163
164 _filesize $out
165
166 echo "*** test 8 - alloc & truncate"
167 rm -f $out
168 cat <<EOF | src/alloc -n -b $bsize -f $out | _block_filter
169 a 1000b
170 m
171 t 500b
172 m
173 EOF
174
175 _filesize $out
176
177 echo "*** test 9 - reserve & truncate"
178 rm -f $out
179 cat <<EOF | src/alloc -n -b $bsize -f $out | _block_filter
180 r 0 1000b
181 m
182 t 500b
183 m
184 EOF
185
186 _filesize $out
187
188
189 status=0
190 exit