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