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