tests/qemu-iotests: Explicit usage of Python 3 (scripts with __main__)
[qemu/ar7.git] / tests / qemu-iotests / 061
blob36b040491fefd9e194d19671e42698475fc7623e
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 _unsupported_imgopts 'refcount_bits=\([^1]\|.\([^6]\|$\)\)' data_file
50 echo
51 echo "=== Testing version downgrade with zero expansion ==="
52 echo
53 _make_test_img -o "compat=1.1,lazy_refcounts=on" 64M
54 $QEMU_IO -c "write -z 0 128k" "$TEST_IMG" | _filter_qemu_io
55 $PYTHON qcow2.py "$TEST_IMG" dump-header
56 $QEMU_IMG amend -o "compat=0.10" "$TEST_IMG"
57 $PYTHON qcow2.py "$TEST_IMG" dump-header
58 $QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io
59 _check_test_img
61 echo
62 echo "=== Testing version downgrade with zero expansion and 4K cache entries ==="
63 echo
64 _make_test_img -o "compat=1.1,lazy_refcounts=on" 64M
65 $QEMU_IO -c "write -z 0 128k" "$TEST_IMG" | _filter_qemu_io
66 $QEMU_IO -c "write -z 32M 128k" "$TEST_IMG" | _filter_qemu_io
67 $QEMU_IO -c map "$TEST_IMG" | _filter_qemu_io
68 $PYTHON qcow2.py "$TEST_IMG" dump-header
69 $QEMU_IMG amend -o "compat=0.10" --image-opts \
70 driver=qcow2,file.filename=$TEST_IMG,l2-cache-entry-size=4096
71 $PYTHON qcow2.py "$TEST_IMG" dump-header
72 $QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io
73 $QEMU_IO -c "read -P 0 32M 128k" "$TEST_IMG" | _filter_qemu_io
74 $QEMU_IO -c map "$TEST_IMG" | _filter_qemu_io
75 _check_test_img
77 echo
78 echo "=== Testing dirty version downgrade ==="
79 echo
80 _make_test_img -o "compat=1.1,lazy_refcounts=on" 64M
81 _NO_VALGRIND \
82 $QEMU_IO -c "write -P 0x2a 0 128k" -c flush \
83 -c "sigraise $(kill -l KILL)" "$TEST_IMG" 2>&1 | _filter_qemu_io
84 $PYTHON qcow2.py "$TEST_IMG" dump-header
85 $QEMU_IMG amend -o "compat=0.10" "$TEST_IMG"
86 $PYTHON qcow2.py "$TEST_IMG" dump-header
87 $QEMU_IO -c "read -P 0x2a 0 128k" "$TEST_IMG" | _filter_qemu_io
88 _check_test_img
90 echo
91 echo "=== Testing version downgrade with unknown compat/autoclear flags ==="
92 echo
93 _make_test_img -o "compat=1.1" 64M
94 $PYTHON qcow2.py "$TEST_IMG" set-feature-bit compatible 42
95 $PYTHON qcow2.py "$TEST_IMG" set-feature-bit autoclear 42
96 $PYTHON qcow2.py "$TEST_IMG" dump-header
97 $QEMU_IMG amend -o "compat=0.10" "$TEST_IMG"
98 $PYTHON qcow2.py "$TEST_IMG" dump-header
99 _check_test_img
101 echo
102 echo "=== Testing version upgrade and resize ==="
103 echo
104 _make_test_img -o "compat=0.10" 64M
105 $QEMU_IO -c "write -P 0x2a 42M 64k" "$TEST_IMG" | _filter_qemu_io
106 $PYTHON qcow2.py "$TEST_IMG" dump-header
107 $QEMU_IMG amend -o "compat=1.1,lazy_refcounts=on,size=128M" "$TEST_IMG"
108 $PYTHON qcow2.py "$TEST_IMG" dump-header
109 $QEMU_IO -c "read -P 0x2a 42M 64k" "$TEST_IMG" | _filter_qemu_io
110 _check_test_img
112 echo
113 echo "=== Testing dirty lazy_refcounts=off ==="
114 echo
115 _make_test_img -o "compat=1.1,lazy_refcounts=on" 64M
116 _NO_VALGRIND \
117 $QEMU_IO -c "write -P 0x2a 0 128k" -c flush \
118 -c "sigraise $(kill -l KILL)" "$TEST_IMG" 2>&1 | _filter_qemu_io
119 $PYTHON qcow2.py "$TEST_IMG" dump-header
120 $QEMU_IMG amend -o "lazy_refcounts=off" "$TEST_IMG"
121 $PYTHON qcow2.py "$TEST_IMG" dump-header
122 $QEMU_IO -c "read -P 0x2a 0 128k" "$TEST_IMG" | _filter_qemu_io
123 _check_test_img
125 echo
126 echo "=== Testing backing file ==="
127 echo
128 _make_test_img -o "compat=1.1" 64M
129 TEST_IMG="$TEST_IMG.base" _make_test_img -o "compat=1.1" 64M
130 $QEMU_IO -c "write -P 0x2a 0 128k" "$TEST_IMG.base" | _filter_qemu_io
131 $QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io
132 $QEMU_IMG amend -o "backing_file=$TEST_IMG.base,backing_fmt=qcow2" "$TEST_IMG"
133 $QEMU_IO -c "read -P 0x2a 0 128k" "$TEST_IMG" | _filter_qemu_io
134 _check_test_img
136 echo
137 echo "=== Testing invalid configurations ==="
138 echo
139 _make_test_img -o "compat=0.10" 64M
140 $QEMU_IMG amend -o "lazy_refcounts=on" "$TEST_IMG"
141 $QEMU_IMG amend -o "compat=1.1" "$TEST_IMG" # actually valid
142 $QEMU_IMG amend -o "compat=0.10,lazy_refcounts=on" "$TEST_IMG"
143 $QEMU_IMG amend -o "compat=0.42" "$TEST_IMG"
144 $QEMU_IMG amend -o "foo=bar" "$TEST_IMG"
145 $QEMU_IMG amend -o "cluster_size=1k" "$TEST_IMG"
146 $QEMU_IMG amend -o "encryption=on" "$TEST_IMG"
147 $QEMU_IMG amend -o "preallocation=on" "$TEST_IMG"
149 echo
150 echo "=== Testing correct handling of unset value ==="
151 echo
152 _make_test_img -o "compat=1.1,cluster_size=1k" 64M
153 echo "Should work:"
154 $QEMU_IMG amend -o "lazy_refcounts=on" "$TEST_IMG"
155 echo "Should not work:" # Just to know which of these tests actually fails
156 $QEMU_IMG amend -o "cluster_size=64k" "$TEST_IMG"
158 echo
159 echo "=== Testing zero expansion on inactive clusters ==="
160 echo
161 _make_test_img -o "compat=1.1" 64M
162 $QEMU_IO -c "write -z 0 128k" "$TEST_IMG" | _filter_qemu_io
163 $QEMU_IMG snapshot -c foo "$TEST_IMG"
164 $QEMU_IO -c "write -P 0x2a 0 128k" "$TEST_IMG" | _filter_qemu_io
165 $QEMU_IMG amend -o "compat=0.10" "$TEST_IMG"
166 _check_test_img
167 $QEMU_IO -c "read -P 0x2a 0 128k" "$TEST_IMG" | _filter_qemu_io
168 $QEMU_IMG snapshot -a foo "$TEST_IMG"
169 _check_test_img
170 $QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io
172 echo
173 echo "=== Testing zero expansion on shared L2 table ==="
174 echo
175 _make_test_img -o "compat=1.1" 64M
176 $QEMU_IO -c "write -z 0 128k" "$TEST_IMG" | _filter_qemu_io
177 $QEMU_IMG snapshot -c foo "$TEST_IMG"
178 $QEMU_IMG amend -o "compat=0.10" "$TEST_IMG"
179 _check_test_img
180 $QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io
181 $QEMU_IMG snapshot -a foo "$TEST_IMG"
182 _check_test_img
183 $QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io
185 echo
186 echo "=== Testing zero expansion on backed image ==="
187 echo
188 TEST_IMG="$TEST_IMG.base" _make_test_img -o "compat=1.1" 64M
189 $QEMU_IO -c "write -P 0x2a 0 128k" "$TEST_IMG.base" | _filter_qemu_io
190 _make_test_img -o "compat=1.1" -b "$TEST_IMG.base" 64M
191 $QEMU_IO -c "read -P 0x2a 0 128k" -c "write -z 0 64k" "$TEST_IMG" | _filter_qemu_io
192 $QEMU_IMG amend -o "compat=0.10" "$TEST_IMG"
193 _check_test_img
194 $QEMU_IO -c "read -P 0 0 64k" -c "read -P 0x2a 64k 64k" "$TEST_IMG" | _filter_qemu_io
196 echo
197 echo "=== Testing zero expansion on backed inactive clusters ==="
198 echo
199 TEST_IMG="$TEST_IMG.base" _make_test_img -o "compat=1.1" 64M
200 $QEMU_IO -c "write -P 0x2a 0 128k" "$TEST_IMG.base" | _filter_qemu_io
201 _make_test_img -o "compat=1.1" -b "$TEST_IMG.base" 64M
202 $QEMU_IO -c "write -z 0 64k" "$TEST_IMG" | _filter_qemu_io
203 $QEMU_IMG snapshot -c foo "$TEST_IMG"
204 $QEMU_IO -c "write -P 0x42 0 128k" "$TEST_IMG" | _filter_qemu_io
205 $QEMU_IMG amend -o "compat=0.10" "$TEST_IMG"
206 _check_test_img
207 $QEMU_IO -c "read -P 0x42 0 128k" "$TEST_IMG" | _filter_qemu_io
208 $QEMU_IMG snapshot -a foo "$TEST_IMG"
209 _check_test_img
210 $QEMU_IO -c "read -P 0 0 64k" -c "read -P 0x2a 64k 64k" "$TEST_IMG" | _filter_qemu_io
212 echo
213 echo "=== Testing zero expansion on backed image with shared L2 table ==="
214 echo
215 TEST_IMG="$TEST_IMG.base" _make_test_img -o "compat=1.1" 64M
216 $QEMU_IO -c "write -P 0x2a 0 128k" "$TEST_IMG.base" | _filter_qemu_io
217 _make_test_img -o "compat=1.1" -b "$TEST_IMG.base" 64M
218 $QEMU_IO -c "write -z 0 128k" "$TEST_IMG" | _filter_qemu_io
219 $QEMU_IMG snapshot -c foo "$TEST_IMG"
220 $QEMU_IMG amend -o "compat=0.10" "$TEST_IMG"
221 _check_test_img
222 $QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io
223 $QEMU_IMG snapshot -a foo "$TEST_IMG"
224 _check_test_img
225 $QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io
227 echo
228 echo "=== Testing preallocated zero expansion on full image ==="
229 echo
230 TEST_IMG="$TEST_IMG" _make_test_img -o "compat=1.1" 64M
231 $QEMU_IO -c "write -P 0x2a 0 64M" "$TEST_IMG" -c "write -z 0 64M" | _filter_qemu_io
232 $QEMU_IMG amend -o "compat=0.10" "$TEST_IMG"
233 _check_test_img
234 $QEMU_IO -c "read -P 0 0 64M" "$TEST_IMG" | _filter_qemu_io
236 echo
237 echo "=== Testing progress report without snapshot ==="
238 echo
239 TEST_IMG="$TEST_IMG.base" _make_test_img -o "compat=1.1" 4G
240 _make_test_img -o "compat=1.1" -b "$TEST_IMG.base" 4G
241 $QEMU_IO -c "write -z 0 64k" \
242 -c "write -z 1G 64k" \
243 -c "write -z 2G 64k" \
244 -c "write -z 3G 64k" "$TEST_IMG" | _filter_qemu_io
245 $QEMU_IMG amend -p -o "compat=0.10" "$TEST_IMG"
246 _check_test_img
248 echo
249 echo "=== Testing progress report with snapshot ==="
250 echo
251 TEST_IMG="$TEST_IMG.base" _make_test_img -o "compat=1.1" 4G
252 _make_test_img -o "compat=1.1" -b "$TEST_IMG.base" 4G
253 $QEMU_IO -c "write -z 0 64k" \
254 -c "write -z 1G 64k" \
255 -c "write -z 2G 64k" \
256 -c "write -z 3G 64k" "$TEST_IMG" | _filter_qemu_io
257 $QEMU_IMG snapshot -c foo "$TEST_IMG"
258 $QEMU_IMG amend -p -o "compat=0.10" "$TEST_IMG"
259 _check_test_img
261 echo
262 echo "=== Testing version downgrade with external data file ==="
263 echo
264 _make_test_img -o "compat=1.1,data_file=$TEST_IMG.data" 64M
265 $QEMU_IMG amend -o "compat=0.10" "$TEST_IMG"
266 _img_info --format-specific
267 _check_test_img
269 echo
270 echo "=== Try changing the external data file ==="
271 echo
272 _make_test_img -o "compat=1.1" 64M
273 $QEMU_IMG amend -o "data_file=foo" "$TEST_IMG"
275 echo
276 _make_test_img -o "compat=1.1,data_file=$TEST_IMG.data" 64M
277 $QEMU_IMG amend -o "data_file=foo" "$TEST_IMG"
278 _img_info --format-specific
279 TEST_IMG="data-file.filename=$TEST_IMG.data,file.filename=$TEST_IMG" _img_info --format-specific --image-opts
281 echo
282 $QEMU_IMG amend -o "data_file=" --image-opts "data-file.filename=$TEST_IMG.data,file.filename=$TEST_IMG"
283 _img_info --format-specific
284 TEST_IMG="data-file.filename=$TEST_IMG.data,file.filename=$TEST_IMG" _img_info --format-specific --image-opts
286 echo
287 echo "=== Clearing and setting data-file-raw ==="
288 echo
289 _make_test_img -o "compat=1.1,data_file=$TEST_IMG.data,data_file_raw=on" 64M
290 $QEMU_IMG amend -o "data_file_raw=on" "$TEST_IMG"
291 _img_info --format-specific
292 _check_test_img
294 $QEMU_IMG amend -o "data_file_raw=off" "$TEST_IMG"
295 _img_info --format-specific
296 _check_test_img
298 $QEMU_IMG amend -o "data_file_raw=on" "$TEST_IMG"
299 _img_info --format-specific
300 _check_test_img
303 # success, all done
304 echo "*** done"
305 rm -f $seq.full
306 status=0