]>
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 ([email protected]) | |
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 | [email protected] | |
24 | ||
25 | seq=`basename $0` | |
26 | echo "QA output created by $seq" | |
27 | ||
28 | here=`pwd` | |
b2e10493 AD |
29 | status=1 # failure is the default! |
30 | ||
31 | _cleanup() | |
32 | { | |
33 | _cleanup_test_img | |
fef9c191 | 34 | rm -f "$TEST_IMG.orig" "$TEST_IMG.raw" "$TEST_IMG.raw2" |
b2e10493 AD |
35 | } |
36 | trap "_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 | |
1f7bf7d0 | 44 | _supported_proto file |
b2e10493 | 45 | _supported_os Linux |
d2329f27 FZ |
46 | _unsupported_imgopts "subformat=monolithicFlat" \ |
47 | "subformat=twoGbMaxExtentFlat" \ | |
48 | "subformat=twoGbMaxExtentSparse" | |
b2e10493 AD |
49 | |
50 | _make_test_img 4M | |
51 | ||
52 | echo "== Testing conversion with -n fails with no target file ==" | |
53 | # check .orig file does not exist | |
fef9c191 JC |
54 | rm -f "$TEST_IMG.orig" |
55 | if $QEMU_IMG convert -f $IMGFMT -O $IMGFMT -n "$TEST_IMG" "$TEST_IMG.orig" >/dev/null 2>&1; then | |
b2e10493 AD |
56 | exit 1 |
57 | fi | |
58 | ||
59 | echo "== Testing conversion with -n succeeds with a target file ==" | |
fef9c191 JC |
60 | rm -f "$TEST_IMG.orig" |
61 | cp "$TEST_IMG" "$TEST_IMG.orig" | |
62 | if ! $QEMU_IMG convert -f $IMGFMT -O $IMGFMT -n "$TEST_IMG" "$TEST_IMG.orig" ; then | |
b2e10493 AD |
63 | exit 1 |
64 | fi | |
65 | ||
66 | echo "== Testing conversion to raw is the same after conversion with -n ==" | |
67 | # compare the raw files | |
fef9c191 | 68 | if ! $QEMU_IMG convert -f $IMGFMT -O raw "$TEST_IMG" "$TEST_IMG.raw1" ; then |
b2e10493 AD |
69 | exit 1 |
70 | fi | |
71 | ||
fef9c191 | 72 | if ! $QEMU_IMG convert -f $IMGFMT -O raw "$TEST_IMG.orig" "$TEST_IMG.raw2" ; then |
b2e10493 AD |
73 | exit 1 |
74 | fi | |
75 | ||
fef9c191 | 76 | if ! cmp "$TEST_IMG.raw1" "$TEST_IMG.raw2" ; then |
b2e10493 AD |
77 | exit 1 |
78 | fi | |
79 | ||
80 | echo "== Testing conversion back to original format ==" | |
fef9c191 | 81 | if ! $QEMU_IMG convert -f raw -O $IMGFMT -n "$TEST_IMG.raw2" "$TEST_IMG" ; then |
b2e10493 AD |
82 | exit 1 |
83 | fi | |
84 | _check_test_img | |
85 | ||
86 | echo "== Testing conversion to a smaller file fails ==" | |
fef9c191 JC |
87 | rm -f "$TEST_IMG.orig" |
88 | mv "$TEST_IMG" "$TEST_IMG.orig" | |
b2e10493 | 89 | _make_test_img 2M |
fef9c191 | 90 | if $QEMU_IMG convert -f $IMGFMT -O $IMGFMT -n "$TEST_IMG.orig" "$TEST_IMG" >/dev/null 2>&1; then |
b2e10493 AD |
91 | exit 1 |
92 | fi | |
93 | ||
fef9c191 | 94 | rm -f "$TEST_IMG.orig" "$TEST_IMG.raw" "$TEST_IMG.raw2" |
b2e10493 AD |
95 | |
96 | echo "*** done" | |
97 | rm -f $seq.full | |
98 | status=0 | |
99 | exit 0 |