blob: b05db6814157f0bed29004b0dd8df521c18f0d4f [file] [log] [blame]
Philippe Mathieu-Daudé11a82d12019-03-07 15:58:38 +01001#!/usr/bin/env bash
Kevin Wolf7c61a4a2017-06-29 19:56:48 +02002#
3# Test commit block job where top has two parents
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
22owner=kwolf@redhat.com
23
24seq=`basename $0`
25echo "QA output created by $seq"
26
Kevin Wolf7c61a4a2017-06-29 19:56:48 +020027status=1 # failure is the default!
28
Kevin Wolf7c61a4a2017-06-29 19:56:48 +020029_cleanup()
30{
Max Reitzf91ecbd2019-11-07 17:37:01 +010031 _rm_test_img "${TEST_IMG}.mid"
32 _rm_test_img "${TEST_IMG}.ovl2"
33 _rm_test_img "${TEST_IMG}.ovl3"
Kevin Wolf7c61a4a2017-06-29 19:56:48 +020034 _cleanup_test_img
35 _cleanup_qemu
36}
37trap "_cleanup; exit \$status" 0 1 2 3 15
38
39# get standard environment, filters and checks
40. ./common.rc
41. ./common.filter
42. ./common.qemu
43
44_supported_fmt qcow2
Kevin Wolf7c61a4a2017-06-29 19:56:48 +020045_supported_proto file
Max Reitz3be20242019-11-07 17:37:07 +010046# An external data file would change the query-named-block-nodes output
47_unsupported_imgopts data_file
Kevin Wolf7c61a4a2017-06-29 19:56:48 +020048
49size=64M
50
51echo
52echo === Preparing and starting VM ===
53echo
54
55TEST_IMG="${TEST_IMG}.base" _make_test_img $size
Max Reitz407fb562019-11-07 17:36:57 +010056TEST_IMG="${TEST_IMG}.mid" _make_test_img -o "backing_fmt=$IMGFMT" -b "${TEST_IMG}.base"
Kevin Wolf7c61a4a2017-06-29 19:56:48 +020057_make_test_img -b "${TEST_IMG}.mid"
58TEST_IMG="${TEST_IMG}.ovl2" _make_test_img -b "${TEST_IMG}.mid"
59
60$QEMU_IO -c 'write -P 0x55 1M 64k' "${TEST_IMG}.mid" | _filter_qemu_io
61
62qemu_comm_method="qmp"
63qmp_pretty="y"
64
65_launch_qemu \
66 -blockdev "driver=${IMGFMT},file.driver=file,file.filename=${TEST_IMG}.base,node-name=base" \
67 -blockdev "driver=${IMGFMT},file.driver=file,file.filename=${TEST_IMG}.mid,node-name=mid,backing=base" \
68 -blockdev "driver=${IMGFMT},file.driver=file,file.filename=${TEST_IMG},node-name=top,backing=mid" \
69 -blockdev "driver=${IMGFMT},file.driver=file,file.filename=${TEST_IMG}.ovl2,node-name=top2,backing=mid"
70h=$QEMU_HANDLE
71_send_qemu_cmd $h "{ 'execute': 'qmp_capabilities' }" '^}'
72
73echo
74echo === Perform commit job ===
75echo
76
77_send_qemu_cmd $h \
78 "{ 'execute': 'block-commit',
79 'arguments': { 'job-id': 'commit0',
80 'device': 'top',
81 'base':'$TEST_IMG.base',
82 'top': '$TEST_IMG.mid' } }" \
Kevin Wolf1dac83f2018-04-30 19:09:46 +020083 '"status": "null"'
Kevin Wolf7c61a4a2017-06-29 19:56:48 +020084_send_qemu_cmd $h "" "^}"
85
86echo
87echo === Check that both top and top2 point to base now ===
88echo
89
90_send_qemu_cmd $h "{ 'execute': 'query-named-block-nodes' }" "^}" |
Max Reitz24835372017-11-23 03:08:31 +010091 _filter_generated_node_ids | _filter_actual_image_size | _filter_img_info
Kevin Wolf7c61a4a2017-06-29 19:56:48 +020092
93_send_qemu_cmd $h "{ 'execute': 'quit' }" "^}"
94wait=1 _cleanup_qemu
95
96_img_info
97TEST_IMG="$TEST_IMG.ovl2" _img_info
98
99
100echo
101echo === Preparing and starting VM with -drive ===
102echo
103
104TEST_IMG="${TEST_IMG}.base" _make_test_img $size
105TEST_IMG="${TEST_IMG}.mid" _make_test_img -b "${TEST_IMG}.base"
106_make_test_img -b "${TEST_IMG}.mid"
107TEST_IMG="${TEST_IMG}.ovl2" _make_test_img -b "${TEST_IMG}.mid"
108TEST_IMG="${TEST_IMG}.ovl3" _make_test_img -b "${TEST_IMG}.ovl2"
109
110$QEMU_IO -c 'write -P 0x55 1M 64k' "${TEST_IMG}.mid" | _filter_qemu_io
111
112qemu_comm_method="qmp"
113qmp_pretty="y"
114
115_launch_qemu \
116 -drive "driver=${IMGFMT},file=${TEST_IMG},node-name=top,backing.node-name=mid" \
117 -drive "driver=${IMGFMT},file=${TEST_IMG}.ovl3,node-name=top2,backing.backing=mid"
118h=$QEMU_HANDLE
119_send_qemu_cmd $h "{ 'execute': 'qmp_capabilities' }" '^}'
120
121echo
122echo === Perform commit job ===
123echo
124
125_send_qemu_cmd $h \
126 "{ 'execute': 'block-commit',
127 'arguments': { 'job-id': 'commit0',
128 'device': 'top',
129 'base':'$TEST_IMG.base',
130 'top': '$TEST_IMG.mid' } }" \
Kevin Wolf1dac83f2018-04-30 19:09:46 +0200131 '"status": "null"'
Kevin Wolf7c61a4a2017-06-29 19:56:48 +0200132_send_qemu_cmd $h "" "^}"
133
134echo
135echo === Check that both top and top2 point to base now ===
136echo
137
138_send_qemu_cmd $h "{ 'execute': 'query-named-block-nodes' }" "^}" |
Max Reitz24835372017-11-23 03:08:31 +0100139 _filter_generated_node_ids | _filter_actual_image_size | _filter_img_info
Kevin Wolf7c61a4a2017-06-29 19:56:48 +0200140
141_send_qemu_cmd $h "{ 'execute': 'quit' }" "^}"
142wait=1 _cleanup_qemu
143
144_img_info
145TEST_IMG="$TEST_IMG.ovl2" _img_info
146
147# success, all done
148echo "*** done"
149rm -f $seq.full
150status=0