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