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"
27 status
=1 # failure is the default!
33 trap "_cleanup; exit \$status" 0 1 2 3 15
35 # get standard environment, filters and checks
40 _supported_proto
file nfs
45 echo Testing
: "$@" | _filter_testdir
46 "$QEMU_IMG" "$@" 2>&1 | _filter_testdir
52 echo === create
: Options specified
more than once
===
55 run_qemu_img create
-f foo
-f $IMGFMT "$TEST_IMG" $size
58 # Multiple -o should be merged
59 run_qemu_img create
-f $IMGFMT -o cluster_size
=4k
-o lazy_refcounts
=on
"$TEST_IMG" $size
60 _img_info
--format-specific
62 # If the same -o key is specified more than once, the last one wins
63 run_qemu_img create
-f $IMGFMT -o cluster_size
=4k
-o lazy_refcounts
=on
-o cluster_size
=8k
"$TEST_IMG" $size
64 _img_info
--format-specific
65 run_qemu_img create
-f $IMGFMT -o cluster_size
=4k
,cluster_size
=8k
"$TEST_IMG" $size
69 echo === create
: help for -o ===
71 # Adding the help option to a command without other -o options
72 run_qemu_img create
-f $IMGFMT -o help "$TEST_IMG" $size
73 run_qemu_img create
-f $IMGFMT -o \? "$TEST_IMG" $size
75 # Adding the help option to the same -o option
76 run_qemu_img create
-f $IMGFMT -o cluster_size
=4k
,help "$TEST_IMG" $size
77 run_qemu_img create
-f $IMGFMT -o cluster_size
=4k
,\? "$TEST_IMG" $size
78 run_qemu_img create
-f $IMGFMT -o help,cluster_size
=4k
"$TEST_IMG" $size
79 run_qemu_img create
-f $IMGFMT -o \?,cluster_size
=4k
"$TEST_IMG" $size
81 # Adding the help option to a separate -o option
82 run_qemu_img create
-f $IMGFMT -o cluster_size
=4k
-o help "$TEST_IMG" $size
83 run_qemu_img create
-f $IMGFMT -o cluster_size
=4k
-o \? "$TEST_IMG" $size
85 # Looks like a help option, but is part of the backing file name
86 run_qemu_img create
-f $IMGFMT -u -o backing_file
="$TEST_IMG",,help "$TEST_IMG" $size
87 run_qemu_img create
-f $IMGFMT -u -o backing_file
="$TEST_IMG",,\? "$TEST_IMG" $size
89 # Try to trick qemu-img into creating escaped commas
90 run_qemu_img create
-f $IMGFMT -o backing_file
="$TEST_IMG", -o help "$TEST_IMG" $size
91 run_qemu_img create
-f $IMGFMT -o backing_file
="$TEST_IMG" -o ,help "$TEST_IMG" $size
92 run_qemu_img create
-f $IMGFMT -o backing_file
="$TEST_IMG" -o ,, -o help "$TEST_IMG" $size
94 # Leave out everything that isn't needed
95 run_qemu_img create
-f $IMGFMT -o help
96 run_qemu_img create
-o help
98 # Try help option for a format that does not support creation
99 run_qemu_img create
-f bochs
-o help
102 echo === convert
: Options specified
more than once
===
104 # We need a valid source image
105 run_qemu_img create
-f $IMGFMT "$TEST_IMG" $size
108 run_qemu_img convert
-f foo
-f $IMGFMT "$TEST_IMG" "$TEST_IMG".base
109 TEST_IMG
="${TEST_IMG}.base" _img_info
112 run_qemu_img convert
-O foo
-O $IMGFMT "$TEST_IMG" "$TEST_IMG".base
113 TEST_IMG
="${TEST_IMG}.base" _img_info
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
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
126 echo === convert
: help for -o ===
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
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
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
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
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
151 # Leave out everything that isn't needed
152 run_qemu_img convert
-O $IMGFMT -o help
153 run_qemu_img convert
-o help
155 # Try help option for a format that does not support creation
156 run_qemu_img convert
-O bochs
-o help
159 echo === convert
: -C and other options
===
161 # Adding the help option to a command without other -o options
162 run_qemu_img convert
-C -S 4k
-O $IMGFMT "$TEST_IMG" "$TEST_IMG".target
163 run_qemu_img convert
-C -S 8k
-O $IMGFMT "$TEST_IMG" "$TEST_IMG".target
164 run_qemu_img convert
-C -c -O $IMGFMT "$TEST_IMG" "$TEST_IMG".target
165 run_qemu_img convert
-C --salvage -O $IMGFMT "$TEST_IMG" "$TEST_IMG".target
168 echo === amend
: Options specified
more than once
===
171 run_qemu_img amend
-f foo
-f $IMGFMT -o lazy_refcounts
=on
"$TEST_IMG"
172 _img_info
--format-specific
174 # Multiple -o should be merged
175 run_qemu_img amend
-f $IMGFMT -o size
=130M
-o lazy_refcounts
=off
"$TEST_IMG"
176 _img_info
--format-specific
178 # If the same -o key is specified more than once, the last one wins
179 run_qemu_img amend
-f $IMGFMT -o size
=8M
-o lazy_refcounts
=on
-o size
=132M
"$TEST_IMG"
180 _img_info
--format-specific
181 run_qemu_img amend
-f $IMGFMT -o size
=4M
,size
=148M
"$TEST_IMG"
185 echo === amend
: help for -o ===
187 # Adding the help option to a command without other -o options
188 run_qemu_img amend
-f $IMGFMT -o help "$TEST_IMG"
189 run_qemu_img amend
-f $IMGFMT -o \? "$TEST_IMG"
191 # Adding the help option to the same -o option
192 run_qemu_img amend
-f $IMGFMT -o cluster_size
=4k
,help "$TEST_IMG"
193 run_qemu_img amend
-f $IMGFMT -o cluster_size
=4k
,\? "$TEST_IMG"
194 run_qemu_img amend
-f $IMGFMT -o help,cluster_size
=4k
"$TEST_IMG"
195 run_qemu_img amend
-f $IMGFMT -o \?,cluster_size
=4k
"$TEST_IMG"
197 # Adding the help option to a separate -o option
198 run_qemu_img amend
-f $IMGFMT -o cluster_size
=4k
-o help "$TEST_IMG"
199 run_qemu_img amend
-f $IMGFMT -o cluster_size
=4k
-o \? "$TEST_IMG"
201 # Looks like a help option, but is part of the backing file name
202 run_qemu_img amend
-f $IMGFMT -o backing_file
="$TEST_IMG",,help "$TEST_IMG"
203 run_qemu_img rebase
-u -b "" -f $IMGFMT "$TEST_IMG"
205 run_qemu_img amend
-f $IMGFMT -o backing_file
="$TEST_IMG",,\? "$TEST_IMG"
206 run_qemu_img rebase
-u -b "" -f $IMGFMT "$TEST_IMG"
208 # Try to trick qemu-img into creating escaped commas
209 run_qemu_img amend
-f $IMGFMT -o backing_file
="$TEST_IMG", -o help "$TEST_IMG"
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 ,, -o help "$TEST_IMG"
213 # Leave out everything that isn't needed
214 run_qemu_img amend
-f $IMGFMT -o help
216 # amend requires specifying either a format explicitly, or a file
218 run_qemu_img amend
-o help
220 # Try help option for a format that does not support amendment
221 run_qemu_img amend
-f bochs
-o help