xref: /openbmc/qemu/tests/qemu-iotests/221 (revision c6a9d2f6f9bc0c163b3a3073126464a2446bad5f)
1*c6a9d2f6SEric Blake#!/bin/bash
2*c6a9d2f6SEric Blake#
3*c6a9d2f6SEric Blake# Test qemu-img vs. unaligned images
4*c6a9d2f6SEric Blake#
5*c6a9d2f6SEric Blake# Copyright (C) 2018 Red Hat, Inc.
6*c6a9d2f6SEric Blake#
7*c6a9d2f6SEric Blake# This program is free software; you can redistribute it and/or modify
8*c6a9d2f6SEric Blake# it under the terms of the GNU General Public License as published by
9*c6a9d2f6SEric Blake# the Free Software Foundation; either version 2 of the License, or
10*c6a9d2f6SEric Blake# (at your option) any later version.
11*c6a9d2f6SEric Blake#
12*c6a9d2f6SEric Blake# This program is distributed in the hope that it will be useful,
13*c6a9d2f6SEric Blake# but WITHOUT ANY WARRANTY; without even the implied warranty of
14*c6a9d2f6SEric Blake# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15*c6a9d2f6SEric Blake# GNU General Public License for more details.
16*c6a9d2f6SEric Blake#
17*c6a9d2f6SEric Blake# You should have received a copy of the GNU General Public License
18*c6a9d2f6SEric Blake# along with this program.  If not, see <http://www.gnu.org/licenses/>.
19*c6a9d2f6SEric Blake#
20*c6a9d2f6SEric Blake
21*c6a9d2f6SEric Blakeseq="$(basename $0)"
22*c6a9d2f6SEric Blakeecho "QA output created by $seq"
23*c6a9d2f6SEric Blake
24*c6a9d2f6SEric Blakehere="$PWD"
25*c6a9d2f6SEric Blakestatus=1 # failure is the default!
26*c6a9d2f6SEric Blake
27*c6a9d2f6SEric Blake_cleanup()
28*c6a9d2f6SEric Blake{
29*c6a9d2f6SEric Blake    _cleanup_test_img
30*c6a9d2f6SEric Blake}
31*c6a9d2f6SEric Blaketrap "_cleanup; exit \$status" 0 1 2 3 15
32*c6a9d2f6SEric Blake
33*c6a9d2f6SEric Blake# get standard environment, filters and checks
34*c6a9d2f6SEric Blake. ./common.rc
35*c6a9d2f6SEric Blake. ./common.filter
36*c6a9d2f6SEric Blake
37*c6a9d2f6SEric Blake_supported_fmt raw
38*c6a9d2f6SEric Blake_supported_proto file
39*c6a9d2f6SEric Blake_supported_os Linux
40*c6a9d2f6SEric Blake
41*c6a9d2f6SEric Blakeecho
42*c6a9d2f6SEric Blakeecho "=== Check mapping of unaligned raw image ==="
43*c6a9d2f6SEric Blakeecho
44*c6a9d2f6SEric Blake
45*c6a9d2f6SEric Blake_make_test_img 43009 # qemu-img create rounds size up
46*c6a9d2f6SEric Blake$QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map
47*c6a9d2f6SEric Blake
48*c6a9d2f6SEric Blaketruncate --size=43009 "$TEST_IMG" # so we resize it and check again
49*c6a9d2f6SEric Blake$QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map
50*c6a9d2f6SEric Blake
51*c6a9d2f6SEric Blake$QEMU_IO -c 'w 43008 1' "$TEST_IMG" | _filter_qemu_io # writing also rounds up
52*c6a9d2f6SEric Blake$QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map
53*c6a9d2f6SEric Blake
54*c6a9d2f6SEric Blaketruncate --size=43009 "$TEST_IMG" # so we resize it and check again
55*c6a9d2f6SEric Blake$QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map
56*c6a9d2f6SEric Blake
57*c6a9d2f6SEric Blake# success, all done
58*c6a9d2f6SEric Blakeecho '*** done'
59*c6a9d2f6SEric Blakerm -f $seq.full
60*c6a9d2f6SEric Blakestatus=0
61