]>
Commit | Line | Data |
---|---|---|
11a82d14 | 1 | #!/usr/bin/env bash |
a33cc31d KW |
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 | ||
a33cc31d KW |
27 | status=1 # failure is the default! |
28 | ||
29 | _cleanup() | |
30 | { | |
31 | _cleanup_test_img | |
32 | } | |
33 | trap "_cleanup; exit \$status" 0 1 2 3 15 | |
34 | ||
35 | # get standard environment, filters and checks | |
36 | . ./common.rc | |
37 | . ./common.filter | |
38 | ||
39 | _supported_fmt qcow2 | |
c5f7c0af | 40 | _supported_proto file nfs |
a33cc31d KW |
41 | _supported_os Linux |
42 | ||
8cedcffd | 43 | run_qemu_img() |
a33cc31d KW |
44 | { |
45 | echo | |
46 | echo Testing: "$@" | _filter_testdir | |
47 | "$QEMU_IMG" "$@" 2>&1 | _filter_testdir | |
48 | } | |
49 | ||
50 | size=128M | |
51 | ||
52 | echo | |
53 | echo === create: Options specified more than once === | |
54 | ||
55 | # Last -f should win | |
56 | run_qemu_img create -f foo -f $IMGFMT "$TEST_IMG" $size | |
1b53eab2 | 57 | _img_info |
a33cc31d KW |
58 | |
59 | # Multiple -o should be merged | |
60 | run_qemu_img create -f $IMGFMT -o cluster_size=4k -o lazy_refcounts=on "$TEST_IMG" $size | |
d1103231 | 61 | _img_info --format-specific |
a33cc31d KW |
62 | |
63 | # If the same -o key is specified more than once, the last one wins | |
64 | run_qemu_img create -f $IMGFMT -o cluster_size=4k -o lazy_refcounts=on -o cluster_size=8k "$TEST_IMG" $size | |
d1103231 | 65 | _img_info --format-specific |
a33cc31d | 66 | run_qemu_img create -f $IMGFMT -o cluster_size=4k,cluster_size=8k "$TEST_IMG" $size |
1b53eab2 | 67 | _img_info |
a33cc31d KW |
68 | |
69 | echo | |
70 | echo === create: help for -o === | |
71 | ||
72 | # Adding the help option to a command without other -o options | |
73 | run_qemu_img create -f $IMGFMT -o help "$TEST_IMG" $size | |
74 | run_qemu_img create -f $IMGFMT -o \? "$TEST_IMG" $size | |
75 | ||
76 | # Adding the help option to the same -o option | |
77 | run_qemu_img create -f $IMGFMT -o cluster_size=4k,help "$TEST_IMG" $size | |
78 | run_qemu_img create -f $IMGFMT -o cluster_size=4k,\? "$TEST_IMG" $size | |
79 | run_qemu_img create -f $IMGFMT -o help,cluster_size=4k "$TEST_IMG" $size | |
80 | run_qemu_img create -f $IMGFMT -o \?,cluster_size=4k "$TEST_IMG" $size | |
81 | ||
82 | # Adding the help option to a separate -o option | |
83 | run_qemu_img create -f $IMGFMT -o cluster_size=4k -o help "$TEST_IMG" $size | |
84 | run_qemu_img create -f $IMGFMT -o cluster_size=4k -o \? "$TEST_IMG" $size | |
85 | ||
86 | # Looks like a help option, but is part of the backing file name | |
6e6e55f5 JS |
87 | run_qemu_img create -f $IMGFMT -u -o backing_file="$TEST_IMG",,help "$TEST_IMG" $size |
88 | run_qemu_img create -f $IMGFMT -u -o backing_file="$TEST_IMG",,\? "$TEST_IMG" $size | |
a33cc31d KW |
89 | |
90 | # Try to trick qemu-img into creating escaped commas | |
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 ,help "$TEST_IMG" $size | |
93 | run_qemu_img create -f $IMGFMT -o backing_file="$TEST_IMG" -o ,, -o help "$TEST_IMG" $size | |
94 | ||
95 | # Leave out everything that isn't needed | |
96 | run_qemu_img create -f $IMGFMT -o help | |
97 | run_qemu_img create -o help | |
98 | ||
e53995eb HR |
99 | # Try help option for a format that does not support creation |
100 | run_qemu_img create -f bochs -o help | |
101 | ||
a33cc31d KW |
102 | echo |
103 | echo === convert: Options specified more than once === | |
104 | ||
105 | # We need a valid source image | |
106 | run_qemu_img create -f $IMGFMT "$TEST_IMG" $size | |
107 | ||
108 | # Last -f should win | |
109 | run_qemu_img convert -f foo -f $IMGFMT "$TEST_IMG" "$TEST_IMG".base | |
1b53eab2 | 110 | TEST_IMG="${TEST_IMG}.base" _img_info |
a33cc31d KW |
111 | |
112 | # Last -O should win | |
113 | run_qemu_img convert -O foo -O $IMGFMT "$TEST_IMG" "$TEST_IMG".base | |
1b53eab2 | 114 | TEST_IMG="${TEST_IMG}.base" _img_info |
a33cc31d KW |
115 | |
116 | # Multiple -o should be merged | |
117 | run_qemu_img convert -O $IMGFMT -o cluster_size=4k -o lazy_refcounts=on "$TEST_IMG" "$TEST_IMG".base | |
d1103231 | 118 | TEST_IMG="${TEST_IMG}.base" _img_info --format-specific |
a33cc31d KW |
119 | |
120 | # If the same -o key is specified more than once, the last one wins | |
121 | run_qemu_img convert -O $IMGFMT -o cluster_size=4k -o lazy_refcounts=on -o cluster_size=8k "$TEST_IMG" "$TEST_IMG".base | |
d1103231 | 122 | TEST_IMG="${TEST_IMG}.base" _img_info --format-specific |
a33cc31d | 123 | run_qemu_img convert -O $IMGFMT -o cluster_size=4k,cluster_size=8k "$TEST_IMG" "$TEST_IMG".base |
1b53eab2 | 124 | TEST_IMG="${TEST_IMG}.base" _img_info |
a33cc31d KW |
125 | |
126 | echo | |
127 | echo === convert: help for -o === | |
128 | ||
129 | # Adding the help option to a command without other -o options | |
130 | run_qemu_img convert -O $IMGFMT -o help "$TEST_IMG" "$TEST_IMG".base | |
131 | run_qemu_img convert -O $IMGFMT -o \? "$TEST_IMG" "$TEST_IMG".base | |
132 | ||
133 | # Adding the help option to the same -o option | |
134 | run_qemu_img convert -O $IMGFMT -o cluster_size=4k,help "$TEST_IMG" "$TEST_IMG".base | |
135 | run_qemu_img convert -O $IMGFMT -o cluster_size=4k,\? "$TEST_IMG" "$TEST_IMG".base | |
136 | run_qemu_img convert -O $IMGFMT -o help,cluster_size=4k "$TEST_IMG" "$TEST_IMG".base | |
137 | run_qemu_img convert -O $IMGFMT -o \?,cluster_size=4k "$TEST_IMG" "$TEST_IMG".base | |
138 | ||
139 | # Adding the help option to a separate -o option | |
140 | run_qemu_img convert -O $IMGFMT -o cluster_size=4k -o help "$TEST_IMG" "$TEST_IMG".base | |
141 | run_qemu_img convert -O $IMGFMT -o cluster_size=4k -o \? "$TEST_IMG" "$TEST_IMG".base | |
142 | ||
143 | # Looks like a help option, but is part of the backing file name | |
144 | run_qemu_img convert -O $IMGFMT -o backing_file="$TEST_IMG",,help "$TEST_IMG" "$TEST_IMG".base | |
145 | run_qemu_img convert -O $IMGFMT -o backing_file="$TEST_IMG",,\? "$TEST_IMG" "$TEST_IMG".base | |
146 | ||
147 | # Try to trick qemu-img into creating escaped commas | |
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 ,help "$TEST_IMG" "$TEST_IMG".base | |
150 | run_qemu_img convert -O $IMGFMT -o backing_file="$TEST_IMG" -o ,, -o help "$TEST_IMG" "$TEST_IMG".base | |
151 | ||
152 | # Leave out everything that isn't needed | |
153 | run_qemu_img convert -O $IMGFMT -o help | |
154 | run_qemu_img convert -o help | |
155 | ||
e53995eb HR |
156 | # Try help option for a format that does not support creation |
157 | run_qemu_img convert -O bochs -o help | |
158 | ||
8ba4f10f FZ |
159 | echo |
160 | echo === convert: -C and other options === | |
161 | ||
162 | # Adding the help option to a command without other -o options | |
163 | run_qemu_img convert -C -S 4k -O $IMGFMT "$TEST_IMG" "$TEST_IMG".target | |
164 | run_qemu_img convert -C -S 8k -O $IMGFMT "$TEST_IMG" "$TEST_IMG".target | |
165 | run_qemu_img convert -C -c -O $IMGFMT "$TEST_IMG" "$TEST_IMG".target | |
166 | ||
a33cc31d KW |
167 | echo |
168 | echo === amend: Options specified more than once === | |
169 | ||
170 | # Last -f should win | |
171 | run_qemu_img amend -f foo -f $IMGFMT -o lazy_refcounts=on "$TEST_IMG" | |
d1103231 | 172 | _img_info --format-specific |
a33cc31d KW |
173 | |
174 | # Multiple -o should be merged | |
175 | run_qemu_img amend -f $IMGFMT -o size=130M -o lazy_refcounts=off "$TEST_IMG" | |
d1103231 | 176 | _img_info --format-specific |
a33cc31d KW |
177 | |
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" | |
d1103231 | 180 | _img_info --format-specific |
a33cc31d | 181 | run_qemu_img amend -f $IMGFMT -o size=4M,size=148M "$TEST_IMG" |
1b53eab2 | 182 | _img_info |
a33cc31d KW |
183 | |
184 | echo | |
185 | echo === amend: help for -o === | |
186 | ||
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" | |
190 | ||
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" | |
196 | ||
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" | |
200 | ||
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" | |
204 | ||
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" | |
207 | ||
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" | |
212 | ||
213 | # Leave out everything that isn't needed | |
214 | run_qemu_img amend -f $IMGFMT -o help | |
215 | run_qemu_img convert -o help | |
216 | ||
e53995eb HR |
217 | # Try help option for a format that does not support amendment |
218 | run_qemu_img amend -f bochs -o help | |
219 | ||
a33cc31d KW |
220 | # success, all done |
221 | echo "*** done" | |
222 | rm -f $seq.full | |
223 | status=0 |