]>
Commit | Line | Data |
---|---|---|
11a82d14 | 1 | #!/usr/bin/env bash |
30bd6a4d HR |
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 | |
22 | [email protected] | |
23 | ||
24 | seq="$(basename $0)" | |
25 | echo "QA output created by $seq" | |
26 | ||
30bd6a4d HR |
27 | status=1 # failure is the default! |
28 | ||
29 | _cleanup() | |
30 | { | |
31 | _cleanup_test_img | |
32 | } | |
33 | trap "_cleanup; exit \$status" 0 1 2 3 15 | |
34 | ||
35 | # get standard environment, filters and checks | |
36 | . ./common.rc | |
37 | . ./common.filter | |
38 | ||
1b7650ef | 39 | _supported_fmt qcow2 |
1f7bf7d0 | 40 | _supported_proto file |
21b43d00 | 41 | _require_drivers blkdebug blkverify |
3be2024a HR |
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 | |
30bd6a4d | 45 | |
8cedcffd | 46 | do_run_qemu() |
30bd6a4d HR |
47 | { |
48 | echo Testing: "$@" | _filter_imgfmt | |
49 | $QEMU -nographic -qmp stdio -serial none "$@" | |
50 | echo | |
51 | } | |
52 | ||
8cedcffd | 53 | run_qemu() |
30bd6a4d | 54 | { |
4dd7b8d3 | 55 | do_run_qemu "$@" 2>&1 | _filter_testdir | _filter_qemu | _filter_qmp | _filter_qemu_io |
30bd6a4d HR |
56 | } |
57 | ||
58 | IMG_SIZE=64M | |
59 | ||
60 | echo | |
61 | echo "=== Testing blkverify through filename ===" | |
62 | echo | |
63 | ||
10b61256 | 64 | TEST_IMG="$TEST_IMG.base" IMGFMT="raw" _make_test_img --no-opts $IMG_SIZE |\ |
30bd6a4d HR |
65 | _filter_imgfmt |
66 | _make_test_img $IMG_SIZE | |
8f9e835f | 67 | $QEMU_IO -c "open -o driver=raw,file.driver=blkverify,file.raw.filename=$TEST_IMG.base $TEST_IMG" \ |
30bd6a4d HR |
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 | ||
8f9e835f | 72 | $QEMU_IO -c "open -o driver=raw,file.driver=blkverify,file.raw.filename=$TEST_IMG.base $TEST_IMG" \ |
30bd6a4d HR |
73 | -c 'read -P 42 0 512' | _filter_qemu_io |
74 | ||
75 | echo | |
76 | echo "=== Testing blkverify through file blockref ===" | |
77 | echo | |
78 | ||
10b61256 | 79 | TEST_IMG="$TEST_IMG.base" IMGFMT="raw" _make_test_img --no-opts $IMG_SIZE |\ |
30bd6a4d HR |
80 | _filter_imgfmt |
81 | _make_test_img $IMG_SIZE | |
8f9e835f | 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" \ |
30bd6a4d HR |
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 | ||
8f9e835f | 87 | $QEMU_IO -c "open -o driver=raw,file.driver=blkverify,file.raw.filename=$TEST_IMG.base $TEST_IMG" \ |
30bd6a4d HR |
88 | -c 'read -P 42 0 512' | _filter_qemu_io |
89 | ||
90 | echo | |
91 | echo "=== Testing blkdebug through filename ===" | |
92 | echo | |
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 | ||
97 | echo | |
98 | echo "=== Testing blkdebug through file blockref ===" | |
99 | echo | |
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 | ||
104 | echo | |
105 | echo "=== Testing blkdebug on existing block device ===" | |
106 | echo | |
107 | ||
8e9e6530 | 108 | run_qemu <<EOF |
30bd6a4d | 109 | { "execute": "qmp_capabilities" } |
8e9e6530 HR |
110 | { "execute": "blockdev-add", |
111 | "arguments": { | |
0153d2f5 KW |
112 | "node-name": "drive0", |
113 | "driver": "file", | |
114 | "filename": "$TEST_IMG" | |
8e9e6530 HR |
115 | } |
116 | } | |
30bd6a4d HR |
117 | { "execute": "blockdev-add", |
118 | "arguments": { | |
0153d2f5 KW |
119 | "driver": "$IMGFMT", |
120 | "node-name": "drive0-debug", | |
121 | "file": { | |
122 | "driver": "blkdebug", | |
123 | "image": "drive0", | |
124 | "inject-error": [{ | |
125 | "event": "l2_load" | |
126 | }] | |
30bd6a4d HR |
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" } | |
136 | EOF | |
137 | ||
138 | echo | |
139 | echo "=== Testing blkverify on existing block device ===" | |
140 | echo | |
141 | ||
8e9e6530 | 142 | run_qemu <<EOF |
30bd6a4d | 143 | { "execute": "qmp_capabilities" } |
8e9e6530 HR |
144 | { "execute": "blockdev-add", |
145 | "arguments": { | |
0153d2f5 KW |
146 | "node-name": "drive0", |
147 | "driver": "$IMGFMT", | |
148 | "file": { | |
149 | "driver": "file", | |
150 | "filename": "$TEST_IMG" | |
8e9e6530 HR |
151 | } |
152 | } | |
153 | } | |
30bd6a4d HR |
154 | { "execute": "blockdev-add", |
155 | "arguments": { | |
0153d2f5 KW |
156 | "driver": "blkverify", |
157 | "node-name": "drive0-verify", | |
158 | "test": "drive0", | |
159 | "raw": { | |
160 | "driver": "file", | |
161 | "filename": "$TEST_IMG.base" | |
30bd6a4d HR |
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" } | |
171 | EOF | |
172 | ||
173 | echo | |
174 | echo "=== Testing blkverify on existing raw block device ===" | |
175 | echo | |
176 | ||
8e9e6530 | 177 | run_qemu <<EOF |
30bd6a4d | 178 | { "execute": "qmp_capabilities" } |
8e9e6530 HR |
179 | { "execute": "blockdev-add", |
180 | "arguments": { | |
0153d2f5 KW |
181 | "node-name": "drive0", |
182 | "driver": "file", | |
183 | "filename": "$TEST_IMG.base" | |
8e9e6530 HR |
184 | } |
185 | } | |
30bd6a4d HR |
186 | { "execute": "blockdev-add", |
187 | "arguments": { | |
0153d2f5 KW |
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" | |
30bd6a4d HR |
198 | } |
199 | } | |
200 | { "execute": "human-monitor-command", | |
201 | "arguments": { | |
202 | "command-line": 'qemu-io drive0-verify "read 0 512"' | |
203 | } | |
204 | } | |
205 | { "execute": "quit" } | |
206 | EOF | |
207 | ||
208 | echo | |
209 | echo "=== Testing blkdebug's set-state through QMP ===" | |
210 | echo | |
211 | ||
8e9e6530 | 212 | run_qemu <<EOF |
30bd6a4d | 213 | { "execute": "qmp_capabilities" } |
8e9e6530 HR |
214 | { "execute": "blockdev-add", |
215 | "arguments": { | |
0153d2f5 KW |
216 | "node-name": "drive0", |
217 | "driver": "file", | |
218 | "filename": "$TEST_IMG" | |
8e9e6530 HR |
219 | } |
220 | } | |
30bd6a4d HR |
221 | { "execute": "blockdev-add", |
222 | "arguments": { | |
0153d2f5 KW |
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 | }] | |
30bd6a4d HR |
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" } | |
255 | EOF | |
256 | ||
257 | # success, all done | |
258 | echo "*** done" | |
259 | rm -f $seq.full | |
260 | status=0 |