xref: /openbmc/qemu/tests/qemu-iotests/102 (revision 4ffca8904a350460cdaa6304ea8c9b9c693d2d91)
1925bb323SMax Reitz#!/bin/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 Reitzhere=$PWD
28925bb323SMax Reitzstatus=1    # failure is the default!
29925bb323SMax Reitz
30925bb323SMax Reitz_cleanup()
31925bb323SMax Reitz{
32ecfa1854SJeff Cody    _cleanup_qemu
33925bb323SMax Reitz    _cleanup_test_img
34925bb323SMax Reitz}
35925bb323SMax Reitztrap "_cleanup; exit \$status" 0 1 2 3 15
36925bb323SMax Reitz
3770a5ff6bSMax Reitz# get standard environment, filters and qemu instance handling
38925bb323SMax Reitz. ./common.rc
39925bb323SMax Reitz. ./common.filter
4070a5ff6bSMax Reitz. ./common.qemu
41925bb323SMax Reitz
42925bb323SMax Reitz_supported_fmt qcow2
43925bb323SMax Reitz_supported_proto file
44925bb323SMax Reitz_supported_os Linux
45925bb323SMax Reitz
46925bb323SMax ReitzIMG_SIZE=64K
47925bb323SMax Reitz
48925bb323SMax Reitzecho
49925bb323SMax Reitzecho '=== Testing map command on truncated image ==='
50925bb323SMax Reitzecho
51925bb323SMax Reitz
52925bb323SMax Reitz_make_test_img $IMG_SIZE
53925bb323SMax Reitz# Create cluster
54925bb323SMax Reitz$QEMU_IO -c 'write 0 64k' "$TEST_IMG" | _filter_qemu_io
55925bb323SMax Reitz# Remove data cluster from image (first cluster: image header, second: reftable,
56925bb323SMax Reitz# third: refblock, fourth: L1 table, fifth: L2 table)
57*4ffca890SPavel Butsykin$QEMU_IMG resize -f raw --shrink "$TEST_IMG" $((5 * 64 * 1024))
58925bb323SMax Reitz
59925bb323SMax Reitz$QEMU_IO -c map "$TEST_IMG"
60925bb323SMax Reitz$QEMU_IMG map "$TEST_IMG"
61925bb323SMax Reitz
6270a5ff6bSMax Reitzecho
6370a5ff6bSMax Reitzecho '=== Testing map on an image file truncated outside of qemu ==='
6470a5ff6bSMax Reitzecho
6570a5ff6bSMax Reitz
6670a5ff6bSMax Reitz# Same as above, only now we concurrently truncate and map the image
6770a5ff6bSMax Reitz_make_test_img $IMG_SIZE
6870a5ff6bSMax Reitz$QEMU_IO -c 'write 0 64k' "$TEST_IMG" | _filter_qemu_io
6970a5ff6bSMax Reitz
7070a5ff6bSMax Reitzqemu_comm_method=monitor _launch_qemu -drive if=none,file="$TEST_IMG",id=drv0
7170a5ff6bSMax Reitz
72*4ffca890SPavel Butsykin$QEMU_IMG resize -f raw --shrink "$TEST_IMG" $((5 * 64 * 1024))
7370a5ff6bSMax Reitz
7470a5ff6bSMax Reitz_send_qemu_cmd $QEMU_HANDLE 'qemu-io drv0 map' 'allocated' \
7570a5ff6bSMax Reitz    | sed -e 's/^(qemu).*qemu-io drv0 map...$/(qemu) qemu-io drv0 map/'
7670a5ff6bSMax Reitz_send_qemu_cmd $QEMU_HANDLE 'quit' ''
7770a5ff6bSMax Reitz
78925bb323SMax Reitz# success, all done
79925bb323SMax Reitzecho '*** done'
80925bb323SMax Reitzrm -f $seq.full
81925bb323SMax Reitzstatus=0
82