tests: fix ptimer leaks
[qemu/ar7.git] / tests / qemu-iotests / 061
blobf5678b10c95d41b8d0cffb44d430ecade38d7336
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 dirty version downgrade ==="
58 echo
59 IMGOPTS="compat=1.1,lazy_refcounts=on" _make_test_img 64M
60 $QEMU_IO -c "write -P 0x2a 0 128k" -c flush \
61 -c "sigraise $(kill -l KILL)" "$TEST_IMG" 2>&1 | _filter_qemu_io
62 $PYTHON qcow2.py "$TEST_IMG" dump-header
63 $QEMU_IMG amend -o "compat=0.10" "$TEST_IMG"
64 $PYTHON qcow2.py "$TEST_IMG" dump-header
65 $QEMU_IO -c "read -P 0x2a 0 128k" "$TEST_IMG" | _filter_qemu_io
66 _check_test_img
68 echo
69 echo "=== Testing version downgrade with unknown compat/autoclear flags ==="
70 echo
71 IMGOPTS="compat=1.1" _make_test_img 64M
72 $PYTHON qcow2.py "$TEST_IMG" set-feature-bit compatible 42
73 $PYTHON qcow2.py "$TEST_IMG" set-feature-bit autoclear 42
74 $PYTHON qcow2.py "$TEST_IMG" dump-header
75 $QEMU_IMG amend -o "compat=0.10" "$TEST_IMG"
76 $PYTHON qcow2.py "$TEST_IMG" dump-header
77 _check_test_img
79 echo
80 echo "=== Testing version upgrade and resize ==="
81 echo
82 IMGOPTS="compat=0.10" _make_test_img 64M
83 $QEMU_IO -c "write -P 0x2a 42M 64k" "$TEST_IMG" | _filter_qemu_io
84 $PYTHON qcow2.py "$TEST_IMG" dump-header
85 $QEMU_IMG amend -o "compat=1.1,lazy_refcounts=on,size=128M" "$TEST_IMG"
86 $PYTHON qcow2.py "$TEST_IMG" dump-header
87 $QEMU_IO -c "read -P 0x2a 42M 64k" "$TEST_IMG" | _filter_qemu_io
88 _check_test_img
90 echo
91 echo "=== Testing dirty lazy_refcounts=off ==="
92 echo
93 IMGOPTS="compat=1.1,lazy_refcounts=on" _make_test_img 64M
94 $QEMU_IO -c "write -P 0x2a 0 128k" -c flush \
95 -c "sigraise $(kill -l KILL)" "$TEST_IMG" 2>&1 | _filter_qemu_io
96 $PYTHON qcow2.py "$TEST_IMG" dump-header
97 $QEMU_IMG amend -o "lazy_refcounts=off" "$TEST_IMG"
98 $PYTHON qcow2.py "$TEST_IMG" dump-header
99 $QEMU_IO -c "read -P 0x2a 0 128k" "$TEST_IMG" | _filter_qemu_io
100 _check_test_img
102 echo
103 echo "=== Testing backing file ==="
104 echo
105 IMGOPTS="compat=1.1" _make_test_img 64M
106 IMGOPTS="compat=1.1" TEST_IMG="$TEST_IMG.base" _make_test_img 64M
107 $QEMU_IO -c "write -P 0x2a 0 128k" "$TEST_IMG.base" | _filter_qemu_io
108 $QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io
109 $QEMU_IMG amend -o "backing_file=$TEST_IMG.base,backing_fmt=qcow2" "$TEST_IMG"
110 $QEMU_IO -c "read -P 0x2a 0 128k" "$TEST_IMG" | _filter_qemu_io
111 _check_test_img
113 echo
114 echo "=== Testing invalid configurations ==="
115 echo
116 IMGOPTS="compat=0.10" _make_test_img 64M
117 $QEMU_IMG amend -o "lazy_refcounts=on" "$TEST_IMG"
118 $QEMU_IMG amend -o "compat=1.1" "$TEST_IMG" # actually valid
119 $QEMU_IMG amend -o "compat=0.10,lazy_refcounts=on" "$TEST_IMG"
120 $QEMU_IMG amend -o "compat=0.42" "$TEST_IMG"
121 $QEMU_IMG amend -o "foo=bar" "$TEST_IMG"
122 $QEMU_IMG amend -o "cluster_size=1k" "$TEST_IMG"
123 $QEMU_IMG amend -o "encryption=on" "$TEST_IMG"
124 $QEMU_IMG amend -o "preallocation=on" "$TEST_IMG"
126 echo
127 echo "=== Testing correct handling of unset value ==="
128 echo
129 IMGOPTS="compat=1.1,cluster_size=1k" _make_test_img 64M
130 echo "Should work:"
131 $QEMU_IMG amend -o "lazy_refcounts=on" "$TEST_IMG"
132 echo "Should not work:" # Just to know which of these tests actually fails
133 $QEMU_IMG amend -o "cluster_size=64k" "$TEST_IMG"
135 echo
136 echo "=== Testing zero expansion on inactive clusters ==="
137 echo
138 IMGOPTS="compat=1.1" _make_test_img 64M
139 $QEMU_IO -c "write -z 0 128k" "$TEST_IMG" | _filter_qemu_io
140 $QEMU_IMG snapshot -c foo "$TEST_IMG"
141 $QEMU_IO -c "write -P 0x2a 0 128k" "$TEST_IMG" | _filter_qemu_io
142 $QEMU_IMG amend -o "compat=0.10" "$TEST_IMG"
143 _check_test_img
144 $QEMU_IO -c "read -P 0x2a 0 128k" "$TEST_IMG" | _filter_qemu_io
145 $QEMU_IMG snapshot -a foo "$TEST_IMG"
146 _check_test_img
147 $QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io
149 echo
150 echo "=== Testing zero expansion on shared L2 table ==="
151 echo
152 IMGOPTS="compat=1.1" _make_test_img 64M
153 $QEMU_IO -c "write -z 0 128k" "$TEST_IMG" | _filter_qemu_io
154 $QEMU_IMG snapshot -c foo "$TEST_IMG"
155 $QEMU_IMG amend -o "compat=0.10" "$TEST_IMG"
156 _check_test_img
157 $QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io
158 $QEMU_IMG snapshot -a foo "$TEST_IMG"
159 _check_test_img
160 $QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io
162 echo
163 echo "=== Testing zero expansion on backed image ==="
164 echo
165 IMGOPTS="compat=1.1" TEST_IMG="$TEST_IMG.base" _make_test_img 64M
166 $QEMU_IO -c "write -P 0x2a 0 128k" "$TEST_IMG.base" | _filter_qemu_io
167 IMGOPTS="compat=1.1" _make_test_img -b "$TEST_IMG.base" 64M
168 $QEMU_IO -c "read -P 0x2a 0 128k" -c "write -z 0 64k" "$TEST_IMG" | _filter_qemu_io
169 $QEMU_IMG amend -o "compat=0.10" "$TEST_IMG"
170 _check_test_img
171 $QEMU_IO -c "read -P 0 0 64k" -c "read -P 0x2a 64k 64k" "$TEST_IMG" | _filter_qemu_io
173 echo
174 echo "=== Testing zero expansion on backed inactive clusters ==="
175 echo
176 IMGOPTS="compat=1.1" TEST_IMG="$TEST_IMG.base" _make_test_img 64M
177 $QEMU_IO -c "write -P 0x2a 0 128k" "$TEST_IMG.base" | _filter_qemu_io
178 IMGOPTS="compat=1.1" _make_test_img -b "$TEST_IMG.base" 64M
179 $QEMU_IO -c "write -z 0 64k" "$TEST_IMG" | _filter_qemu_io
180 $QEMU_IMG snapshot -c foo "$TEST_IMG"
181 $QEMU_IO -c "write -P 0x42 0 128k" "$TEST_IMG" | _filter_qemu_io
182 $QEMU_IMG amend -o "compat=0.10" "$TEST_IMG"
183 _check_test_img
184 $QEMU_IO -c "read -P 0x42 0 128k" "$TEST_IMG" | _filter_qemu_io
185 $QEMU_IMG snapshot -a foo "$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 image with shared L2 table ==="
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 128k" "$TEST_IMG" | _filter_qemu_io
196 $QEMU_IMG snapshot -c foo "$TEST_IMG"
197 $QEMU_IMG amend -o "compat=0.10" "$TEST_IMG"
198 _check_test_img
199 $QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io
200 $QEMU_IMG snapshot -a foo "$TEST_IMG"
201 _check_test_img
202 $QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io
204 echo
205 echo "=== Testing preallocated zero expansion on full image ==="
206 echo
207 IMGOPTS="compat=1.1" TEST_IMG="$TEST_IMG" _make_test_img 64M
208 $QEMU_IO -c "write -P 0x2a 0 64M" "$TEST_IMG" -c "write -z 0 64M" | _filter_qemu_io
209 $QEMU_IMG amend -o "compat=0.10" "$TEST_IMG"
210 _check_test_img
211 $QEMU_IO -c "read -P 0 0 64M" "$TEST_IMG" | _filter_qemu_io
213 echo
214 echo "=== Testing progress report without snapshot ==="
215 echo
216 IMGOPTS="compat=1.1" TEST_IMG="$TEST_IMG.base" _make_test_img 4G
217 IMGOPTS="compat=1.1" _make_test_img -b "$TEST_IMG.base" 4G
218 $QEMU_IO -c "write -z 0 64k" \
219 -c "write -z 1G 64k" \
220 -c "write -z 2G 64k" \
221 -c "write -z 3G 64k" "$TEST_IMG" | _filter_qemu_io
222 $QEMU_IMG amend -p -o "compat=0.10" "$TEST_IMG"
223 _check_test_img
225 echo
226 echo "=== Testing progress report with snapshot ==="
227 echo
228 IMGOPTS="compat=1.1" TEST_IMG="$TEST_IMG.base" _make_test_img 4G
229 IMGOPTS="compat=1.1" _make_test_img -b "$TEST_IMG.base" 4G
230 $QEMU_IO -c "write -z 0 64k" \
231 -c "write -z 1G 64k" \
232 -c "write -z 2G 64k" \
233 -c "write -z 3G 64k" "$TEST_IMG" | _filter_qemu_io
234 $QEMU_IMG snapshot -c foo "$TEST_IMG"
235 $QEMU_IMG amend -p -o "compat=0.10" "$TEST_IMG"
236 _check_test_img
238 # success, all done
239 echo "*** done"
240 rm -f $seq.full
241 status=0