Merge remote-tracking branch 'remotes/maxreitz/tags/pull-block-2019-07-15' into staging
[qemu/ar7.git] / tests / qemu-iotests / 071
blob1cca9233d09d72f9a8c09163b42aaa47f6fb5b9f
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
42 do_run_qemu()
44 echo Testing: "$@" | _filter_imgfmt
45 $QEMU -nographic -qmp stdio -serial none "$@"
46 echo
49 run_qemu()
51 do_run_qemu "$@" 2>&1 | _filter_testdir | _filter_qemu | _filter_qmp | _filter_qemu_io
54 IMG_SIZE=64M
56 echo
57 echo "=== Testing blkverify through filename ==="
58 echo
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
66 $QEMU_IO -c 'write -P 42 0 512' "$TEST_IMG" | _filter_qemu_io
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
71 echo
72 echo "=== Testing blkverify through file blockref ==="
73 echo
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
81 $QEMU_IO -c 'write -P 42 0 512' "$TEST_IMG" | _filter_qemu_io
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
86 echo
87 echo "=== Testing blkdebug through filename ==="
88 echo
90 $QEMU_IO -c "open -o file.driver=blkdebug,file.inject-error.event=l2_load $TEST_IMG" \
91 -c 'read -P 42 0x38000 512'
93 echo
94 echo "=== Testing blkdebug through file blockref ==="
95 echo
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'
100 echo
101 echo "=== Testing blkdebug on existing block device ==="
102 echo
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"
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"
126 { "execute": "human-monitor-command",
127 "arguments": {
128 "command-line": 'qemu-io drive0-debug "read 0 512"'
131 { "execute": "quit" }
134 echo
135 echo "=== Testing blkverify on existing block device ==="
136 echo
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"
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"
161 { "execute": "human-monitor-command",
162 "arguments": {
163 "command-line": 'qemu-io drive0-verify "read 0 512"'
166 { "execute": "quit" }
169 echo
170 echo "=== Testing blkverify on existing raw block device ==="
171 echo
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"
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"
193 "raw": "drive0"
196 { "execute": "human-monitor-command",
197 "arguments": {
198 "command-line": 'qemu-io drive0-verify "read 0 512"'
201 { "execute": "quit" }
204 echo
205 echo "=== Testing blkdebug's set-state through QMP ==="
206 echo
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"
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
228 "set-state": [{
229 "event": "write_aio",
230 "new_state": 42
235 { "execute": "human-monitor-command",
236 "arguments": {
237 "command-line": 'qemu-io drive0-debug "read 0 512"'
240 { "execute": "human-monitor-command",
241 "arguments": {
242 "command-line": 'qemu-io drive0-debug "write 0 512"'
245 { "execute": "human-monitor-command",
246 "arguments": {
247 "command-line": 'qemu-io drive0-debug "read 0 512"'
250 { "execute": "quit" }
253 # success, all done
254 echo "*** done"
255 rm -f $seq.full
256 status=0