3 # Test qemu-img command line parsing
5 # Copyright (C) 2014 Red Hat, Inc.
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.
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.
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/>.
22 owner
=kwolf@redhat.com
25 echo "QA output created by $seq"
28 status
=1 # failure is the default!
34 trap "_cleanup; exit \$status" 0 1 2 3 15
36 # get standard environment, filters and checks
41 _supported_proto
file nfs
44 function run_qemu_img
()
47 echo Testing
: "$@" | _filter_testdir
48 "$QEMU_IMG" "$@" 2>&1 | _filter_testdir
54 echo === create
: Options specified
more than once
===
57 run_qemu_img create
-f foo
-f $IMGFMT "$TEST_IMG" $size
60 # Multiple -o should be merged
61 run_qemu_img create
-f $IMGFMT -o cluster_size
=4k
-o lazy_refcounts
=on
"$TEST_IMG" $size
62 _img_info
--format-specific
64 # If the same -o key is specified more than once, the last one wins
65 run_qemu_img create
-f $IMGFMT -o cluster_size
=4k
-o lazy_refcounts
=on
-o cluster_size
=8k
"$TEST_IMG" $size
66 _img_info
--format-specific
67 run_qemu_img create
-f $IMGFMT -o cluster_size
=4k
,cluster_size
=8k
"$TEST_IMG" $size
71 echo === create
: help for -o ===
73 # Adding the help option to a command without other -o options
74 run_qemu_img create
-f $IMGFMT -o help "$TEST_IMG" $size
75 run_qemu_img create
-f $IMGFMT -o \? "$TEST_IMG" $size
77 # Adding the help option to the same -o option
78 run_qemu_img create
-f $IMGFMT -o cluster_size
=4k
,help "$TEST_IMG" $size
79 run_qemu_img create
-f $IMGFMT -o cluster_size
=4k
,\? "$TEST_IMG" $size
80 run_qemu_img create
-f $IMGFMT -o help,cluster_size
=4k
"$TEST_IMG" $size
81 run_qemu_img create
-f $IMGFMT -o \?,cluster_size
=4k
"$TEST_IMG" $size
83 # Adding the help option to a separate -o option
84 run_qemu_img create
-f $IMGFMT -o cluster_size
=4k
-o help "$TEST_IMG" $size
85 run_qemu_img create
-f $IMGFMT -o cluster_size
=4k
-o \? "$TEST_IMG" $size
87 # Looks like a help option, but is part of the backing file name
88 run_qemu_img create
-f $IMGFMT -u -o backing_file
="$TEST_IMG",,help "$TEST_IMG" $size
89 run_qemu_img create
-f $IMGFMT -u -o backing_file
="$TEST_IMG",,\? "$TEST_IMG" $size
91 # Try to trick qemu-img into creating escaped commas
92 run_qemu_img create
-f $IMGFMT -o backing_file
="$TEST_IMG", -o help "$TEST_IMG" $size
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 ,, -o help "$TEST_IMG" $size
96 # Leave out everything that isn't needed
97 run_qemu_img create
-f $IMGFMT -o help
98 run_qemu_img create
-o help
100 # Try help option for a format that does not support creation
101 run_qemu_img create
-f bochs
-o help
104 echo === convert
: Options specified
more than once
===
106 # We need a valid source image
107 run_qemu_img create
-f $IMGFMT "$TEST_IMG" $size
110 run_qemu_img convert
-f foo
-f $IMGFMT "$TEST_IMG" "$TEST_IMG".base
111 TEST_IMG
="${TEST_IMG}.base" _img_info
114 run_qemu_img convert
-O foo
-O $IMGFMT "$TEST_IMG" "$TEST_IMG".base
115 TEST_IMG
="${TEST_IMG}.base" _img_info
117 # Multiple -o should be merged
118 run_qemu_img convert
-O $IMGFMT -o cluster_size
=4k
-o lazy_refcounts
=on
"$TEST_IMG" "$TEST_IMG".base
119 TEST_IMG
="${TEST_IMG}.base" _img_info
--format-specific
121 # If the same -o key is specified more than once, the last one wins
122 run_qemu_img convert
-O $IMGFMT -o cluster_size
=4k
-o lazy_refcounts
=on
-o cluster_size
=8k
"$TEST_IMG" "$TEST_IMG".base
123 TEST_IMG
="${TEST_IMG}.base" _img_info
--format-specific
124 run_qemu_img convert
-O $IMGFMT -o cluster_size
=4k
,cluster_size
=8k
"$TEST_IMG" "$TEST_IMG".base
125 TEST_IMG
="${TEST_IMG}.base" _img_info
128 echo === convert
: help for -o ===
130 # Adding the help option to a command without other -o options
131 run_qemu_img convert
-O $IMGFMT -o help "$TEST_IMG" "$TEST_IMG".base
132 run_qemu_img convert
-O $IMGFMT -o \? "$TEST_IMG" "$TEST_IMG".base
134 # Adding the help option to the same -o option
135 run_qemu_img convert
-O $IMGFMT -o cluster_size
=4k
,help "$TEST_IMG" "$TEST_IMG".base
136 run_qemu_img convert
-O $IMGFMT -o cluster_size
=4k
,\? "$TEST_IMG" "$TEST_IMG".base
137 run_qemu_img convert
-O $IMGFMT -o help,cluster_size
=4k
"$TEST_IMG" "$TEST_IMG".base
138 run_qemu_img convert
-O $IMGFMT -o \?,cluster_size
=4k
"$TEST_IMG" "$TEST_IMG".base
140 # Adding the help option to a separate -o option
141 run_qemu_img convert
-O $IMGFMT -o cluster_size
=4k
-o help "$TEST_IMG" "$TEST_IMG".base
142 run_qemu_img convert
-O $IMGFMT -o cluster_size
=4k
-o \? "$TEST_IMG" "$TEST_IMG".base
144 # Looks like a help option, but is part of the backing file name
145 run_qemu_img convert
-O $IMGFMT -o backing_file
="$TEST_IMG",,help "$TEST_IMG" "$TEST_IMG".base
146 run_qemu_img convert
-O $IMGFMT -o backing_file
="$TEST_IMG",,\? "$TEST_IMG" "$TEST_IMG".base
148 # Try to trick qemu-img into creating escaped commas
149 run_qemu_img convert
-O $IMGFMT -o backing_file
="$TEST_IMG", -o help "$TEST_IMG" "$TEST_IMG".base
150 run_qemu_img convert
-O $IMGFMT -o backing_file
="$TEST_IMG" -o ,help "$TEST_IMG" "$TEST_IMG".base
151 run_qemu_img convert
-O $IMGFMT -o backing_file
="$TEST_IMG" -o ,, -o help "$TEST_IMG" "$TEST_IMG".base
153 # Leave out everything that isn't needed
154 run_qemu_img convert
-O $IMGFMT -o help
155 run_qemu_img convert
-o help
157 # Try help option for a format that does not support creation
158 run_qemu_img convert
-O bochs
-o help
161 echo === convert
: -C and other options
===
163 # Adding the help option to a command without other -o options
164 run_qemu_img convert
-C -S 4k
-O $IMGFMT "$TEST_IMG" "$TEST_IMG".target
165 run_qemu_img convert
-C -S 8k
-O $IMGFMT "$TEST_IMG" "$TEST_IMG".target
166 run_qemu_img convert
-C -c -O $IMGFMT "$TEST_IMG" "$TEST_IMG".target
169 echo === amend
: Options specified
more than once
===
172 run_qemu_img amend
-f foo
-f $IMGFMT -o lazy_refcounts
=on
"$TEST_IMG"
173 _img_info
--format-specific
175 # Multiple -o should be merged
176 run_qemu_img amend
-f $IMGFMT -o size
=130M
-o lazy_refcounts
=off
"$TEST_IMG"
177 _img_info
--format-specific
179 # If the same -o key is specified more than once, the last one wins
180 run_qemu_img amend
-f $IMGFMT -o size
=8M
-o lazy_refcounts
=on
-o size
=132M
"$TEST_IMG"
181 _img_info
--format-specific
182 run_qemu_img amend
-f $IMGFMT -o size
=4M
,size
=148M
"$TEST_IMG"
186 echo === amend
: help for -o ===
188 # Adding the help option to a command without other -o options
189 run_qemu_img amend
-f $IMGFMT -o help "$TEST_IMG"
190 run_qemu_img amend
-f $IMGFMT -o \? "$TEST_IMG"
192 # Adding the help option to the same -o option
193 run_qemu_img amend
-f $IMGFMT -o cluster_size
=4k
,help "$TEST_IMG"
194 run_qemu_img amend
-f $IMGFMT -o cluster_size
=4k
,\? "$TEST_IMG"
195 run_qemu_img amend
-f $IMGFMT -o help,cluster_size
=4k
"$TEST_IMG"
196 run_qemu_img amend
-f $IMGFMT -o \?,cluster_size
=4k
"$TEST_IMG"
198 # Adding the help option to a separate -o option
199 run_qemu_img amend
-f $IMGFMT -o cluster_size
=4k
-o help "$TEST_IMG"
200 run_qemu_img amend
-f $IMGFMT -o cluster_size
=4k
-o \? "$TEST_IMG"
202 # Looks like a help option, but is part of the backing file name
203 run_qemu_img amend
-f $IMGFMT -o backing_file
="$TEST_IMG",,help "$TEST_IMG"
204 run_qemu_img rebase
-u -b "" -f $IMGFMT "$TEST_IMG"
206 run_qemu_img amend
-f $IMGFMT -o backing_file
="$TEST_IMG",,\? "$TEST_IMG"
207 run_qemu_img rebase
-u -b "" -f $IMGFMT "$TEST_IMG"
209 # Try to trick qemu-img into creating escaped commas
210 run_qemu_img amend
-f $IMGFMT -o backing_file
="$TEST_IMG", -o help "$TEST_IMG"
211 run_qemu_img amend
-f $IMGFMT -o backing_file
="$TEST_IMG" -o ,help "$TEST_IMG"
212 run_qemu_img amend
-f $IMGFMT -o backing_file
="$TEST_IMG" -o ,, -o help "$TEST_IMG"
214 # Leave out everything that isn't needed
215 run_qemu_img amend
-f $IMGFMT -o help
216 run_qemu_img convert
-o help
218 # Try help option for a format that does not support amendment
219 run_qemu_img amend
-f bochs
-o help