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