xref: /openbmc/qemu/tests/qemu-iotests/063 (revision 8e6fe6b8)
1#!/usr/bin/env bash
2#
3# test of qemu-img convert -n - convert without creation
4#
5# Copyright (C) 2009 Red Hat, Inc.
6# Copyright (C) 2013 Alex Bligh (alex@alex.org.uk)
7#
8# This program is free software; you can redistribute it and/or modify
9# it under the terms of the GNU General Public License as published by
10# the Free Software Foundation; either version 2 of the License, or
11# (at your option) any later version.
12#
13# This program is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16# GNU General Public License for more details.
17#
18# You should have received a copy of the GNU General Public License
19# along with this program.  If not, see <http://www.gnu.org/licenses/>.
20#
21
22# creator
23owner=alex@alex.org.uk
24
25seq=`basename $0`
26echo "QA output created by $seq"
27
28status=1	# failure is the default!
29
30_cleanup()
31{
32	_cleanup_test_img
33	rm -f "$TEST_IMG.orig" "$TEST_IMG.raw1" "$TEST_IMG.raw2"
34}
35trap "_cleanup; exit \$status" 0 1 2 3 15
36
37# get standard environment, filters and checks
38. ./common.rc
39. ./common.filter
40. ./common.pattern
41
42_supported_fmt qcow qcow2 vmdk qed raw
43_supported_proto file
44_unsupported_imgopts "subformat=monolithicFlat" \
45                     "subformat=twoGbMaxExtentFlat" \
46                     "subformat=twoGbMaxExtentSparse"
47
48_make_test_img 4M
49
50echo "== Testing conversion with -n fails with no target file =="
51# check .orig file does not exist
52rm -f "$TEST_IMG.orig"
53if $QEMU_IMG convert -f $IMGFMT -O $IMGFMT -n "$TEST_IMG" "$TEST_IMG.orig" >/dev/null 2>&1; then
54    exit 1
55fi
56
57echo "== Testing conversion with -n succeeds with a target file =="
58rm -f "$TEST_IMG.orig"
59cp "$TEST_IMG" "$TEST_IMG.orig"
60if ! $QEMU_IMG convert -f $IMGFMT -O $IMGFMT -n "$TEST_IMG" "$TEST_IMG.orig" ; then
61    exit 1
62fi
63
64echo "== Testing conversion to raw is the same after conversion with -n =="
65# compare the raw files
66if ! $QEMU_IMG convert -f $IMGFMT -O raw "$TEST_IMG" "$TEST_IMG.raw1" ; then
67    exit 1
68fi
69
70if ! $QEMU_IMG convert -f $IMGFMT -O raw "$TEST_IMG.orig" "$TEST_IMG.raw2" ; then
71    exit 1
72fi
73
74if ! cmp "$TEST_IMG.raw1" "$TEST_IMG.raw2" ; then
75    exit 1
76fi
77
78echo "== Testing conversion back to original format =="
79if ! $QEMU_IMG convert -f raw -O $IMGFMT -n "$TEST_IMG.raw2" "$TEST_IMG" ; then
80    exit 1
81fi
82_check_test_img
83
84echo "== Testing conversion to a smaller file fails =="
85rm -f "$TEST_IMG.orig"
86mv "$TEST_IMG" "$TEST_IMG.orig"
87_make_test_img 2M
88if $QEMU_IMG convert -f $IMGFMT -O $IMGFMT -n "$TEST_IMG.orig" "$TEST_IMG" >/dev/null 2>&1; then
89    exit 1
90fi
91
92echo "== Regression testing for copy offloading bug =="
93
94_make_test_img 1M
95TEST_IMG="$TEST_IMG.target" _make_test_img 1M
96$QEMU_IO -c 'write -P 1 0 512k' -c 'write -P 2 512k 512k' "$TEST_IMG" | _filter_qemu_io
97$QEMU_IO -c 'write -P 4 512k 512k' -c 'write -P 3 0 512k' "$TEST_IMG.target" | _filter_qemu_io
98$QEMU_IMG convert -n -O $IMGFMT "$TEST_IMG" "$TEST_IMG.target"
99$QEMU_IMG compare "$TEST_IMG" "$TEST_IMG.target"
100
101echo "*** done"
102rm -f $seq.full
103status=0
104exit 0
105