commit: Make base read-only if there is an early failure
[qemu/ar7.git] / tests / qemu-iotests / 071
blob7f3e5abd57024105883e36c42bf6fb1fa2fc2452
1 #!/usr/bin/env bash
3 # Test case for the QMP blkdebug and blkverify interfaces
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 status=1 # failure is the default!
29 _cleanup()
31 _cleanup_test_img
33 trap "_cleanup; exit \$status" 0 1 2 3 15
35 # get standard environment, filters and checks
36 . ./common.rc
37 . ./common.filter
39 _supported_fmt qcow2
40 _supported_proto file
41 _supported_os Linux
43 do_run_qemu()
45 echo Testing: "$@" | _filter_imgfmt
46 $QEMU -nographic -qmp stdio -serial none "$@"
47 echo
50 run_qemu()
52 do_run_qemu "$@" 2>&1 | _filter_testdir | _filter_qemu | _filter_qmp | _filter_qemu_io
55 IMG_SIZE=64M
57 echo
58 echo "=== Testing blkverify through filename ==="
59 echo
61 TEST_IMG="$TEST_IMG.base" IMGOPTS="" IMGFMT="raw" _make_test_img $IMG_SIZE |\
62 _filter_imgfmt
63 _make_test_img $IMG_SIZE
64 $QEMU_IO -c "open -o driver=raw,file.driver=blkverify,file.raw.filename=$TEST_IMG.base $TEST_IMG" \
65 -c 'read 0 512' -c 'write -P 42 0x38000 512' -c 'read -P 42 0x38000 512' | _filter_qemu_io
67 $QEMU_IO -c 'write -P 42 0 512' "$TEST_IMG" | _filter_qemu_io
69 $QEMU_IO -c "open -o driver=raw,file.driver=blkverify,file.raw.filename=$TEST_IMG.base $TEST_IMG" \
70 -c 'read -P 42 0 512' | _filter_qemu_io
72 echo
73 echo "=== Testing blkverify through file blockref ==="
74 echo
76 TEST_IMG="$TEST_IMG.base" IMGOPTS="" IMGFMT="raw" _make_test_img $IMG_SIZE |\
77 _filter_imgfmt
78 _make_test_img $IMG_SIZE
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" \
80 -c 'read 0 512' -c 'write -P 42 0x38000 512' -c 'read -P 42 0x38000 512' | _filter_qemu_io
82 $QEMU_IO -c 'write -P 42 0 512' "$TEST_IMG" | _filter_qemu_io
84 $QEMU_IO -c "open -o driver=raw,file.driver=blkverify,file.raw.filename=$TEST_IMG.base $TEST_IMG" \
85 -c 'read -P 42 0 512' | _filter_qemu_io
87 echo
88 echo "=== Testing blkdebug through filename ==="
89 echo
91 $QEMU_IO -c "open -o file.driver=blkdebug,file.inject-error.event=l2_load $TEST_IMG" \
92 -c 'read -P 42 0x38000 512'
94 echo
95 echo "=== Testing blkdebug through file blockref ==="
96 echo
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'
101 echo
102 echo "=== Testing blkdebug on existing block device ==="
103 echo
105 run_qemu <<EOF
106 { "execute": "qmp_capabilities" }
107 { "execute": "blockdev-add",
108 "arguments": {
109 "node-name": "drive0",
110 "driver": "file",
111 "filename": "$TEST_IMG"
114 { "execute": "blockdev-add",
115 "arguments": {
116 "driver": "$IMGFMT",
117 "node-name": "drive0-debug",
118 "file": {
119 "driver": "blkdebug",
120 "image": "drive0",
121 "inject-error": [{
122 "event": "l2_load"
127 { "execute": "human-monitor-command",
128 "arguments": {
129 "command-line": 'qemu-io drive0-debug "read 0 512"'
132 { "execute": "quit" }
135 echo
136 echo "=== Testing blkverify on existing block device ==="
137 echo
139 run_qemu <<EOF
140 { "execute": "qmp_capabilities" }
141 { "execute": "blockdev-add",
142 "arguments": {
143 "node-name": "drive0",
144 "driver": "$IMGFMT",
145 "file": {
146 "driver": "file",
147 "filename": "$TEST_IMG"
151 { "execute": "blockdev-add",
152 "arguments": {
153 "driver": "blkverify",
154 "node-name": "drive0-verify",
155 "test": "drive0",
156 "raw": {
157 "driver": "file",
158 "filename": "$TEST_IMG.base"
162 { "execute": "human-monitor-command",
163 "arguments": {
164 "command-line": 'qemu-io drive0-verify "read 0 512"'
167 { "execute": "quit" }
170 echo
171 echo "=== Testing blkverify on existing raw block device ==="
172 echo
174 run_qemu <<EOF
175 { "execute": "qmp_capabilities" }
176 { "execute": "blockdev-add",
177 "arguments": {
178 "node-name": "drive0",
179 "driver": "file",
180 "filename": "$TEST_IMG.base"
183 { "execute": "blockdev-add",
184 "arguments": {
185 "driver": "blkverify",
186 "node-name": "drive0-verify",
187 "test": {
188 "driver": "$IMGFMT",
189 "file": {
190 "driver": "file",
191 "filename": "$TEST_IMG"
194 "raw": "drive0"
197 { "execute": "human-monitor-command",
198 "arguments": {
199 "command-line": 'qemu-io drive0-verify "read 0 512"'
202 { "execute": "quit" }
205 echo
206 echo "=== Testing blkdebug's set-state through QMP ==="
207 echo
209 run_qemu <<EOF
210 { "execute": "qmp_capabilities" }
211 { "execute": "blockdev-add",
212 "arguments": {
213 "node-name": "drive0",
214 "driver": "file",
215 "filename": "$TEST_IMG"
218 { "execute": "blockdev-add",
219 "arguments": {
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
229 "set-state": [{
230 "event": "write_aio",
231 "new_state": 42
236 { "execute": "human-monitor-command",
237 "arguments": {
238 "command-line": 'qemu-io drive0-debug "read 0 512"'
241 { "execute": "human-monitor-command",
242 "arguments": {
243 "command-line": 'qemu-io drive0-debug "write 0 512"'
246 { "execute": "human-monitor-command",
247 "arguments": {
248 "command-line": 'qemu-io drive0-debug "read 0 512"'
251 { "execute": "quit" }
254 # success, all done
255 echo "*** done"
256 rm -f $seq.full
257 status=0