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