| 1 | #!/usr/bin/env bash |
| 2 | # group: rw auto quick |
| 3 | # |
| 4 | # Test case for the QMP blkdebug and blkverify interfaces |
| 5 | # |
| 6 | # Copyright (C) 2013 Red Hat, Inc. |
| 7 | # |
| 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. |
| 12 | # |
| 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. |
| 17 | # |
| 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/>. |
| 20 | # |
| 21 | |
| 22 | # creator |
| 23 | owner=hreitz@redhat.com |
| 24 | |
| 25 | seq="$(basename $0)" |
| 26 | echo "QA output created by $seq" |
| 27 | |
| 28 | status=1 # failure is the default! |
| 29 | |
| 30 | _cleanup() |
| 31 | { |
| 32 | _cleanup_test_img |
| 33 | } |
| 34 | trap "_cleanup; exit \$status" 0 1 2 3 15 |
| 35 | |
| 36 | # get standard environment, filters and checks |
| 37 | . ./common.rc |
| 38 | . ./common.filter |
| 39 | |
| 40 | _supported_fmt qcow2 |
| 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 this test does not work with external data files |
| 45 | _unsupported_imgopts data_file |
| 46 | _require_hmp |
| 47 | |
| 48 | do_run_qemu() |
| 49 | { |
| 50 | echo Testing: "$@" | _filter_imgfmt |
| 51 | $QEMU -nographic -qmp stdio -serial none "$@" |
| 52 | echo |
| 53 | } |
| 54 | |
| 55 | run_qemu() |
| 56 | { |
| 57 | do_run_qemu "$@" 2>&1 | _filter_testdir | _filter_qemu | _filter_qmp | _filter_qemu_io |
| 58 | } |
| 59 | |
| 60 | IMG_SIZE=64M |
| 61 | |
| 62 | echo |
| 63 | echo "=== Testing blkverify through filename ===" |
| 64 | echo |
| 65 | |
| 66 | # _make_test_img may set variables that we need to retain. Everything |
| 67 | # in a pipe is executed in a subshell, so doing so would throw away |
| 68 | # all changes. Therefore, we have to store the output in some temp |
| 69 | # file and filter that. |
| 70 | scratch_out="$TEST_DIR/img-create.out" |
| 71 | |
| 72 | TEST_IMG="$TEST_IMG.base" IMGFMT="raw" _make_test_img --no-opts $IMG_SIZE \ |
| 73 | >"$scratch_out" |
| 74 | _filter_imgfmt <"$scratch_out" |
| 75 | rm -f "$scratch_out" |
| 76 | |
| 77 | _make_test_img $IMG_SIZE |
| 78 | $QEMU_IO -c "open -o driver=raw,file.driver=blkverify,file.raw.filename=$TEST_IMG.base $TEST_IMG" \ |
| 79 | -c 'read 0 512' -c 'write -P 42 0x38000 512' -c 'read -P 42 0x38000 512' | _filter_qemu_io |
| 80 | |
| 81 | $QEMU_IO -c 'write -P 42 0 512' "$TEST_IMG" | _filter_qemu_io |
| 82 | |
| 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 |
| 85 | |
| 86 | echo |
| 87 | echo "=== Testing blkverify through file blockref ===" |
| 88 | echo |
| 89 | |
| 90 | TEST_IMG="$TEST_IMG.base" IMGFMT="raw" _make_test_img --no-opts $IMG_SIZE \ |
| 91 | >"$scratch_out" |
| 92 | _filter_imgfmt <"$scratch_out" |
| 93 | |
| 94 | _make_test_img $IMG_SIZE |
| 95 | $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" \ |
| 96 | -c 'read 0 512' -c 'write -P 42 0x38000 512' -c 'read -P 42 0x38000 512' | _filter_qemu_io |
| 97 | |
| 98 | $QEMU_IO -c 'write -P 42 0 512' "$TEST_IMG" | _filter_qemu_io |
| 99 | |
| 100 | $QEMU_IO -c "open -o driver=raw,file.driver=blkverify,file.raw.filename=$TEST_IMG.base $TEST_IMG" \ |
| 101 | -c 'read -P 42 0 512' | _filter_qemu_io |
| 102 | |
| 103 | echo |
| 104 | echo "=== Testing blkdebug through filename ===" |
| 105 | echo |
| 106 | |
| 107 | $QEMU_IO -c "open -o file.driver=blkdebug,file.inject-error.event=l2_load $TEST_IMG" \ |
| 108 | -c 'read -P 42 0x38000 512' |
| 109 | |
| 110 | echo |
| 111 | echo "=== Testing blkdebug through file blockref ===" |
| 112 | echo |
| 113 | |
| 114 | $QEMU_IO -c "open -o driver=$IMGFMT,file.driver=blkdebug,file.inject-error.event=l2_load,file.image.filename=$TEST_IMG" \ |
| 115 | -c 'read -P 42 0x38000 512' |
| 116 | |
| 117 | echo |
| 118 | echo "=== Testing blkdebug on existing block device ===" |
| 119 | echo |
| 120 | |
| 121 | run_qemu <<EOF |
| 122 | { "execute": "qmp_capabilities" } |
| 123 | { "execute": "blockdev-add", |
| 124 | "arguments": { |
| 125 | "node-name": "drive0", |
| 126 | "driver": "file", |
| 127 | "filename": "$TEST_IMG" |
| 128 | } |
| 129 | } |
| 130 | { "execute": "blockdev-add", |
| 131 | "arguments": { |
| 132 | "driver": "$IMGFMT", |
| 133 | "node-name": "drive0-debug", |
| 134 | "file": { |
| 135 | "driver": "blkdebug", |
| 136 | "image": "drive0", |
| 137 | "inject-error": [{ |
| 138 | "event": "l2_load" |
| 139 | }] |
| 140 | } |
| 141 | } |
| 142 | } |
| 143 | { "execute": "human-monitor-command", |
| 144 | "arguments": { |
| 145 | "command-line": 'qemu-io drive0-debug "read 0 512"' |
| 146 | } |
| 147 | } |
| 148 | { "execute": "quit" } |
| 149 | EOF |
| 150 | |
| 151 | echo |
| 152 | echo "=== Testing blkverify on existing block device ===" |
| 153 | echo |
| 154 | |
| 155 | run_qemu <<EOF |
| 156 | { "execute": "qmp_capabilities" } |
| 157 | { "execute": "blockdev-add", |
| 158 | "arguments": { |
| 159 | "node-name": "drive0", |
| 160 | "driver": "$IMGFMT", |
| 161 | "file": { |
| 162 | "driver": "file", |
| 163 | "filename": "$TEST_IMG" |
| 164 | } |
| 165 | } |
| 166 | } |
| 167 | { "execute": "blockdev-add", |
| 168 | "arguments": { |
| 169 | "driver": "blkverify", |
| 170 | "node-name": "drive0-verify", |
| 171 | "test": "drive0", |
| 172 | "raw": { |
| 173 | "driver": "file", |
| 174 | "filename": "$TEST_IMG.base" |
| 175 | } |
| 176 | } |
| 177 | } |
| 178 | { "execute": "human-monitor-command", |
| 179 | "arguments": { |
| 180 | "command-line": 'qemu-io drive0-verify "read 0 512"' |
| 181 | } |
| 182 | } |
| 183 | { "execute": "quit" } |
| 184 | EOF |
| 185 | |
| 186 | echo |
| 187 | echo "=== Testing blkverify on existing raw block device ===" |
| 188 | echo |
| 189 | |
| 190 | run_qemu <<EOF |
| 191 | { "execute": "qmp_capabilities" } |
| 192 | { "execute": "blockdev-add", |
| 193 | "arguments": { |
| 194 | "node-name": "drive0", |
| 195 | "driver": "file", |
| 196 | "filename": "$TEST_IMG.base" |
| 197 | } |
| 198 | } |
| 199 | { "execute": "blockdev-add", |
| 200 | "arguments": { |
| 201 | "driver": "blkverify", |
| 202 | "node-name": "drive0-verify", |
| 203 | "test": { |
| 204 | "driver": "$IMGFMT", |
| 205 | "file": { |
| 206 | "driver": "file", |
| 207 | "filename": "$TEST_IMG" |
| 208 | } |
| 209 | }, |
| 210 | "raw": "drive0" |
| 211 | } |
| 212 | } |
| 213 | { "execute": "human-monitor-command", |
| 214 | "arguments": { |
| 215 | "command-line": 'qemu-io drive0-verify "read 0 512"' |
| 216 | } |
| 217 | } |
| 218 | { "execute": "quit" } |
| 219 | EOF |
| 220 | |
| 221 | echo |
| 222 | echo "=== Testing blkdebug's set-state through QMP ===" |
| 223 | echo |
| 224 | |
| 225 | run_qemu <<EOF |
| 226 | { "execute": "qmp_capabilities" } |
| 227 | { "execute": "blockdev-add", |
| 228 | "arguments": { |
| 229 | "node-name": "drive0", |
| 230 | "driver": "file", |
| 231 | "filename": "$TEST_IMG" |
| 232 | } |
| 233 | } |
| 234 | { "execute": "blockdev-add", |
| 235 | "arguments": { |
| 236 | "driver": "$IMGFMT", |
| 237 | "node-name": "drive0-debug", |
| 238 | "file": { |
| 239 | "driver": "blkdebug", |
| 240 | "image": "drive0", |
| 241 | "inject-error": [{ |
| 242 | "event": "read_aio", |
| 243 | "state": 42 |
| 244 | }], |
| 245 | "set-state": [{ |
| 246 | "event": "write_aio", |
| 247 | "new_state": 42 |
| 248 | }] |
| 249 | } |
| 250 | } |
| 251 | } |
| 252 | { "execute": "human-monitor-command", |
| 253 | "arguments": { |
| 254 | "command-line": 'qemu-io drive0-debug "read 0 512"' |
| 255 | } |
| 256 | } |
| 257 | { "execute": "human-monitor-command", |
| 258 | "arguments": { |
| 259 | "command-line": 'qemu-io drive0-debug "write 0 512"' |
| 260 | } |
| 261 | } |
| 262 | { "execute": "human-monitor-command", |
| 263 | "arguments": { |
| 264 | "command-line": 'qemu-io drive0-debug "read 0 512"' |
| 265 | } |
| 266 | } |
| 267 | { "execute": "quit" } |
| 268 | EOF |
| 269 | |
| 270 | # success, all done |
| 271 | echo "*** done" |
| 272 | rm -f $seq.full |
| 273 | status=0 |