Add qemu 2.4.0
[kvmfornfv.git] / qemu / tests / qemu-iotests / 082
1 #!/bin/bash
2 #
3 # Test qemu-img command line parsing
4 #
5 # Copyright (C) 2014 Red Hat, Inc.
6 #
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
11 #
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
19 #
20
21 # creator
22 owner=kwolf@redhat.com
23
24 seq=`basename $0`
25 echo "QA output created by $seq"
26
27 here=`pwd`
28 tmp=/tmp/$$
29 status=1        # failure is the default!
30
31 _cleanup()
32 {
33         _cleanup_test_img
34 }
35 trap "_cleanup; exit \$status" 0 1 2 3 15
36
37 # get standard environment, filters and checks
38 . ./common.rc
39 . ./common.filter
40
41 _supported_fmt qcow2
42 _supported_proto file nfs
43 _supported_os Linux
44
45 function run_qemu_img()
46 {
47     echo
48     echo Testing: "$@" | _filter_testdir
49     "$QEMU_IMG" "$@" 2>&1 | _filter_testdir
50 }
51
52 size=128M
53
54 echo
55 echo === create: Options specified more than once ===
56
57 # Last -f should win
58 run_qemu_img create -f foo -f $IMGFMT "$TEST_IMG" $size
59 _img_info
60
61 # Multiple -o should be merged
62 run_qemu_img create -f $IMGFMT -o cluster_size=4k -o lazy_refcounts=on "$TEST_IMG" $size
63 _img_info --format-specific
64
65 # If the same -o key is specified more than once, the last one wins
66 run_qemu_img create -f $IMGFMT -o cluster_size=4k -o lazy_refcounts=on -o cluster_size=8k "$TEST_IMG" $size
67 _img_info --format-specific
68 run_qemu_img create -f $IMGFMT -o cluster_size=4k,cluster_size=8k "$TEST_IMG" $size
69 _img_info
70
71 echo
72 echo === create: help for -o ===
73
74 # Adding the help option to a command without other -o options
75 run_qemu_img create -f $IMGFMT -o help "$TEST_IMG" $size
76 run_qemu_img create -f $IMGFMT -o \? "$TEST_IMG" $size
77
78 # Adding the help option to the same -o option
79 run_qemu_img create -f $IMGFMT -o cluster_size=4k,help "$TEST_IMG" $size
80 run_qemu_img create -f $IMGFMT -o cluster_size=4k,\? "$TEST_IMG" $size
81 run_qemu_img create -f $IMGFMT -o help,cluster_size=4k "$TEST_IMG" $size
82 run_qemu_img create -f $IMGFMT -o \?,cluster_size=4k "$TEST_IMG" $size
83
84 # Adding the help option to a separate -o option
85 run_qemu_img create -f $IMGFMT -o cluster_size=4k -o help "$TEST_IMG" $size
86 run_qemu_img create -f $IMGFMT -o cluster_size=4k -o \? "$TEST_IMG" $size
87
88 # Looks like a help option, but is part of the backing file name
89 run_qemu_img create -f $IMGFMT -o backing_file="$TEST_IMG",,help "$TEST_IMG" $size
90 run_qemu_img create -f $IMGFMT -o backing_file="$TEST_IMG",,\? "$TEST_IMG" $size
91
92 # Try to trick qemu-img into creating escaped commas
93 run_qemu_img create -f $IMGFMT -o backing_file="$TEST_IMG", -o help "$TEST_IMG" $size
94 run_qemu_img create -f $IMGFMT -o backing_file="$TEST_IMG" -o ,help "$TEST_IMG" $size
95 run_qemu_img create -f $IMGFMT -o backing_file="$TEST_IMG" -o ,, -o help "$TEST_IMG" $size
96
97 # Leave out everything that isn't needed
98 run_qemu_img create -f $IMGFMT -o help
99 run_qemu_img create -o help
100
101 echo
102 echo === convert: Options specified more than once ===
103
104 # We need a valid source image
105 run_qemu_img create -f $IMGFMT "$TEST_IMG" $size
106
107 # Last -f should win
108 run_qemu_img convert -f foo -f $IMGFMT "$TEST_IMG" "$TEST_IMG".base
109 TEST_IMG="${TEST_IMG}.base" _img_info
110
111 # Last -O should win
112 run_qemu_img convert -O foo -O $IMGFMT "$TEST_IMG" "$TEST_IMG".base
113 TEST_IMG="${TEST_IMG}.base" _img_info
114
115 # Multiple -o should be merged
116 run_qemu_img convert -O $IMGFMT -o cluster_size=4k -o lazy_refcounts=on "$TEST_IMG" "$TEST_IMG".base
117 TEST_IMG="${TEST_IMG}.base" _img_info --format-specific
118
119 # If the same -o key is specified more than once, the last one wins
120 run_qemu_img convert -O $IMGFMT -o cluster_size=4k -o lazy_refcounts=on -o cluster_size=8k "$TEST_IMG" "$TEST_IMG".base
121 TEST_IMG="${TEST_IMG}.base" _img_info --format-specific
122 run_qemu_img convert -O $IMGFMT -o cluster_size=4k,cluster_size=8k "$TEST_IMG" "$TEST_IMG".base
123 TEST_IMG="${TEST_IMG}.base" _img_info
124
125 echo
126 echo === convert: help for -o ===
127
128 # Adding the help option to a command without other -o options
129 run_qemu_img convert -O $IMGFMT -o help "$TEST_IMG" "$TEST_IMG".base
130 run_qemu_img convert -O $IMGFMT -o \? "$TEST_IMG" "$TEST_IMG".base
131
132 # Adding the help option to the same -o option
133 run_qemu_img convert -O $IMGFMT -o cluster_size=4k,help "$TEST_IMG" "$TEST_IMG".base
134 run_qemu_img convert -O $IMGFMT -o cluster_size=4k,\? "$TEST_IMG" "$TEST_IMG".base
135 run_qemu_img convert -O $IMGFMT -o help,cluster_size=4k "$TEST_IMG" "$TEST_IMG".base
136 run_qemu_img convert -O $IMGFMT -o \?,cluster_size=4k "$TEST_IMG" "$TEST_IMG".base
137
138 # Adding the help option to a separate -o option
139 run_qemu_img convert -O $IMGFMT -o cluster_size=4k -o help "$TEST_IMG" "$TEST_IMG".base
140 run_qemu_img convert -O $IMGFMT -o cluster_size=4k -o \? "$TEST_IMG" "$TEST_IMG".base
141
142 # Looks like a help option, but is part of the backing file name
143 run_qemu_img convert -O $IMGFMT -o backing_file="$TEST_IMG",,help "$TEST_IMG" "$TEST_IMG".base
144 run_qemu_img convert -O $IMGFMT -o backing_file="$TEST_IMG",,\? "$TEST_IMG" "$TEST_IMG".base
145
146 # Try to trick qemu-img into creating escaped commas
147 run_qemu_img convert -O $IMGFMT -o backing_file="$TEST_IMG", -o help "$TEST_IMG" "$TEST_IMG".base
148 run_qemu_img convert -O $IMGFMT -o backing_file="$TEST_IMG" -o ,help "$TEST_IMG" "$TEST_IMG".base
149 run_qemu_img convert -O $IMGFMT -o backing_file="$TEST_IMG" -o ,, -o help "$TEST_IMG" "$TEST_IMG".base
150
151 # Leave out everything that isn't needed
152 run_qemu_img convert -O $IMGFMT -o help
153 run_qemu_img convert -o help
154
155 echo
156 echo === amend: Options specified more than once ===
157
158 # Last -f should win
159 run_qemu_img amend -f foo -f $IMGFMT -o lazy_refcounts=on "$TEST_IMG"
160 _img_info --format-specific
161
162 # Multiple -o should be merged
163 run_qemu_img amend -f $IMGFMT -o size=130M -o lazy_refcounts=off "$TEST_IMG"
164 _img_info --format-specific
165
166 # If the same -o key is specified more than once, the last one wins
167 run_qemu_img amend -f $IMGFMT -o size=8M -o lazy_refcounts=on -o size=132M "$TEST_IMG"
168 _img_info --format-specific
169 run_qemu_img amend -f $IMGFMT -o size=4M,size=148M "$TEST_IMG"
170 _img_info
171
172 echo
173 echo === amend: help for -o ===
174
175 # Adding the help option to a command without other -o options
176 run_qemu_img amend -f $IMGFMT -o help "$TEST_IMG"
177 run_qemu_img amend -f $IMGFMT -o \? "$TEST_IMG"
178
179 # Adding the help option to the same -o option
180 run_qemu_img amend -f $IMGFMT -o cluster_size=4k,help "$TEST_IMG"
181 run_qemu_img amend -f $IMGFMT -o cluster_size=4k,\? "$TEST_IMG"
182 run_qemu_img amend -f $IMGFMT -o help,cluster_size=4k "$TEST_IMG"
183 run_qemu_img amend -f $IMGFMT -o \?,cluster_size=4k "$TEST_IMG"
184
185 # Adding the help option to a separate -o option
186 run_qemu_img amend -f $IMGFMT -o cluster_size=4k -o help "$TEST_IMG"
187 run_qemu_img amend -f $IMGFMT -o cluster_size=4k -o \? "$TEST_IMG"
188
189 # Looks like a help option, but is part of the backing file name
190 run_qemu_img amend -f $IMGFMT -o backing_file="$TEST_IMG",,help "$TEST_IMG"
191 run_qemu_img rebase -u -b "" -f $IMGFMT "$TEST_IMG"
192
193 run_qemu_img amend -f $IMGFMT -o backing_file="$TEST_IMG",,\? "$TEST_IMG"
194 run_qemu_img rebase -u -b "" -f $IMGFMT "$TEST_IMG"
195
196 # Try to trick qemu-img into creating escaped commas
197 run_qemu_img amend -f $IMGFMT -o backing_file="$TEST_IMG", -o help "$TEST_IMG"
198 run_qemu_img amend -f $IMGFMT -o backing_file="$TEST_IMG" -o ,help "$TEST_IMG"
199 run_qemu_img amend -f $IMGFMT -o backing_file="$TEST_IMG" -o ,, -o help "$TEST_IMG"
200
201 # Leave out everything that isn't needed
202 run_qemu_img amend -f $IMGFMT -o help
203 run_qemu_img convert -o help
204
205 # success, all done
206 echo "*** done"
207 rm -f $seq.full
208 status=0