70728eaeead1d31a549e74f6008db76b7478fe87
[xfstests-dev.git] / tests / generic / 286
1 #! /bin/bash
2 # FS QA Test No. 286
3 #
4 # SEEK_DATA/SEEK_HOLE copy tests.
5 #
6 #-----------------------------------------------------------------------
7 # Copyright (c) 2011 Oracle 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
25 seq=`basename $0`
26 seqres=$RESULT_DIR/$seq
27 seqres=$RESULT_DIR/$seq
28 seqres=$RESULT_DIR/$seq
29 echo "QA output created by $seq"
30
31 here=`pwd`
32 status=1        # failure is the default!
33 trap "_cleanup; exit \$status" 0 1 2 3 15
34
35 # get standard environment, filters and checks
36 . ./common/rc
37 . ./common/filter
38
39 # real QA test starts here
40 _supported_fs generic
41 _supported_os Linux
42
43 src=$TEST_DIR/seek_copy_testfile
44 dest=$TEST_DIR/seek_copy_testfile.dest
45
46 [ -x $here/src/seek_copy_test ] || _notrun "seek_copy_test not built"
47
48 _cleanup()
49 {
50         rm -f $src $dest
51 }
52
53 # seek_copy_test_01: tests file with holes and written data extents.
54 # verify results:
55 # 1. file size is identical.
56 # 2. perform cmp(1) to compare SRC and DEST file byte by byte.
57 test01()
58 {
59         rm -f $src $dest
60
61         write_cmd="-c \"truncate 100m\""
62         for i in $(seq 0 5 100); do
63                 offset=$(($i * $((1 << 20))))
64                 write_cmd="$write_cmd -c \"pwrite $offset 1m\""
65         done
66
67         echo "*** test01() create sparse file ***" >>$seqres.full
68         eval ${XFS_IO_PROG} -F -f "${write_cmd}" $src >>$seqres.full 2>&1 ||
69                 _fail "create sparse file failed!"
70         echo "*** test01() create sparse file done ***" >>$seqres.full
71         echo >>$seqres.full
72
73         $here/src/seek_copy_test $src $dest
74         
75         test $(stat --printf "%s" $src) = $(stat --printf "%s" $dest) ||
76                 _fail "TEST01: file size check failed"
77
78         cmp $src $dest || _fail "TEST01: file bytes check failed"
79 }
80
81 # seek_copy_test_02 - tests file with holes, written and unwritten extents.
82 # verify results:
83 # 1. file size is identical.
84 # 2. perform cmp(1) to compare SRC and DEST file byte by byte.
85 test02()
86 {
87         rm -rf $src $dest
88
89         write_cmd="-c \"truncate 200m\""
90         for i in $(seq 0 10 100); do
91                 offset=$(($((6 << 20)) + $i * $((1 << 20))))
92                 write_cmd="$write_cmd -c \"falloc $offset 3m\" -c \"pwrite $offset 1m\""
93         done
94
95         echo "*** test02() create sparse file ***" >>$seqres.full
96         eval ${XFS_IO_PROG} -F -f "${write_cmd}" $src >>$seqres.full 2>&1 ||
97                 _fail "create sparse file failed!"
98         echo "*** test02() create sparse file done ***" >>$seqres.full
99         echo >>$seqres.full
100
101         $here/src/seek_copy_test $src $dest
102
103         test $(stat --printf "%s" $src) = $(stat --printf "%s" $dest) ||
104                 _fail "TEST02: file size check failed"
105
106         cmp $src $dest || _fail "TEST02: file bytes check failed"
107 }
108
109 # seek_copy_test_03 - tests file with unwritten with data, repeated unwritten
110 # without data, as well as data extents mapping.
111 # verify results:
112 # 1. file size is identical.
113 # 2. perform cmp(1) to compare SRC and DEST file byte by byte.
114 test03()
115 {
116         rm -rf $src $dest
117
118         write_cmd="-c \"truncate 200m\""
119
120         #
121         # Firstly, make the file with allocated && reserved extents
122         # mapping without real data wrote.
123         #
124         for i in $(seq 0 10 180); do
125                 offset=$(($((10 << 20)) + $i * $((1 << 20))))
126                 write_cmd="$write_cmd -c \"falloc $offset 10m\""
127         done
128
129         #
130         # Secondly, write data to some unwritten extents, hence we
131         # have a test file will extents mapping as:
132         # |data|multiple unwritten_without_data|data| repeat...
133         for i in $(seq 0 60 180); do
134                 offset=$(($((20 << 20)) + $i * $((1 << 20))))
135                 write_cmd="$write_cmd -c \"pwrite $offset 10m\""
136         done
137
138         echo "*** test03() create sparse file ***" >>$seqres.full
139         eval ${XFS_IO_PROG} -F -f "${write_cmd}" $src >>$seqres.full 2>&1 ||
140                 _fail "create sparse file failed!"
141         echo "*** test03() create sparse file done ***" >>$seqres.full
142         echo >>$seqres.full
143         $here/src/seek_copy_test $src $dest
144
145         test $(stat --printf "%s" $src) = $(stat --printf "%s" $dest) ||
146                 _fail "TEST03: file size check failed"
147
148         cmp $src $dest || _fail "TEST03: file bytes check failed"
149 }
150
151 # seek_copy_test_04 - tests file with hole, repeated unwritten
152 # without data, as well as data extents mapping.
153 # verify results:
154 # 1. file size is identical.
155 # 2. perform cmp(1) to compare SRC and DEST file byte by byte.
156 test04()
157 {
158         rm -rf $src $dest
159
160         write_cmd="-c \"truncate 200m\""
161
162         #
163         # Firstly, make the file with allocated && reserved extents
164         # mapping without real data wrote.
165         #
166         for i in $(seq 30 30 180); do
167                 offset=$(($((30 << 20)) + $i * $((1 << 20))))
168                 write_cmd="$write_cmd -c \"falloc $offset 5m\""
169         done
170
171         #
172         # Secondly, write data to some unwritten extents, hence we
173         # have a test file will extents mapping as:
174         # |hole|multiple unwritten_without_data|hole|data| repeat...
175         for i in $(seq 30 90 180); do
176                 offset=$(($((30 << 20)) + $i * $((1 << 20))))
177                 write_cmd="$write_cmd -c \"pwrite $offset 2m\""
178         done
179
180         echo "*** test04() create sparse file ***" >>$seqres.full
181         eval ${XFS_IO_PROG} -F -f "${write_cmd}" $src >>$seqres.full 2>&1 ||
182                 _fail "create sparse file failed!"
183         echo "*** test04() create sparse file done ***" >>$seqres.full
184         echo >>$seqres.full
185         $here/src/seek_copy_test $src $dest
186
187         test $(stat --printf "%s" $src) = $(stat --printf "%s" $dest) ||
188                 _fail "TEST04: file size check failed"
189
190         cmp $src $dest || _fail "TEST04: file bytes check failed"
191 }
192
193 rm -f $seqres.full
194 test01
195 test02
196 test03
197 test04
198
199 status=0
200 exit