Philippe Mathieu-Daudé | 11a82d1 | 2019-03-07 15:58:38 +0100 | [diff] [blame] | 1 | #!/usr/bin/env bash |
Vladimir Sementsov-Ogievskiy | 9dd003a | 2021-01-16 16:44:19 +0300 | [diff] [blame] | 2 | # group: rw auto |
Kevin Wolf | 7c61a4a | 2017-06-29 19:56:48 +0200 | [diff] [blame] | 3 | # |
| 4 | # Test commit block job where top has two parents |
| 5 | # |
| 6 | # Copyright (C) 2017 Red Hat, Inc. |
| 7 | # |
| 8 | # This program is free software; you can redistribute it and/or modify |
| 9 | # it under the terms of the GNU General Public License as published by |
| 10 | # the Free Software Foundation; either version 2 of the License, or |
| 11 | # (at your option) any later version. |
| 12 | # |
| 13 | # This program is distributed in the hope that it will be useful, |
| 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | # GNU General Public License for more details. |
| 17 | # |
| 18 | # You should have received a copy of the GNU General Public License |
| 19 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 20 | # |
| 21 | |
| 22 | # creator |
| 23 | owner=kwolf@redhat.com |
| 24 | |
| 25 | seq=`basename $0` |
| 26 | echo "QA output created by $seq" |
| 27 | |
Kevin Wolf | 7c61a4a | 2017-06-29 19:56:48 +0200 | [diff] [blame] | 28 | status=1 # failure is the default! |
| 29 | |
Kevin Wolf | 7c61a4a | 2017-06-29 19:56:48 +0200 | [diff] [blame] | 30 | _cleanup() |
| 31 | { |
Max Reitz | f91ecbd | 2019-11-07 17:37:01 +0100 | [diff] [blame] | 32 | _rm_test_img "${TEST_IMG}.mid" |
| 33 | _rm_test_img "${TEST_IMG}.ovl2" |
| 34 | _rm_test_img "${TEST_IMG}.ovl3" |
Kevin Wolf | 7c61a4a | 2017-06-29 19:56:48 +0200 | [diff] [blame] | 35 | _cleanup_test_img |
| 36 | _cleanup_qemu |
| 37 | } |
| 38 | trap "_cleanup; exit \$status" 0 1 2 3 15 |
| 39 | |
| 40 | # get standard environment, filters and checks |
| 41 | . ./common.rc |
| 42 | . ./common.filter |
| 43 | . ./common.qemu |
| 44 | |
| 45 | _supported_fmt qcow2 |
Max Reitz | 57284d2 | 2020-10-27 20:05:59 +0100 | [diff] [blame] | 46 | _supported_proto file fuse |
Max Reitz | 3be2024 | 2019-11-07 17:37:07 +0100 | [diff] [blame] | 47 | # An external data file would change the query-named-block-nodes output |
| 48 | _unsupported_imgopts data_file |
Kevin Wolf | 7c61a4a | 2017-06-29 19:56:48 +0200 | [diff] [blame] | 49 | |
| 50 | size=64M |
| 51 | |
| 52 | echo |
| 53 | echo === Preparing and starting VM === |
| 54 | echo |
| 55 | |
| 56 | TEST_IMG="${TEST_IMG}.base" _make_test_img $size |
Max Reitz | 407fb56 | 2019-11-07 17:36:57 +0100 | [diff] [blame] | 57 | TEST_IMG="${TEST_IMG}.mid" _make_test_img -o "backing_fmt=$IMGFMT" -b "${TEST_IMG}.base" |
Eric Blake | b66ff2c | 2020-07-06 15:39:52 -0500 | [diff] [blame] | 58 | _make_test_img -b "${TEST_IMG}.mid" -F $IMGFMT |
| 59 | TEST_IMG="${TEST_IMG}.ovl2" _make_test_img -b "${TEST_IMG}.mid" -F $IMGFMT |
Kevin Wolf | 7c61a4a | 2017-06-29 19:56:48 +0200 | [diff] [blame] | 60 | |
| 61 | $QEMU_IO -c 'write -P 0x55 1M 64k' "${TEST_IMG}.mid" | _filter_qemu_io |
| 62 | |
| 63 | qemu_comm_method="qmp" |
| 64 | qmp_pretty="y" |
| 65 | |
| 66 | _launch_qemu \ |
| 67 | -blockdev "driver=${IMGFMT},file.driver=file,file.filename=${TEST_IMG}.base,node-name=base" \ |
| 68 | -blockdev "driver=${IMGFMT},file.driver=file,file.filename=${TEST_IMG}.mid,node-name=mid,backing=base" \ |
| 69 | -blockdev "driver=${IMGFMT},file.driver=file,file.filename=${TEST_IMG},node-name=top,backing=mid" \ |
| 70 | -blockdev "driver=${IMGFMT},file.driver=file,file.filename=${TEST_IMG}.ovl2,node-name=top2,backing=mid" |
| 71 | h=$QEMU_HANDLE |
| 72 | _send_qemu_cmd $h "{ 'execute': 'qmp_capabilities' }" '^}' |
| 73 | |
| 74 | echo |
| 75 | echo === Perform commit job === |
| 76 | echo |
| 77 | |
| 78 | _send_qemu_cmd $h \ |
| 79 | "{ 'execute': 'block-commit', |
| 80 | 'arguments': { 'job-id': 'commit0', |
| 81 | 'device': 'top', |
| 82 | 'base':'$TEST_IMG.base', |
| 83 | 'top': '$TEST_IMG.mid' } }" \ |
Kevin Wolf | 1dac83f | 2018-04-30 19:09:46 +0200 | [diff] [blame] | 84 | '"status": "null"' |
Kevin Wolf | 7c61a4a | 2017-06-29 19:56:48 +0200 | [diff] [blame] | 85 | _send_qemu_cmd $h "" "^}" |
| 86 | |
| 87 | echo |
| 88 | echo === Check that both top and top2 point to base now === |
| 89 | echo |
| 90 | |
| 91 | _send_qemu_cmd $h "{ 'execute': 'query-named-block-nodes' }" "^}" | |
Max Reitz | 2483537 | 2017-11-23 03:08:31 +0100 | [diff] [blame] | 92 | _filter_generated_node_ids | _filter_actual_image_size | _filter_img_info |
Kevin Wolf | 7c61a4a | 2017-06-29 19:56:48 +0200 | [diff] [blame] | 93 | |
| 94 | _send_qemu_cmd $h "{ 'execute': 'quit' }" "^}" |
| 95 | wait=1 _cleanup_qemu |
| 96 | |
| 97 | _img_info |
| 98 | TEST_IMG="$TEST_IMG.ovl2" _img_info |
| 99 | |
| 100 | |
| 101 | echo |
| 102 | echo === Preparing and starting VM with -drive === |
| 103 | echo |
| 104 | |
| 105 | TEST_IMG="${TEST_IMG}.base" _make_test_img $size |
Eric Blake | b66ff2c | 2020-07-06 15:39:52 -0500 | [diff] [blame] | 106 | TEST_IMG="${TEST_IMG}.mid" _make_test_img -b "${TEST_IMG}.base" -F $IMGFMT |
| 107 | _make_test_img -b "${TEST_IMG}.mid" -F $IMGFMT |
| 108 | TEST_IMG="${TEST_IMG}.ovl2" _make_test_img -b "${TEST_IMG}.mid" -F $IMGFMT |
| 109 | TEST_IMG="${TEST_IMG}.ovl3" _make_test_img -b "${TEST_IMG}.ovl2" -F $IMGFMT |
Kevin Wolf | 7c61a4a | 2017-06-29 19:56:48 +0200 | [diff] [blame] | 110 | |
| 111 | $QEMU_IO -c 'write -P 0x55 1M 64k' "${TEST_IMG}.mid" | _filter_qemu_io |
| 112 | |
| 113 | qemu_comm_method="qmp" |
| 114 | qmp_pretty="y" |
| 115 | |
| 116 | _launch_qemu \ |
| 117 | -drive "driver=${IMGFMT},file=${TEST_IMG},node-name=top,backing.node-name=mid" \ |
| 118 | -drive "driver=${IMGFMT},file=${TEST_IMG}.ovl3,node-name=top2,backing.backing=mid" |
| 119 | h=$QEMU_HANDLE |
| 120 | _send_qemu_cmd $h "{ 'execute': 'qmp_capabilities' }" '^}' |
| 121 | |
| 122 | echo |
| 123 | echo === Perform commit job === |
| 124 | echo |
| 125 | |
| 126 | _send_qemu_cmd $h \ |
| 127 | "{ 'execute': 'block-commit', |
| 128 | 'arguments': { 'job-id': 'commit0', |
| 129 | 'device': 'top', |
| 130 | 'base':'$TEST_IMG.base', |
| 131 | 'top': '$TEST_IMG.mid' } }" \ |
Kevin Wolf | 1dac83f | 2018-04-30 19:09:46 +0200 | [diff] [blame] | 132 | '"status": "null"' |
Kevin Wolf | 7c61a4a | 2017-06-29 19:56:48 +0200 | [diff] [blame] | 133 | _send_qemu_cmd $h "" "^}" |
| 134 | |
| 135 | echo |
| 136 | echo === Check that both top and top2 point to base now === |
| 137 | echo |
| 138 | |
| 139 | _send_qemu_cmd $h "{ 'execute': 'query-named-block-nodes' }" "^}" | |
Max Reitz | 2483537 | 2017-11-23 03:08:31 +0100 | [diff] [blame] | 140 | _filter_generated_node_ids | _filter_actual_image_size | _filter_img_info |
Kevin Wolf | 7c61a4a | 2017-06-29 19:56:48 +0200 | [diff] [blame] | 141 | |
| 142 | _send_qemu_cmd $h "{ 'execute': 'quit' }" "^}" |
| 143 | wait=1 _cleanup_qemu |
| 144 | |
| 145 | _img_info |
| 146 | TEST_IMG="$TEST_IMG.ovl2" _img_info |
| 147 | |
| 148 | # success, all done |
| 149 | echo "*** done" |
| 150 | rm -f $seq.full |
| 151 | status=0 |