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