]> git.proxmox.com Git - mirror_qemu.git/blame - tests/qemu-iotests/071
qemu-iotests: Test qcow2 preallocation modes
[mirror_qemu.git] / tests / qemu-iotests / 071
CommitLineData
11a82d14 1#!/usr/bin/env bash
30bd6a4d
HR
2#
3# Test case for the QMP blkdebug and blkverify interfaces
4#
5# Copyright (C) 2013 Red Hat, Inc.
6#
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.
11#
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.
16#
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/>.
19#
20
21# creator
22owner=mreitz@redhat.com
23
24seq="$(basename $0)"
25echo "QA output created by $seq"
26
30bd6a4d
HR
27status=1 # failure is the default!
28
29_cleanup()
30{
31 _cleanup_test_img
32}
33trap "_cleanup; exit \$status" 0 1 2 3 15
34
35# get standard environment, filters and checks
36. ./common.rc
37. ./common.filter
38
1b7650ef 39_supported_fmt qcow2
1f7bf7d0 40_supported_proto file
30bd6a4d
HR
41_supported_os Linux
42
8cedcffd 43do_run_qemu()
30bd6a4d
HR
44{
45 echo Testing: "$@" | _filter_imgfmt
46 $QEMU -nographic -qmp stdio -serial none "$@"
47 echo
48}
49
8cedcffd 50run_qemu()
30bd6a4d 51{
4dd7b8d3 52 do_run_qemu "$@" 2>&1 | _filter_testdir | _filter_qemu | _filter_qmp | _filter_qemu_io
30bd6a4d
HR
53}
54
55IMG_SIZE=64M
56
57echo
58echo "=== Testing blkverify through filename ==="
59echo
60
61TEST_IMG="$TEST_IMG.base" IMGOPTS="" IMGFMT="raw" _make_test_img $IMG_SIZE |\
62 _filter_imgfmt
63_make_test_img $IMG_SIZE
8f9e835f 64$QEMU_IO -c "open -o driver=raw,file.driver=blkverify,file.raw.filename=$TEST_IMG.base $TEST_IMG" \
30bd6a4d
HR
65 -c 'read 0 512' -c 'write -P 42 0x38000 512' -c 'read -P 42 0x38000 512' | _filter_qemu_io
66
67$QEMU_IO -c 'write -P 42 0 512' "$TEST_IMG" | _filter_qemu_io
68
8f9e835f 69$QEMU_IO -c "open -o driver=raw,file.driver=blkverify,file.raw.filename=$TEST_IMG.base $TEST_IMG" \
30bd6a4d
HR
70 -c 'read -P 42 0 512' | _filter_qemu_io
71
72echo
73echo "=== Testing blkverify through file blockref ==="
74echo
75
76TEST_IMG="$TEST_IMG.base" IMGOPTS="" IMGFMT="raw" _make_test_img $IMG_SIZE |\
77 _filter_imgfmt
78_make_test_img $IMG_SIZE
8f9e835f 79$QEMU_IO -c "open -o driver=raw,file.driver=blkverify,file.raw.filename=$TEST_IMG.base,file.test.driver=$IMGFMT,file.test.file.filename=$TEST_IMG" \
30bd6a4d
HR
80 -c 'read 0 512' -c 'write -P 42 0x38000 512' -c 'read -P 42 0x38000 512' | _filter_qemu_io
81
82$QEMU_IO -c 'write -P 42 0 512' "$TEST_IMG" | _filter_qemu_io
83
8f9e835f 84$QEMU_IO -c "open -o driver=raw,file.driver=blkverify,file.raw.filename=$TEST_IMG.base $TEST_IMG" \
30bd6a4d
HR
85 -c 'read -P 42 0 512' | _filter_qemu_io
86
87echo
88echo "=== Testing blkdebug through filename ==="
89echo
90
91$QEMU_IO -c "open -o file.driver=blkdebug,file.inject-error.event=l2_load $TEST_IMG" \
92 -c 'read -P 42 0x38000 512'
93
94echo
95echo "=== Testing blkdebug through file blockref ==="
96echo
97
98$QEMU_IO -c "open -o driver=$IMGFMT,file.driver=blkdebug,file.inject-error.event=l2_load,file.image.filename=$TEST_IMG" \
99 -c 'read -P 42 0x38000 512'
100
101echo
102echo "=== Testing blkdebug on existing block device ==="
103echo
104
8e9e6530 105run_qemu <<EOF
30bd6a4d 106{ "execute": "qmp_capabilities" }
8e9e6530
HR
107{ "execute": "blockdev-add",
108 "arguments": {
0153d2f5
KW
109 "node-name": "drive0",
110 "driver": "file",
111 "filename": "$TEST_IMG"
8e9e6530
HR
112 }
113}
30bd6a4d
HR
114{ "execute": "blockdev-add",
115 "arguments": {
0153d2f5
KW
116 "driver": "$IMGFMT",
117 "node-name": "drive0-debug",
118 "file": {
119 "driver": "blkdebug",
120 "image": "drive0",
121 "inject-error": [{
122 "event": "l2_load"
123 }]
30bd6a4d
HR
124 }
125 }
126}
127{ "execute": "human-monitor-command",
128 "arguments": {
129 "command-line": 'qemu-io drive0-debug "read 0 512"'
130 }
131}
132{ "execute": "quit" }
133EOF
134
135echo
136echo "=== Testing blkverify on existing block device ==="
137echo
138
8e9e6530 139run_qemu <<EOF
30bd6a4d 140{ "execute": "qmp_capabilities" }
8e9e6530
HR
141{ "execute": "blockdev-add",
142 "arguments": {
0153d2f5
KW
143 "node-name": "drive0",
144 "driver": "$IMGFMT",
145 "file": {
146 "driver": "file",
147 "filename": "$TEST_IMG"
8e9e6530
HR
148 }
149 }
150}
30bd6a4d
HR
151{ "execute": "blockdev-add",
152 "arguments": {
0153d2f5
KW
153 "driver": "blkverify",
154 "node-name": "drive0-verify",
155 "test": "drive0",
156 "raw": {
157 "driver": "file",
158 "filename": "$TEST_IMG.base"
30bd6a4d
HR
159 }
160 }
161}
162{ "execute": "human-monitor-command",
163 "arguments": {
164 "command-line": 'qemu-io drive0-verify "read 0 512"'
165 }
166}
167{ "execute": "quit" }
168EOF
169
170echo
171echo "=== Testing blkverify on existing raw block device ==="
172echo
173
8e9e6530 174run_qemu <<EOF
30bd6a4d 175{ "execute": "qmp_capabilities" }
8e9e6530
HR
176{ "execute": "blockdev-add",
177 "arguments": {
0153d2f5
KW
178 "node-name": "drive0",
179 "driver": "file",
180 "filename": "$TEST_IMG.base"
8e9e6530
HR
181 }
182}
30bd6a4d
HR
183{ "execute": "blockdev-add",
184 "arguments": {
0153d2f5
KW
185 "driver": "blkverify",
186 "node-name": "drive0-verify",
187 "test": {
188 "driver": "$IMGFMT",
189 "file": {
190 "driver": "file",
191 "filename": "$TEST_IMG"
192 }
193 },
194 "raw": "drive0"
30bd6a4d
HR
195 }
196}
197{ "execute": "human-monitor-command",
198 "arguments": {
199 "command-line": 'qemu-io drive0-verify "read 0 512"'
200 }
201}
202{ "execute": "quit" }
203EOF
204
205echo
206echo "=== Testing blkdebug's set-state through QMP ==="
207echo
208
8e9e6530 209run_qemu <<EOF
30bd6a4d 210{ "execute": "qmp_capabilities" }
8e9e6530
HR
211{ "execute": "blockdev-add",
212 "arguments": {
0153d2f5
KW
213 "node-name": "drive0",
214 "driver": "file",
215 "filename": "$TEST_IMG"
8e9e6530
HR
216 }
217}
30bd6a4d
HR
218{ "execute": "blockdev-add",
219 "arguments": {
0153d2f5
KW
220 "driver": "$IMGFMT",
221 "node-name": "drive0-debug",
222 "file": {
223 "driver": "blkdebug",
224 "image": "drive0",
225 "inject-error": [{
226 "event": "read_aio",
227 "state": 42
228 }],
229 "set-state": [{
230 "event": "write_aio",
231 "new_state": 42
232 }]
30bd6a4d
HR
233 }
234 }
235}
236{ "execute": "human-monitor-command",
237 "arguments": {
238 "command-line": 'qemu-io drive0-debug "read 0 512"'
239 }
240}
241{ "execute": "human-monitor-command",
242 "arguments": {
243 "command-line": 'qemu-io drive0-debug "write 0 512"'
244 }
245}
246{ "execute": "human-monitor-command",
247 "arguments": {
248 "command-line": 'qemu-io drive0-debug "read 0 512"'
249 }
250}
251{ "execute": "quit" }
252EOF
253
254# success, all done
255echo "*** done"
256rm -f $seq.full
257status=0