xref: /openbmc/qemu/tests/qemu-iotests/185 (revision f91ecbd74eb75e9d4c7b4016edaf69d070cb3f9b)
111a82d14SPhilippe Mathieu-Daudé#!/usr/bin/env bash
224575bfaSKevin Wolf#
324575bfaSKevin Wolf# Test exiting qemu while jobs are still running
424575bfaSKevin Wolf#
524575bfaSKevin Wolf# Copyright (C) 2017 Red Hat, Inc.
624575bfaSKevin Wolf#
724575bfaSKevin Wolf# This program is free software; you can redistribute it and/or modify
824575bfaSKevin Wolf# it under the terms of the GNU General Public License as published by
924575bfaSKevin Wolf# the Free Software Foundation; either version 2 of the License, or
1024575bfaSKevin Wolf# (at your option) any later version.
1124575bfaSKevin Wolf#
1224575bfaSKevin Wolf# This program is distributed in the hope that it will be useful,
1324575bfaSKevin Wolf# but WITHOUT ANY WARRANTY; without even the implied warranty of
1424575bfaSKevin Wolf# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1524575bfaSKevin Wolf# GNU General Public License for more details.
1624575bfaSKevin Wolf#
1724575bfaSKevin Wolf# You should have received a copy of the GNU General Public License
1824575bfaSKevin Wolf# along with this program.  If not, see <http://www.gnu.org/licenses/>.
1924575bfaSKevin Wolf#
2024575bfaSKevin Wolf
2124575bfaSKevin Wolf# creator
2224575bfaSKevin Wolfowner=kwolf@redhat.com
2324575bfaSKevin Wolf
2424575bfaSKevin Wolfseq=`basename $0`
2524575bfaSKevin Wolfecho "QA output created by $seq"
2624575bfaSKevin Wolf
2724575bfaSKevin Wolfstatus=1 # failure is the default!
2824575bfaSKevin Wolf
2924575bfaSKevin Wolf_cleanup()
3024575bfaSKevin Wolf{
31*f91ecbd7SMax Reitz    _rm_test_img "${TEST_IMG}.mid"
32*f91ecbd7SMax Reitz    _rm_test_img "${TEST_IMG}.copy"
3324575bfaSKevin Wolf    _cleanup_test_img
3424575bfaSKevin Wolf    _cleanup_qemu
3524575bfaSKevin Wolf}
3624575bfaSKevin Wolftrap "_cleanup; exit \$status" 0 1 2 3 15
3724575bfaSKevin Wolf
3824575bfaSKevin Wolf# get standard environment, filters and checks
3924575bfaSKevin Wolf. ./common.rc
4024575bfaSKevin Wolf. ./common.filter
4124575bfaSKevin Wolf. ./common.qemu
4224575bfaSKevin Wolf
4324575bfaSKevin Wolf_supported_fmt qcow2
4424575bfaSKevin Wolf_supported_proto file
4524575bfaSKevin Wolf_supported_os Linux
4624575bfaSKevin Wolf
4724575bfaSKevin Wolfsize=64M
4824575bfaSKevin WolfTEST_IMG="${TEST_IMG}.base" _make_test_img $size
4924575bfaSKevin Wolf
5024575bfaSKevin Wolfecho
5124575bfaSKevin Wolfecho === Starting VM ===
5224575bfaSKevin Wolfecho
5324575bfaSKevin Wolf
5424575bfaSKevin Wolfqemu_comm_method="qmp"
5524575bfaSKevin Wolf
5624575bfaSKevin Wolf_launch_qemu \
5724575bfaSKevin Wolf    -drive file="${TEST_IMG}.base",cache=$CACHEMODE,driver=$IMGFMT,id=disk
5824575bfaSKevin Wolfh=$QEMU_HANDLE
5924575bfaSKevin Wolf_send_qemu_cmd $h "{ 'execute': 'qmp_capabilities' }" 'return'
6024575bfaSKevin Wolf
6124575bfaSKevin Wolfecho
6224575bfaSKevin Wolfecho === Creating backing chain ===
6324575bfaSKevin Wolfecho
6424575bfaSKevin Wolf
6524575bfaSKevin Wolf_send_qemu_cmd $h \
6624575bfaSKevin Wolf    "{ 'execute': 'blockdev-snapshot-sync',
6724575bfaSKevin Wolf       'arguments': { 'device': 'disk',
6824575bfaSKevin Wolf                      'snapshot-file': '$TEST_IMG.mid',
6924575bfaSKevin Wolf                      'format': '$IMGFMT',
7024575bfaSKevin Wolf                      'mode': 'absolute-paths' } }" \
7124575bfaSKevin Wolf    "return"
7224575bfaSKevin Wolf
7324575bfaSKevin Wolf_send_qemu_cmd $h \
7424575bfaSKevin Wolf    "{ 'execute': 'human-monitor-command',
7524575bfaSKevin Wolf       'arguments': { 'command-line':
7624575bfaSKevin Wolf                      'qemu-io disk \"write 0 4M\"' } }" \
7724575bfaSKevin Wolf    "return"
7824575bfaSKevin Wolf
7924575bfaSKevin Wolf_send_qemu_cmd $h \
8024575bfaSKevin Wolf    "{ 'execute': 'blockdev-snapshot-sync',
8124575bfaSKevin Wolf       'arguments': { 'device': 'disk',
8224575bfaSKevin Wolf                      'snapshot-file': '$TEST_IMG',
8324575bfaSKevin Wolf                      'format': '$IMGFMT',
8424575bfaSKevin Wolf                      'mode': 'absolute-paths' } }" \
8524575bfaSKevin Wolf    "return"
8624575bfaSKevin Wolf
8724575bfaSKevin Wolfecho
8824575bfaSKevin Wolfecho === Start commit job and exit qemu ===
8924575bfaSKevin Wolfecho
9024575bfaSKevin Wolf
9124575bfaSKevin Wolf# Note that the reference output intentionally includes the 'offset' field in
92c1de5696SStefan Hajnoczi# BLOCK_JOB_* events for all of the following block jobs. They are predictable
93c1de5696SStefan Hajnoczi# and any change in the offsets would hint at a bug in the job throttling code.
9424575bfaSKevin Wolf#
9524575bfaSKevin Wolf# In order to achieve these predictable offsets, all of the following tests
9624575bfaSKevin Wolf# use speed=65536. Each job will perform exactly one iteration before it has
9724575bfaSKevin Wolf# to sleep at least for a second, which is plenty of time for the 'quit' QMP
9824575bfaSKevin Wolf# command to be received (after receiving the command, the rest runs
9924575bfaSKevin Wolf# synchronously, so jobs can arbitrarily continue or complete).
10024575bfaSKevin Wolf#
10124575bfaSKevin Wolf# The buffer size for commit and streaming is 512k (waiting for 8 seconds after
10224575bfaSKevin Wolf# the first request), for active commit and mirror it's large enough to cover
10324575bfaSKevin Wolf# the full 4M, and for backup it's the qcow2 cluster size, which we know is
10424575bfaSKevin Wolf# 64k. As all of these are at least as large as the speed, we are sure that the
1054c7e813cSStefan Hajnoczi# offset advances exactly once before qemu exits.
10624575bfaSKevin Wolf
10724575bfaSKevin Wolf_send_qemu_cmd $h \
10824575bfaSKevin Wolf    "{ 'execute': 'block-commit',
10924575bfaSKevin Wolf       'arguments': { 'device': 'disk',
11024575bfaSKevin Wolf                      'base':'$TEST_IMG.base',
11124575bfaSKevin Wolf                      'top': '$TEST_IMG.mid',
11224575bfaSKevin Wolf                      'speed': 65536 } }" \
11324575bfaSKevin Wolf    "return"
11424575bfaSKevin Wolf
115ddf2d98aSStefan Hajnoczi# If we don't sleep here 'quit' command races with disk I/O
116ddf2d98aSStefan Hajnoczisleep 0.5
117ddf2d98aSStefan Hajnoczi
1181dac83f1SKevin Wolf# Ignore the JOB_STATUS_CHANGE events while shutting down the VM. Depending on
1191dac83f1SKevin Wolf# the timing, jobs may or may not transition through a paused state.
12024575bfaSKevin Wolf_send_qemu_cmd $h "{ 'execute': 'quit' }" "return"
1211dac83f1SKevin Wolfwait=1 _cleanup_qemu | grep -v 'JOB_STATUS_CHANGE'
12224575bfaSKevin Wolf
12324575bfaSKevin Wolfecho
12424575bfaSKevin Wolfecho === Start active commit job and exit qemu ===
12524575bfaSKevin Wolfecho
12624575bfaSKevin Wolf
12724575bfaSKevin Wolf_launch_qemu \
12824575bfaSKevin Wolf    -drive file="${TEST_IMG}",cache=$CACHEMODE,driver=$IMGFMT,id=disk
12924575bfaSKevin Wolfh=$QEMU_HANDLE
13024575bfaSKevin Wolf_send_qemu_cmd $h "{ 'execute': 'qmp_capabilities' }" 'return'
13124575bfaSKevin Wolf
13224575bfaSKevin Wolf_send_qemu_cmd $h \
13324575bfaSKevin Wolf    "{ 'execute': 'block-commit',
13424575bfaSKevin Wolf       'arguments': { 'device': 'disk',
13524575bfaSKevin Wolf                      'base':'$TEST_IMG.base',
13624575bfaSKevin Wolf                      'speed': 65536 } }" \
13724575bfaSKevin Wolf    "return"
13824575bfaSKevin Wolf
139ddf2d98aSStefan Hajnoczi# If we don't sleep here 'quit' command races with disk I/O
140ddf2d98aSStefan Hajnoczisleep 0.5
141ddf2d98aSStefan Hajnoczi
14224575bfaSKevin Wolf_send_qemu_cmd $h "{ 'execute': 'quit' }" "return"
1431dac83f1SKevin Wolfwait=1 _cleanup_qemu | grep -v 'JOB_STATUS_CHANGE'
14424575bfaSKevin Wolf
14524575bfaSKevin Wolfecho
14624575bfaSKevin Wolfecho === Start mirror job and exit qemu ===
14724575bfaSKevin Wolfecho
14824575bfaSKevin Wolf
14924575bfaSKevin Wolf_launch_qemu \
15024575bfaSKevin Wolf    -drive file="${TEST_IMG}",cache=$CACHEMODE,driver=$IMGFMT,id=disk
15124575bfaSKevin Wolfh=$QEMU_HANDLE
15224575bfaSKevin Wolf_send_qemu_cmd $h "{ 'execute': 'qmp_capabilities' }" 'return'
15324575bfaSKevin Wolf
15424575bfaSKevin Wolf_send_qemu_cmd $h \
15524575bfaSKevin Wolf    "{ 'execute': 'drive-mirror',
15624575bfaSKevin Wolf       'arguments': { 'device': 'disk',
15724575bfaSKevin Wolf                      'target': '$TEST_IMG.copy',
15824575bfaSKevin Wolf                      'format': '$IMGFMT',
15924575bfaSKevin Wolf                      'sync': 'full',
16024575bfaSKevin Wolf                      'speed': 65536 } }" \
16124575bfaSKevin Wolf    "return"
16224575bfaSKevin Wolf
1638565c3abSVladimir Sementsov-Ogievskiy# If we don't sleep here 'quit' command may be handled before
1648565c3abSVladimir Sementsov-Ogievskiy# the first mirror iteration is done
1658565c3abSVladimir Sementsov-Ogievskiysleep 0.5
1668565c3abSVladimir Sementsov-Ogievskiy
16724575bfaSKevin Wolf_send_qemu_cmd $h "{ 'execute': 'quit' }" "return"
1681dac83f1SKevin Wolfwait=1 _cleanup_qemu | grep -v 'JOB_STATUS_CHANGE'
16924575bfaSKevin Wolf
17024575bfaSKevin Wolfecho
17124575bfaSKevin Wolfecho === Start backup job and exit qemu ===
17224575bfaSKevin Wolfecho
17324575bfaSKevin Wolf
17424575bfaSKevin Wolf_launch_qemu \
17524575bfaSKevin Wolf    -drive file="${TEST_IMG}",cache=$CACHEMODE,driver=$IMGFMT,id=disk
17624575bfaSKevin Wolfh=$QEMU_HANDLE
17724575bfaSKevin Wolf_send_qemu_cmd $h "{ 'execute': 'qmp_capabilities' }" 'return'
17824575bfaSKevin Wolf
17924575bfaSKevin Wolf_send_qemu_cmd $h \
18024575bfaSKevin Wolf    "{ 'execute': 'drive-backup',
18124575bfaSKevin Wolf       'arguments': { 'device': 'disk',
18224575bfaSKevin Wolf                      'target': '$TEST_IMG.copy',
18324575bfaSKevin Wolf                      'format': '$IMGFMT',
18424575bfaSKevin Wolf                      'sync': 'full',
18524575bfaSKevin Wolf                      'speed': 65536 } }" \
18624575bfaSKevin Wolf    "return"
18724575bfaSKevin Wolf
188ddf2d98aSStefan Hajnoczi# If we don't sleep here 'quit' command races with disk I/O
189ddf2d98aSStefan Hajnoczisleep 0.5
190ddf2d98aSStefan Hajnoczi
19124575bfaSKevin Wolf_send_qemu_cmd $h "{ 'execute': 'quit' }" "return"
1921dac83f1SKevin Wolfwait=1 _cleanup_qemu | grep -v 'JOB_STATUS_CHANGE'
19324575bfaSKevin Wolf
19424575bfaSKevin Wolfecho
19524575bfaSKevin Wolfecho === Start streaming job and exit qemu ===
19624575bfaSKevin Wolfecho
19724575bfaSKevin Wolf
19824575bfaSKevin Wolf_launch_qemu \
19924575bfaSKevin Wolf    -drive file="${TEST_IMG}",cache=$CACHEMODE,driver=$IMGFMT,id=disk
20024575bfaSKevin Wolfh=$QEMU_HANDLE
20124575bfaSKevin Wolf_send_qemu_cmd $h "{ 'execute': 'qmp_capabilities' }" 'return'
20224575bfaSKevin Wolf
20324575bfaSKevin Wolf_send_qemu_cmd $h \
20424575bfaSKevin Wolf    "{ 'execute': 'block-stream',
20524575bfaSKevin Wolf       'arguments': { 'device': 'disk',
20624575bfaSKevin Wolf                      'speed': 65536 } }" \
20724575bfaSKevin Wolf    "return"
20824575bfaSKevin Wolf
209ddf2d98aSStefan Hajnoczi# If we don't sleep here 'quit' command races with disk I/O
210ddf2d98aSStefan Hajnoczisleep 0.5
211ddf2d98aSStefan Hajnoczi
21224575bfaSKevin Wolf_send_qemu_cmd $h "{ 'execute': 'quit' }" "return"
2131dac83f1SKevin Wolfwait=1 _cleanup_qemu | grep -v 'JOB_STATUS_CHANGE'
21424575bfaSKevin Wolf
21524575bfaSKevin Wolf_check_test_img
21624575bfaSKevin Wolf
21724575bfaSKevin Wolf# success, all done
21824575bfaSKevin Wolfecho "*** done"
21924575bfaSKevin Wolfrm -f $seq.full
22024575bfaSKevin Wolfstatus=0
221