xref: /openbmc/qemu/tests/qemu-iotests/292 (revision e4d7019e1a81c61de6a925c3ac5bb6e62ea21b29)
1*e4d7019eSAlberto Garcia#!/usr/bin/env bash
2*e4d7019eSAlberto Garcia#
3*e4d7019eSAlberto Garcia# Test resizing a qcow2 image with a backing file
4*e4d7019eSAlberto Garcia#
5*e4d7019eSAlberto Garcia# Copyright (C) 2020 Igalia, S.L.
6*e4d7019eSAlberto Garcia# Author: Alberto Garcia <berto@igalia.com>
7*e4d7019eSAlberto Garcia#
8*e4d7019eSAlberto Garcia# This program is free software; you can redistribute it and/or modify
9*e4d7019eSAlberto Garcia# it under the terms of the GNU General Public License as published by
10*e4d7019eSAlberto Garcia# the Free Software Foundation; either version 2 of the License, or
11*e4d7019eSAlberto Garcia# (at your option) any later version.
12*e4d7019eSAlberto Garcia#
13*e4d7019eSAlberto Garcia# This program is distributed in the hope that it will be useful,
14*e4d7019eSAlberto Garcia# but WITHOUT ANY WARRANTY; without even the implied warranty of
15*e4d7019eSAlberto Garcia# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16*e4d7019eSAlberto Garcia# GNU General Public License for more details.
17*e4d7019eSAlberto Garcia#
18*e4d7019eSAlberto Garcia# You should have received a copy of the GNU General Public License
19*e4d7019eSAlberto Garcia# along with this program.  If not, see <http://www.gnu.org/licenses/>.
20*e4d7019eSAlberto Garcia#
21*e4d7019eSAlberto Garcia
22*e4d7019eSAlberto Garcia# creator
23*e4d7019eSAlberto Garciaowner=berto@igalia.com
24*e4d7019eSAlberto Garcia
25*e4d7019eSAlberto Garciaseq=`basename $0`
26*e4d7019eSAlberto Garciaecho "QA output created by $seq"
27*e4d7019eSAlberto Garcia
28*e4d7019eSAlberto Garciastatus=1    # failure is the default!
29*e4d7019eSAlberto Garcia
30*e4d7019eSAlberto Garcia_cleanup()
31*e4d7019eSAlberto Garcia{
32*e4d7019eSAlberto Garcia    _cleanup_test_img
33*e4d7019eSAlberto Garcia}
34*e4d7019eSAlberto Garciatrap "_cleanup; exit \$status" 0 1 2 3 15
35*e4d7019eSAlberto Garcia
36*e4d7019eSAlberto Garcia# get standard environment, filters and checks
37*e4d7019eSAlberto Garcia. ./common.rc
38*e4d7019eSAlberto Garcia. ./common.filter
39*e4d7019eSAlberto Garcia
40*e4d7019eSAlberto Garcia_supported_fmt qcow2
41*e4d7019eSAlberto Garcia_supported_proto file
42*e4d7019eSAlberto Garcia_supported_os Linux
43*e4d7019eSAlberto Garcia
44*e4d7019eSAlberto Garciaecho '### Create the backing image'
45*e4d7019eSAlberto GarciaBACKING_IMG="$TEST_IMG.base"
46*e4d7019eSAlberto GarciaTEST_IMG="$BACKING_IMG" _make_test_img 1M
47*e4d7019eSAlberto Garcia
48*e4d7019eSAlberto Garciaecho '### Fill the backing image with data (0x11)'
49*e4d7019eSAlberto Garcia$QEMU_IO -c 'write -P 0x11 0 1M' "$BACKING_IMG" | _filter_qemu_io
50*e4d7019eSAlberto Garcia
51*e4d7019eSAlberto Garciaecho '### Create the top image'
52*e4d7019eSAlberto Garcia_make_test_img -F "$IMGFMT" -b "$BACKING_IMG"
53*e4d7019eSAlberto Garcia
54*e4d7019eSAlberto Garciaecho '### Fill the top image with data (0x22)'
55*e4d7019eSAlberto Garcia$QEMU_IO -c 'write -P 0x22 0 1M' "$TEST_IMG" | _filter_qemu_io
56*e4d7019eSAlberto Garcia
57*e4d7019eSAlberto Garcia# Both offsets are part of the same cluster.
58*e4d7019eSAlberto Garciaecho '### Shrink the image to 520k'
59*e4d7019eSAlberto Garcia$QEMU_IMG resize --shrink "$TEST_IMG" 520k
60*e4d7019eSAlberto Garciaecho '### Grow the image to 567k'
61*e4d7019eSAlberto Garcia$QEMU_IMG resize "$TEST_IMG" 567k
62*e4d7019eSAlberto Garcia
63*e4d7019eSAlberto Garciaecho '### Check that the tail of the image reads as zeroes'
64*e4d7019eSAlberto Garcia$QEMU_IO -c 'read -P 0x22    0 520k' "$TEST_IMG" | _filter_qemu_io
65*e4d7019eSAlberto Garcia$QEMU_IO -c 'read -P 0x00 520k  47k' "$TEST_IMG" | _filter_qemu_io
66*e4d7019eSAlberto Garcia
67*e4d7019eSAlberto Garciaecho '### Show output of qemu-img map'
68*e4d7019eSAlberto Garcia$QEMU_IMG map "$TEST_IMG" | _filter_testdir
69*e4d7019eSAlberto Garcia
70*e4d7019eSAlberto Garcia# success, all done
71*e4d7019eSAlberto Garciaecho "*** done"
72*e4d7019eSAlberto Garciarm -f $seq.full
73*e4d7019eSAlberto Garciastatus=0
74