xref: /openbmc/qemu/tests/qemu-iotests/141 (revision 4b196cd16dcfb17de19a4121f12aa4ef4bf7925f)
111a82d14SPhilippe Mathieu-Daudé#!/usr/bin/env bash
2c78dc182SMax Reitz#
3c78dc182SMax Reitz# Test case for ejecting BDSs with block jobs still running on them
4c78dc182SMax Reitz#
5c78dc182SMax Reitz# Copyright (C) 2016 Red Hat, Inc.
6c78dc182SMax Reitz#
7c78dc182SMax Reitz# This program is free software; you can redistribute it and/or modify
8c78dc182SMax Reitz# it under the terms of the GNU General Public License as published by
9c78dc182SMax Reitz# the Free Software Foundation; either version 2 of the License, or
10c78dc182SMax Reitz# (at your option) any later version.
11c78dc182SMax Reitz#
12c78dc182SMax Reitz# This program is distributed in the hope that it will be useful,
13c78dc182SMax Reitz# but WITHOUT ANY WARRANTY; without even the implied warranty of
14c78dc182SMax Reitz# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15c78dc182SMax Reitz# GNU General Public License for more details.
16c78dc182SMax Reitz#
17c78dc182SMax Reitz# You should have received a copy of the GNU General Public License
18c78dc182SMax Reitz# along with this program.  If not, see <http://www.gnu.org/licenses/>.
19c78dc182SMax Reitz#
20c78dc182SMax Reitz
21c78dc182SMax Reitz# creator
22c78dc182SMax Reitzowner=mreitz@redhat.com
23c78dc182SMax Reitz
24c78dc182SMax Reitzseq="$(basename $0)"
25c78dc182SMax Reitzecho "QA output created by $seq"
26c78dc182SMax Reitz
27c78dc182SMax Reitzstatus=1	# failure is the default!
28c78dc182SMax Reitz
29c78dc182SMax Reitz_cleanup()
30c78dc182SMax Reitz{
31ecfa1854SJeff Cody    _cleanup_qemu
32c78dc182SMax Reitz    _cleanup_test_img
33f91ecbd7SMax Reitz    for img in "$TEST_DIR"/{b,m,o}.$IMGFMT; do
34f91ecbd7SMax Reitz        _rm_test_img "$img"
35f91ecbd7SMax Reitz    done
36c78dc182SMax Reitz}
37c78dc182SMax Reitztrap "_cleanup; exit \$status" 0 1 2 3 15
38c78dc182SMax Reitz
39c78dc182SMax Reitz# get standard environment, filters and checks
40c78dc182SMax Reitz. ./common.rc
41c78dc182SMax Reitz. ./common.filter
42c78dc182SMax Reitz. ./common.qemu
43c78dc182SMax Reitz
44c78dc182SMax Reitz# Needs backing file and backing format support
45c78dc182SMax Reitz_supported_fmt qcow2 qed
46c78dc182SMax Reitz_supported_proto file
47c78dc182SMax Reitz_supported_os Linux
48c78dc182SMax Reitz
49c78dc182SMax Reitz
50c78dc182SMax Reitztest_blockjob()
51c78dc182SMax Reitz{
52c78dc182SMax Reitz    _send_qemu_cmd $QEMU_HANDLE \
53c78dc182SMax Reitz        "{'execute': 'blockdev-add',
54c78dc182SMax Reitz          'arguments': {
5578645881SKevin Wolf              'node-name': 'drv0',
56c78dc182SMax Reitz              'driver': '$IMGFMT',
57c78dc182SMax Reitz              'file': {
58c78dc182SMax Reitz                  'driver': 'file',
59c78dc182SMax Reitz                  'filename': '$TEST_IMG'
600153d2f5SKevin Wolf              }}}" \
61c78dc182SMax Reitz        'return'
62c78dc182SMax Reitz
639c46f4a0SMax Reitz    # If "$2" is an event, we may or may not see it before the
649c46f4a0SMax Reitz    # {"return": {}}.  Therefore, filter the {"return": {}} out both
659c46f4a0SMax Reitz    # here and in the next command.  (Naturally, if we do not see it
669c46f4a0SMax Reitz    # here, we will see it before the next command can be executed,
679c46f4a0SMax Reitz    # so it will appear in the next _send_qemu_cmd's output.)
68c78dc182SMax Reitz    _send_qemu_cmd $QEMU_HANDLE \
69c78dc182SMax Reitz        "$1" \
70c78dc182SMax Reitz        "$2" \
71*4b196cd1SMax Reitz        | _filter_img_create | _filter_qmp_empty_return
72c78dc182SMax Reitz
73c78dc182SMax Reitz    # We want this to return an error because the block job is still running
74c78dc182SMax Reitz    _send_qemu_cmd $QEMU_HANDLE \
7579b7a77eSMarkus Armbruster        "{'execute': 'blockdev-del',
7678645881SKevin Wolf          'arguments': {'node-name': 'drv0'}}" \
779c46f4a0SMax Reitz        'error' | _filter_generated_node_ids | _filter_qmp_empty_return
78c78dc182SMax Reitz
79c78dc182SMax Reitz    _send_qemu_cmd $QEMU_HANDLE \
80c78dc182SMax Reitz        "{'execute': 'block-job-cancel',
8178645881SKevin Wolf          'arguments': {'device': 'job0'}}" \
82c78dc182SMax Reitz        "$3"
83c78dc182SMax Reitz
84c78dc182SMax Reitz    _send_qemu_cmd $QEMU_HANDLE \
8579b7a77eSMarkus Armbruster        "{'execute': 'blockdev-del',
8678645881SKevin Wolf          'arguments': {'node-name': 'drv0'}}" \
87c78dc182SMax Reitz        'return'
88c78dc182SMax Reitz}
89c78dc182SMax Reitz
90c78dc182SMax Reitz
91c78dc182SMax ReitzTEST_IMG="$TEST_DIR/b.$IMGFMT" _make_test_img 1M
92c78dc182SMax ReitzTEST_IMG="$TEST_DIR/m.$IMGFMT" _make_test_img -b "$TEST_DIR/b.$IMGFMT" 1M
93c78dc182SMax Reitz_make_test_img -b "$TEST_DIR/m.$IMGFMT" 1M
94c78dc182SMax Reitz
95c78dc182SMax Reitz_launch_qemu -nodefaults
96c78dc182SMax Reitz
97c78dc182SMax Reitz_send_qemu_cmd $QEMU_HANDLE \
98c78dc182SMax Reitz    "{'execute': 'qmp_capabilities'}" \
99c78dc182SMax Reitz    'return'
100c78dc182SMax Reitz
101c78dc182SMax Reitzecho
102c78dc182SMax Reitzecho '=== Testing drive-backup ==='
103c78dc182SMax Reitzecho
104c78dc182SMax Reitz
105c78dc182SMax Reitz# drive-backup will not send BLOCK_JOB_READY by itself, and cancelling the job
106c78dc182SMax Reitz# will consequently result in BLOCK_JOB_CANCELLED being emitted.
107c78dc182SMax Reitz
108c78dc182SMax Reitztest_blockjob \
109c78dc182SMax Reitz    "{'execute': 'drive-backup',
11078645881SKevin Wolf      'arguments': {'job-id': 'job0',
11178645881SKevin Wolf                    'device': 'drv0',
112c78dc182SMax Reitz                    'target': '$TEST_DIR/o.$IMGFMT',
113c78dc182SMax Reitz                    'format': '$IMGFMT',
114c78dc182SMax Reitz                    'sync': 'none'}}" \
115c78dc182SMax Reitz    'return' \
1161dac83f1SKevin Wolf    '"status": "null"'
117c78dc182SMax Reitz
118c78dc182SMax Reitzecho
119c78dc182SMax Reitzecho '=== Testing drive-mirror ==='
120c78dc182SMax Reitzecho
121c78dc182SMax Reitz
122c78dc182SMax Reitz# drive-mirror will send BLOCK_JOB_READY basically immediately, and cancelling
123c78dc182SMax Reitz# the job will consequently result in BLOCK_JOB_COMPLETED being emitted.
124c78dc182SMax Reitz
125c78dc182SMax Reitztest_blockjob \
126c78dc182SMax Reitz    "{'execute': 'drive-mirror',
12778645881SKevin Wolf      'arguments': {'job-id': 'job0',
12878645881SKevin Wolf                    'device': 'drv0',
129c78dc182SMax Reitz                    'target': '$TEST_DIR/o.$IMGFMT',
130c78dc182SMax Reitz                    'format': '$IMGFMT',
131c78dc182SMax Reitz                    'sync': 'none'}}" \
132c78dc182SMax Reitz    'BLOCK_JOB_READY' \
1331dac83f1SKevin Wolf    '"status": "null"'
134c78dc182SMax Reitz
135c78dc182SMax Reitzecho
136c78dc182SMax Reitzecho '=== Testing active block-commit ==='
137c78dc182SMax Reitzecho
138c78dc182SMax Reitz
139c78dc182SMax Reitz# An active block-commit will send BLOCK_JOB_READY basically immediately, and
140c78dc182SMax Reitz# cancelling the job will consequently result in BLOCK_JOB_COMPLETED being
141c78dc182SMax Reitz# emitted.
142c78dc182SMax Reitz
143c78dc182SMax Reitztest_blockjob \
144c78dc182SMax Reitz    "{'execute': 'block-commit',
14578645881SKevin Wolf      'arguments': {'job-id': 'job0', 'device': 'drv0'}}" \
146c78dc182SMax Reitz    'BLOCK_JOB_READY' \
1471dac83f1SKevin Wolf    '"status": "null"'
148c78dc182SMax Reitz
149c78dc182SMax Reitzecho
150c78dc182SMax Reitzecho '=== Testing non-active block-commit ==='
151c78dc182SMax Reitzecho
152c78dc182SMax Reitz
153c78dc182SMax Reitz# Give block-commit something to work on, otherwise it would be done
154c78dc182SMax Reitz# immediately, send a BLOCK_JOB_COMPLETED and ejecting the BDS would work just
155c78dc182SMax Reitz# fine without the block job still running.
156c78dc182SMax Reitz
157c78dc182SMax Reitz$QEMU_IO -c 'write 0 1M' "$TEST_DIR/m.$IMGFMT" | _filter_qemu_io
158c78dc182SMax Reitz
159c78dc182SMax Reitztest_blockjob \
160c78dc182SMax Reitz    "{'execute': 'block-commit',
16178645881SKevin Wolf      'arguments': {'job-id': 'job0',
16278645881SKevin Wolf                    'device': 'drv0',
163c78dc182SMax Reitz                    'top':    '$TEST_DIR/m.$IMGFMT',
164c78dc182SMax Reitz                    'speed':  1}}" \
165c78dc182SMax Reitz    'return' \
1661dac83f1SKevin Wolf    '"status": "null"'
167c78dc182SMax Reitz
168c78dc182SMax Reitzecho
169c78dc182SMax Reitzecho '=== Testing block-stream ==='
170c78dc182SMax Reitzecho
171c78dc182SMax Reitz
172c78dc182SMax Reitz# Give block-stream something to work on, otherwise it would be done
173c78dc182SMax Reitz# immediately, send a BLOCK_JOB_COMPLETED and ejecting the BDS would work just
174c78dc182SMax Reitz# fine without the block job still running.
175c78dc182SMax Reitz
176c78dc182SMax Reitz$QEMU_IO -c 'write 0 1M' "$TEST_DIR/b.$IMGFMT" | _filter_qemu_io
177c78dc182SMax Reitz
178c78dc182SMax Reitz# With some data to stream (and @speed set to 1), block-stream will not complete
1791dac83f1SKevin Wolf# until we send the block-job-cancel command.
180c78dc182SMax Reitz
181c78dc182SMax Reitztest_blockjob \
182c78dc182SMax Reitz    "{'execute': 'block-stream',
18378645881SKevin Wolf      'arguments': {'job-id': 'job0',
18478645881SKevin Wolf                    'device': 'drv0',
185c78dc182SMax Reitz                    'speed': 1}}" \
186c78dc182SMax Reitz    'return' \
1871dac83f1SKevin Wolf    '"status": "null"'
188c78dc182SMax Reitz
189c78dc182SMax Reitz_cleanup_qemu
190c78dc182SMax Reitz
191c78dc182SMax Reitz# success, all done
192c78dc182SMax Reitzecho "*** done"
193c78dc182SMax Reitzrm -f $seq.full
194c78dc182SMax Reitzstatus=0
195