xref: /qemu/tests/qemu-iotests/082 (revision 308e7549)
1#!/usr/bin/env 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
22owner=kwolf@redhat.com
23
24seq=`basename $0`
25echo "QA output created by $seq"
26
27status=1	# failure is the default!
28
29_cleanup()
30{
31	_cleanup_test_img
32}
33trap "_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
40_supported_proto file nfs
41_require_drivers bochs
42
43run_qemu_img()
44{
45    echo
46    echo Testing: "$@" | _filter_testdir
47    "$QEMU_IMG" "$@" 2>&1 | _filter_testdir
48}
49
50size=128M
51
52echo
53echo === create: Options specified more than once ===
54
55# Last -f should win
56run_qemu_img create -f foo -f $IMGFMT "$TEST_IMG" $size
57_img_info
58
59# Multiple -o should be merged
60run_qemu_img create -f $IMGFMT -o cluster_size=4k -o lazy_refcounts=on "$TEST_IMG" $size
61_img_info --format-specific
62
63# If the same -o key is specified more than once, the last one wins
64run_qemu_img create -f $IMGFMT -o cluster_size=4k -o lazy_refcounts=on -o cluster_size=8k "$TEST_IMG" $size
65_img_info --format-specific
66run_qemu_img create -f $IMGFMT -o cluster_size=4k,cluster_size=8k "$TEST_IMG" $size
67_img_info
68
69echo
70echo === create: help for -o ===
71
72# Adding the help option to a command without other -o options
73run_qemu_img create -f $IMGFMT -o help "$TEST_IMG" $size
74run_qemu_img create -f $IMGFMT -o \? "$TEST_IMG" $size
75
76# Adding the help option to the same -o option
77run_qemu_img create -f $IMGFMT -o cluster_size=4k,help "$TEST_IMG" $size
78run_qemu_img create -f $IMGFMT -o cluster_size=4k,\? "$TEST_IMG" $size
79run_qemu_img create -f $IMGFMT -o help,cluster_size=4k "$TEST_IMG" $size
80run_qemu_img create -f $IMGFMT -o \?,cluster_size=4k "$TEST_IMG" $size
81
82# Adding the help option to a separate -o option
83run_qemu_img create -f $IMGFMT -o cluster_size=4k -o help "$TEST_IMG" $size
84run_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
87run_qemu_img create -f $IMGFMT -u -o backing_file="$TEST_IMG",,help "$TEST_IMG" $size
88run_qemu_img create -f $IMGFMT -u -o backing_file="$TEST_IMG",,\? "$TEST_IMG" $size
89
90# Try to trick qemu-img into creating escaped commas
91run_qemu_img create -f $IMGFMT -o backing_file="$TEST_IMG", -o help "$TEST_IMG" $size
92run_qemu_img create -f $IMGFMT -o backing_file="$TEST_IMG" -o ,help "$TEST_IMG" $size
93run_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
96run_qemu_img create -f $IMGFMT -o help
97run_qemu_img create -o help
98
99# Try help option for a format that does not support creation
100run_qemu_img create -f bochs -o help
101
102echo
103echo === convert: Options specified more than once ===
104
105# We need a valid source image
106run_qemu_img create -f $IMGFMT "$TEST_IMG" $size
107
108# Last -f should win
109run_qemu_img convert -f foo -f $IMGFMT "$TEST_IMG" "$TEST_IMG".base
110TEST_IMG="${TEST_IMG}.base" _img_info
111
112# Last -O should win
113run_qemu_img convert -O foo -O $IMGFMT "$TEST_IMG" "$TEST_IMG".base
114TEST_IMG="${TEST_IMG}.base" _img_info
115
116# Multiple -o should be merged
117run_qemu_img convert -O $IMGFMT -o cluster_size=4k -o lazy_refcounts=on "$TEST_IMG" "$TEST_IMG".base
118TEST_IMG="${TEST_IMG}.base" _img_info --format-specific
119
120# If the same -o key is specified more than once, the last one wins
121run_qemu_img convert -O $IMGFMT -o cluster_size=4k -o lazy_refcounts=on -o cluster_size=8k "$TEST_IMG" "$TEST_IMG".base
122TEST_IMG="${TEST_IMG}.base" _img_info --format-specific
123run_qemu_img convert -O $IMGFMT -o cluster_size=4k,cluster_size=8k "$TEST_IMG" "$TEST_IMG".base
124TEST_IMG="${TEST_IMG}.base" _img_info
125
126echo
127echo === convert: help for -o ===
128
129# Adding the help option to a command without other -o options
130run_qemu_img convert -O $IMGFMT -o help "$TEST_IMG" "$TEST_IMG".base
131run_qemu_img convert -O $IMGFMT -o \? "$TEST_IMG" "$TEST_IMG".base
132
133# Adding the help option to the same -o option
134run_qemu_img convert -O $IMGFMT -o cluster_size=4k,help "$TEST_IMG" "$TEST_IMG".base
135run_qemu_img convert -O $IMGFMT -o cluster_size=4k,\? "$TEST_IMG" "$TEST_IMG".base
136run_qemu_img convert -O $IMGFMT -o help,cluster_size=4k "$TEST_IMG" "$TEST_IMG".base
137run_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
140run_qemu_img convert -O $IMGFMT -o cluster_size=4k -o help "$TEST_IMG" "$TEST_IMG".base
141run_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
144run_qemu_img convert -O $IMGFMT -o backing_file="$TEST_IMG",,help "$TEST_IMG" "$TEST_IMG".base
145run_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
148run_qemu_img convert -O $IMGFMT -o backing_file="$TEST_IMG", -o help "$TEST_IMG" "$TEST_IMG".base
149run_qemu_img convert -O $IMGFMT -o backing_file="$TEST_IMG" -o ,help "$TEST_IMG" "$TEST_IMG".base
150run_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
153run_qemu_img convert -O $IMGFMT -o help
154run_qemu_img convert -o help
155
156# Try help option for a format that does not support creation
157run_qemu_img convert -O bochs -o help
158
159echo
160echo === convert: -C and other options ===
161
162# Adding the help option to a command without other -o options
163run_qemu_img convert -C -S 4k -O $IMGFMT "$TEST_IMG" "$TEST_IMG".target
164run_qemu_img convert -C -S 8k -O $IMGFMT "$TEST_IMG" "$TEST_IMG".target
165run_qemu_img convert -C -c -O $IMGFMT "$TEST_IMG" "$TEST_IMG".target
166run_qemu_img convert -C --salvage -O $IMGFMT "$TEST_IMG" "$TEST_IMG".target
167
168echo
169echo === amend: Options specified more than once ===
170
171# Last -f should win
172run_qemu_img amend -f foo -f $IMGFMT -o lazy_refcounts=on "$TEST_IMG"
173_img_info --format-specific
174
175# Multiple -o should be merged
176run_qemu_img amend -f $IMGFMT -o size=130M -o lazy_refcounts=off "$TEST_IMG"
177_img_info --format-specific
178
179# If the same -o key is specified more than once, the last one wins
180run_qemu_img amend -f $IMGFMT -o size=8M -o lazy_refcounts=on -o size=132M "$TEST_IMG"
181_img_info --format-specific
182run_qemu_img amend -f $IMGFMT -o size=4M,size=148M "$TEST_IMG"
183_img_info
184
185echo
186echo === amend: help for -o ===
187
188# Adding the help option to a command without other -o options
189run_qemu_img amend -f $IMGFMT -o help "$TEST_IMG"
190run_qemu_img amend -f $IMGFMT -o \? "$TEST_IMG"
191
192# Adding the help option to the same -o option
193run_qemu_img amend -f $IMGFMT -o cluster_size=4k,help "$TEST_IMG"
194run_qemu_img amend -f $IMGFMT -o cluster_size=4k,\? "$TEST_IMG"
195run_qemu_img amend -f $IMGFMT -o help,cluster_size=4k "$TEST_IMG"
196run_qemu_img amend -f $IMGFMT -o \?,cluster_size=4k "$TEST_IMG"
197
198# Adding the help option to a separate -o option
199run_qemu_img amend -f $IMGFMT -o cluster_size=4k -o help "$TEST_IMG"
200run_qemu_img amend -f $IMGFMT -o cluster_size=4k -o \? "$TEST_IMG"
201
202# Looks like a help option, but is part of the backing file name
203run_qemu_img amend -f $IMGFMT -o backing_file="$TEST_IMG",,help "$TEST_IMG"
204run_qemu_img rebase -u -b "" -f $IMGFMT "$TEST_IMG"
205
206run_qemu_img amend -f $IMGFMT -o backing_file="$TEST_IMG",,\? "$TEST_IMG"
207run_qemu_img rebase -u -b "" -f $IMGFMT "$TEST_IMG"
208
209# Try to trick qemu-img into creating escaped commas
210run_qemu_img amend -f $IMGFMT -o backing_file="$TEST_IMG", -o help "$TEST_IMG"
211run_qemu_img amend -f $IMGFMT -o backing_file="$TEST_IMG" -o ,help "$TEST_IMG"
212run_qemu_img amend -f $IMGFMT -o backing_file="$TEST_IMG" -o ,, -o help "$TEST_IMG"
213
214# Leave out everything that isn't needed
215run_qemu_img amend -f $IMGFMT -o help
216
217# amend requires specifying either a format explicitly, or a file
218# which it can probe
219run_qemu_img amend -o help
220
221# Try help option for a format that does not support amendment
222run_qemu_img amend -f bochs -o help
223
224# success, all done
225echo "*** done"
226rm -f $seq.full
227status=0
228