111a82d14SPhilippe Mathieu-Daudé#!/usr/bin/env bash 2925bb323SMax Reitz# 3925bb323SMax Reitz# Test case for qemu-io -c map and qemu-img map 4925bb323SMax Reitz# 5925bb323SMax Reitz# Copyright (C) 2014 Red Hat, Inc. 6925bb323SMax Reitz# 7925bb323SMax Reitz# This program is free software; you can redistribute it and/or modify 8925bb323SMax Reitz# it under the terms of the GNU General Public License as published by 9925bb323SMax Reitz# the Free Software Foundation; either version 2 of the License, or 10925bb323SMax Reitz# (at your option) any later version. 11925bb323SMax Reitz# 12925bb323SMax Reitz# This program is distributed in the hope that it will be useful, 13925bb323SMax Reitz# but WITHOUT ANY WARRANTY; without even the implied warranty of 14925bb323SMax Reitz# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15925bb323SMax Reitz# GNU General Public License for more details. 16925bb323SMax Reitz# 17925bb323SMax Reitz# You should have received a copy of the GNU General Public License 18925bb323SMax Reitz# along with this program. If not, see <http://www.gnu.org/licenses/>. 19925bb323SMax Reitz# 20925bb323SMax Reitz 21925bb323SMax Reitz# creator 22925bb323SMax Reitzowner=mreitz@redhat.com 23925bb323SMax Reitz 24925bb323SMax Reitzseq=$(basename $0) 25925bb323SMax Reitzecho "QA output created by $seq" 26925bb323SMax Reitz 27925bb323SMax Reitzstatus=1 # failure is the default! 28925bb323SMax Reitz 29925bb323SMax Reitz_cleanup() 30925bb323SMax Reitz{ 31ecfa1854SJeff Cody _cleanup_qemu 32925bb323SMax Reitz _cleanup_test_img 33925bb323SMax Reitz} 34925bb323SMax Reitztrap "_cleanup; exit \$status" 0 1 2 3 15 35925bb323SMax Reitz 3670a5ff6bSMax Reitz# get standard environment, filters and qemu instance handling 37925bb323SMax Reitz. ./common.rc 38925bb323SMax Reitz. ./common.filter 3970a5ff6bSMax Reitz. ./common.qemu 40925bb323SMax Reitz 41925bb323SMax Reitz_supported_fmt qcow2 4257284d2aSMax Reitz_supported_proto file fuse 43925bb323SMax Reitz 44925bb323SMax ReitzIMG_SIZE=64K 45925bb323SMax Reitz 46925bb323SMax Reitzecho 47925bb323SMax Reitzecho '=== Testing map command on truncated image ===' 48925bb323SMax Reitzecho 49925bb323SMax Reitz 50925bb323SMax Reitz_make_test_img $IMG_SIZE 51925bb323SMax Reitz# Create cluster 52925bb323SMax Reitz$QEMU_IO -c 'write 0 64k' "$TEST_IMG" | _filter_qemu_io 53925bb323SMax Reitz# Remove data cluster from image (first cluster: image header, second: reftable, 54925bb323SMax Reitz# third: refblock, fourth: L1 table, fifth: L2 table) 554ffca890SPavel Butsykin$QEMU_IMG resize -f raw --shrink "$TEST_IMG" $((5 * 64 * 1024)) 56925bb323SMax Reitz 57925bb323SMax Reitz$QEMU_IO -c map "$TEST_IMG" 5869f47505SVladimir Sementsov-Ogievskiy$QEMU_IMG map "$TEST_IMG" | _filter_qemu_img_map 59925bb323SMax Reitz 6070a5ff6bSMax Reitzecho 6170a5ff6bSMax Reitzecho '=== Testing map on an image file truncated outside of qemu ===' 6270a5ff6bSMax Reitzecho 6370a5ff6bSMax Reitz 6470a5ff6bSMax Reitz# Same as above, only now we concurrently truncate and map the image 6570a5ff6bSMax Reitz_make_test_img $IMG_SIZE 6670a5ff6bSMax Reitz$QEMU_IO -c 'write 0 64k' "$TEST_IMG" | _filter_qemu_io 6770a5ff6bSMax Reitz 6870a5ff6bSMax Reitzqemu_comm_method=monitor _launch_qemu -drive if=none,file="$TEST_IMG",id=drv0 6970a5ff6bSMax Reitz 706bfc907dSMax Reitz# Wait for a prompt to appear (so we know qemu has opened the image) 71*0c8fbfb9SMax Reitz_send_qemu_cmd $QEMU_HANDLE '' '(qemu)' 726bfc907dSMax Reitz 736bfc907dSMax Reitz$QEMU_IMG resize --shrink --image-opts \ 746bfc907dSMax Reitz "driver=raw,file.driver=file,file.filename=$TEST_IMG,file.locking=off" \ 756bfc907dSMax Reitz $((5 * 64 * 1024)) 7670a5ff6bSMax Reitz 7770a5ff6bSMax Reitz_send_qemu_cmd $QEMU_HANDLE 'qemu-io drv0 map' 'allocated' \ 7870a5ff6bSMax Reitz | sed -e 's/^(qemu).*qemu-io drv0 map...$/(qemu) qemu-io drv0 map/' 7970a5ff6bSMax Reitz_send_qemu_cmd $QEMU_HANDLE 'quit' '' 8070a5ff6bSMax Reitz 81925bb323SMax Reitz# success, all done 82925bb323SMax Reitzecho '*** done' 83925bb323SMax Reitzrm -f $seq.full 84925bb323SMax Reitzstatus=0 85