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/>.
22 owner
=mreitz@redhat.com
25 echo "QA output created by $seq"
27 status
=1 # failure is the default!
33 trap "_cleanup; exit \$status" 0 1 2 3 15
35 # get standard environment, filters and checks
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
48 echo Testing
: "$@" | _filter_imgfmt
49 $QEMU -nographic -qmp stdio
-serial none
"$@"
55 do_run_qemu
"$@" 2>&1 | _filter_testdir | _filter_qemu | _filter_qmp | _filter_qemu_io
61 echo "=== Testing blkverify through filename ==="
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 \
72 _filter_imgfmt
<"$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
85 echo "=== Testing blkverify through file blockref ==="
88 TEST_IMG
="$TEST_IMG.base" IMGFMT
="raw" _make_test_img
--no-opts $IMG_SIZE \
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
102 echo "=== Testing blkdebug through filename ==="
105 $QEMU_IO -c "open -o file.driver=blkdebug,file.inject-error.event=l2_load $TEST_IMG" \
106 -c 'read -P 42 0x38000 512'
109 echo "=== Testing blkdebug through file blockref ==="
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'
116 echo "=== Testing blkdebug on existing block device ==="
120 { "execute": "qmp_capabilities" }
121 { "execute": "blockdev-add",
123 "node-name": "drive0",
125 "filename": "$TEST_IMG"
128 { "execute": "blockdev-add",
131 "node-name": "drive0-debug",
133 "driver": "blkdebug",
141 { "execute": "human-monitor-command",
143 "command-line": 'qemu-io drive0-debug "read 0 512"'
146 { "execute": "quit" }
150 echo "=== Testing blkverify on existing block device ==="
154 { "execute": "qmp_capabilities" }
155 { "execute": "blockdev-add",
157 "node-name": "drive0",
161 "filename": "$TEST_IMG"
165 { "execute": "blockdev-add",
167 "driver": "blkverify",
168 "node-name": "drive0-verify",
172 "filename": "$TEST_IMG.base"
176 { "execute": "human-monitor-command",
178 "command-line": 'qemu-io drive0-verify "read 0 512"'
181 { "execute": "quit" }
185 echo "=== Testing blkverify on existing raw block device ==="
189 { "execute": "qmp_capabilities" }
190 { "execute": "blockdev-add",
192 "node-name": "drive0",
194 "filename": "$TEST_IMG.base"
197 { "execute": "blockdev-add",
199 "driver": "blkverify",
200 "node-name": "drive0-verify",
205 "filename": "$TEST_IMG"
211 { "execute": "human-monitor-command",
213 "command-line": 'qemu-io drive0-verify "read 0 512"'
216 { "execute": "quit" }
220 echo "=== Testing blkdebug's set-state through QMP ==="
224 { "execute": "qmp_capabilities" }
225 { "execute": "blockdev-add",
227 "node-name": "drive0",
229 "filename": "$TEST_IMG"
232 { "execute": "blockdev-add",
235 "node-name": "drive0-debug",
237 "driver": "blkdebug",
244 "event": "write_aio",
250 { "execute": "human-monitor-command",
252 "command-line": 'qemu-io drive0-debug "read 0 512"'
255 { "execute": "human-monitor-command",
257 "command-line": 'qemu-io drive0-debug "write 0 512"'
260 { "execute": "human-monitor-command",
262 "command-line": 'qemu-io drive0-debug "read 0 512"'
265 { "execute": "quit" }