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