blob: e4f6ea938586ef2d5f2c222477880c49999bec01 [file] [log] [blame]
Alexandre Derumierb2e10492013-09-02 19:07:24 +01001#!/bin/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
28here=`pwd`
Alexandre Derumierb2e10492013-09-02 19:07:24 +010029status=1 # failure is the default!
30
31_cleanup()
32{
33 _cleanup_test_img
Kevin Wolf1803f3f2017-07-27 15:13:20 +020034 rm -f "$TEST_IMG.orig" "$TEST_IMG.raw1" "$TEST_IMG.raw2"
Alexandre Derumierb2e10492013-09-02 19:07:24 +010035}
36trap "_cleanup; exit \$status" 0 1 2 3 15
37
38# get standard environment, filters and checks
39. ./common.rc
40. ./common.filter
41. ./common.pattern
42
43_supported_fmt qcow qcow2 vmdk qed raw
Peter Lieven1f7bf7d2014-02-03 10:26:14 +010044_supported_proto file
Alexandre Derumierb2e10492013-09-02 19:07:24 +010045_supported_os Linux
Fam Zhengd2329f22013-11-26 14:40:33 +080046_unsupported_imgopts "subformat=monolithicFlat" \
47 "subformat=twoGbMaxExtentFlat" \
48 "subformat=twoGbMaxExtentSparse"
Alexandre Derumierb2e10492013-09-02 19:07:24 +010049
50_make_test_img 4M
51
52echo "== Testing conversion with -n fails with no target file =="
53# check .orig file does not exist
Jeff Codyfef9c192013-09-25 08:12:22 -040054rm -f "$TEST_IMG.orig"
55if $QEMU_IMG convert -f $IMGFMT -O $IMGFMT -n "$TEST_IMG" "$TEST_IMG.orig" >/dev/null 2>&1; then
Alexandre Derumierb2e10492013-09-02 19:07:24 +010056 exit 1
57fi
58
59echo "== Testing conversion with -n succeeds with a target file =="
Jeff Codyfef9c192013-09-25 08:12:22 -040060rm -f "$TEST_IMG.orig"
61cp "$TEST_IMG" "$TEST_IMG.orig"
62if ! $QEMU_IMG convert -f $IMGFMT -O $IMGFMT -n "$TEST_IMG" "$TEST_IMG.orig" ; then
Alexandre Derumierb2e10492013-09-02 19:07:24 +010063 exit 1
64fi
65
66echo "== Testing conversion to raw is the same after conversion with -n =="
67# compare the raw files
Jeff Codyfef9c192013-09-25 08:12:22 -040068if ! $QEMU_IMG convert -f $IMGFMT -O raw "$TEST_IMG" "$TEST_IMG.raw1" ; then
Alexandre Derumierb2e10492013-09-02 19:07:24 +010069 exit 1
70fi
71
Jeff Codyfef9c192013-09-25 08:12:22 -040072if ! $QEMU_IMG convert -f $IMGFMT -O raw "$TEST_IMG.orig" "$TEST_IMG.raw2" ; then
Alexandre Derumierb2e10492013-09-02 19:07:24 +010073 exit 1
74fi
75
Jeff Codyfef9c192013-09-25 08:12:22 -040076if ! cmp "$TEST_IMG.raw1" "$TEST_IMG.raw2" ; then
Alexandre Derumierb2e10492013-09-02 19:07:24 +010077 exit 1
78fi
79
80echo "== Testing conversion back to original format =="
Jeff Codyfef9c192013-09-25 08:12:22 -040081if ! $QEMU_IMG convert -f raw -O $IMGFMT -n "$TEST_IMG.raw2" "$TEST_IMG" ; then
Alexandre Derumierb2e10492013-09-02 19:07:24 +010082 exit 1
83fi
84_check_test_img
85
86echo "== Testing conversion to a smaller file fails =="
Jeff Codyfef9c192013-09-25 08:12:22 -040087rm -f "$TEST_IMG.orig"
88mv "$TEST_IMG" "$TEST_IMG.orig"
Alexandre Derumierb2e10492013-09-02 19:07:24 +010089_make_test_img 2M
Jeff Codyfef9c192013-09-25 08:12:22 -040090if $QEMU_IMG convert -f $IMGFMT -O $IMGFMT -n "$TEST_IMG.orig" "$TEST_IMG" >/dev/null 2>&1; then
Alexandre Derumierb2e10492013-09-02 19:07:24 +010091 exit 1
92fi
93
Alexandre Derumierb2e10492013-09-02 19:07:24 +010094echo "*** done"
95rm -f $seq.full
96status=0
97exit 0