]>
Commit | Line | Data |
---|---|---|
b2e10493 AD |
1 | #!/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 | |
23 | owner=alex@alex.org.uk | |
24 | ||
25 | seq=`basename $0` | |
26 | echo "QA output created by $seq" | |
27 | ||
28 | here=`pwd` | |
29 | tmp=/tmp/$$ | |
30 | status=1 # failure is the default! | |
31 | ||
32 | _cleanup() | |
33 | { | |
34 | _cleanup_test_img | |
fef9c191 | 35 | rm -f "$TEST_IMG.orig" "$TEST_IMG.raw" "$TEST_IMG.raw2" |
b2e10493 AD |
36 | } |
37 | trap "_cleanup; exit \$status" 0 1 2 3 15 | |
38 | ||
39 | # get standard environment, filters and checks | |
40 | . ./common.rc | |
41 | . ./common.filter | |
42 | . ./common.pattern | |
43 | ||
44 | _supported_fmt qcow qcow2 vmdk qed raw | |
45 | _supported_proto generic | |
46 | _supported_os Linux | |
47 | ||
48 | _make_test_img 4M | |
49 | ||
50 | echo "== Testing conversion with -n fails with no target file ==" | |
51 | # check .orig file does not exist | |
fef9c191 JC |
52 | rm -f "$TEST_IMG.orig" |
53 | if $QEMU_IMG convert -f $IMGFMT -O $IMGFMT -n "$TEST_IMG" "$TEST_IMG.orig" >/dev/null 2>&1; then | |
b2e10493 AD |
54 | exit 1 |
55 | fi | |
56 | ||
57 | echo "== Testing conversion with -n succeeds with a target file ==" | |
fef9c191 JC |
58 | rm -f "$TEST_IMG.orig" |
59 | cp "$TEST_IMG" "$TEST_IMG.orig" | |
60 | if ! $QEMU_IMG convert -f $IMGFMT -O $IMGFMT -n "$TEST_IMG" "$TEST_IMG.orig" ; then | |
b2e10493 AD |
61 | exit 1 |
62 | fi | |
63 | ||
64 | echo "== Testing conversion to raw is the same after conversion with -n ==" | |
65 | # compare the raw files | |
fef9c191 | 66 | if ! $QEMU_IMG convert -f $IMGFMT -O raw "$TEST_IMG" "$TEST_IMG.raw1" ; then |
b2e10493 AD |
67 | exit 1 |
68 | fi | |
69 | ||
fef9c191 | 70 | if ! $QEMU_IMG convert -f $IMGFMT -O raw "$TEST_IMG.orig" "$TEST_IMG.raw2" ; then |
b2e10493 AD |
71 | exit 1 |
72 | fi | |
73 | ||
fef9c191 | 74 | if ! cmp "$TEST_IMG.raw1" "$TEST_IMG.raw2" ; then |
b2e10493 AD |
75 | exit 1 |
76 | fi | |
77 | ||
78 | echo "== Testing conversion back to original format ==" | |
fef9c191 | 79 | if ! $QEMU_IMG convert -f raw -O $IMGFMT -n "$TEST_IMG.raw2" "$TEST_IMG" ; then |
b2e10493 AD |
80 | exit 1 |
81 | fi | |
82 | _check_test_img | |
83 | ||
84 | echo "== Testing conversion to a smaller file fails ==" | |
fef9c191 JC |
85 | rm -f "$TEST_IMG.orig" |
86 | mv "$TEST_IMG" "$TEST_IMG.orig" | |
b2e10493 | 87 | _make_test_img 2M |
fef9c191 | 88 | if $QEMU_IMG convert -f $IMGFMT -O $IMGFMT -n "$TEST_IMG.orig" "$TEST_IMG" >/dev/null 2>&1; then |
b2e10493 AD |
89 | exit 1 |
90 | fi | |
91 | ||
fef9c191 | 92 | rm -f "$TEST_IMG.orig" "$TEST_IMG.raw" "$TEST_IMG.raw2" |
b2e10493 AD |
93 | |
94 | echo "*** done" | |
95 | rm -f $seq.full | |
96 | status=0 | |
97 | exit 0 |