iotests: Do not pipe _make_test_img
[qemu.git] / tests / qemu-iotests / 071
blob18fe9054b07ea351dae96c7f51bc1f030be6ad24
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 _require_drivers blkdebug blkverify
42 # blkdebug can only inject errors on bs->file, not on the data_file,
43 # so thie test does not work with external data files
44 _unsupported_imgopts data_file
46 do_run_qemu()
48 echo Testing: "$@" | _filter_imgfmt
49 $QEMU -nographic -qmp stdio -serial none "$@"
50 echo
53 run_qemu()
55 do_run_qemu "$@" 2>&1 | _filter_testdir | _filter_qemu | _filter_qmp | _filter_qemu_io
58 IMG_SIZE=64M
60 echo
61 echo "=== Testing blkverify through filename ==="
62 echo
64 # _make_test_img may set variables that we need to retain. Everything
65 # in a pipe is executed in a subshell, so doing so would throw away
66 # all changes. Therefore, we have to store the output in some temp
67 # file and filter that.
68 scratch_out="$TEST_DIR/img-create.out"
70 TEST_IMG="$TEST_IMG.base" IMGFMT="raw" _make_test_img --no-opts $IMG_SIZE \
71 >"$scratch_out"
72 _filter_imgfmt <"$scratch_out"
73 rm -f "$scratch_out"
75 _make_test_img $IMG_SIZE
76 $QEMU_IO -c "open -o driver=raw,file.driver=blkverify,file.raw.filename=$TEST_IMG.base $TEST_IMG" \
77 -c 'read 0 512' -c 'write -P 42 0x38000 512' -c 'read -P 42 0x38000 512' | _filter_qemu_io
79 $QEMU_IO -c 'write -P 42 0 512' "$TEST_IMG" | _filter_qemu_io
81 $QEMU_IO -c "open -o driver=raw,file.driver=blkverify,file.raw.filename=$TEST_IMG.base $TEST_IMG" \
82 -c 'read -P 42 0 512' | _filter_qemu_io
84 echo
85 echo "=== Testing blkverify through file blockref ==="
86 echo
88 TEST_IMG="$TEST_IMG.base" IMGFMT="raw" _make_test_img --no-opts $IMG_SIZE \
89 >"$scratch_out"
90 _filter_imgfmt <"$scratch_out"
92 _make_test_img $IMG_SIZE
93 $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" \
94 -c 'read 0 512' -c 'write -P 42 0x38000 512' -c 'read -P 42 0x38000 512' | _filter_qemu_io
96 $QEMU_IO -c 'write -P 42 0 512' "$TEST_IMG" | _filter_qemu_io
98 $QEMU_IO -c "open -o driver=raw,file.driver=blkverify,file.raw.filename=$TEST_IMG.base $TEST_IMG" \
99 -c 'read -P 42 0 512' | _filter_qemu_io
101 echo
102 echo "=== Testing blkdebug through filename ==="
103 echo
105 $QEMU_IO -c "open -o file.driver=blkdebug,file.inject-error.event=l2_load $TEST_IMG" \
106 -c 'read -P 42 0x38000 512'
108 echo
109 echo "=== Testing blkdebug through file blockref ==="
110 echo
112 $QEMU_IO -c "open -o driver=$IMGFMT,file.driver=blkdebug,file.inject-error.event=l2_load,file.image.filename=$TEST_IMG" \
113 -c 'read -P 42 0x38000 512'
115 echo
116 echo "=== Testing blkdebug on existing block device ==="
117 echo
119 run_qemu <<EOF
120 { "execute": "qmp_capabilities" }
121 { "execute": "blockdev-add",
122 "arguments": {
123 "node-name": "drive0",
124 "driver": "file",
125 "filename": "$TEST_IMG"
128 { "execute": "blockdev-add",
129 "arguments": {
130 "driver": "$IMGFMT",
131 "node-name": "drive0-debug",
132 "file": {
133 "driver": "blkdebug",
134 "image": "drive0",
135 "inject-error": [{
136 "event": "l2_load"
141 { "execute": "human-monitor-command",
142 "arguments": {
143 "command-line": 'qemu-io drive0-debug "read 0 512"'
146 { "execute": "quit" }
149 echo
150 echo "=== Testing blkverify on existing block device ==="
151 echo
153 run_qemu <<EOF
154 { "execute": "qmp_capabilities" }
155 { "execute": "blockdev-add",
156 "arguments": {
157 "node-name": "drive0",
158 "driver": "$IMGFMT",
159 "file": {
160 "driver": "file",
161 "filename": "$TEST_IMG"
165 { "execute": "blockdev-add",
166 "arguments": {
167 "driver": "blkverify",
168 "node-name": "drive0-verify",
169 "test": "drive0",
170 "raw": {
171 "driver": "file",
172 "filename": "$TEST_IMG.base"
176 { "execute": "human-monitor-command",
177 "arguments": {
178 "command-line": 'qemu-io drive0-verify "read 0 512"'
181 { "execute": "quit" }
184 echo
185 echo "=== Testing blkverify on existing raw block device ==="
186 echo
188 run_qemu <<EOF
189 { "execute": "qmp_capabilities" }
190 { "execute": "blockdev-add",
191 "arguments": {
192 "node-name": "drive0",
193 "driver": "file",
194 "filename": "$TEST_IMG.base"
197 { "execute": "blockdev-add",
198 "arguments": {
199 "driver": "blkverify",
200 "node-name": "drive0-verify",
201 "test": {
202 "driver": "$IMGFMT",
203 "file": {
204 "driver": "file",
205 "filename": "$TEST_IMG"
208 "raw": "drive0"
211 { "execute": "human-monitor-command",
212 "arguments": {
213 "command-line": 'qemu-io drive0-verify "read 0 512"'
216 { "execute": "quit" }
219 echo
220 echo "=== Testing blkdebug's set-state through QMP ==="
221 echo
223 run_qemu <<EOF
224 { "execute": "qmp_capabilities" }
225 { "execute": "blockdev-add",
226 "arguments": {
227 "node-name": "drive0",
228 "driver": "file",
229 "filename": "$TEST_IMG"
232 { "execute": "blockdev-add",
233 "arguments": {
234 "driver": "$IMGFMT",
235 "node-name": "drive0-debug",
236 "file": {
237 "driver": "blkdebug",
238 "image": "drive0",
239 "inject-error": [{
240 "event": "read_aio",
241 "state": 42
243 "set-state": [{
244 "event": "write_aio",
245 "new_state": 42
250 { "execute": "human-monitor-command",
251 "arguments": {
252 "command-line": 'qemu-io drive0-debug "read 0 512"'
255 { "execute": "human-monitor-command",
256 "arguments": {
257 "command-line": 'qemu-io drive0-debug "write 0 512"'
260 { "execute": "human-monitor-command",
261 "arguments": {
262 "command-line": 'qemu-io drive0-debug "read 0 512"'
265 { "execute": "quit" }
268 # success, all done
269 echo "*** done"
270 rm -f $seq.full
271 status=0