tests/acceptance: verify s390x device detection
[qemu/kevin.git] / tests / qemu-iotests / 061
blob5747beb7ed60cd96f2ce6f836589b8872ab60c42
1 #!/usr/bin/env bash
3 # Test case for image option amendment in qcow2.
5 # Copyright (C) 2013 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=mreitz@redhat.com
24 seq=`basename $0`
25 echo "QA output created by $seq"
27 status=1 # failure is the default!
29 _cleanup()
31 _cleanup_test_img
32 _rm_test_img "$TEST_IMG.data"
34 trap "_cleanup; exit \$status" 0 1 2 3 15
36 # get standard environment, filters and checks
37 . ./common.rc
38 . ./common.filter
40 # This tests qcow2-specific low-level functionality
41 _supported_fmt qcow2
42 _supported_proto file
43 _supported_os Linux
44 # Conversion between different compat versions can only really work
45 # with refcount_bits=16;
46 # we have explicit tests for data_file here, but the whole test does
47 # not work with it;
48 # we have explicit tests for various cluster sizes, the remaining tests
49 # require the default 64k cluster
50 _unsupported_imgopts 'refcount_bits=\([^1]\|.\([^6]\|$\)\)' data_file cluster_size
52 echo
53 echo "=== Testing version downgrade with zero expansion ==="
54 echo
55 _make_test_img -o "compat=1.1,lazy_refcounts=on" 64M
56 $QEMU_IO -c "write -z 0 128k" "$TEST_IMG" | _filter_qemu_io
57 $PYTHON qcow2.py "$TEST_IMG" dump-header
58 $QEMU_IMG amend -o "compat=0.10" "$TEST_IMG"
59 $PYTHON qcow2.py "$TEST_IMG" dump-header
60 $QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io
61 _check_test_img
63 echo
64 echo "=== Testing version downgrade with zero expansion and 4K cache entries ==="
65 echo
66 _make_test_img -o "compat=1.1,lazy_refcounts=on" 64M
67 $QEMU_IO -c "write -z 0 128k" "$TEST_IMG" | _filter_qemu_io
68 $QEMU_IO -c "write -z 32M 128k" "$TEST_IMG" | _filter_qemu_io
69 $QEMU_IO -c map "$TEST_IMG" | _filter_qemu_io
70 $PYTHON qcow2.py "$TEST_IMG" dump-header
71 $QEMU_IMG amend -o "compat=0.10" --image-opts \
72 driver=qcow2,file.filename=$TEST_IMG,l2-cache-entry-size=4096
73 $PYTHON qcow2.py "$TEST_IMG" dump-header
74 $QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io
75 $QEMU_IO -c "read -P 0 32M 128k" "$TEST_IMG" | _filter_qemu_io
76 $QEMU_IO -c map "$TEST_IMG" | _filter_qemu_io
77 _check_test_img
79 echo
80 echo "=== Testing dirty version downgrade ==="
81 echo
82 _make_test_img -o "compat=1.1,lazy_refcounts=on" 64M
83 _NO_VALGRIND \
84 $QEMU_IO -c "write -P 0x2a 0 128k" -c flush \
85 -c "sigraise $(kill -l KILL)" "$TEST_IMG" 2>&1 | _filter_qemu_io
86 $PYTHON qcow2.py "$TEST_IMG" dump-header
87 $QEMU_IMG amend -o "compat=0.10" "$TEST_IMG"
88 $PYTHON qcow2.py "$TEST_IMG" dump-header
89 $QEMU_IO -c "read -P 0x2a 0 128k" "$TEST_IMG" | _filter_qemu_io
90 _check_test_img
92 echo
93 echo "=== Testing version downgrade with unknown compat/autoclear flags ==="
94 echo
95 _make_test_img -o "compat=1.1" 64M
96 $PYTHON qcow2.py "$TEST_IMG" set-feature-bit compatible 42
97 $PYTHON qcow2.py "$TEST_IMG" set-feature-bit autoclear 42
98 $PYTHON qcow2.py "$TEST_IMG" dump-header
99 $QEMU_IMG amend -o "compat=0.10" "$TEST_IMG"
100 $PYTHON qcow2.py "$TEST_IMG" dump-header
101 _check_test_img
103 echo
104 echo "=== Testing version upgrade and resize ==="
105 echo
106 _make_test_img -o "compat=0.10" 64M
107 $QEMU_IO -c "write -P 0x2a 42M 64k" "$TEST_IMG" | _filter_qemu_io
108 $PYTHON qcow2.py "$TEST_IMG" dump-header
109 $QEMU_IMG amend -o "compat=1.1,lazy_refcounts=on,size=128M" "$TEST_IMG"
110 $PYTHON qcow2.py "$TEST_IMG" dump-header
111 $QEMU_IO -c "read -P 0x2a 42M 64k" "$TEST_IMG" | _filter_qemu_io
112 _check_test_img
114 echo
115 echo "=== Testing resize with snapshots ==="
116 echo
117 _make_test_img -o "compat=0.10" 32M
118 $QEMU_IO -c "write -P 0x2a 24M 64k" "$TEST_IMG" | _filter_qemu_io
119 $QEMU_IMG snapshot -c foo "$TEST_IMG"
120 $QEMU_IMG resize "$TEST_IMG" 64M &&
121 echo "unexpected pass"
122 $PYTHON qcow2.py "$TEST_IMG" dump-header | grep '^\(version\|size\|nb_snap\)'
124 $QEMU_IMG amend -o "compat=1.1,size=128M" "$TEST_IMG" ||
125 echo "unexpected fail"
126 $PYTHON qcow2.py "$TEST_IMG" dump-header | grep '^\(version\|size\|nb_snap\)'
128 $QEMU_IMG snapshot -c bar "$TEST_IMG"
129 $QEMU_IMG resize --shrink "$TEST_IMG" 64M ||
130 echo "unexpected fail"
131 $PYTHON qcow2.py "$TEST_IMG" dump-header | grep '^\(version\|size\|nb_snap\)'
133 $QEMU_IMG amend -o "compat=0.10,size=32M" "$TEST_IMG" &&
134 echo "unexpected pass"
135 $PYTHON qcow2.py "$TEST_IMG" dump-header | grep '^\(version\|size\|nb_snap\)'
137 $QEMU_IMG snapshot -a bar "$TEST_IMG" ||
138 echo "unexpected fail"
139 $PYTHON qcow2.py "$TEST_IMG" dump-header | grep '^\(version\|size\|nb_snap\)'
141 $QEMU_IMG snapshot -d bar "$TEST_IMG"
142 $QEMU_IMG amend -o "compat=0.10,size=32M" "$TEST_IMG" ||
143 echo "unexpected fail"
144 $PYTHON qcow2.py "$TEST_IMG" dump-header | grep '^\(version\|size\|nb_snap\)'
146 _check_test_img
149 echo
150 echo "=== Testing dirty lazy_refcounts=off ==="
151 echo
152 _make_test_img -o "compat=1.1,lazy_refcounts=on" 64M
153 _NO_VALGRIND \
154 $QEMU_IO -c "write -P 0x2a 0 128k" -c flush \
155 -c "sigraise $(kill -l KILL)" "$TEST_IMG" 2>&1 | _filter_qemu_io
156 $PYTHON qcow2.py "$TEST_IMG" dump-header
157 $QEMU_IMG amend -o "lazy_refcounts=off" "$TEST_IMG"
158 $PYTHON qcow2.py "$TEST_IMG" dump-header
159 $QEMU_IO -c "read -P 0x2a 0 128k" "$TEST_IMG" | _filter_qemu_io
160 _check_test_img
162 echo
163 echo "=== Testing backing file ==="
164 echo
165 _make_test_img -o "compat=1.1" 64M
166 TEST_IMG="$TEST_IMG.base" _make_test_img -o "compat=1.1" 64M
167 $QEMU_IO -c "write -P 0x2a 0 128k" "$TEST_IMG.base" | _filter_qemu_io
168 $QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io
169 $QEMU_IMG amend -o "backing_file=$TEST_IMG.base,backing_fmt=qcow2" "$TEST_IMG"
170 $QEMU_IO -c "read -P 0x2a 0 128k" "$TEST_IMG" | _filter_qemu_io
171 _check_test_img
173 echo
174 echo "=== Testing invalid configurations ==="
175 echo
176 _make_test_img -o "compat=0.10" 64M
177 $QEMU_IMG amend -o "lazy_refcounts=on" "$TEST_IMG"
178 $QEMU_IMG amend -o "compat=1.1" "$TEST_IMG" # actually valid
179 $QEMU_IMG amend -o "compat=0.10,lazy_refcounts=on" "$TEST_IMG"
180 $QEMU_IMG amend -o "compat=0.42" "$TEST_IMG"
181 $QEMU_IMG amend -o "foo=bar" "$TEST_IMG"
182 $QEMU_IMG amend -o "cluster_size=1k" "$TEST_IMG"
183 $QEMU_IMG amend -o "encryption=on" "$TEST_IMG"
184 $QEMU_IMG amend -o "preallocation=on" "$TEST_IMG"
186 echo
187 echo "=== Testing correct handling of unset value ==="
188 echo
189 _make_test_img -o "compat=1.1,cluster_size=1k" 64M
190 echo "Should work:"
191 $QEMU_IMG amend -o "lazy_refcounts=on" "$TEST_IMG"
192 echo "Should not work:" # Just to know which of these tests actually fails
193 $QEMU_IMG amend -o "cluster_size=64k" "$TEST_IMG"
195 echo
196 echo "=== Testing zero expansion on inactive clusters ==="
197 echo
198 _make_test_img -o "compat=1.1" 64M
199 $QEMU_IO -c "write -z 0 128k" "$TEST_IMG" | _filter_qemu_io
200 $QEMU_IMG snapshot -c foo "$TEST_IMG"
201 $QEMU_IO -c "write -P 0x2a 0 128k" "$TEST_IMG" | _filter_qemu_io
202 $QEMU_IMG amend -o "compat=0.10" "$TEST_IMG"
203 _check_test_img
204 $QEMU_IO -c "read -P 0x2a 0 128k" "$TEST_IMG" | _filter_qemu_io
205 $QEMU_IMG snapshot -a foo "$TEST_IMG"
206 _check_test_img
207 $QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io
209 echo
210 echo "=== Testing zero expansion on shared L2 table ==="
211 echo
212 _make_test_img -o "compat=1.1" 64M
213 $QEMU_IO -c "write -z 0 128k" "$TEST_IMG" | _filter_qemu_io
214 $QEMU_IMG snapshot -c foo "$TEST_IMG"
215 $QEMU_IMG amend -o "compat=0.10" "$TEST_IMG"
216 _check_test_img
217 $QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io
218 $QEMU_IMG snapshot -a foo "$TEST_IMG"
219 _check_test_img
220 $QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io
222 echo
223 echo "=== Testing zero expansion on backed image ==="
224 echo
225 TEST_IMG="$TEST_IMG.base" _make_test_img -o "compat=1.1" 64M
226 $QEMU_IO -c "write -P 0x2a 0 128k" "$TEST_IMG.base" | _filter_qemu_io
227 _make_test_img -o "compat=1.1" -b "$TEST_IMG.base" -F $IMGFMT 64M
228 $QEMU_IO -c "read -P 0x2a 0 128k" -c "write -z 0 64k" "$TEST_IMG" | _filter_qemu_io
229 $QEMU_IMG amend -o "compat=0.10" "$TEST_IMG"
230 _check_test_img
231 $QEMU_IO -c "read -P 0 0 64k" -c "read -P 0x2a 64k 64k" "$TEST_IMG" | _filter_qemu_io
233 echo
234 echo "=== Testing zero expansion on backed inactive clusters ==="
235 echo
236 TEST_IMG="$TEST_IMG.base" _make_test_img -o "compat=1.1" 64M
237 $QEMU_IO -c "write -P 0x2a 0 128k" "$TEST_IMG.base" | _filter_qemu_io
238 _make_test_img -o "compat=1.1" -b "$TEST_IMG.base" -F $IMGFMT 64M
239 $QEMU_IO -c "write -z 0 64k" "$TEST_IMG" | _filter_qemu_io
240 $QEMU_IMG snapshot -c foo "$TEST_IMG"
241 $QEMU_IO -c "write -P 0x42 0 128k" "$TEST_IMG" | _filter_qemu_io
242 $QEMU_IMG amend -o "compat=0.10" "$TEST_IMG"
243 _check_test_img
244 $QEMU_IO -c "read -P 0x42 0 128k" "$TEST_IMG" | _filter_qemu_io
245 $QEMU_IMG snapshot -a foo "$TEST_IMG"
246 _check_test_img
247 $QEMU_IO -c "read -P 0 0 64k" -c "read -P 0x2a 64k 64k" "$TEST_IMG" | _filter_qemu_io
249 echo
250 echo "=== Testing zero expansion on backed image with shared L2 table ==="
251 echo
252 TEST_IMG="$TEST_IMG.base" _make_test_img -o "compat=1.1" 64M
253 $QEMU_IO -c "write -P 0x2a 0 128k" "$TEST_IMG.base" | _filter_qemu_io
254 _make_test_img -o "compat=1.1" -b "$TEST_IMG.base" -F $IMGFMT 64M
255 $QEMU_IO -c "write -z 0 128k" "$TEST_IMG" | _filter_qemu_io
256 $QEMU_IMG snapshot -c foo "$TEST_IMG"
257 $QEMU_IMG amend -o "compat=0.10" "$TEST_IMG"
258 _check_test_img
259 $QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io
260 $QEMU_IMG snapshot -a foo "$TEST_IMG"
261 _check_test_img
262 $QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io
264 echo
265 echo "=== Testing preallocated zero expansion on full image ==="
266 echo
267 TEST_IMG="$TEST_IMG" _make_test_img -o "compat=1.1" 64M
268 $QEMU_IO -c "write -P 0x2a 0 64M" "$TEST_IMG" -c "write -z 0 64M" | _filter_qemu_io
269 $QEMU_IMG amend -o "compat=0.10" "$TEST_IMG"
270 _check_test_img
271 $QEMU_IO -c "read -P 0 0 64M" "$TEST_IMG" | _filter_qemu_io
273 echo
274 echo "=== Testing progress report without snapshot ==="
275 echo
276 TEST_IMG="$TEST_IMG.base" _make_test_img -o "compat=1.1" 4G
277 _make_test_img -o "compat=1.1" -b "$TEST_IMG.base" -F $IMGFMT 4G
278 $QEMU_IO -c "write -z 0 64k" \
279 -c "write -z 1G 64k" \
280 -c "write -z 2G 64k" \
281 -c "write -z 3G 64k" "$TEST_IMG" | _filter_qemu_io
282 $QEMU_IMG amend -p -o "compat=0.10" "$TEST_IMG"
283 _check_test_img
285 echo
286 echo "=== Testing progress report with snapshot ==="
287 echo
288 TEST_IMG="$TEST_IMG.base" _make_test_img -o "compat=1.1" 4G
289 _make_test_img -o "compat=1.1" -b "$TEST_IMG.base" -F $IMGFMT 4G
290 $QEMU_IO -c "write -z 0 64k" \
291 -c "write -z 1G 64k" \
292 -c "write -z 2G 64k" \
293 -c "write -z 3G 64k" "$TEST_IMG" | _filter_qemu_io
294 $QEMU_IMG snapshot -c foo "$TEST_IMG"
295 $QEMU_IMG amend -p -o "compat=0.10" "$TEST_IMG"
296 _check_test_img
298 echo
299 echo "=== Testing version downgrade with external data file ==="
300 echo
301 _make_test_img -o "compat=1.1,data_file=$TEST_IMG.data" 64M
302 $QEMU_IMG amend -o "compat=0.10" "$TEST_IMG"
303 _img_info --format-specific
304 _check_test_img
306 echo
307 echo "=== Testing version downgrade with extended L2 entries ==="
308 echo
309 _make_test_img -o "compat=1.1,extended_l2=on" 64M
310 $QEMU_IMG amend -o "compat=0.10" "$TEST_IMG"
312 echo
313 echo "=== Try changing the external data file ==="
314 echo
315 _make_test_img -o "compat=1.1" 64M
316 $QEMU_IMG amend -o "data_file=foo" "$TEST_IMG"
318 echo
319 _make_test_img -o "compat=1.1,data_file=$TEST_IMG.data" 64M
320 $QEMU_IMG amend -o "data_file=foo" "$TEST_IMG"
321 _img_info --format-specific
322 TEST_IMG="data-file.filename=$TEST_IMG.data,file.filename=$TEST_IMG" _img_info --format-specific --image-opts
324 echo
325 $QEMU_IMG amend -o "data_file=" --image-opts "data-file.filename=$TEST_IMG.data,file.filename=$TEST_IMG"
326 _img_info --format-specific
327 TEST_IMG="data-file.filename=$TEST_IMG.data,file.filename=$TEST_IMG" _img_info --format-specific --image-opts
329 echo
330 echo "=== Clearing and setting data-file-raw ==="
331 echo
332 _make_test_img -o "compat=1.1,data_file=$TEST_IMG.data,data_file_raw=on" 64M
333 $QEMU_IMG amend -o "data_file_raw=on" "$TEST_IMG"
334 _img_info --format-specific
335 _check_test_img
337 $QEMU_IMG amend -o "data_file_raw=off" "$TEST_IMG"
338 _img_info --format-specific
339 _check_test_img
341 $QEMU_IMG amend -o "data_file_raw=on" "$TEST_IMG"
342 _img_info --format-specific
343 _check_test_img
346 # success, all done
347 echo "*** done"
348 rm -f $seq.full
349 status=0