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