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