2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2011 Oracle Inc. All Rights Reserved.
7 # SEEK_DATA/SEEK_HOLE copy tests.
10 seqres=$RESULT_DIR/$seq
11 echo "QA output created by $seq"
14 status=1 # failure is the default!
15 trap "_cleanup; exit \$status" 0 1 2 3 15
17 # get standard environment, filters and checks
21 # real QA test starts here
26 _require_seek_data_hole
28 src=$TEST_DIR/seek_copy_testfile
29 dest=$TEST_DIR/seek_copy_testfile.dest
31 _require_test_program "seek_copy_test"
38 # seek_copy_test_01: tests file with holes and written data extents.
40 # 1. file size is identical.
41 # 2. perform cmp(1) to compare SRC and DEST file byte by byte.
46 write_cmd="-c \"truncate 100m\""
47 for i in $(seq 0 5 100); do
48 offset=$(($i * $((1 << 20))))
49 write_cmd="$write_cmd -c \"pwrite $offset 1m\""
52 echo "*** test01() create sparse file ***" >>$seqres.full
53 eval ${XFS_IO_PROG} -f "${write_cmd}" $src >>$seqres.full 2>&1 ||
54 _fail "create sparse file failed!"
55 echo "*** test01() create sparse file done ***" >>$seqres.full
58 $here/src/seek_copy_test $src $dest
60 test $(stat -c "%s" $src) = $(stat -c "%s" $dest) ||
61 _fail "TEST01: file size check failed"
63 cmp $src $dest || _fail "TEST01: file bytes check failed"
66 # seek_copy_test_02 - tests file with holes, written and unwritten extents.
68 # 1. file size is identical.
69 # 2. perform cmp(1) to compare SRC and DEST file byte by byte.
74 write_cmd="-c \"truncate 200m\""
75 for i in $(seq 0 10 100); do
76 offset=$(($((6 << 20)) + $i * $((1 << 20))))
77 write_cmd="$write_cmd -c \"falloc $offset 3m\" -c \"pwrite $offset 1m\""
80 echo "*** test02() create sparse file ***" >>$seqres.full
81 eval ${XFS_IO_PROG} -f "${write_cmd}" $src >>$seqres.full 2>&1 ||
82 _fail "create sparse file failed!"
83 echo "*** test02() create sparse file done ***" >>$seqres.full
86 $here/src/seek_copy_test $src $dest
88 test $(stat -c "%s" $src) = $(stat -c "%s" $dest) ||
89 _fail "TEST02: file size check failed"
91 cmp $src $dest || _fail "TEST02: file bytes check failed"
94 # seek_copy_test_03 - tests file with unwritten with data, repeated unwritten
95 # without data, as well as data extents mapping.
97 # 1. file size is identical.
98 # 2. perform cmp(1) to compare SRC and DEST file byte by byte.
103 write_cmd="-c \"truncate 200m\""
106 # Firstly, make the file with allocated && reserved extents
107 # mapping without real data wrote.
109 for i in $(seq 0 10 180); do
110 offset=$(($((10 << 20)) + $i * $((1 << 20))))
111 write_cmd="$write_cmd -c \"falloc $offset 10m\""
115 # Secondly, write data to some unwritten extents, hence we
116 # have a test file will extents mapping as:
117 # |data|multiple unwritten_without_data|data| repeat...
118 for i in $(seq 0 60 180); do
119 offset=$(($((20 << 20)) + $i * $((1 << 20))))
120 write_cmd="$write_cmd -c \"pwrite $offset 10m\""
123 echo "*** test03() create sparse file ***" >>$seqres.full
124 eval ${XFS_IO_PROG} -f "${write_cmd}" $src >>$seqres.full 2>&1 ||
125 _fail "create sparse file failed!"
126 echo "*** test03() create sparse file done ***" >>$seqres.full
128 $here/src/seek_copy_test $src $dest
130 test $(stat -c "%s" $src) = $(stat -c "%s" $dest) ||
131 _fail "TEST03: file size check failed"
133 cmp $src $dest || _fail "TEST03: file bytes check failed"
136 # seek_copy_test_04 - tests file with hole, repeated unwritten
137 # without data, as well as data extents mapping.
139 # 1. file size is identical.
140 # 2. perform cmp(1) to compare SRC and DEST file byte by byte.
145 write_cmd="-c \"truncate 200m\""
148 # Firstly, make the file with allocated && reserved extents
149 # mapping without real data wrote.
151 for i in $(seq 30 30 180); do
152 offset=$(($((30 << 20)) + $i * $((1 << 20))))
153 write_cmd="$write_cmd -c \"falloc $offset 5m\""
157 # Secondly, write data to some unwritten extents, hence we
158 # have a test file will extents mapping as:
159 # |hole|multiple unwritten_without_data|hole|data| repeat...
160 for i in $(seq 30 90 180); do
161 offset=$(($((30 << 20)) + $i * $((1 << 20))))
162 write_cmd="$write_cmd -c \"pwrite $offset 2m\""
165 echo "*** test04() create sparse file ***" >>$seqres.full
166 eval ${XFS_IO_PROG} -f "${write_cmd}" $src >>$seqres.full 2>&1 ||
167 _fail "create sparse file failed!"
168 echo "*** test04() create sparse file done ***" >>$seqres.full
170 $here/src/seek_copy_test $src $dest
172 test $(stat -c "%s" $src) = $(stat -c "%s" $dest) ||
173 _fail "TEST04: file size check failed"
175 cmp $src $dest || _fail "TEST04: file bytes check failed"