xref: /openbmc/qemu/tests/qemu-iotests/185 (revision 24575bfa8c05041db097d203c5506814db0fa110)
1*24575bfaSKevin Wolf#!/bin/bash
2*24575bfaSKevin Wolf#
3*24575bfaSKevin Wolf# Test exiting qemu while jobs are still running
4*24575bfaSKevin Wolf#
5*24575bfaSKevin Wolf# Copyright (C) 2017 Red Hat, Inc.
6*24575bfaSKevin Wolf#
7*24575bfaSKevin Wolf# This program is free software; you can redistribute it and/or modify
8*24575bfaSKevin Wolf# it under the terms of the GNU General Public License as published by
9*24575bfaSKevin Wolf# the Free Software Foundation; either version 2 of the License, or
10*24575bfaSKevin Wolf# (at your option) any later version.
11*24575bfaSKevin Wolf#
12*24575bfaSKevin Wolf# This program is distributed in the hope that it will be useful,
13*24575bfaSKevin Wolf# but WITHOUT ANY WARRANTY; without even the implied warranty of
14*24575bfaSKevin Wolf# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15*24575bfaSKevin Wolf# GNU General Public License for more details.
16*24575bfaSKevin Wolf#
17*24575bfaSKevin Wolf# You should have received a copy of the GNU General Public License
18*24575bfaSKevin Wolf# along with this program.  If not, see <http://www.gnu.org/licenses/>.
19*24575bfaSKevin Wolf#
20*24575bfaSKevin Wolf
21*24575bfaSKevin Wolf# creator
22*24575bfaSKevin Wolfowner=kwolf@redhat.com
23*24575bfaSKevin Wolf
24*24575bfaSKevin Wolfseq=`basename $0`
25*24575bfaSKevin Wolfecho "QA output created by $seq"
26*24575bfaSKevin Wolf
27*24575bfaSKevin Wolfhere=`pwd`
28*24575bfaSKevin Wolfstatus=1 # failure is the default!
29*24575bfaSKevin Wolf
30*24575bfaSKevin WolfMIG_SOCKET="${TEST_DIR}/migrate"
31*24575bfaSKevin Wolf
32*24575bfaSKevin Wolf_cleanup()
33*24575bfaSKevin Wolf{
34*24575bfaSKevin Wolf    rm -f "${TEST_IMG}.mid"
35*24575bfaSKevin Wolf    rm -f "${TEST_IMG}.copy"
36*24575bfaSKevin Wolf    _cleanup_test_img
37*24575bfaSKevin Wolf    _cleanup_qemu
38*24575bfaSKevin Wolf}
39*24575bfaSKevin Wolftrap "_cleanup; exit \$status" 0 1 2 3 15
40*24575bfaSKevin Wolf
41*24575bfaSKevin Wolf# get standard environment, filters and checks
42*24575bfaSKevin Wolf. ./common.rc
43*24575bfaSKevin Wolf. ./common.filter
44*24575bfaSKevin Wolf. ./common.qemu
45*24575bfaSKevin Wolf
46*24575bfaSKevin Wolf_supported_fmt qcow2
47*24575bfaSKevin Wolf_supported_proto file
48*24575bfaSKevin Wolf_supported_os Linux
49*24575bfaSKevin Wolf
50*24575bfaSKevin Wolfsize=64M
51*24575bfaSKevin WolfTEST_IMG="${TEST_IMG}.base" _make_test_img $size
52*24575bfaSKevin Wolf
53*24575bfaSKevin Wolfecho
54*24575bfaSKevin Wolfecho === Starting VM ===
55*24575bfaSKevin Wolfecho
56*24575bfaSKevin Wolf
57*24575bfaSKevin Wolfqemu_comm_method="qmp"
58*24575bfaSKevin Wolf
59*24575bfaSKevin Wolf_launch_qemu \
60*24575bfaSKevin Wolf    -drive file="${TEST_IMG}.base",cache=$CACHEMODE,driver=$IMGFMT,id=disk
61*24575bfaSKevin Wolfh=$QEMU_HANDLE
62*24575bfaSKevin Wolf_send_qemu_cmd $h "{ 'execute': 'qmp_capabilities' }" 'return'
63*24575bfaSKevin Wolf
64*24575bfaSKevin Wolfecho
65*24575bfaSKevin Wolfecho === Creating backing chain ===
66*24575bfaSKevin Wolfecho
67*24575bfaSKevin Wolf
68*24575bfaSKevin Wolf_send_qemu_cmd $h \
69*24575bfaSKevin Wolf    "{ 'execute': 'blockdev-snapshot-sync',
70*24575bfaSKevin Wolf       'arguments': { 'device': 'disk',
71*24575bfaSKevin Wolf                      'snapshot-file': '$TEST_IMG.mid',
72*24575bfaSKevin Wolf                      'format': '$IMGFMT',
73*24575bfaSKevin Wolf                      'mode': 'absolute-paths' } }" \
74*24575bfaSKevin Wolf    "return"
75*24575bfaSKevin Wolf
76*24575bfaSKevin Wolf_send_qemu_cmd $h \
77*24575bfaSKevin Wolf    "{ 'execute': 'human-monitor-command',
78*24575bfaSKevin Wolf       'arguments': { 'command-line':
79*24575bfaSKevin Wolf                      'qemu-io disk \"write 0 4M\"' } }" \
80*24575bfaSKevin Wolf    "return"
81*24575bfaSKevin Wolf
82*24575bfaSKevin Wolf_send_qemu_cmd $h \
83*24575bfaSKevin Wolf    "{ 'execute': 'blockdev-snapshot-sync',
84*24575bfaSKevin Wolf       'arguments': { 'device': 'disk',
85*24575bfaSKevin Wolf                      'snapshot-file': '$TEST_IMG',
86*24575bfaSKevin Wolf                      'format': '$IMGFMT',
87*24575bfaSKevin Wolf                      'mode': 'absolute-paths' } }" \
88*24575bfaSKevin Wolf    "return"
89*24575bfaSKevin Wolf
90*24575bfaSKevin Wolfecho
91*24575bfaSKevin Wolfecho === Start commit job and exit qemu ===
92*24575bfaSKevin Wolfecho
93*24575bfaSKevin Wolf
94*24575bfaSKevin Wolf# Note that the reference output intentionally includes the 'offset' field in
95*24575bfaSKevin Wolf# BLOCK_JOB_CANCELLED events for all of the following block jobs. They are
96*24575bfaSKevin Wolf# predictable and any change in the offsets would hint at a bug in the job
97*24575bfaSKevin Wolf# throttling code.
98*24575bfaSKevin Wolf#
99*24575bfaSKevin Wolf# In order to achieve these predictable offsets, all of the following tests
100*24575bfaSKevin Wolf# use speed=65536. Each job will perform exactly one iteration before it has
101*24575bfaSKevin Wolf# to sleep at least for a second, which is plenty of time for the 'quit' QMP
102*24575bfaSKevin Wolf# command to be received (after receiving the command, the rest runs
103*24575bfaSKevin Wolf# synchronously, so jobs can arbitrarily continue or complete).
104*24575bfaSKevin Wolf#
105*24575bfaSKevin Wolf# The buffer size for commit and streaming is 512k (waiting for 8 seconds after
106*24575bfaSKevin Wolf# the first request), for active commit and mirror it's large enough to cover
107*24575bfaSKevin Wolf# the full 4M, and for backup it's the qcow2 cluster size, which we know is
108*24575bfaSKevin Wolf# 64k. As all of these are at least as large as the speed, we are sure that the
109*24575bfaSKevin Wolf# offset doesn't advance after the first iteration before qemu exits.
110*24575bfaSKevin Wolf
111*24575bfaSKevin Wolf_send_qemu_cmd $h \
112*24575bfaSKevin Wolf    "{ 'execute': 'block-commit',
113*24575bfaSKevin Wolf       'arguments': { 'device': 'disk',
114*24575bfaSKevin Wolf                      'base':'$TEST_IMG.base',
115*24575bfaSKevin Wolf                      'top': '$TEST_IMG.mid',
116*24575bfaSKevin Wolf                      'speed': 65536 } }" \
117*24575bfaSKevin Wolf    "return"
118*24575bfaSKevin Wolf
119*24575bfaSKevin Wolf_send_qemu_cmd $h "{ 'execute': 'quit' }" "return"
120*24575bfaSKevin Wolfwait=1 _cleanup_qemu
121*24575bfaSKevin Wolf
122*24575bfaSKevin Wolfecho
123*24575bfaSKevin Wolfecho === Start active commit job and exit qemu ===
124*24575bfaSKevin Wolfecho
125*24575bfaSKevin Wolf
126*24575bfaSKevin Wolf_launch_qemu \
127*24575bfaSKevin Wolf    -drive file="${TEST_IMG}",cache=$CACHEMODE,driver=$IMGFMT,id=disk
128*24575bfaSKevin Wolfh=$QEMU_HANDLE
129*24575bfaSKevin Wolf_send_qemu_cmd $h "{ 'execute': 'qmp_capabilities' }" 'return'
130*24575bfaSKevin Wolf
131*24575bfaSKevin Wolf_send_qemu_cmd $h \
132*24575bfaSKevin Wolf    "{ 'execute': 'block-commit',
133*24575bfaSKevin Wolf       'arguments': { 'device': 'disk',
134*24575bfaSKevin Wolf                      'base':'$TEST_IMG.base',
135*24575bfaSKevin Wolf                      'speed': 65536 } }" \
136*24575bfaSKevin Wolf    "return"
137*24575bfaSKevin Wolf
138*24575bfaSKevin Wolf_send_qemu_cmd $h "{ 'execute': 'quit' }" "return"
139*24575bfaSKevin Wolfwait=1 _cleanup_qemu
140*24575bfaSKevin Wolf
141*24575bfaSKevin Wolfecho
142*24575bfaSKevin Wolfecho === Start mirror job and exit qemu ===
143*24575bfaSKevin Wolfecho
144*24575bfaSKevin Wolf
145*24575bfaSKevin Wolf_launch_qemu \
146*24575bfaSKevin Wolf    -drive file="${TEST_IMG}",cache=$CACHEMODE,driver=$IMGFMT,id=disk
147*24575bfaSKevin Wolfh=$QEMU_HANDLE
148*24575bfaSKevin Wolf_send_qemu_cmd $h "{ 'execute': 'qmp_capabilities' }" 'return'
149*24575bfaSKevin Wolf
150*24575bfaSKevin Wolf_send_qemu_cmd $h \
151*24575bfaSKevin Wolf    "{ 'execute': 'drive-mirror',
152*24575bfaSKevin Wolf       'arguments': { 'device': 'disk',
153*24575bfaSKevin Wolf                      'target': '$TEST_IMG.copy',
154*24575bfaSKevin Wolf                      'format': '$IMGFMT',
155*24575bfaSKevin Wolf                      'sync': 'full',
156*24575bfaSKevin Wolf                      'speed': 65536 } }" \
157*24575bfaSKevin Wolf    "return"
158*24575bfaSKevin Wolf
159*24575bfaSKevin Wolf_send_qemu_cmd $h "{ 'execute': 'quit' }" "return"
160*24575bfaSKevin Wolfwait=1 _cleanup_qemu
161*24575bfaSKevin Wolf
162*24575bfaSKevin Wolfecho
163*24575bfaSKevin Wolfecho === Start backup job and exit qemu ===
164*24575bfaSKevin Wolfecho
165*24575bfaSKevin Wolf
166*24575bfaSKevin Wolf_launch_qemu \
167*24575bfaSKevin Wolf    -drive file="${TEST_IMG}",cache=$CACHEMODE,driver=$IMGFMT,id=disk
168*24575bfaSKevin Wolfh=$QEMU_HANDLE
169*24575bfaSKevin Wolf_send_qemu_cmd $h "{ 'execute': 'qmp_capabilities' }" 'return'
170*24575bfaSKevin Wolf
171*24575bfaSKevin Wolf_send_qemu_cmd $h \
172*24575bfaSKevin Wolf    "{ 'execute': 'drive-backup',
173*24575bfaSKevin Wolf       'arguments': { 'device': 'disk',
174*24575bfaSKevin Wolf                      'target': '$TEST_IMG.copy',
175*24575bfaSKevin Wolf                      'format': '$IMGFMT',
176*24575bfaSKevin Wolf                      'sync': 'full',
177*24575bfaSKevin Wolf                      'speed': 65536 } }" \
178*24575bfaSKevin Wolf    "return"
179*24575bfaSKevin Wolf
180*24575bfaSKevin Wolf_send_qemu_cmd $h "{ 'execute': 'quit' }" "return"
181*24575bfaSKevin Wolfwait=1 _cleanup_qemu
182*24575bfaSKevin Wolf
183*24575bfaSKevin Wolfecho
184*24575bfaSKevin Wolfecho === Start streaming job and exit qemu ===
185*24575bfaSKevin Wolfecho
186*24575bfaSKevin Wolf
187*24575bfaSKevin Wolf_launch_qemu \
188*24575bfaSKevin Wolf    -drive file="${TEST_IMG}",cache=$CACHEMODE,driver=$IMGFMT,id=disk
189*24575bfaSKevin Wolfh=$QEMU_HANDLE
190*24575bfaSKevin Wolf_send_qemu_cmd $h "{ 'execute': 'qmp_capabilities' }" 'return'
191*24575bfaSKevin Wolf
192*24575bfaSKevin Wolf_send_qemu_cmd $h \
193*24575bfaSKevin Wolf    "{ 'execute': 'block-stream',
194*24575bfaSKevin Wolf       'arguments': { 'device': 'disk',
195*24575bfaSKevin Wolf                      'speed': 65536 } }" \
196*24575bfaSKevin Wolf    "return"
197*24575bfaSKevin Wolf
198*24575bfaSKevin Wolf_send_qemu_cmd $h "{ 'execute': 'quit' }" "return"
199*24575bfaSKevin Wolfwait=1 _cleanup_qemu
200*24575bfaSKevin Wolf
201*24575bfaSKevin Wolf_check_test_img
202*24575bfaSKevin Wolf
203*24575bfaSKevin Wolf# success, all done
204*24575bfaSKevin Wolfecho "*** done"
205*24575bfaSKevin Wolfrm -f $seq.full
206*24575bfaSKevin Wolfstatus=0
207