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