xref: /openbmc/qemu/tests/qemu-iotests/191 (revision 1dac83f1)
17c61a4a3SKevin Wolf#!/bin/bash
27c61a4a3SKevin Wolf#
37c61a4a3SKevin Wolf# Test commit block job where top has two parents
47c61a4a3SKevin Wolf#
57c61a4a3SKevin Wolf# Copyright (C) 2017 Red Hat, Inc.
67c61a4a3SKevin Wolf#
77c61a4a3SKevin Wolf# This program is free software; you can redistribute it and/or modify
87c61a4a3SKevin Wolf# it under the terms of the GNU General Public License as published by
97c61a4a3SKevin Wolf# the Free Software Foundation; either version 2 of the License, or
107c61a4a3SKevin Wolf# (at your option) any later version.
117c61a4a3SKevin Wolf#
127c61a4a3SKevin Wolf# This program is distributed in the hope that it will be useful,
137c61a4a3SKevin Wolf# but WITHOUT ANY WARRANTY; without even the implied warranty of
147c61a4a3SKevin Wolf# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
157c61a4a3SKevin Wolf# GNU General Public License for more details.
167c61a4a3SKevin Wolf#
177c61a4a3SKevin Wolf# You should have received a copy of the GNU General Public License
187c61a4a3SKevin Wolf# along with this program.  If not, see <http://www.gnu.org/licenses/>.
197c61a4a3SKevin Wolf#
207c61a4a3SKevin Wolf
217c61a4a3SKevin Wolf# creator
227c61a4a3SKevin Wolfowner=kwolf@redhat.com
237c61a4a3SKevin Wolf
247c61a4a3SKevin Wolfseq=`basename $0`
257c61a4a3SKevin Wolfecho "QA output created by $seq"
267c61a4a3SKevin Wolf
277c61a4a3SKevin Wolfhere=`pwd`
287c61a4a3SKevin Wolfstatus=1 # failure is the default!
297c61a4a3SKevin Wolf
307c61a4a3SKevin Wolf_cleanup()
317c61a4a3SKevin Wolf{
327c61a4a3SKevin Wolf    rm -f "${TEST_IMG}.mid"
337c61a4a3SKevin Wolf    rm -f "${TEST_IMG}.ovl2"
347c61a4a3SKevin Wolf    rm -f "${TEST_IMG}.ovl3"
357c61a4a3SKevin Wolf    _cleanup_test_img
367c61a4a3SKevin Wolf    _cleanup_qemu
377c61a4a3SKevin Wolf}
387c61a4a3SKevin Wolftrap "_cleanup; exit \$status" 0 1 2 3 15
397c61a4a3SKevin Wolf
407c61a4a3SKevin Wolf# get standard environment, filters and checks
417c61a4a3SKevin Wolf. ./common.rc
427c61a4a3SKevin Wolf. ./common.filter
437c61a4a3SKevin Wolf. ./common.qemu
447c61a4a3SKevin Wolf
457c61a4a3SKevin Wolf_supported_fmt qcow2
467c61a4a3SKevin Wolf_supported_proto file
477c61a4a3SKevin Wolf_supported_os Linux
487c61a4a3SKevin Wolf
497c61a4a3SKevin Wolfsize=64M
507c61a4a3SKevin Wolf
517c61a4a3SKevin Wolfecho
527c61a4a3SKevin Wolfecho === Preparing and starting VM ===
537c61a4a3SKevin Wolfecho
547c61a4a3SKevin Wolf
557c61a4a3SKevin WolfTEST_IMG="${TEST_IMG}.base" _make_test_img $size
56760c4d43SKevin WolfIMGOPTS=$(_optstr_add "$IMGOPTS" "backing_fmt=$IMGFMT") \
577c61a4a3SKevin Wolf    TEST_IMG="${TEST_IMG}.mid" _make_test_img -b "${TEST_IMG}.base"
587c61a4a3SKevin Wolf_make_test_img -b "${TEST_IMG}.mid"
597c61a4a3SKevin WolfTEST_IMG="${TEST_IMG}.ovl2" _make_test_img -b "${TEST_IMG}.mid"
607c61a4a3SKevin Wolf
617c61a4a3SKevin Wolf$QEMU_IO -c 'write -P 0x55 1M 64k' "${TEST_IMG}.mid" | _filter_qemu_io
627c61a4a3SKevin Wolf
637c61a4a3SKevin Wolfqemu_comm_method="qmp"
647c61a4a3SKevin Wolfqmp_pretty="y"
657c61a4a3SKevin Wolf
667c61a4a3SKevin Wolf_launch_qemu \
677c61a4a3SKevin Wolf    -blockdev "driver=${IMGFMT},file.driver=file,file.filename=${TEST_IMG}.base,node-name=base" \
687c61a4a3SKevin Wolf    -blockdev "driver=${IMGFMT},file.driver=file,file.filename=${TEST_IMG}.mid,node-name=mid,backing=base" \
697c61a4a3SKevin Wolf    -blockdev "driver=${IMGFMT},file.driver=file,file.filename=${TEST_IMG},node-name=top,backing=mid" \
707c61a4a3SKevin Wolf    -blockdev "driver=${IMGFMT},file.driver=file,file.filename=${TEST_IMG}.ovl2,node-name=top2,backing=mid"
717c61a4a3SKevin Wolfh=$QEMU_HANDLE
727c61a4a3SKevin Wolf_send_qemu_cmd $h "{ 'execute': 'qmp_capabilities' }" '^}'
737c61a4a3SKevin Wolf
747c61a4a3SKevin Wolfecho
757c61a4a3SKevin Wolfecho === Perform commit job ===
767c61a4a3SKevin Wolfecho
777c61a4a3SKevin Wolf
787c61a4a3SKevin Wolf_send_qemu_cmd $h \
797c61a4a3SKevin Wolf    "{ 'execute': 'block-commit',
807c61a4a3SKevin Wolf       'arguments': { 'job-id': 'commit0',
817c61a4a3SKevin Wolf                      'device': 'top',
827c61a4a3SKevin Wolf                      'base':'$TEST_IMG.base',
837c61a4a3SKevin Wolf                      'top': '$TEST_IMG.mid' } }" \
84*1dac83f1SKevin Wolf    '"status": "null"'
857c61a4a3SKevin Wolf_send_qemu_cmd $h "" "^}"
867c61a4a3SKevin Wolf
877c61a4a3SKevin Wolfecho
887c61a4a3SKevin Wolfecho === Check that both top and top2 point to base now ===
897c61a4a3SKevin Wolfecho
907c61a4a3SKevin Wolf
917c61a4a3SKevin Wolf_send_qemu_cmd $h "{ 'execute': 'query-named-block-nodes' }" "^}" |
922483537eSMax Reitz    _filter_generated_node_ids | _filter_actual_image_size | _filter_img_info
937c61a4a3SKevin Wolf
947c61a4a3SKevin Wolf_send_qemu_cmd $h "{ 'execute': 'quit' }" "^}"
957c61a4a3SKevin Wolfwait=1 _cleanup_qemu
967c61a4a3SKevin Wolf
977c61a4a3SKevin Wolf_img_info
987c61a4a3SKevin WolfTEST_IMG="$TEST_IMG.ovl2" _img_info
997c61a4a3SKevin Wolf
1007c61a4a3SKevin Wolf
1017c61a4a3SKevin Wolfecho
1027c61a4a3SKevin Wolfecho === Preparing and starting VM with -drive ===
1037c61a4a3SKevin Wolfecho
1047c61a4a3SKevin Wolf
1057c61a4a3SKevin WolfTEST_IMG="${TEST_IMG}.base" _make_test_img $size
1067c61a4a3SKevin WolfTEST_IMG="${TEST_IMG}.mid" _make_test_img -b "${TEST_IMG}.base"
1077c61a4a3SKevin Wolf_make_test_img -b "${TEST_IMG}.mid"
1087c61a4a3SKevin WolfTEST_IMG="${TEST_IMG}.ovl2" _make_test_img -b "${TEST_IMG}.mid"
1097c61a4a3SKevin WolfTEST_IMG="${TEST_IMG}.ovl3" _make_test_img -b "${TEST_IMG}.ovl2"
1107c61a4a3SKevin Wolf
1117c61a4a3SKevin Wolf$QEMU_IO -c 'write -P 0x55 1M 64k' "${TEST_IMG}.mid" | _filter_qemu_io
1127c61a4a3SKevin Wolf
1137c61a4a3SKevin Wolfqemu_comm_method="qmp"
1147c61a4a3SKevin Wolfqmp_pretty="y"
1157c61a4a3SKevin Wolf
1167c61a4a3SKevin Wolf_launch_qemu \
1177c61a4a3SKevin Wolf    -drive "driver=${IMGFMT},file=${TEST_IMG},node-name=top,backing.node-name=mid" \
1187c61a4a3SKevin Wolf    -drive "driver=${IMGFMT},file=${TEST_IMG}.ovl3,node-name=top2,backing.backing=mid"
1197c61a4a3SKevin Wolfh=$QEMU_HANDLE
1207c61a4a3SKevin Wolf_send_qemu_cmd $h "{ 'execute': 'qmp_capabilities' }" '^}'
1217c61a4a3SKevin Wolf
1227c61a4a3SKevin Wolfecho
1237c61a4a3SKevin Wolfecho === Perform commit job ===
1247c61a4a3SKevin Wolfecho
1257c61a4a3SKevin Wolf
1267c61a4a3SKevin Wolf_send_qemu_cmd $h \
1277c61a4a3SKevin Wolf    "{ 'execute': 'block-commit',
1287c61a4a3SKevin Wolf       'arguments': { 'job-id': 'commit0',
1297c61a4a3SKevin Wolf                      'device': 'top',
1307c61a4a3SKevin Wolf                      'base':'$TEST_IMG.base',
1317c61a4a3SKevin Wolf                      'top': '$TEST_IMG.mid' } }" \
132*1dac83f1SKevin Wolf    '"status": "null"'
1337c61a4a3SKevin Wolf_send_qemu_cmd $h "" "^}"
1347c61a4a3SKevin Wolf
1357c61a4a3SKevin Wolfecho
1367c61a4a3SKevin Wolfecho === Check that both top and top2 point to base now ===
1377c61a4a3SKevin Wolfecho
1387c61a4a3SKevin Wolf
1397c61a4a3SKevin Wolf_send_qemu_cmd $h "{ 'execute': 'query-named-block-nodes' }" "^}" |
1402483537eSMax Reitz    _filter_generated_node_ids | _filter_actual_image_size | _filter_img_info
1417c61a4a3SKevin Wolf
1427c61a4a3SKevin Wolf_send_qemu_cmd $h "{ 'execute': 'quit' }" "^}"
1437c61a4a3SKevin Wolfwait=1 _cleanup_qemu
1447c61a4a3SKevin Wolf
1457c61a4a3SKevin Wolf_img_info
1467c61a4a3SKevin WolfTEST_IMG="$TEST_IMG.ovl2" _img_info
1477c61a4a3SKevin Wolf
1487c61a4a3SKevin Wolf# success, all done
1497c61a4a3SKevin Wolfecho "*** done"
1507c61a4a3SKevin Wolfrm -f $seq.full
1517c61a4a3SKevin Wolfstatus=0
152