]> git.proxmox.com Git - mirror_qemu.git/blob - tests/qemu-iotests/185
Merge remote-tracking branch 'remotes/kevin/tags/for-upstream' into staging
[mirror_qemu.git] / tests / qemu-iotests / 185
1 #!/bin/bash
2 #
3 # Test exiting qemu while jobs are still running
4 #
5 # Copyright (C) 2017 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 owner=kwolf@redhat.com
23
24 seq=`basename $0`
25 echo "QA output created by $seq"
26
27 here=`pwd`
28 status=1 # failure is the default!
29
30 MIG_SOCKET="${TEST_DIR}/migrate"
31
32 _cleanup()
33 {
34 rm -f "${TEST_IMG}.mid"
35 rm -f "${TEST_IMG}.copy"
36 _cleanup_test_img
37 _cleanup_qemu
38 }
39 trap "_cleanup; exit \$status" 0 1 2 3 15
40
41 # get standard environment, filters and checks
42 . ./common.rc
43 . ./common.filter
44 . ./common.qemu
45
46 _supported_fmt qcow2
47 _supported_proto file
48 _supported_os Linux
49
50 size=64M
51 TEST_IMG="${TEST_IMG}.base" _make_test_img $size
52
53 echo
54 echo === Starting VM ===
55 echo
56
57 qemu_comm_method="qmp"
58
59 _launch_qemu \
60 -drive file="${TEST_IMG}.base",cache=$CACHEMODE,driver=$IMGFMT,id=disk
61 h=$QEMU_HANDLE
62 _send_qemu_cmd $h "{ 'execute': 'qmp_capabilities' }" 'return'
63
64 echo
65 echo === Creating backing chain ===
66 echo
67
68 _send_qemu_cmd $h \
69 "{ 'execute': 'blockdev-snapshot-sync',
70 'arguments': { 'device': 'disk',
71 'snapshot-file': '$TEST_IMG.mid',
72 'format': '$IMGFMT',
73 'mode': 'absolute-paths' } }" \
74 "return"
75
76 _send_qemu_cmd $h \
77 "{ 'execute': 'human-monitor-command',
78 'arguments': { 'command-line':
79 'qemu-io disk \"write 0 4M\"' } }" \
80 "return"
81
82 _send_qemu_cmd $h \
83 "{ 'execute': 'blockdev-snapshot-sync',
84 'arguments': { 'device': 'disk',
85 'snapshot-file': '$TEST_IMG',
86 'format': '$IMGFMT',
87 'mode': 'absolute-paths' } }" \
88 "return"
89
90 echo
91 echo === Start commit job and exit qemu ===
92 echo
93
94 # Note that the reference output intentionally includes the 'offset' field in
95 # BLOCK_JOB_* events for all of the following block jobs. They are predictable
96 # and any change in the offsets would hint at a bug in the job throttling code.
97 #
98 # In order to achieve these predictable offsets, all of the following tests
99 # use speed=65536. Each job will perform exactly one iteration before it has
100 # to sleep at least for a second, which is plenty of time for the 'quit' QMP
101 # command to be received (after receiving the command, the rest runs
102 # synchronously, so jobs can arbitrarily continue or complete).
103 #
104 # Jobs present while QEMU is terminating iterate once more due to
105 # bdrv_drain_all().
106 #
107 # The buffer size for commit and streaming is 512k (waiting for 8 seconds after
108 # the first request), for active commit and mirror it's large enough to cover
109 # the full 4M, and for backup it's the qcow2 cluster size, which we know is
110 # 64k. As all of these are at least as large as the speed, we are sure that the
111 # offset advances exactly twice before qemu exits.
112
113 _send_qemu_cmd $h \
114 "{ 'execute': 'block-commit',
115 'arguments': { 'device': 'disk',
116 'base':'$TEST_IMG.base',
117 'top': '$TEST_IMG.mid',
118 'speed': 65536 } }" \
119 "return"
120
121 _send_qemu_cmd $h "{ 'execute': 'quit' }" "return"
122 wait=1 _cleanup_qemu
123
124 echo
125 echo === Start active commit job and exit qemu ===
126 echo
127
128 _launch_qemu \
129 -drive file="${TEST_IMG}",cache=$CACHEMODE,driver=$IMGFMT,id=disk
130 h=$QEMU_HANDLE
131 _send_qemu_cmd $h "{ 'execute': 'qmp_capabilities' }" 'return'
132
133 _send_qemu_cmd $h \
134 "{ 'execute': 'block-commit',
135 'arguments': { 'device': 'disk',
136 'base':'$TEST_IMG.base',
137 'speed': 65536 } }" \
138 "return"
139
140 _send_qemu_cmd $h "{ 'execute': 'quit' }" "return"
141 wait=1 _cleanup_qemu
142
143 echo
144 echo === Start mirror job and exit qemu ===
145 echo
146
147 _launch_qemu \
148 -drive file="${TEST_IMG}",cache=$CACHEMODE,driver=$IMGFMT,id=disk
149 h=$QEMU_HANDLE
150 _send_qemu_cmd $h "{ 'execute': 'qmp_capabilities' }" 'return'
151
152 _send_qemu_cmd $h \
153 "{ 'execute': 'drive-mirror',
154 'arguments': { 'device': 'disk',
155 'target': '$TEST_IMG.copy',
156 'format': '$IMGFMT',
157 'sync': 'full',
158 'speed': 65536 } }" \
159 "return"
160
161 # If we don't sleep here 'quit' command may be handled before
162 # the first mirror iteration is done
163 sleep 0.5
164
165 _send_qemu_cmd $h "{ 'execute': 'quit' }" "return"
166 wait=1 _cleanup_qemu
167
168 echo
169 echo === Start backup job and exit qemu ===
170 echo
171
172 _launch_qemu \
173 -drive file="${TEST_IMG}",cache=$CACHEMODE,driver=$IMGFMT,id=disk
174 h=$QEMU_HANDLE
175 _send_qemu_cmd $h "{ 'execute': 'qmp_capabilities' }" 'return'
176
177 _send_qemu_cmd $h \
178 "{ 'execute': 'drive-backup',
179 'arguments': { 'device': 'disk',
180 'target': '$TEST_IMG.copy',
181 'format': '$IMGFMT',
182 'sync': 'full',
183 'speed': 65536 } }" \
184 "return"
185
186 _send_qemu_cmd $h "{ 'execute': 'quit' }" "return"
187 wait=1 _cleanup_qemu
188
189 echo
190 echo === Start streaming job and exit qemu ===
191 echo
192
193 _launch_qemu \
194 -drive file="${TEST_IMG}",cache=$CACHEMODE,driver=$IMGFMT,id=disk
195 h=$QEMU_HANDLE
196 _send_qemu_cmd $h "{ 'execute': 'qmp_capabilities' }" 'return'
197
198 _send_qemu_cmd $h \
199 "{ 'execute': 'block-stream',
200 'arguments': { 'device': 'disk',
201 'speed': 65536 } }" \
202 "return"
203
204 _send_qemu_cmd $h "{ 'execute': 'quit' }" "return"
205 wait=1 _cleanup_qemu
206
207 _check_test_img
208
209 # success, all done
210 echo "*** done"
211 rm -f $seq.full
212 status=0