4 # Test case for the QMP blkdebug and blkverify interfaces
6 # Copyright (C) 2013 Red Hat, Inc.
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
23 owner
=mreitz@redhat.com
26 echo "QA output created by $seq"
28 status
=1 # failure is the default!
34 trap "_cleanup; exit \$status" 0 1 2 3 15
36 # get standard environment, filters and checks
41 _supported_proto
file fuse
42 _require_drivers blkdebug blkverify
43 # blkdebug can only inject errors on bs->file, not on the data_file,
44 # so thie test does not work with external data files
45 _unsupported_imgopts data_file
49 echo Testing
: "$@" | _filter_imgfmt
50 $QEMU -nographic -qmp stdio
-serial none
"$@"
56 do_run_qemu
"$@" 2>&1 | _filter_testdir | _filter_qemu | _filter_qmp | _filter_qemu_io
62 echo "=== Testing blkverify through filename ==="
65 # _make_test_img may set variables that we need to retain. Everything
66 # in a pipe is executed in a subshell, so doing so would throw away
67 # all changes. Therefore, we have to store the output in some temp
68 # file and filter that.
69 scratch_out
="$TEST_DIR/img-create.out"
71 TEST_IMG
="$TEST_IMG.base" IMGFMT
="raw" _make_test_img
--no-opts $IMG_SIZE \
73 _filter_imgfmt
<"$scratch_out"
76 _make_test_img
$IMG_SIZE
77 $QEMU_IO -c "open -o driver=raw,file.driver=blkverify,file.raw.filename=$TEST_IMG.base $TEST_IMG" \
78 -c 'read 0 512' -c 'write -P 42 0x38000 512' -c 'read -P 42 0x38000 512' | _filter_qemu_io
80 $QEMU_IO -c 'write -P 42 0 512' "$TEST_IMG" | _filter_qemu_io
82 $QEMU_IO -c "open -o driver=raw,file.driver=blkverify,file.raw.filename=$TEST_IMG.base $TEST_IMG" \
83 -c 'read -P 42 0 512' | _filter_qemu_io
86 echo "=== Testing blkverify through file blockref ==="
89 TEST_IMG
="$TEST_IMG.base" IMGFMT
="raw" _make_test_img
--no-opts $IMG_SIZE \
91 _filter_imgfmt
<"$scratch_out"
93 _make_test_img
$IMG_SIZE
94 $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" \
95 -c 'read 0 512' -c 'write -P 42 0x38000 512' -c 'read -P 42 0x38000 512' | _filter_qemu_io
97 $QEMU_IO -c 'write -P 42 0 512' "$TEST_IMG" | _filter_qemu_io
99 $QEMU_IO -c "open -o driver=raw,file.driver=blkverify,file.raw.filename=$TEST_IMG.base $TEST_IMG" \
100 -c 'read -P 42 0 512' | _filter_qemu_io
103 echo "=== Testing blkdebug through filename ==="
106 $QEMU_IO -c "open -o file.driver=blkdebug,file.inject-error.event=l2_load $TEST_IMG" \
107 -c 'read -P 42 0x38000 512'
110 echo "=== Testing blkdebug through file blockref ==="
113 $QEMU_IO -c "open -o driver=$IMGFMT,file.driver=blkdebug,file.inject-error.event=l2_load,file.image.filename=$TEST_IMG" \
114 -c 'read -P 42 0x38000 512'
117 echo "=== Testing blkdebug on existing block device ==="
121 { "execute": "qmp_capabilities" }
122 { "execute": "blockdev-add",
124 "node-name": "drive0",
126 "filename": "$TEST_IMG"
129 { "execute": "blockdev-add",
132 "node-name": "drive0-debug",
134 "driver": "blkdebug",
142 { "execute": "human-monitor-command",
144 "command-line": 'qemu-io drive0-debug "read 0 512"'
147 { "execute": "quit" }
151 echo "=== Testing blkverify on existing block device ==="
155 { "execute": "qmp_capabilities" }
156 { "execute": "blockdev-add",
158 "node-name": "drive0",
162 "filename": "$TEST_IMG"
166 { "execute": "blockdev-add",
168 "driver": "blkverify",
169 "node-name": "drive0-verify",
173 "filename": "$TEST_IMG.base"
177 { "execute": "human-monitor-command",
179 "command-line": 'qemu-io drive0-verify "read 0 512"'
182 { "execute": "quit" }
186 echo "=== Testing blkverify on existing raw block device ==="
190 { "execute": "qmp_capabilities" }
191 { "execute": "blockdev-add",
193 "node-name": "drive0",
195 "filename": "$TEST_IMG.base"
198 { "execute": "blockdev-add",
200 "driver": "blkverify",
201 "node-name": "drive0-verify",
206 "filename": "$TEST_IMG"
212 { "execute": "human-monitor-command",
214 "command-line": 'qemu-io drive0-verify "read 0 512"'
217 { "execute": "quit" }
221 echo "=== Testing blkdebug's set-state through QMP ==="
225 { "execute": "qmp_capabilities" }
226 { "execute": "blockdev-add",
228 "node-name": "drive0",
230 "filename": "$TEST_IMG"
233 { "execute": "blockdev-add",
236 "node-name": "drive0-debug",
238 "driver": "blkdebug",
245 "event": "write_aio",
251 { "execute": "human-monitor-command",
253 "command-line": 'qemu-io drive0-debug "read 0 512"'
256 { "execute": "human-monitor-command",
258 "command-line": 'qemu-io drive0-debug "write 0 512"'
261 { "execute": "human-monitor-command",
263 "command-line": 'qemu-io drive0-debug "read 0 512"'
266 { "execute": "quit" }