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