111a82d14SPhilippe Mathieu-Daudé#!/usr/bin/env bash 23fb23e07SKevin Wolf# 33fb23e07SKevin Wolf# Test change-backing-file command 43fb23e07SKevin Wolf# 53fb23e07SKevin Wolf# Copyright (C) 2017 Red Hat, Inc. 63fb23e07SKevin Wolf# 73fb23e07SKevin Wolf# This program is free software; you can redistribute it and/or modify 83fb23e07SKevin Wolf# it under the terms of the GNU General Public License as published by 93fb23e07SKevin Wolf# the Free Software Foundation; either version 2 of the License, or 103fb23e07SKevin Wolf# (at your option) any later version. 113fb23e07SKevin Wolf# 123fb23e07SKevin Wolf# This program is distributed in the hope that it will be useful, 133fb23e07SKevin Wolf# but WITHOUT ANY WARRANTY; without even the implied warranty of 143fb23e07SKevin Wolf# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 153fb23e07SKevin Wolf# GNU General Public License for more details. 163fb23e07SKevin Wolf# 173fb23e07SKevin Wolf# You should have received a copy of the GNU General Public License 183fb23e07SKevin Wolf# along with this program. If not, see <http://www.gnu.org/licenses/>. 193fb23e07SKevin Wolf# 203fb23e07SKevin Wolf 213fb23e07SKevin Wolf# creator 223fb23e07SKevin Wolfowner=kwolf@redhat.com 233fb23e07SKevin Wolf 243fb23e07SKevin Wolfseq=`basename $0` 253fb23e07SKevin Wolfecho "QA output created by $seq" 263fb23e07SKevin Wolf 273fb23e07SKevin Wolfstatus=1 # failure is the default! 283fb23e07SKevin Wolf 293fb23e07SKevin Wolf_cleanup() 303fb23e07SKevin Wolf{ 313fb23e07SKevin Wolf _cleanup_test_img 32*f91ecbd7SMax Reitz _rm_test_img "$TEST_IMG.mid" 333fb23e07SKevin Wolf} 343fb23e07SKevin Wolftrap "_cleanup; exit \$status" 0 1 2 3 15 353fb23e07SKevin Wolf 363fb23e07SKevin Wolf# get standard environment, filters and checks 373fb23e07SKevin Wolf. ./common.rc 383fb23e07SKevin Wolf. ./common.filter 393fb23e07SKevin Wolf 403fb23e07SKevin Wolf_supported_fmt qcow2 413fb23e07SKevin Wolf_supported_proto file 423fb23e07SKevin Wolf 438cedcffdSEric Blakedo_run_qemu() 443fb23e07SKevin Wolf{ 4547500c67SMax Reitz echo Testing: "$@" 463fb23e07SKevin Wolf $QEMU -nographic -qmp-pretty stdio -serial none "$@" 473fb23e07SKevin Wolf echo 483fb23e07SKevin Wolf} 493fb23e07SKevin Wolf 508cedcffdSEric Blakerun_qemu() 513fb23e07SKevin Wolf{ 5247500c67SMax Reitz do_run_qemu "$@" 2>&1 | _filter_testdir | _filter_imgfmt | _filter_qemu \ 5347500c67SMax Reitz | _filter_qmp | _filter_qemu_io \ 5447500c67SMax Reitz | _filter_generated_node_ids 553fb23e07SKevin Wolf} 563fb23e07SKevin Wolf 573fb23e07SKevin Wolfsize=64M 583fb23e07SKevin WolfTEST_IMG="$TEST_IMG.base" _make_test_img $size 593fb23e07SKevin WolfTEST_IMG="$TEST_IMG.mid" _make_test_img -b "$TEST_IMG.base" 603fb23e07SKevin Wolf_make_test_img -b "$TEST_IMG.mid" 613fb23e07SKevin Wolf 623fb23e07SKevin Wolfecho 633fb23e07SKevin Wolfecho "Change backing file of mid (opened read-only)" 643fb23e07SKevin Wolfecho 653fb23e07SKevin Wolf 663fb23e07SKevin Wolfrun_qemu -drive if=none,file="$TEST_IMG",backing.node-name=mid <<EOF 673fb23e07SKevin Wolf{"execute":"qmp_capabilities"} 683fb23e07SKevin Wolf{"execute":"change-backing-file", "arguments":{"device":"none0","image-node-name":"mid","backing-file":"/dev/null"}} 693fb23e07SKevin Wolf{"execute":"quit"} 703fb23e07SKevin WolfEOF 713fb23e07SKevin Wolf 723fb23e07SKevin WolfTEST_IMG="$TEST_IMG.mid" _img_info 733fb23e07SKevin Wolf 743fb23e07SKevin Wolfecho 753fb23e07SKevin Wolfecho "Change backing file of top (opened writable)" 763fb23e07SKevin Wolfecho 773fb23e07SKevin Wolf 783fb23e07SKevin WolfTEST_IMG="$TEST_IMG.mid" _make_test_img -b "$TEST_IMG.base" 793fb23e07SKevin Wolf 803fb23e07SKevin Wolfrun_qemu -drive if=none,file="$TEST_IMG",node-name=top <<EOF 813fb23e07SKevin Wolf{"execute":"qmp_capabilities"} 823fb23e07SKevin Wolf{"execute":"change-backing-file", "arguments":{"device":"none0","image-node-name":"top","backing-file":"/dev/null"}} 833fb23e07SKevin Wolf{"execute":"quit"} 843fb23e07SKevin WolfEOF 853fb23e07SKevin Wolf 863fb23e07SKevin Wolf_img_info 873fb23e07SKevin Wolf 883fb23e07SKevin Wolf# success, all done 893fb23e07SKevin Wolfecho "*** done" 903fb23e07SKevin Wolfrm -f $seq.full 913fb23e07SKevin Wolfstatus=0 92