hw/ssi/pl022: Set up reset function in class init
[qemu.git] / tests / qemu-iotests / 061
blob911b6f289462bf9a8eb0bdb0628ddf220d1eb77d
1 #!/bin/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 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 # This tests qocw2-specific low-level functionality
41 _supported_fmt qcow2
42 _supported_proto file
43 _supported_os Linux
45 echo
46 echo "=== Testing version downgrade with zero expansion ==="
47 echo
48 IMGOPTS="compat=1.1,lazy_refcounts=on" _make_test_img 64M
49 $QEMU_IO -c "write -z 0 128k" "$TEST_IMG" | _filter_qemu_io
50 $PYTHON qcow2.py "$TEST_IMG" dump-header
51 $QEMU_IMG amend -o "compat=0.10" "$TEST_IMG"
52 $PYTHON qcow2.py "$TEST_IMG" dump-header
53 $QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io
54 _check_test_img
56 echo
57 echo "=== Testing version downgrade with zero expansion and 4K cache entries ==="
58 echo
59 IMGOPTS="compat=1.1,lazy_refcounts=on" _make_test_img 64M
60 $QEMU_IO -c "write -z 0 128k" "$TEST_IMG" | _filter_qemu_io
61 $QEMU_IO -c "write -z 32M 128k" "$TEST_IMG" | _filter_qemu_io
62 $QEMU_IO -c map "$TEST_IMG" | _filter_qemu_io
63 $PYTHON qcow2.py "$TEST_IMG" dump-header
64 $QEMU_IMG amend -o "compat=0.10" --image-opts \
65 driver=qcow2,file.filename=$TEST_IMG,l2-cache-entry-size=4096
66 $PYTHON qcow2.py "$TEST_IMG" dump-header
67 $QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io
68 $QEMU_IO -c "read -P 0 32M 128k" "$TEST_IMG" | _filter_qemu_io
69 $QEMU_IO -c map "$TEST_IMG" | _filter_qemu_io
70 _check_test_img
72 echo
73 echo "=== Testing dirty version downgrade ==="
74 echo
75 IMGOPTS="compat=1.1,lazy_refcounts=on" _make_test_img 64M
76 $QEMU_IO -c "write -P 0x2a 0 128k" -c flush \
77 -c "sigraise $(kill -l KILL)" "$TEST_IMG" 2>&1 | _filter_qemu_io
78 $PYTHON qcow2.py "$TEST_IMG" dump-header
79 $QEMU_IMG amend -o "compat=0.10" "$TEST_IMG"
80 $PYTHON qcow2.py "$TEST_IMG" dump-header
81 $QEMU_IO -c "read -P 0x2a 0 128k" "$TEST_IMG" | _filter_qemu_io
82 _check_test_img
84 echo
85 echo "=== Testing version downgrade with unknown compat/autoclear flags ==="
86 echo
87 IMGOPTS="compat=1.1" _make_test_img 64M
88 $PYTHON qcow2.py "$TEST_IMG" set-feature-bit compatible 42
89 $PYTHON qcow2.py "$TEST_IMG" set-feature-bit autoclear 42
90 $PYTHON qcow2.py "$TEST_IMG" dump-header
91 $QEMU_IMG amend -o "compat=0.10" "$TEST_IMG"
92 $PYTHON qcow2.py "$TEST_IMG" dump-header
93 _check_test_img
95 echo
96 echo "=== Testing version upgrade and resize ==="
97 echo
98 IMGOPTS="compat=0.10" _make_test_img 64M
99 $QEMU_IO -c "write -P 0x2a 42M 64k" "$TEST_IMG" | _filter_qemu_io
100 $PYTHON qcow2.py "$TEST_IMG" dump-header
101 $QEMU_IMG amend -o "compat=1.1,lazy_refcounts=on,size=128M" "$TEST_IMG"
102 $PYTHON qcow2.py "$TEST_IMG" dump-header
103 $QEMU_IO -c "read -P 0x2a 42M 64k" "$TEST_IMG" | _filter_qemu_io
104 _check_test_img
106 echo
107 echo "=== Testing dirty lazy_refcounts=off ==="
108 echo
109 IMGOPTS="compat=1.1,lazy_refcounts=on" _make_test_img 64M
110 $QEMU_IO -c "write -P 0x2a 0 128k" -c flush \
111 -c "sigraise $(kill -l KILL)" "$TEST_IMG" 2>&1 | _filter_qemu_io
112 $PYTHON qcow2.py "$TEST_IMG" dump-header
113 $QEMU_IMG amend -o "lazy_refcounts=off" "$TEST_IMG"
114 $PYTHON qcow2.py "$TEST_IMG" dump-header
115 $QEMU_IO -c "read -P 0x2a 0 128k" "$TEST_IMG" | _filter_qemu_io
116 _check_test_img
118 echo
119 echo "=== Testing backing file ==="
120 echo
121 IMGOPTS="compat=1.1" _make_test_img 64M
122 IMGOPTS="compat=1.1" TEST_IMG="$TEST_IMG.base" _make_test_img 64M
123 $QEMU_IO -c "write -P 0x2a 0 128k" "$TEST_IMG.base" | _filter_qemu_io
124 $QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io
125 $QEMU_IMG amend -o "backing_file=$TEST_IMG.base,backing_fmt=qcow2" "$TEST_IMG"
126 $QEMU_IO -c "read -P 0x2a 0 128k" "$TEST_IMG" | _filter_qemu_io
127 _check_test_img
129 echo
130 echo "=== Testing invalid configurations ==="
131 echo
132 IMGOPTS="compat=0.10" _make_test_img 64M
133 $QEMU_IMG amend -o "lazy_refcounts=on" "$TEST_IMG"
134 $QEMU_IMG amend -o "compat=1.1" "$TEST_IMG" # actually valid
135 $QEMU_IMG amend -o "compat=0.10,lazy_refcounts=on" "$TEST_IMG"
136 $QEMU_IMG amend -o "compat=0.42" "$TEST_IMG"
137 $QEMU_IMG amend -o "foo=bar" "$TEST_IMG"
138 $QEMU_IMG amend -o "cluster_size=1k" "$TEST_IMG"
139 $QEMU_IMG amend -o "encryption=on" "$TEST_IMG"
140 $QEMU_IMG amend -o "preallocation=on" "$TEST_IMG"
142 echo
143 echo "=== Testing correct handling of unset value ==="
144 echo
145 IMGOPTS="compat=1.1,cluster_size=1k" _make_test_img 64M
146 echo "Should work:"
147 $QEMU_IMG amend -o "lazy_refcounts=on" "$TEST_IMG"
148 echo "Should not work:" # Just to know which of these tests actually fails
149 $QEMU_IMG amend -o "cluster_size=64k" "$TEST_IMG"
151 echo
152 echo "=== Testing zero expansion on inactive clusters ==="
153 echo
154 IMGOPTS="compat=1.1" _make_test_img 64M
155 $QEMU_IO -c "write -z 0 128k" "$TEST_IMG" | _filter_qemu_io
156 $QEMU_IMG snapshot -c foo "$TEST_IMG"
157 $QEMU_IO -c "write -P 0x2a 0 128k" "$TEST_IMG" | _filter_qemu_io
158 $QEMU_IMG amend -o "compat=0.10" "$TEST_IMG"
159 _check_test_img
160 $QEMU_IO -c "read -P 0x2a 0 128k" "$TEST_IMG" | _filter_qemu_io
161 $QEMU_IMG snapshot -a foo "$TEST_IMG"
162 _check_test_img
163 $QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io
165 echo
166 echo "=== Testing zero expansion on shared L2 table ==="
167 echo
168 IMGOPTS="compat=1.1" _make_test_img 64M
169 $QEMU_IO -c "write -z 0 128k" "$TEST_IMG" | _filter_qemu_io
170 $QEMU_IMG snapshot -c foo "$TEST_IMG"
171 $QEMU_IMG amend -o "compat=0.10" "$TEST_IMG"
172 _check_test_img
173 $QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io
174 $QEMU_IMG snapshot -a foo "$TEST_IMG"
175 _check_test_img
176 $QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io
178 echo
179 echo "=== Testing zero expansion on backed image ==="
180 echo
181 IMGOPTS="compat=1.1" TEST_IMG="$TEST_IMG.base" _make_test_img 64M
182 $QEMU_IO -c "write -P 0x2a 0 128k" "$TEST_IMG.base" | _filter_qemu_io
183 IMGOPTS="compat=1.1" _make_test_img -b "$TEST_IMG.base" 64M
184 $QEMU_IO -c "read -P 0x2a 0 128k" -c "write -z 0 64k" "$TEST_IMG" | _filter_qemu_io
185 $QEMU_IMG amend -o "compat=0.10" "$TEST_IMG"
186 _check_test_img
187 $QEMU_IO -c "read -P 0 0 64k" -c "read -P 0x2a 64k 64k" "$TEST_IMG" | _filter_qemu_io
189 echo
190 echo "=== Testing zero expansion on backed inactive clusters ==="
191 echo
192 IMGOPTS="compat=1.1" TEST_IMG="$TEST_IMG.base" _make_test_img 64M
193 $QEMU_IO -c "write -P 0x2a 0 128k" "$TEST_IMG.base" | _filter_qemu_io
194 IMGOPTS="compat=1.1" _make_test_img -b "$TEST_IMG.base" 64M
195 $QEMU_IO -c "write -z 0 64k" "$TEST_IMG" | _filter_qemu_io
196 $QEMU_IMG snapshot -c foo "$TEST_IMG"
197 $QEMU_IO -c "write -P 0x42 0 128k" "$TEST_IMG" | _filter_qemu_io
198 $QEMU_IMG amend -o "compat=0.10" "$TEST_IMG"
199 _check_test_img
200 $QEMU_IO -c "read -P 0x42 0 128k" "$TEST_IMG" | _filter_qemu_io
201 $QEMU_IMG snapshot -a foo "$TEST_IMG"
202 _check_test_img
203 $QEMU_IO -c "read -P 0 0 64k" -c "read -P 0x2a 64k 64k" "$TEST_IMG" | _filter_qemu_io
205 echo
206 echo "=== Testing zero expansion on backed image with shared L2 table ==="
207 echo
208 IMGOPTS="compat=1.1" TEST_IMG="$TEST_IMG.base" _make_test_img 64M
209 $QEMU_IO -c "write -P 0x2a 0 128k" "$TEST_IMG.base" | _filter_qemu_io
210 IMGOPTS="compat=1.1" _make_test_img -b "$TEST_IMG.base" 64M
211 $QEMU_IO -c "write -z 0 128k" "$TEST_IMG" | _filter_qemu_io
212 $QEMU_IMG snapshot -c foo "$TEST_IMG"
213 $QEMU_IMG amend -o "compat=0.10" "$TEST_IMG"
214 _check_test_img
215 $QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io
216 $QEMU_IMG snapshot -a foo "$TEST_IMG"
217 _check_test_img
218 $QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io
220 echo
221 echo "=== Testing preallocated zero expansion on full image ==="
222 echo
223 IMGOPTS="compat=1.1" TEST_IMG="$TEST_IMG" _make_test_img 64M
224 $QEMU_IO -c "write -P 0x2a 0 64M" "$TEST_IMG" -c "write -z 0 64M" | _filter_qemu_io
225 $QEMU_IMG amend -o "compat=0.10" "$TEST_IMG"
226 _check_test_img
227 $QEMU_IO -c "read -P 0 0 64M" "$TEST_IMG" | _filter_qemu_io
229 echo
230 echo "=== Testing progress report without snapshot ==="
231 echo
232 IMGOPTS="compat=1.1" TEST_IMG="$TEST_IMG.base" _make_test_img 4G
233 IMGOPTS="compat=1.1" _make_test_img -b "$TEST_IMG.base" 4G
234 $QEMU_IO -c "write -z 0 64k" \
235 -c "write -z 1G 64k" \
236 -c "write -z 2G 64k" \
237 -c "write -z 3G 64k" "$TEST_IMG" | _filter_qemu_io
238 $QEMU_IMG amend -p -o "compat=0.10" "$TEST_IMG"
239 _check_test_img
241 echo
242 echo "=== Testing progress report with snapshot ==="
243 echo
244 IMGOPTS="compat=1.1" TEST_IMG="$TEST_IMG.base" _make_test_img 4G
245 IMGOPTS="compat=1.1" _make_test_img -b "$TEST_IMG.base" 4G
246 $QEMU_IO -c "write -z 0 64k" \
247 -c "write -z 1G 64k" \
248 -c "write -z 2G 64k" \
249 -c "write -z 3G 64k" "$TEST_IMG" | _filter_qemu_io
250 $QEMU_IMG snapshot -c foo "$TEST_IMG"
251 $QEMU_IMG amend -p -o "compat=0.10" "$TEST_IMG"
252 _check_test_img
254 # success, all done
255 echo "*** done"
256 rm -f $seq.full
257 status=0