xref: /openbmc/qemu/tests/qemu-iotests/071 (revision a68694cd)
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_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
45
46do_run_qemu()
47{
48    echo Testing: "$@" | _filter_imgfmt
49    $QEMU -nographic -qmp stdio -serial none "$@"
50    echo
51}
52
53run_qemu()
54{
55    do_run_qemu "$@" 2>&1 | _filter_testdir | _filter_qemu | _filter_qmp | _filter_qemu_io
56}
57
58IMG_SIZE=64M
59
60echo
61echo "=== Testing blkverify through filename ==="
62echo
63
64TEST_IMG="$TEST_IMG.base" IMGFMT="raw" _make_test_img --no-opts $IMG_SIZE |\
65    _filter_imgfmt
66_make_test_img $IMG_SIZE
67$QEMU_IO -c "open -o driver=raw,file.driver=blkverify,file.raw.filename=$TEST_IMG.base $TEST_IMG" \
68         -c 'read 0 512' -c 'write -P 42 0x38000 512' -c 'read -P 42 0x38000 512' | _filter_qemu_io
69
70$QEMU_IO -c 'write -P 42 0 512' "$TEST_IMG" | _filter_qemu_io
71
72$QEMU_IO -c "open -o driver=raw,file.driver=blkverify,file.raw.filename=$TEST_IMG.base $TEST_IMG" \
73         -c 'read -P 42 0 512' | _filter_qemu_io
74
75echo
76echo "=== Testing blkverify through file blockref ==="
77echo
78
79TEST_IMG="$TEST_IMG.base" IMGFMT="raw" _make_test_img --no-opts $IMG_SIZE |\
80    _filter_imgfmt
81_make_test_img $IMG_SIZE
82$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" \
83         -c 'read 0 512' -c 'write -P 42 0x38000 512' -c 'read -P 42 0x38000 512' | _filter_qemu_io
84
85$QEMU_IO -c 'write -P 42 0 512' "$TEST_IMG" | _filter_qemu_io
86
87$QEMU_IO -c "open -o driver=raw,file.driver=blkverify,file.raw.filename=$TEST_IMG.base $TEST_IMG" \
88         -c 'read -P 42 0 512' | _filter_qemu_io
89
90echo
91echo "=== Testing blkdebug through filename ==="
92echo
93
94$QEMU_IO -c "open -o file.driver=blkdebug,file.inject-error.event=l2_load $TEST_IMG" \
95         -c 'read -P 42 0x38000 512'
96
97echo
98echo "=== Testing blkdebug through file blockref ==="
99echo
100
101$QEMU_IO -c "open -o driver=$IMGFMT,file.driver=blkdebug,file.inject-error.event=l2_load,file.image.filename=$TEST_IMG" \
102         -c 'read -P 42 0x38000 512'
103
104echo
105echo "=== Testing blkdebug on existing block device ==="
106echo
107
108run_qemu <<EOF
109{ "execute": "qmp_capabilities" }
110{ "execute": "blockdev-add",
111    "arguments": {
112        "node-name": "drive0",
113        "driver": "file",
114        "filename": "$TEST_IMG"
115    }
116}
117{ "execute": "blockdev-add",
118    "arguments": {
119        "driver": "$IMGFMT",
120        "node-name": "drive0-debug",
121        "file": {
122            "driver": "blkdebug",
123            "image": "drive0",
124            "inject-error": [{
125                "event": "l2_load"
126            }]
127        }
128    }
129}
130{ "execute": "human-monitor-command",
131    "arguments": {
132        "command-line": 'qemu-io drive0-debug "read 0 512"'
133    }
134}
135{ "execute": "quit" }
136EOF
137
138echo
139echo "=== Testing blkverify on existing block device ==="
140echo
141
142run_qemu <<EOF
143{ "execute": "qmp_capabilities" }
144{ "execute": "blockdev-add",
145    "arguments": {
146        "node-name": "drive0",
147        "driver": "$IMGFMT",
148        "file": {
149            "driver": "file",
150            "filename": "$TEST_IMG"
151        }
152    }
153}
154{ "execute": "blockdev-add",
155    "arguments": {
156        "driver": "blkverify",
157        "node-name": "drive0-verify",
158        "test": "drive0",
159        "raw": {
160            "driver": "file",
161            "filename": "$TEST_IMG.base"
162        }
163    }
164}
165{ "execute": "human-monitor-command",
166    "arguments": {
167        "command-line": 'qemu-io drive0-verify "read 0 512"'
168    }
169}
170{ "execute": "quit" }
171EOF
172
173echo
174echo "=== Testing blkverify on existing raw block device ==="
175echo
176
177run_qemu <<EOF
178{ "execute": "qmp_capabilities" }
179{ "execute": "blockdev-add",
180    "arguments": {
181        "node-name": "drive0",
182        "driver": "file",
183        "filename": "$TEST_IMG.base"
184    }
185}
186{ "execute": "blockdev-add",
187    "arguments": {
188        "driver": "blkverify",
189        "node-name": "drive0-verify",
190        "test": {
191            "driver": "$IMGFMT",
192            "file": {
193                "driver": "file",
194                "filename": "$TEST_IMG"
195            }
196        },
197        "raw": "drive0"
198    }
199}
200{ "execute": "human-monitor-command",
201    "arguments": {
202        "command-line": 'qemu-io drive0-verify "read 0 512"'
203    }
204}
205{ "execute": "quit" }
206EOF
207
208echo
209echo "=== Testing blkdebug's set-state through QMP ==="
210echo
211
212run_qemu <<EOF
213{ "execute": "qmp_capabilities" }
214{ "execute": "blockdev-add",
215    "arguments": {
216        "node-name": "drive0",
217        "driver": "file",
218        "filename": "$TEST_IMG"
219    }
220}
221{ "execute": "blockdev-add",
222    "arguments": {
223        "driver": "$IMGFMT",
224        "node-name": "drive0-debug",
225        "file": {
226            "driver": "blkdebug",
227            "image": "drive0",
228            "inject-error": [{
229                "event": "read_aio",
230                "state": 42
231            }],
232            "set-state": [{
233                "event": "write_aio",
234                "new_state": 42
235            }]
236        }
237    }
238}
239{ "execute": "human-monitor-command",
240    "arguments": {
241        "command-line": 'qemu-io drive0-debug "read 0 512"'
242    }
243}
244{ "execute": "human-monitor-command",
245    "arguments": {
246        "command-line": 'qemu-io drive0-debug "write 0 512"'
247    }
248}
249{ "execute": "human-monitor-command",
250    "arguments": {
251        "command-line": 'qemu-io drive0-debug "read 0 512"'
252    }
253}
254{ "execute": "quit" }
255EOF
256
257# success, all done
258echo "*** done"
259rm -f $seq.full
260status=0
261