Philippe Mathieu-Daudé | 11a82d1 | 2019-03-07 15:58:38 +0100 | [diff] [blame] | 1 | #!/usr/bin/env bash |
Vladimir Sementsov-Ogievskiy | 9dd003a | 2021-01-16 16:44:19 +0300 | [diff] [blame] | 2 | # group: rw auto quick |
Max Reitz | 30bd6a4 | 2013-12-20 19:28:23 +0100 | [diff] [blame] | 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=mreitz@redhat.com |
| 24 | |
| 25 | seq="$(basename $0)" |
| 26 | echo "QA output created by $seq" |
| 27 | |
Max Reitz | 30bd6a4 | 2013-12-20 19:28:23 +0100 | [diff] [blame] | 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 | |
Stefan Hajnoczi | 1b7650e | 2014-01-29 16:33:54 +0100 | [diff] [blame] | 40 | _supported_fmt qcow2 |
Max Reitz | 57284d2 | 2020-10-27 20:05:59 +0100 | [diff] [blame] | 41 | _supported_proto file fuse |
Thomas Huth | 21b43d0 | 2019-08-23 15:35:52 +0200 | [diff] [blame] | 42 | _require_drivers blkdebug blkverify |
Max Reitz | 3be2024 | 2019-11-07 17:37:07 +0100 | [diff] [blame] | 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 |
Max Reitz | 30bd6a4 | 2013-12-20 19:28:23 +0100 | [diff] [blame] | 46 | |
Eric Blake | 8cedcff | 2018-11-16 15:50:02 -0600 | [diff] [blame] | 47 | do_run_qemu() |
Max Reitz | 30bd6a4 | 2013-12-20 19:28:23 +0100 | [diff] [blame] | 48 | { |
| 49 | echo Testing: "$@" | _filter_imgfmt |
| 50 | $QEMU -nographic -qmp stdio -serial none "$@" |
| 51 | echo |
| 52 | } |
| 53 | |
Eric Blake | 8cedcff | 2018-11-16 15:50:02 -0600 | [diff] [blame] | 54 | run_qemu() |
Max Reitz | 30bd6a4 | 2013-12-20 19:28:23 +0100 | [diff] [blame] | 55 | { |
Max Reitz | 4dd7b8d | 2014-12-19 17:17:06 +0100 | [diff] [blame] | 56 | do_run_qemu "$@" 2>&1 | _filter_testdir | _filter_qemu | _filter_qmp | _filter_qemu_io |
Max Reitz | 30bd6a4 | 2013-12-20 19:28:23 +0100 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | IMG_SIZE=64M |
| 60 | |
| 61 | echo |
| 62 | echo "=== Testing blkverify through filename ===" |
| 63 | echo |
| 64 | |
Max Reitz | d81fe25 | 2020-10-27 20:05:48 +0100 | [diff] [blame] | 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" |
| 70 | |
| 71 | TEST_IMG="$TEST_IMG.base" IMGFMT="raw" _make_test_img --no-opts $IMG_SIZE \ |
| 72 | >"$scratch_out" |
| 73 | _filter_imgfmt <"$scratch_out" |
| 74 | rm -f "$scratch_out" |
| 75 | |
Max Reitz | 30bd6a4 | 2013-12-20 19:28:23 +0100 | [diff] [blame] | 76 | _make_test_img $IMG_SIZE |
Kevin Wolf | 8f9e835 | 2014-11-20 16:27:07 +0100 | [diff] [blame] | 77 | $QEMU_IO -c "open -o driver=raw,file.driver=blkverify,file.raw.filename=$TEST_IMG.base $TEST_IMG" \ |
Max Reitz | 30bd6a4 | 2013-12-20 19:28:23 +0100 | [diff] [blame] | 78 | -c 'read 0 512' -c 'write -P 42 0x38000 512' -c 'read -P 42 0x38000 512' | _filter_qemu_io |
| 79 | |
| 80 | $QEMU_IO -c 'write -P 42 0 512' "$TEST_IMG" | _filter_qemu_io |
| 81 | |
Kevin Wolf | 8f9e835 | 2014-11-20 16:27:07 +0100 | [diff] [blame] | 82 | $QEMU_IO -c "open -o driver=raw,file.driver=blkverify,file.raw.filename=$TEST_IMG.base $TEST_IMG" \ |
Max Reitz | 30bd6a4 | 2013-12-20 19:28:23 +0100 | [diff] [blame] | 83 | -c 'read -P 42 0 512' | _filter_qemu_io |
| 84 | |
| 85 | echo |
| 86 | echo "=== Testing blkverify through file blockref ===" |
| 87 | echo |
| 88 | |
Max Reitz | d81fe25 | 2020-10-27 20:05:48 +0100 | [diff] [blame] | 89 | TEST_IMG="$TEST_IMG.base" IMGFMT="raw" _make_test_img --no-opts $IMG_SIZE \ |
| 90 | >"$scratch_out" |
| 91 | _filter_imgfmt <"$scratch_out" |
| 92 | |
Max Reitz | 30bd6a4 | 2013-12-20 19:28:23 +0100 | [diff] [blame] | 93 | _make_test_img $IMG_SIZE |
Kevin Wolf | 8f9e835 | 2014-11-20 16:27:07 +0100 | [diff] [blame] | 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" \ |
Max Reitz | 30bd6a4 | 2013-12-20 19:28:23 +0100 | [diff] [blame] | 95 | -c 'read 0 512' -c 'write -P 42 0x38000 512' -c 'read -P 42 0x38000 512' | _filter_qemu_io |
| 96 | |
| 97 | $QEMU_IO -c 'write -P 42 0 512' "$TEST_IMG" | _filter_qemu_io |
| 98 | |
Kevin Wolf | 8f9e835 | 2014-11-20 16:27:07 +0100 | [diff] [blame] | 99 | $QEMU_IO -c "open -o driver=raw,file.driver=blkverify,file.raw.filename=$TEST_IMG.base $TEST_IMG" \ |
Max Reitz | 30bd6a4 | 2013-12-20 19:28:23 +0100 | [diff] [blame] | 100 | -c 'read -P 42 0 512' | _filter_qemu_io |
| 101 | |
| 102 | echo |
| 103 | echo "=== Testing blkdebug through filename ===" |
| 104 | echo |
| 105 | |
| 106 | $QEMU_IO -c "open -o file.driver=blkdebug,file.inject-error.event=l2_load $TEST_IMG" \ |
| 107 | -c 'read -P 42 0x38000 512' |
| 108 | |
| 109 | echo |
| 110 | echo "=== Testing blkdebug through file blockref ===" |
| 111 | echo |
| 112 | |
| 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' |
| 115 | |
| 116 | echo |
| 117 | echo "=== Testing blkdebug on existing block device ===" |
| 118 | echo |
| 119 | |
Max Reitz | 8e9e653 | 2015-10-19 17:53:10 +0200 | [diff] [blame] | 120 | run_qemu <<EOF |
Max Reitz | 30bd6a4 | 2013-12-20 19:28:23 +0100 | [diff] [blame] | 121 | { "execute": "qmp_capabilities" } |
| 122 | { "execute": "blockdev-add", |
| 123 | "arguments": { |
Kevin Wolf | 0153d2f | 2016-10-07 17:05:04 +0200 | [diff] [blame] | 124 | "node-name": "drive0", |
| 125 | "driver": "file", |
| 126 | "filename": "$TEST_IMG" |
Max Reitz | 8e9e653 | 2015-10-19 17:53:10 +0200 | [diff] [blame] | 127 | } |
| 128 | } |
| 129 | { "execute": "blockdev-add", |
| 130 | "arguments": { |
Kevin Wolf | 0153d2f | 2016-10-07 17:05:04 +0200 | [diff] [blame] | 131 | "driver": "$IMGFMT", |
| 132 | "node-name": "drive0-debug", |
| 133 | "file": { |
| 134 | "driver": "blkdebug", |
| 135 | "image": "drive0", |
| 136 | "inject-error": [{ |
| 137 | "event": "l2_load" |
| 138 | }] |
Max Reitz | 30bd6a4 | 2013-12-20 19:28:23 +0100 | [diff] [blame] | 139 | } |
| 140 | } |
| 141 | } |
| 142 | { "execute": "human-monitor-command", |
| 143 | "arguments": { |
| 144 | "command-line": 'qemu-io drive0-debug "read 0 512"' |
| 145 | } |
| 146 | } |
| 147 | { "execute": "quit" } |
| 148 | EOF |
| 149 | |
| 150 | echo |
| 151 | echo "=== Testing blkverify on existing block device ===" |
| 152 | echo |
| 153 | |
Max Reitz | 8e9e653 | 2015-10-19 17:53:10 +0200 | [diff] [blame] | 154 | run_qemu <<EOF |
Max Reitz | 30bd6a4 | 2013-12-20 19:28:23 +0100 | [diff] [blame] | 155 | { "execute": "qmp_capabilities" } |
| 156 | { "execute": "blockdev-add", |
| 157 | "arguments": { |
Kevin Wolf | 0153d2f | 2016-10-07 17:05:04 +0200 | [diff] [blame] | 158 | "node-name": "drive0", |
| 159 | "driver": "$IMGFMT", |
| 160 | "file": { |
| 161 | "driver": "file", |
| 162 | "filename": "$TEST_IMG" |
Max Reitz | 8e9e653 | 2015-10-19 17:53:10 +0200 | [diff] [blame] | 163 | } |
| 164 | } |
| 165 | } |
| 166 | { "execute": "blockdev-add", |
| 167 | "arguments": { |
Kevin Wolf | 0153d2f | 2016-10-07 17:05:04 +0200 | [diff] [blame] | 168 | "driver": "blkverify", |
| 169 | "node-name": "drive0-verify", |
| 170 | "test": "drive0", |
| 171 | "raw": { |
| 172 | "driver": "file", |
| 173 | "filename": "$TEST_IMG.base" |
Max Reitz | 30bd6a4 | 2013-12-20 19:28:23 +0100 | [diff] [blame] | 174 | } |
| 175 | } |
| 176 | } |
| 177 | { "execute": "human-monitor-command", |
| 178 | "arguments": { |
| 179 | "command-line": 'qemu-io drive0-verify "read 0 512"' |
| 180 | } |
| 181 | } |
| 182 | { "execute": "quit" } |
| 183 | EOF |
| 184 | |
| 185 | echo |
| 186 | echo "=== Testing blkverify on existing raw block device ===" |
| 187 | echo |
| 188 | |
Max Reitz | 8e9e653 | 2015-10-19 17:53:10 +0200 | [diff] [blame] | 189 | run_qemu <<EOF |
Max Reitz | 30bd6a4 | 2013-12-20 19:28:23 +0100 | [diff] [blame] | 190 | { "execute": "qmp_capabilities" } |
| 191 | { "execute": "blockdev-add", |
| 192 | "arguments": { |
Kevin Wolf | 0153d2f | 2016-10-07 17:05:04 +0200 | [diff] [blame] | 193 | "node-name": "drive0", |
| 194 | "driver": "file", |
| 195 | "filename": "$TEST_IMG.base" |
Max Reitz | 8e9e653 | 2015-10-19 17:53:10 +0200 | [diff] [blame] | 196 | } |
| 197 | } |
| 198 | { "execute": "blockdev-add", |
| 199 | "arguments": { |
Kevin Wolf | 0153d2f | 2016-10-07 17:05:04 +0200 | [diff] [blame] | 200 | "driver": "blkverify", |
| 201 | "node-name": "drive0-verify", |
| 202 | "test": { |
| 203 | "driver": "$IMGFMT", |
| 204 | "file": { |
| 205 | "driver": "file", |
| 206 | "filename": "$TEST_IMG" |
| 207 | } |
| 208 | }, |
| 209 | "raw": "drive0" |
Max Reitz | 30bd6a4 | 2013-12-20 19:28:23 +0100 | [diff] [blame] | 210 | } |
| 211 | } |
| 212 | { "execute": "human-monitor-command", |
| 213 | "arguments": { |
| 214 | "command-line": 'qemu-io drive0-verify "read 0 512"' |
| 215 | } |
| 216 | } |
| 217 | { "execute": "quit" } |
| 218 | EOF |
| 219 | |
| 220 | echo |
| 221 | echo "=== Testing blkdebug's set-state through QMP ===" |
| 222 | echo |
| 223 | |
Max Reitz | 8e9e653 | 2015-10-19 17:53:10 +0200 | [diff] [blame] | 224 | run_qemu <<EOF |
Max Reitz | 30bd6a4 | 2013-12-20 19:28:23 +0100 | [diff] [blame] | 225 | { "execute": "qmp_capabilities" } |
| 226 | { "execute": "blockdev-add", |
| 227 | "arguments": { |
Kevin Wolf | 0153d2f | 2016-10-07 17:05:04 +0200 | [diff] [blame] | 228 | "node-name": "drive0", |
| 229 | "driver": "file", |
| 230 | "filename": "$TEST_IMG" |
Max Reitz | 8e9e653 | 2015-10-19 17:53:10 +0200 | [diff] [blame] | 231 | } |
| 232 | } |
| 233 | { "execute": "blockdev-add", |
| 234 | "arguments": { |
Kevin Wolf | 0153d2f | 2016-10-07 17:05:04 +0200 | [diff] [blame] | 235 | "driver": "$IMGFMT", |
| 236 | "node-name": "drive0-debug", |
| 237 | "file": { |
| 238 | "driver": "blkdebug", |
| 239 | "image": "drive0", |
| 240 | "inject-error": [{ |
| 241 | "event": "read_aio", |
| 242 | "state": 42 |
| 243 | }], |
| 244 | "set-state": [{ |
| 245 | "event": "write_aio", |
| 246 | "new_state": 42 |
| 247 | }] |
Max Reitz | 30bd6a4 | 2013-12-20 19:28:23 +0100 | [diff] [blame] | 248 | } |
| 249 | } |
| 250 | } |
| 251 | { "execute": "human-monitor-command", |
| 252 | "arguments": { |
| 253 | "command-line": 'qemu-io drive0-debug "read 0 512"' |
| 254 | } |
| 255 | } |
| 256 | { "execute": "human-monitor-command", |
| 257 | "arguments": { |
| 258 | "command-line": 'qemu-io drive0-debug "write 0 512"' |
| 259 | } |
| 260 | } |
| 261 | { "execute": "human-monitor-command", |
| 262 | "arguments": { |
| 263 | "command-line": 'qemu-io drive0-debug "read 0 512"' |
| 264 | } |
| 265 | } |
| 266 | { "execute": "quit" } |
| 267 | EOF |
| 268 | |
| 269 | # success, all done |
| 270 | echo "*** done" |
| 271 | rm -f $seq.full |
| 272 | status=0 |