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