]>
Commit | Line | Data |
---|---|---|
11a82d14 | 1 | #!/usr/bin/env bash |
9dd003a9 | 2 | # group: rw quick |
a33cc31d KW |
3 | # |
4 | # Test qemu-img command line parsing | |
5 | # | |
6 | # Copyright (C) 2014 Red Hat, Inc. | |
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 | owner=kwolf@redhat.com | |
24 | ||
25 | seq=`basename $0` | |
26 | echo "QA output created by $seq" | |
27 | ||
a33cc31d KW |
28 | status=1 # failure is the default! |
29 | ||
30 | _cleanup() | |
31 | { | |
32 | _cleanup_test_img | |
33 | } | |
34 | trap "_cleanup; exit \$status" 0 1 2 3 15 | |
35 | ||
36 | # get standard environment, filters and checks | |
37 | . ./common.rc | |
38 | . ./common.filter | |
39 | ||
40 | _supported_fmt qcow2 | |
c5f7c0af | 41 | _supported_proto file nfs |
f03a8c73 | 42 | _require_drivers bochs |
a33cc31d | 43 | |
8cedcffd | 44 | run_qemu_img() |
a33cc31d KW |
45 | { |
46 | echo | |
47 | echo Testing: "$@" | _filter_testdir | |
48 | "$QEMU_IMG" "$@" 2>&1 | _filter_testdir | |
49 | } | |
50 | ||
51 | size=128M | |
52 | ||
53 | echo | |
54 | echo === create: Options specified more than once === | |
55 | ||
56 | # Last -f should win | |
57 | run_qemu_img create -f foo -f $IMGFMT "$TEST_IMG" $size | |
1b53eab2 | 58 | _img_info |
a33cc31d KW |
59 | |
60 | # Multiple -o should be merged | |
61 | run_qemu_img create -f $IMGFMT -o cluster_size=4k -o lazy_refcounts=on "$TEST_IMG" $size | |
d1103231 | 62 | _img_info --format-specific |
a33cc31d KW |
63 | |
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 | |
d1103231 | 66 | _img_info --format-specific |
a33cc31d | 67 | run_qemu_img create -f $IMGFMT -o cluster_size=4k,cluster_size=8k "$TEST_IMG" $size |
1b53eab2 | 68 | _img_info |
a33cc31d KW |
69 | |
70 | echo | |
71 | echo === create: help for -o === | |
72 | ||
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 | |
76 | ||
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 | |
82 | ||
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 | |
86 | ||
87 | # Looks like a help option, but is part of the backing file name | |
b66ff2c2 EB |
88 | run_qemu_img create -f $IMGFMT -u -o backing_file="$TEST_IMG",,help \ |
89 | -F $IMGFMT "$TEST_IMG" $size | |
90 | run_qemu_img create -f $IMGFMT -u -o backing_file="$TEST_IMG",,\? \ | |
91 | -F $IMGFMT "$TEST_IMG" $size | |
a33cc31d KW |
92 | |
93 | # Try to trick qemu-img into creating escaped commas | |
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 ,help "$TEST_IMG" $size | |
96 | run_qemu_img create -f $IMGFMT -o backing_file="$TEST_IMG" -o ,, -o help "$TEST_IMG" $size | |
97 | ||
98 | # Leave out everything that isn't needed | |
99 | run_qemu_img create -f $IMGFMT -o help | |
100 | run_qemu_img create -o help | |
101 | ||
e53995eb HR |
102 | # Try help option for a format that does not support creation |
103 | run_qemu_img create -f bochs -o help | |
104 | ||
a33cc31d KW |
105 | echo |
106 | echo === convert: Options specified more than once === | |
107 | ||
108 | # We need a valid source image | |
109 | run_qemu_img create -f $IMGFMT "$TEST_IMG" $size | |
110 | ||
111 | # Last -f should win | |
112 | run_qemu_img convert -f foo -f $IMGFMT "$TEST_IMG" "$TEST_IMG".base | |
1b53eab2 | 113 | TEST_IMG="${TEST_IMG}.base" _img_info |
a33cc31d KW |
114 | |
115 | # Last -O should win | |
116 | run_qemu_img convert -O foo -O $IMGFMT "$TEST_IMG" "$TEST_IMG".base | |
1b53eab2 | 117 | TEST_IMG="${TEST_IMG}.base" _img_info |
a33cc31d KW |
118 | |
119 | # Multiple -o should be merged | |
120 | run_qemu_img convert -O $IMGFMT -o cluster_size=4k -o lazy_refcounts=on "$TEST_IMG" "$TEST_IMG".base | |
d1103231 | 121 | TEST_IMG="${TEST_IMG}.base" _img_info --format-specific |
a33cc31d KW |
122 | |
123 | # If the same -o key is specified more than once, the last one wins | |
124 | run_qemu_img convert -O $IMGFMT -o cluster_size=4k -o lazy_refcounts=on -o cluster_size=8k "$TEST_IMG" "$TEST_IMG".base | |
d1103231 | 125 | TEST_IMG="${TEST_IMG}.base" _img_info --format-specific |
a33cc31d | 126 | run_qemu_img convert -O $IMGFMT -o cluster_size=4k,cluster_size=8k "$TEST_IMG" "$TEST_IMG".base |
1b53eab2 | 127 | TEST_IMG="${TEST_IMG}.base" _img_info |
a33cc31d KW |
128 | |
129 | echo | |
130 | echo === convert: help for -o === | |
131 | ||
132 | # Adding the help option to a command without other -o options | |
133 | run_qemu_img convert -O $IMGFMT -o help "$TEST_IMG" "$TEST_IMG".base | |
134 | run_qemu_img convert -O $IMGFMT -o \? "$TEST_IMG" "$TEST_IMG".base | |
135 | ||
136 | # Adding the help option to the same -o option | |
137 | run_qemu_img convert -O $IMGFMT -o cluster_size=4k,help "$TEST_IMG" "$TEST_IMG".base | |
138 | run_qemu_img convert -O $IMGFMT -o cluster_size=4k,\? "$TEST_IMG" "$TEST_IMG".base | |
139 | run_qemu_img convert -O $IMGFMT -o help,cluster_size=4k "$TEST_IMG" "$TEST_IMG".base | |
140 | run_qemu_img convert -O $IMGFMT -o \?,cluster_size=4k "$TEST_IMG" "$TEST_IMG".base | |
141 | ||
142 | # Adding the help option to a separate -o option | |
143 | run_qemu_img convert -O $IMGFMT -o cluster_size=4k -o help "$TEST_IMG" "$TEST_IMG".base | |
144 | run_qemu_img convert -O $IMGFMT -o cluster_size=4k -o \? "$TEST_IMG" "$TEST_IMG".base | |
145 | ||
146 | # Looks like a help option, but is part of the backing file name | |
b66ff2c2 EB |
147 | run_qemu_img convert -O $IMGFMT -o backing_fmt=$IMGFMT,backing_file="$TEST_IMG",,help "$TEST_IMG" "$TEST_IMG".base |
148 | run_qemu_img convert -O $IMGFMT -o backing_fmt=$IMGFMT,backing_file="$TEST_IMG",,\? "$TEST_IMG" "$TEST_IMG".base | |
a33cc31d KW |
149 | |
150 | # Try to trick qemu-img into creating escaped commas | |
151 | run_qemu_img convert -O $IMGFMT -o backing_file="$TEST_IMG", -o help "$TEST_IMG" "$TEST_IMG".base | |
152 | run_qemu_img convert -O $IMGFMT -o backing_file="$TEST_IMG" -o ,help "$TEST_IMG" "$TEST_IMG".base | |
153 | run_qemu_img convert -O $IMGFMT -o backing_file="$TEST_IMG" -o ,, -o help "$TEST_IMG" "$TEST_IMG".base | |
154 | ||
155 | # Leave out everything that isn't needed | |
156 | run_qemu_img convert -O $IMGFMT -o help | |
157 | run_qemu_img convert -o help | |
158 | ||
e53995eb HR |
159 | # Try help option for a format that does not support creation |
160 | run_qemu_img convert -O bochs -o help | |
161 | ||
8ba4f10f FZ |
162 | echo |
163 | echo === convert: -C and other options === | |
164 | ||
165 | # Adding the help option to a command without other -o options | |
166 | run_qemu_img convert -C -S 4k -O $IMGFMT "$TEST_IMG" "$TEST_IMG".target | |
167 | run_qemu_img convert -C -S 8k -O $IMGFMT "$TEST_IMG" "$TEST_IMG".target | |
168 | run_qemu_img convert -C -c -O $IMGFMT "$TEST_IMG" "$TEST_IMG".target | |
21c1ce59 | 169 | run_qemu_img convert -C --salvage -O $IMGFMT "$TEST_IMG" "$TEST_IMG".target |
8ba4f10f | 170 | |
a33cc31d KW |
171 | echo |
172 | echo === amend: Options specified more than once === | |
173 | ||
174 | # Last -f should win | |
175 | run_qemu_img amend -f foo -f $IMGFMT -o lazy_refcounts=on "$TEST_IMG" | |
d1103231 | 176 | _img_info --format-specific |
a33cc31d KW |
177 | |
178 | # Multiple -o should be merged | |
179 | run_qemu_img amend -f $IMGFMT -o size=130M -o lazy_refcounts=off "$TEST_IMG" | |
d1103231 | 180 | _img_info --format-specific |
a33cc31d KW |
181 | |
182 | # If the same -o key is specified more than once, the last one wins | |
183 | run_qemu_img amend -f $IMGFMT -o size=8M -o lazy_refcounts=on -o size=132M "$TEST_IMG" | |
d1103231 | 184 | _img_info --format-specific |
a33cc31d | 185 | run_qemu_img amend -f $IMGFMT -o size=4M,size=148M "$TEST_IMG" |
1b53eab2 | 186 | _img_info |
a33cc31d KW |
187 | |
188 | echo | |
189 | echo === amend: help for -o === | |
190 | ||
191 | # Adding the help option to a command without other -o options | |
192 | run_qemu_img amend -f $IMGFMT -o help "$TEST_IMG" | |
193 | run_qemu_img amend -f $IMGFMT -o \? "$TEST_IMG" | |
194 | ||
195 | # Adding the help option to the same -o option | |
196 | run_qemu_img amend -f $IMGFMT -o cluster_size=4k,help "$TEST_IMG" | |
197 | run_qemu_img amend -f $IMGFMT -o cluster_size=4k,\? "$TEST_IMG" | |
198 | run_qemu_img amend -f $IMGFMT -o help,cluster_size=4k "$TEST_IMG" | |
199 | run_qemu_img amend -f $IMGFMT -o \?,cluster_size=4k "$TEST_IMG" | |
200 | ||
201 | # Adding the help option to a separate -o option | |
202 | run_qemu_img amend -f $IMGFMT -o cluster_size=4k -o help "$TEST_IMG" | |
203 | run_qemu_img amend -f $IMGFMT -o cluster_size=4k -o \? "$TEST_IMG" | |
204 | ||
205 | # Looks like a help option, but is part of the backing file name | |
206 | run_qemu_img amend -f $IMGFMT -o backing_file="$TEST_IMG",,help "$TEST_IMG" | |
207 | run_qemu_img rebase -u -b "" -f $IMGFMT "$TEST_IMG" | |
208 | ||
209 | run_qemu_img amend -f $IMGFMT -o backing_file="$TEST_IMG",,\? "$TEST_IMG" | |
210 | run_qemu_img rebase -u -b "" -f $IMGFMT "$TEST_IMG" | |
211 | ||
212 | # Try to trick qemu-img into creating escaped commas | |
213 | run_qemu_img amend -f $IMGFMT -o backing_file="$TEST_IMG", -o help "$TEST_IMG" | |
214 | run_qemu_img amend -f $IMGFMT -o backing_file="$TEST_IMG" -o ,help "$TEST_IMG" | |
215 | run_qemu_img amend -f $IMGFMT -o backing_file="$TEST_IMG" -o ,, -o help "$TEST_IMG" | |
216 | ||
217 | # Leave out everything that isn't needed | |
218 | run_qemu_img amend -f $IMGFMT -o help | |
0ef5a8e6 HR |
219 | |
220 | # amend requires specifying either a format explicitly, or a file | |
221 | # which it can probe | |
222 | run_qemu_img amend -o help | |
a33cc31d | 223 | |
e53995eb HR |
224 | # Try help option for a format that does not support amendment |
225 | run_qemu_img amend -f bochs -o help | |
226 | ||
a33cc31d KW |
227 | # success, all done |
228 | echo "*** done" | |
229 | rm -f $seq.full | |
230 | status=0 |