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