build: add pc-bios to config-host.mak deps
[qemu/ar7.git] / tests / qemu-iotests / 154
blob7ca7219f089c85572afc1f3404cd028be7237230
1 #!/bin/bash
3 # qcow2 specific bdrv_pwrite_zeroes tests with backing files (complements 034)
5 # Copyright (C) 2016 Red Hat, Inc.
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
21 # creator
22 owner=kwolf@redhat.com
24 seq=`basename $0`
25 echo "QA output created by $seq"
27 here=`pwd`
28 status=1 # failure is the default!
30 _cleanup()
32 _cleanup_test_img
34 trap "_cleanup; exit \$status" 0 1 2 3 15
36 # get standard environment, filters and checks
37 . ./common.rc
38 . ./common.filter
40 _supported_fmt qcow2
41 _supported_proto file
42 _supported_os Linux
44 CLUSTER_SIZE=4k
45 size=128M
47 echo
48 echo == backing file contains zeros ==
50 CLUSTER_SIZE=512 TEST_IMG="$TEST_IMG.base" _make_test_img $size
51 _make_test_img -b "$TEST_IMG.base"
53 # Make sure that the whole cluster is allocated even for partial write_zeroes
54 # when the backing file contains zeros
56 # X = non-zero data sector in backing file
57 # - = sector unallocated in whole backing chain
58 # 0 = sector touched by write_zeroes request
60 # 1. Tail unaligned: 00 00 -- --
61 # 2. Head unaligned: -- -- 00 00
62 # 3. Both unaligned: -- 00 00 --
63 # 4. Both, 2 clusters: -- -- -- 00 | 00 -- -- --
65 $QEMU_IO -c "write -z 0 2k" "$TEST_IMG" | _filter_qemu_io
66 $QEMU_IO -c "write -z 10k 2k" "$TEST_IMG" | _filter_qemu_io
67 $QEMU_IO -c "write -z 17k 2k" "$TEST_IMG" | _filter_qemu_io
68 $QEMU_IO -c "write -z 27k 2k" "$TEST_IMG" | _filter_qemu_io
69 $QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map
71 echo
72 echo == backing file contains non-zero data before write_zeroes ==
74 CLUSTER_SIZE=512 TEST_IMG="$TEST_IMG.base" _make_test_img $size
75 _make_test_img -b "$TEST_IMG.base"
77 # Single cluster; non-zero data at the cluster start
78 # ... | XX -- 00 -- | ...
79 $QEMU_IO -c "write -P 0x11 32k 1k" "$TEST_IMG.base" | _filter_qemu_io
80 $QEMU_IO -c "write -z 34k 1k" "$TEST_IMG" | _filter_qemu_io
81 $QEMU_IO -c "read -P 0x11 32k 1k" "$TEST_IMG" | _filter_qemu_io
82 $QEMU_IO -c "read -P 0 33k 3k" "$TEST_IMG" | _filter_qemu_io
84 # Single cluster; non-zero data exists, but not at the cluster start
85 # ... | -- XX 00 -- | ...
86 $QEMU_IO -c "write -P 0x11 65k 1k" "$TEST_IMG.base" | _filter_qemu_io
87 $QEMU_IO -c "write -z 66k 1k" "$TEST_IMG" | _filter_qemu_io
88 $QEMU_IO -c "read -P 0x11 65k 1k" "$TEST_IMG" | _filter_qemu_io
89 $QEMU_IO -c "read -P 0 64k 1k" "$TEST_IMG" | _filter_qemu_io
90 $QEMU_IO -c "read -P 0 66k 2k" "$TEST_IMG" | _filter_qemu_io
92 $QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map
94 echo
95 echo == backing file contains non-zero data after write_zeroes ==
97 CLUSTER_SIZE=512 TEST_IMG="$TEST_IMG.base" _make_test_img $size
98 _make_test_img -b "$TEST_IMG.base"
100 # Single cluster; non-zero data directly after request
101 # ... | -- 00 XX -- | ...
102 $QEMU_IO -c "write -P 0x11 34k 1k" "$TEST_IMG.base" | _filter_qemu_io
103 $QEMU_IO -c "write -z 33k 1k" "$TEST_IMG" | _filter_qemu_io
104 $QEMU_IO -c "read -P 0 32k 2k" "$TEST_IMG" | _filter_qemu_io
105 $QEMU_IO -c "read -P 0x11 34k 1k" "$TEST_IMG" | _filter_qemu_io
106 $QEMU_IO -c "read -P 0 35k 1k" "$TEST_IMG" | _filter_qemu_io
108 # Single cluster; non-zero data exists, but not directly after request
109 # ... | -- 00 -- XX | ...
110 $QEMU_IO -c "write -P 0x11 43k 1k" "$TEST_IMG.base" | _filter_qemu_io
111 $QEMU_IO -c "write -z 41k 1k" "$TEST_IMG" | _filter_qemu_io
112 $QEMU_IO -c "read -P 0x11 43k 1k" "$TEST_IMG" | _filter_qemu_io
113 $QEMU_IO -c "read -P 0 40k 3k" "$TEST_IMG" | _filter_qemu_io
115 $QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map
117 echo
118 echo == write_zeroes covers non-zero data ==
120 CLUSTER_SIZE=512 TEST_IMG="$TEST_IMG.base" _make_test_img $size
121 _make_test_img -b "$TEST_IMG.base"
123 # non-zero data at front of request
124 # Backing file: -- XX -- --
125 # Active layer: -- 00 00 --
127 $QEMU_IO -c "write -P 0x11 5k 1k" "$TEST_IMG.base" | _filter_qemu_io
128 $QEMU_IO -c "write -z 5k 2k" "$TEST_IMG" | _filter_qemu_io
129 $QEMU_IO -c "read -P 0 4k 4k" "$TEST_IMG" | _filter_qemu_io
131 # non-zero data at end of request
132 # Backing file: -- -- XX --
133 # Active layer: -- 00 00 --
135 $QEMU_IO -c "write -P 0x11 14k 1k" "$TEST_IMG.base" | _filter_qemu_io
136 $QEMU_IO -c "write -z 13k 2k" "$TEST_IMG" | _filter_qemu_io
137 $QEMU_IO -c "read -P 0 12k 4k" "$TEST_IMG" | _filter_qemu_io
139 # non-zero data matches size of request
140 # Backing file: -- XX XX --
141 # Active layer: -- 00 00 --
143 $QEMU_IO -c "write -P 0x11 21k 2k" "$TEST_IMG.base" | _filter_qemu_io
144 $QEMU_IO -c "write -z 21k 2k" "$TEST_IMG" | _filter_qemu_io
145 $QEMU_IO -c "read -P 0 20k 4k" "$TEST_IMG" | _filter_qemu_io
147 # non-zero data smaller than request
148 # Backing file: -- -X X- --
149 # Active layer: -- 00 00 --
151 $QEMU_IO -c "write -P 0x11 30208 1k" "$TEST_IMG.base" | _filter_qemu_io
152 $QEMU_IO -c "write -z 29k 2k" "$TEST_IMG" | _filter_qemu_io
153 $QEMU_IO -c "read -P 0 28k 4k" "$TEST_IMG" | _filter_qemu_io
155 $QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map
157 echo
158 echo == spanning two clusters, non-zero before request ==
160 CLUSTER_SIZE=512 TEST_IMG="$TEST_IMG.base" _make_test_img $size
161 _make_test_img -b "$TEST_IMG.base"
163 # Two clusters; non-zero data before request:
164 # 1. At cluster start: 32k: XX -- -- 00 | 00 -- -- --
165 # 2. Between unallocated space: 48k: -- XX -- 00 | 00 -- -- --
166 # 3. Directly before request: 64k: -- -- XX 00 | 00 -- -- --
168 $QEMU_IO -c "write -P 0x11 32k 1k" "$TEST_IMG.base" | _filter_qemu_io
169 $QEMU_IO -c "write -z 35k 2k" "$TEST_IMG" | _filter_qemu_io
170 $QEMU_IO -c "read -P 0x11 32k 1k" "$TEST_IMG" | _filter_qemu_io
171 $QEMU_IO -c "read -P 0 33k 7k" "$TEST_IMG" | _filter_qemu_io
173 $QEMU_IO -c "write -P 0x11 49k 1k" "$TEST_IMG.base" | _filter_qemu_io
174 $QEMU_IO -c "write -z 51k 2k" "$TEST_IMG" | _filter_qemu_io
175 $QEMU_IO -c "read -P 0 48k 1k" "$TEST_IMG" | _filter_qemu_io
176 $QEMU_IO -c "read -P 0x11 49k 1k" "$TEST_IMG" | _filter_qemu_io
177 $QEMU_IO -c "read -P 0 50k 6k" "$TEST_IMG" | _filter_qemu_io
179 $QEMU_IO -c "write -P 0x11 66k 1k" "$TEST_IMG.base" | _filter_qemu_io
180 $QEMU_IO -c "write -z 67k 2k" "$TEST_IMG" | _filter_qemu_io
181 $QEMU_IO -c "read -P 0 64k 2k" "$TEST_IMG" | _filter_qemu_io
182 $QEMU_IO -c "read -P 0x11 66k 1k" "$TEST_IMG" | _filter_qemu_io
183 $QEMU_IO -c "read -P 0 67k 5k" "$TEST_IMG" | _filter_qemu_io
185 $QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map
187 echo
188 echo == spanning two clusters, non-zero after request ==
190 CLUSTER_SIZE=512 TEST_IMG="$TEST_IMG.base" _make_test_img $size
191 _make_test_img -b "$TEST_IMG.base"
193 # Two clusters; non-zero data after request:
194 # 1. Directly after request: 32k: -- -- -- 00 | 00 XX -- --
195 # 2. Between unallocated space: 48k: -- -- -- 00 | 00 -- XX --
196 # 3. At cluster end: 64k: -- -- -- 00 | 00 -- -- XX
198 $QEMU_IO -c "write -P 0x11 37k 1k" "$TEST_IMG.base" | _filter_qemu_io
199 $QEMU_IO -c "write -z 35k 2k" "$TEST_IMG" | _filter_qemu_io
200 $QEMU_IO -c "read -P 0 32k 5k" "$TEST_IMG" | _filter_qemu_io
201 $QEMU_IO -c "read -P 0x11 37k 1k" "$TEST_IMG" | _filter_qemu_io
202 $QEMU_IO -c "read -P 0 38k 2k" "$TEST_IMG" | _filter_qemu_io
204 $QEMU_IO -c "write -P 0x11 54k 1k" "$TEST_IMG.base" | _filter_qemu_io
205 $QEMU_IO -c "write -z 51k 2k" "$TEST_IMG" | _filter_qemu_io
206 $QEMU_IO -c "read -P 0 48k 6k" "$TEST_IMG" | _filter_qemu_io
207 $QEMU_IO -c "read -P 0x11 54k 1k" "$TEST_IMG" | _filter_qemu_io
208 $QEMU_IO -c "read -P 0 55k 1k" "$TEST_IMG" | _filter_qemu_io
210 $QEMU_IO -c "write -P 0x11 71k 1k" "$TEST_IMG.base" | _filter_qemu_io
211 $QEMU_IO -c "write -z 67k 2k" "$TEST_IMG" | _filter_qemu_io
212 $QEMU_IO -c "read -P 0 64k 7k" "$TEST_IMG" | _filter_qemu_io
213 $QEMU_IO -c "read -P 0x11 71k 1k" "$TEST_IMG" | _filter_qemu_io
215 $QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map
217 echo
218 echo == spanning two clusters, partially overwriting backing file ==
220 CLUSTER_SIZE=512 TEST_IMG="$TEST_IMG.base" _make_test_img $size
221 _make_test_img -b "$TEST_IMG.base"
223 # Backing file: -- -- XX XX | XX XX -- --
224 # Active layer: -- -- XX 00 | 00 XX -- --
226 $QEMU_IO -c "write -P 0x11 2k 4k" "$TEST_IMG.base" | _filter_qemu_io
227 $QEMU_IO -c "write -z 3k 2k" "$TEST_IMG" | _filter_qemu_io
228 $QEMU_IO -c "read -P 0 0k 2k" "$TEST_IMG" | _filter_qemu_io
229 $QEMU_IO -c "read -P 0x11 2k 1k" "$TEST_IMG" | _filter_qemu_io
230 $QEMU_IO -c "read -P 0 3k 2k" "$TEST_IMG" | _filter_qemu_io
231 $QEMU_IO -c "read -P 0x11 5k 1k" "$TEST_IMG" | _filter_qemu_io
232 $QEMU_IO -c "read -P 0 6k 2k" "$TEST_IMG" | _filter_qemu_io
234 $QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map
236 echo
237 echo == spanning multiple clusters, non-zero in first cluster ==
239 CLUSTER_SIZE=512 TEST_IMG="$TEST_IMG.base" _make_test_img $size
240 _make_test_img -b "$TEST_IMG.base"
242 # Backing file: 64k: XX XX -- -- | -- -- -- -- | -- -- -- --
243 # Active layer: 64k: XX XX 00 00 | 00 00 00 00 | 00 -- -- --
245 $QEMU_IO -c "write -P 0x11 64k 2k" "$TEST_IMG.base" | _filter_qemu_io
246 $QEMU_IO -c "write -z 66k 7k" "$TEST_IMG" | _filter_qemu_io
247 $QEMU_IO -c "read -P 0x11 64k 2k" "$TEST_IMG" | _filter_qemu_io
248 $QEMU_IO -c "read -P 0 66k 10k" "$TEST_IMG" | _filter_qemu_io
250 $QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map
252 echo
253 echo == spanning multiple clusters, non-zero in intermediate cluster ==
255 CLUSTER_SIZE=512 TEST_IMG="$TEST_IMG.base" _make_test_img $size
256 _make_test_img -b "$TEST_IMG.base"
258 # Backing file: 64k: -- -- -- -- | -- XX XX -- | -- -- -- --
259 # Active layer: 64k: -- -- 00 00 | 00 00 00 00 | 00 -- -- --
261 $QEMU_IO -c "write -P 0x11 69k 2k" "$TEST_IMG.base" | _filter_qemu_io
262 $QEMU_IO -c "write -z 66k 7k" "$TEST_IMG" | _filter_qemu_io
263 $QEMU_IO -c "read -P 0 64k 12k" "$TEST_IMG" | _filter_qemu_io
265 $QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map
267 echo
268 echo == spanning multiple clusters, non-zero in final cluster ==
270 CLUSTER_SIZE=512 TEST_IMG="$TEST_IMG.base" _make_test_img $size
271 _make_test_img -b "$TEST_IMG.base"
273 # Backing file: 64k: -- -- -- -- | -- -- -- -- | -- -- XX XX
274 # Active layer: 64k: -- -- 00 00 | 00 00 00 00 | 00 -- XX XX
276 $QEMU_IO -c "write -P 0x11 74k 2k" "$TEST_IMG.base" | _filter_qemu_io
277 $QEMU_IO -c "write -z 66k 7k" "$TEST_IMG" | _filter_qemu_io
278 $QEMU_IO -c "read -P 0 64k 10k" "$TEST_IMG" | _filter_qemu_io
279 $QEMU_IO -c "read -P 0x11 74k 2k" "$TEST_IMG" | _filter_qemu_io
281 $QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map
283 echo
284 echo == spanning multiple clusters, partially overwriting backing file ==
286 CLUSTER_SIZE=512 TEST_IMG="$TEST_IMG.base" _make_test_img $size
287 _make_test_img -b "$TEST_IMG.base"
289 # Backing file: 64k: -- XX XX XX | XX XX XX XX | XX XX XX --
290 # Active layer: 64k: -- XX 00 00 | 00 00 00 00 | 00 XX XX --
292 $QEMU_IO -c "write -P 0x11 65k 10k" "$TEST_IMG.base" | _filter_qemu_io
293 $QEMU_IO -c "write -z 66k 7k" "$TEST_IMG" | _filter_qemu_io
294 $QEMU_IO -c "read -P 0 64k 1k" "$TEST_IMG" | _filter_qemu_io
295 $QEMU_IO -c "read -P 0x11 65k 1k" "$TEST_IMG" | _filter_qemu_io
296 $QEMU_IO -c "read -P 0 66k 7k" "$TEST_IMG" | _filter_qemu_io
297 $QEMU_IO -c "read -P 0x11 73k 2k" "$TEST_IMG" | _filter_qemu_io
298 $QEMU_IO -c "read -P 0 75k 1k" "$TEST_IMG" | _filter_qemu_io
300 $QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map
302 # success, all done
303 echo "*** done"
304 rm -f $seq.full
305 status=0