xref: /openbmc/qemu/tests/qemu-iotests/102 (revision 42a5009d)
111a82d14SPhilippe Mathieu-Daudé#!/usr/bin/env bash
29dd003a9SVladimir Sementsov-Ogievskiy# group: rw quick
3925bb323SMax Reitz#
4925bb323SMax Reitz# Test case for qemu-io -c map and qemu-img map
5925bb323SMax Reitz#
6925bb323SMax Reitz# Copyright (C) 2014 Red Hat, Inc.
7925bb323SMax Reitz#
8925bb323SMax Reitz# This program is free software; you can redistribute it and/or modify
9925bb323SMax Reitz# it under the terms of the GNU General Public License as published by
10925bb323SMax Reitz# the Free Software Foundation; either version 2 of the License, or
11925bb323SMax Reitz# (at your option) any later version.
12925bb323SMax Reitz#
13925bb323SMax Reitz# This program is distributed in the hope that it will be useful,
14925bb323SMax Reitz# but WITHOUT ANY WARRANTY; without even the implied warranty of
15925bb323SMax Reitz# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16925bb323SMax Reitz# GNU General Public License for more details.
17925bb323SMax Reitz#
18925bb323SMax Reitz# You should have received a copy of the GNU General Public License
19925bb323SMax Reitz# along with this program.  If not, see <http://www.gnu.org/licenses/>.
20925bb323SMax Reitz#
21925bb323SMax Reitz
22925bb323SMax Reitz# creator
23*42a5009dSJohn Snowowner=hreitz@redhat.com
24925bb323SMax Reitz
25925bb323SMax Reitzseq=$(basename $0)
26925bb323SMax Reitzecho "QA output created by $seq"
27925bb323SMax Reitz
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
4357284d2aSMax Reitz_supported_proto file fuse
44925bb323SMax Reitz
45925bb323SMax ReitzIMG_SIZE=64K
46925bb323SMax Reitz
47925bb323SMax Reitzecho
48925bb323SMax Reitzecho '=== Testing map command on truncated image ==='
49925bb323SMax Reitzecho
50925bb323SMax Reitz
51925bb323SMax Reitz_make_test_img $IMG_SIZE
52925bb323SMax Reitz# Create cluster
53925bb323SMax Reitz$QEMU_IO -c 'write 0 64k' "$TEST_IMG" | _filter_qemu_io
54925bb323SMax Reitz# Remove data cluster from image (first cluster: image header, second: reftable,
55925bb323SMax Reitz# third: refblock, fourth: L1 table, fifth: L2 table)
564ffca890SPavel Butsykin$QEMU_IMG resize -f raw --shrink "$TEST_IMG" $((5 * 64 * 1024))
57925bb323SMax Reitz
58925bb323SMax Reitz$QEMU_IO -c map "$TEST_IMG"
5969f47505SVladimir Sementsov-Ogievskiy$QEMU_IMG map "$TEST_IMG" | _filter_qemu_img_map
60925bb323SMax Reitz
6170a5ff6bSMax Reitzecho
6270a5ff6bSMax Reitzecho '=== Testing map on an image file truncated outside of qemu ==='
6370a5ff6bSMax Reitzecho
6470a5ff6bSMax Reitz
6570a5ff6bSMax Reitz# Same as above, only now we concurrently truncate and map the image
6670a5ff6bSMax Reitz_make_test_img $IMG_SIZE
6770a5ff6bSMax Reitz$QEMU_IO -c 'write 0 64k' "$TEST_IMG" | _filter_qemu_io
6870a5ff6bSMax Reitz
6970a5ff6bSMax Reitzqemu_comm_method=monitor _launch_qemu -drive if=none,file="$TEST_IMG",id=drv0
7070a5ff6bSMax Reitz
716bfc907dSMax Reitz# Wait for a prompt to appear (so we know qemu has opened the image)
720c8fbfb9SMax Reitz_send_qemu_cmd $QEMU_HANDLE '' '(qemu)'
736bfc907dSMax Reitz
746bfc907dSMax Reitz$QEMU_IMG resize --shrink --image-opts \
756bfc907dSMax Reitz    "driver=raw,file.driver=file,file.filename=$TEST_IMG,file.locking=off" \
766bfc907dSMax Reitz    $((5 * 64 * 1024))
7770a5ff6bSMax Reitz
7870a5ff6bSMax Reitz_send_qemu_cmd $QEMU_HANDLE 'qemu-io drv0 map' 'allocated' \
7970a5ff6bSMax Reitz    | sed -e 's/^(qemu).*qemu-io drv0 map...$/(qemu) qemu-io drv0 map/'
8070a5ff6bSMax Reitz_send_qemu_cmd $QEMU_HANDLE 'quit' ''
8170a5ff6bSMax Reitz
82925bb323SMax Reitz# success, all done
83925bb323SMax Reitzecho '*** done'
84925bb323SMax Reitzrm -f $seq.full
85925bb323SMax Reitzstatus=0
86