xref: /openbmc/qemu/tests/qemu-iotests/071 (revision 886ce6f8)
1#!/bin/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
27here="$PWD"
28tmp=/tmp/$$
29status=1	# failure is the default!
30
31_cleanup()
32{
33	_cleanup_test_img
34}
35trap "_cleanup; exit \$status" 0 1 2 3 15
36
37# get standard environment, filters and checks
38. ./common.rc
39. ./common.filter
40
41_supported_fmt qcow2
42_supported_proto file
43_supported_os Linux
44
45function do_run_qemu()
46{
47    echo Testing: "$@" | _filter_imgfmt
48    $QEMU -nographic -qmp stdio -serial none "$@"
49    echo
50}
51
52function run_qemu()
53{
54    do_run_qemu "$@" 2>&1 | _filter_testdir | _filter_qemu | _filter_qmp | _filter_qemu_io
55}
56
57IMG_SIZE=64M
58
59echo
60echo "=== Testing blkverify through filename ==="
61echo
62
63TEST_IMG="$TEST_IMG.base" IMGOPTS="" IMGFMT="raw" _make_test_img $IMG_SIZE |\
64    _filter_imgfmt
65_make_test_img $IMG_SIZE
66$QEMU_IO -c "open -o driver=raw,file.driver=blkverify,file.raw.filename=$TEST_IMG.base $TEST_IMG" \
67         -c 'read 0 512' -c 'write -P 42 0x38000 512' -c 'read -P 42 0x38000 512' | _filter_qemu_io
68
69$QEMU_IO -c 'write -P 42 0 512' "$TEST_IMG" | _filter_qemu_io
70
71$QEMU_IO -c "open -o driver=raw,file.driver=blkverify,file.raw.filename=$TEST_IMG.base $TEST_IMG" \
72         -c 'read -P 42 0 512' | _filter_qemu_io
73
74echo
75echo "=== Testing blkverify through file blockref ==="
76echo
77
78TEST_IMG="$TEST_IMG.base" IMGOPTS="" IMGFMT="raw" _make_test_img $IMG_SIZE |\
79    _filter_imgfmt
80_make_test_img $IMG_SIZE
81$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" \
82         -c 'read 0 512' -c 'write -P 42 0x38000 512' -c 'read -P 42 0x38000 512' | _filter_qemu_io
83
84$QEMU_IO -c 'write -P 42 0 512' "$TEST_IMG" | _filter_qemu_io
85
86$QEMU_IO -c "open -o driver=raw,file.driver=blkverify,file.raw.filename=$TEST_IMG.base $TEST_IMG" \
87         -c 'read -P 42 0 512' | _filter_qemu_io
88
89echo
90echo "=== Testing blkdebug through filename ==="
91echo
92
93$QEMU_IO -c "open -o file.driver=blkdebug,file.inject-error.event=l2_load $TEST_IMG" \
94         -c 'read -P 42 0x38000 512'
95
96echo
97echo "=== Testing blkdebug through file blockref ==="
98echo
99
100$QEMU_IO -c "open -o driver=$IMGFMT,file.driver=blkdebug,file.inject-error.event=l2_load,file.image.filename=$TEST_IMG" \
101         -c 'read -P 42 0x38000 512'
102
103echo
104echo "=== Testing blkdebug on existing block device ==="
105echo
106
107run_qemu <<EOF
108{ "execute": "qmp_capabilities" }
109{ "execute": "blockdev-add",
110    "arguments": {
111        "options": {
112            "node-name": "drive0",
113            "driver": "file",
114            "filename": "$TEST_IMG"
115        }
116    }
117}
118{ "execute": "blockdev-add",
119    "arguments": {
120        "options": {
121            "driver": "$IMGFMT",
122            "id": "drive0-debug",
123            "file": {
124                "driver": "blkdebug",
125                "image": "drive0",
126                "inject-error": [{
127                    "event": "l2_load"
128                }]
129            }
130        }
131    }
132}
133{ "execute": "human-monitor-command",
134    "arguments": {
135        "command-line": 'qemu-io drive0-debug "read 0 512"'
136    }
137}
138{ "execute": "quit" }
139EOF
140
141echo
142echo "=== Testing blkverify on existing block device ==="
143echo
144
145run_qemu <<EOF
146{ "execute": "qmp_capabilities" }
147{ "execute": "blockdev-add",
148    "arguments": {
149        "options": {
150            "node-name": "drive0",
151            "driver": "$IMGFMT",
152            "file": {
153                "driver": "file",
154                "filename": "$TEST_IMG"
155            }
156        }
157    }
158}
159{ "execute": "blockdev-add",
160    "arguments": {
161        "options": {
162            "driver": "blkverify",
163            "id": "drive0-verify",
164            "test": "drive0",
165            "raw": {
166                "driver": "file",
167                "filename": "$TEST_IMG.base"
168            }
169        }
170    }
171}
172{ "execute": "human-monitor-command",
173    "arguments": {
174        "command-line": 'qemu-io drive0-verify "read 0 512"'
175    }
176}
177{ "execute": "quit" }
178EOF
179
180echo
181echo "=== Testing blkverify on existing raw block device ==="
182echo
183
184run_qemu <<EOF
185{ "execute": "qmp_capabilities" }
186{ "execute": "blockdev-add",
187    "arguments": {
188        "options": {
189            "node-name": "drive0",
190            "driver": "file",
191            "filename": "$TEST_IMG.base"
192        }
193    }
194}
195{ "execute": "blockdev-add",
196    "arguments": {
197        "options": {
198            "driver": "blkverify",
199            "id": "drive0-verify",
200            "test": {
201                "driver": "$IMGFMT",
202                "file": {
203                    "driver": "file",
204                    "filename": "$TEST_IMG"
205                }
206            },
207            "raw": "drive0"
208        }
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        "options": {
228            "node-name": "drive0",
229            "driver": "file",
230            "filename": "$TEST_IMG"
231        }
232    }
233}
234{ "execute": "blockdev-add",
235    "arguments": {
236        "options": {
237            "driver": "$IMGFMT",
238            "id": "drive0-debug",
239            "file": {
240                "driver": "blkdebug",
241                "image": "drive0",
242                "inject-error": [{
243                    "event": "read_aio",
244                    "state": 42
245                }],
246                "set-state": [{
247                    "event": "write_aio",
248                    "new_state": 42
249                }]
250            }
251        }
252    }
253}
254{ "execute": "human-monitor-command",
255    "arguments": {
256        "command-line": 'qemu-io drive0-debug "read 0 512"'
257    }
258}
259{ "execute": "human-monitor-command",
260    "arguments": {
261        "command-line": 'qemu-io drive0-debug "write 0 512"'
262    }
263}
264{ "execute": "human-monitor-command",
265    "arguments": {
266        "command-line": 'qemu-io drive0-debug "read 0 512"'
267    }
268}
269{ "execute": "quit" }
270EOF
271
272# success, all done
273echo "*** done"
274rm -f $seq.full
275status=0
276