]>
Commit | Line | Data |
---|---|---|
11a82d14 | 1 | #!/usr/bin/env bash |
b2e10493 AD |
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 | ||
b2e10493 AD |
28 | status=1 # failure is the default! |
29 | ||
30 | _cleanup() | |
31 | { | |
f91ecbd7 HR |
32 | _cleanup_test_img |
33 | for img in "$TEST_IMG".{orig,raw1,raw2,target}; do | |
34 | _rm_test_img "$img" | |
35 | done | |
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 | |
1f7bf7d0 | 45 | _supported_proto file |
d2329f27 FZ |
46 | _unsupported_imgopts "subformat=monolithicFlat" \ |
47 | "subformat=twoGbMaxExtentFlat" \ | |
325dd915 HR |
48 | "subformat=twoGbMaxExtentSparse" \ |
49 | "subformat=streamOptimized" | |
b2e10493 AD |
50 | |
51 | _make_test_img 4M | |
52 | ||
53 | echo "== Testing conversion with -n fails with no target file ==" | |
fef9c191 | 54 | if $QEMU_IMG convert -f $IMGFMT -O $IMGFMT -n "$TEST_IMG" "$TEST_IMG.orig" >/dev/null 2>&1; then |
b2e10493 AD |
55 | exit 1 |
56 | fi | |
57 | ||
58 | echo "== Testing conversion with -n succeeds with a target file ==" | |
d88bef19 HR |
59 | _rm_test_img "$TEST_IMG.orig" |
60 | TEST_IMG="$TEST_IMG.orig" _make_test_img 4M | |
fef9c191 | 61 | if ! $QEMU_IMG convert -f $IMGFMT -O $IMGFMT -n "$TEST_IMG" "$TEST_IMG.orig" ; then |
b2e10493 AD |
62 | exit 1 |
63 | fi | |
64 | ||
65 | echo "== Testing conversion to raw is the same after conversion with -n ==" | |
66 | # compare the raw files | |
fef9c191 | 67 | if ! $QEMU_IMG convert -f $IMGFMT -O raw "$TEST_IMG" "$TEST_IMG.raw1" ; then |
b2e10493 AD |
68 | exit 1 |
69 | fi | |
70 | ||
fef9c191 | 71 | if ! $QEMU_IMG convert -f $IMGFMT -O raw "$TEST_IMG.orig" "$TEST_IMG.raw2" ; then |
b2e10493 AD |
72 | exit 1 |
73 | fi | |
74 | ||
fef9c191 | 75 | if ! cmp "$TEST_IMG.raw1" "$TEST_IMG.raw2" ; then |
b2e10493 AD |
76 | exit 1 |
77 | fi | |
78 | ||
79 | echo "== Testing conversion back to original format ==" | |
fef9c191 | 80 | if ! $QEMU_IMG convert -f raw -O $IMGFMT -n "$TEST_IMG.raw2" "$TEST_IMG" ; then |
b2e10493 AD |
81 | exit 1 |
82 | fi | |
83 | _check_test_img | |
84 | ||
85 | echo "== Testing conversion to a smaller file fails ==" | |
d88bef19 HR |
86 | TEST_IMG="$TEST_IMG.target" _make_test_img 2M |
87 | if $QEMU_IMG convert -f $IMGFMT -O $IMGFMT -n "$TEST_IMG" "$TEST_IMG.target" >/dev/null 2>&1; then | |
b2e10493 AD |
88 | exit 1 |
89 | fi | |
90 | ||
e06f4639 FZ |
91 | echo "== Regression testing for copy offloading bug ==" |
92 | ||
93 | _make_test_img 1M | |
94 | TEST_IMG="$TEST_IMG.target" _make_test_img 1M | |
95 | $QEMU_IO -c 'write -P 1 0 512k' -c 'write -P 2 512k 512k' "$TEST_IMG" | _filter_qemu_io | |
96 | $QEMU_IO -c 'write -P 4 512k 512k' -c 'write -P 3 0 512k' "$TEST_IMG.target" | _filter_qemu_io | |
97 | $QEMU_IMG convert -n -O $IMGFMT "$TEST_IMG" "$TEST_IMG.target" | |
98 | $QEMU_IMG compare "$TEST_IMG" "$TEST_IMG.target" | |
99 | ||
b2e10493 AD |
100 | echo "*** done" |
101 | rm -f $seq.full | |
102 | status=0 | |
103 | exit 0 |