xref: /openbmc/qemu/tests/qemu-iotests/082 (revision c5f7c0af473cadb8b0b5fc6d399e4ede1fc9408d)
1a33cc31dSKevin Wolf#!/bin/bash
2a33cc31dSKevin Wolf#
3a33cc31dSKevin Wolf# Test qemu-img command line parsing
4a33cc31dSKevin Wolf#
5a33cc31dSKevin Wolf# Copyright (C) 2014 Red Hat, Inc.
6a33cc31dSKevin Wolf#
7a33cc31dSKevin Wolf# This program is free software; you can redistribute it and/or modify
8a33cc31dSKevin Wolf# it under the terms of the GNU General Public License as published by
9a33cc31dSKevin Wolf# the Free Software Foundation; either version 2 of the License, or
10a33cc31dSKevin Wolf# (at your option) any later version.
11a33cc31dSKevin Wolf#
12a33cc31dSKevin Wolf# This program is distributed in the hope that it will be useful,
13a33cc31dSKevin Wolf# but WITHOUT ANY WARRANTY; without even the implied warranty of
14a33cc31dSKevin Wolf# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15a33cc31dSKevin Wolf# GNU General Public License for more details.
16a33cc31dSKevin Wolf#
17a33cc31dSKevin Wolf# You should have received a copy of the GNU General Public License
18a33cc31dSKevin Wolf# along with this program.  If not, see <http://www.gnu.org/licenses/>.
19a33cc31dSKevin Wolf#
20a33cc31dSKevin Wolf
21a33cc31dSKevin Wolf# creator
22a33cc31dSKevin Wolfowner=kwolf@redhat.com
23a33cc31dSKevin Wolf
24a33cc31dSKevin Wolfseq=`basename $0`
25a33cc31dSKevin Wolfecho "QA output created by $seq"
26a33cc31dSKevin Wolf
27a33cc31dSKevin Wolfhere=`pwd`
28a33cc31dSKevin Wolftmp=/tmp/$$
29a33cc31dSKevin Wolfstatus=1	# failure is the default!
30a33cc31dSKevin Wolf
31a33cc31dSKevin Wolf_cleanup()
32a33cc31dSKevin Wolf{
33a33cc31dSKevin Wolf	_cleanup_test_img
34a33cc31dSKevin Wolf}
35a33cc31dSKevin Wolftrap "_cleanup; exit \$status" 0 1 2 3 15
36a33cc31dSKevin Wolf
37a33cc31dSKevin Wolf# get standard environment, filters and checks
38a33cc31dSKevin Wolf. ./common.rc
39a33cc31dSKevin Wolf. ./common.filter
40a33cc31dSKevin Wolf
41a33cc31dSKevin Wolf_supported_fmt qcow2
42*c5f7c0afSPeter Lieven_supported_proto file nfs
43a33cc31dSKevin Wolf_supported_os Linux
44a33cc31dSKevin Wolf
45a33cc31dSKevin Wolffunction run_qemu_img()
46a33cc31dSKevin Wolf{
47a33cc31dSKevin Wolf    echo
48a33cc31dSKevin Wolf    echo Testing: "$@" | _filter_testdir
49a33cc31dSKevin Wolf    "$QEMU_IMG" "$@" 2>&1 | _filter_testdir
50a33cc31dSKevin Wolf}
51a33cc31dSKevin Wolf
52a33cc31dSKevin Wolfsize=128M
53a33cc31dSKevin Wolf
54a33cc31dSKevin Wolfecho
55a33cc31dSKevin Wolfecho === create: Options specified more than once ===
56a33cc31dSKevin Wolf
57a33cc31dSKevin Wolf# Last -f should win
58a33cc31dSKevin Wolfrun_qemu_img create -f foo -f $IMGFMT "$TEST_IMG" $size
591b53eab2SMax Reitz_img_info
60a33cc31dSKevin Wolf
61a33cc31dSKevin Wolf# Multiple -o should be merged
62a33cc31dSKevin Wolfrun_qemu_img create -f $IMGFMT -o cluster_size=4k -o lazy_refcounts=on "$TEST_IMG" $size
63a33cc31dSKevin Wolfrun_qemu_img info "$TEST_IMG"
64a33cc31dSKevin Wolf
65a33cc31dSKevin Wolf# If the same -o key is specified more than once, the last one wins
66a33cc31dSKevin Wolfrun_qemu_img create -f $IMGFMT -o cluster_size=4k -o lazy_refcounts=on -o cluster_size=8k "$TEST_IMG" $size
67a33cc31dSKevin Wolfrun_qemu_img info "$TEST_IMG"
68a33cc31dSKevin Wolfrun_qemu_img create -f $IMGFMT -o cluster_size=4k,cluster_size=8k "$TEST_IMG" $size
691b53eab2SMax Reitz_img_info
70a33cc31dSKevin Wolf
71a33cc31dSKevin Wolfecho
72a33cc31dSKevin Wolfecho === create: help for -o ===
73a33cc31dSKevin Wolf
74a33cc31dSKevin Wolf# Adding the help option to a command without other -o options
75a33cc31dSKevin Wolfrun_qemu_img create -f $IMGFMT -o help "$TEST_IMG" $size
76a33cc31dSKevin Wolfrun_qemu_img create -f $IMGFMT -o \? "$TEST_IMG" $size
77a33cc31dSKevin Wolf
78a33cc31dSKevin Wolf# Adding the help option to the same -o option
79a33cc31dSKevin Wolfrun_qemu_img create -f $IMGFMT -o cluster_size=4k,help "$TEST_IMG" $size
80a33cc31dSKevin Wolfrun_qemu_img create -f $IMGFMT -o cluster_size=4k,\? "$TEST_IMG" $size
81a33cc31dSKevin Wolfrun_qemu_img create -f $IMGFMT -o help,cluster_size=4k "$TEST_IMG" $size
82a33cc31dSKevin Wolfrun_qemu_img create -f $IMGFMT -o \?,cluster_size=4k "$TEST_IMG" $size
83a33cc31dSKevin Wolf
84a33cc31dSKevin Wolf# Adding the help option to a separate -o option
85a33cc31dSKevin Wolfrun_qemu_img create -f $IMGFMT -o cluster_size=4k -o help "$TEST_IMG" $size
86a33cc31dSKevin Wolfrun_qemu_img create -f $IMGFMT -o cluster_size=4k -o \? "$TEST_IMG" $size
87a33cc31dSKevin Wolf
88a33cc31dSKevin Wolf# Looks like a help option, but is part of the backing file name
89a33cc31dSKevin Wolfrun_qemu_img create -f $IMGFMT -o backing_file="$TEST_IMG",,help "$TEST_IMG" $size
90a33cc31dSKevin Wolfrun_qemu_img create -f $IMGFMT -o backing_file="$TEST_IMG",,\? "$TEST_IMG" $size
91a33cc31dSKevin Wolf
92a33cc31dSKevin Wolf# Try to trick qemu-img into creating escaped commas
93a33cc31dSKevin Wolfrun_qemu_img create -f $IMGFMT -o backing_file="$TEST_IMG", -o help "$TEST_IMG" $size
94a33cc31dSKevin Wolfrun_qemu_img create -f $IMGFMT -o backing_file="$TEST_IMG" -o ,help "$TEST_IMG" $size
95a33cc31dSKevin Wolfrun_qemu_img create -f $IMGFMT -o backing_file="$TEST_IMG" -o ,, -o help "$TEST_IMG" $size
96a33cc31dSKevin Wolf
97a33cc31dSKevin Wolf# Leave out everything that isn't needed
98a33cc31dSKevin Wolfrun_qemu_img create -f $IMGFMT -o help
99a33cc31dSKevin Wolfrun_qemu_img create -o help
100a33cc31dSKevin Wolf
101a33cc31dSKevin Wolfecho
102a33cc31dSKevin Wolfecho === convert: Options specified more than once ===
103a33cc31dSKevin Wolf
104a33cc31dSKevin Wolf# We need a valid source image
105a33cc31dSKevin Wolfrun_qemu_img create -f $IMGFMT "$TEST_IMG" $size
106a33cc31dSKevin Wolf
107a33cc31dSKevin Wolf# Last -f should win
108a33cc31dSKevin Wolfrun_qemu_img convert -f foo -f $IMGFMT "$TEST_IMG" "$TEST_IMG".base
1091b53eab2SMax ReitzTEST_IMG="${TEST_IMG}.base" _img_info
110a33cc31dSKevin Wolf
111a33cc31dSKevin Wolf# Last -O should win
112a33cc31dSKevin Wolfrun_qemu_img convert -O foo -O $IMGFMT "$TEST_IMG" "$TEST_IMG".base
1131b53eab2SMax ReitzTEST_IMG="${TEST_IMG}.base" _img_info
114a33cc31dSKevin Wolf
115a33cc31dSKevin Wolf# Multiple -o should be merged
116a33cc31dSKevin Wolfrun_qemu_img convert -O $IMGFMT -o cluster_size=4k -o lazy_refcounts=on "$TEST_IMG" "$TEST_IMG".base
117a33cc31dSKevin Wolfrun_qemu_img info "$TEST_IMG".base
118a33cc31dSKevin Wolf
119a33cc31dSKevin Wolf# If the same -o key is specified more than once, the last one wins
120a33cc31dSKevin Wolfrun_qemu_img convert -O $IMGFMT -o cluster_size=4k -o lazy_refcounts=on -o cluster_size=8k "$TEST_IMG" "$TEST_IMG".base
121a33cc31dSKevin Wolfrun_qemu_img info "$TEST_IMG".base
122a33cc31dSKevin Wolfrun_qemu_img convert -O $IMGFMT -o cluster_size=4k,cluster_size=8k "$TEST_IMG" "$TEST_IMG".base
1231b53eab2SMax ReitzTEST_IMG="${TEST_IMG}.base" _img_info
124a33cc31dSKevin Wolf
125a33cc31dSKevin Wolfecho
126a33cc31dSKevin Wolfecho === convert: help for -o ===
127a33cc31dSKevin Wolf
128a33cc31dSKevin Wolf# Adding the help option to a command without other -o options
129a33cc31dSKevin Wolfrun_qemu_img convert -O $IMGFMT -o help "$TEST_IMG" "$TEST_IMG".base
130a33cc31dSKevin Wolfrun_qemu_img convert -O $IMGFMT -o \? "$TEST_IMG" "$TEST_IMG".base
131a33cc31dSKevin Wolf
132a33cc31dSKevin Wolf# Adding the help option to the same -o option
133a33cc31dSKevin Wolfrun_qemu_img convert -O $IMGFMT -o cluster_size=4k,help "$TEST_IMG" "$TEST_IMG".base
134a33cc31dSKevin Wolfrun_qemu_img convert -O $IMGFMT -o cluster_size=4k,\? "$TEST_IMG" "$TEST_IMG".base
135a33cc31dSKevin Wolfrun_qemu_img convert -O $IMGFMT -o help,cluster_size=4k "$TEST_IMG" "$TEST_IMG".base
136a33cc31dSKevin Wolfrun_qemu_img convert -O $IMGFMT -o \?,cluster_size=4k "$TEST_IMG" "$TEST_IMG".base
137a33cc31dSKevin Wolf
138a33cc31dSKevin Wolf# Adding the help option to a separate -o option
139a33cc31dSKevin Wolfrun_qemu_img convert -O $IMGFMT -o cluster_size=4k -o help "$TEST_IMG" "$TEST_IMG".base
140a33cc31dSKevin Wolfrun_qemu_img convert -O $IMGFMT -o cluster_size=4k -o \? "$TEST_IMG" "$TEST_IMG".base
141a33cc31dSKevin Wolf
142a33cc31dSKevin Wolf# Looks like a help option, but is part of the backing file name
143a33cc31dSKevin Wolfrun_qemu_img convert -O $IMGFMT -o backing_file="$TEST_IMG",,help "$TEST_IMG" "$TEST_IMG".base
144a33cc31dSKevin Wolfrun_qemu_img convert -O $IMGFMT -o backing_file="$TEST_IMG",,\? "$TEST_IMG" "$TEST_IMG".base
145a33cc31dSKevin Wolf
146a33cc31dSKevin Wolf# Try to trick qemu-img into creating escaped commas
147a33cc31dSKevin Wolfrun_qemu_img convert -O $IMGFMT -o backing_file="$TEST_IMG", -o help "$TEST_IMG" "$TEST_IMG".base
148a33cc31dSKevin Wolfrun_qemu_img convert -O $IMGFMT -o backing_file="$TEST_IMG" -o ,help "$TEST_IMG" "$TEST_IMG".base
149a33cc31dSKevin Wolfrun_qemu_img convert -O $IMGFMT -o backing_file="$TEST_IMG" -o ,, -o help "$TEST_IMG" "$TEST_IMG".base
150a33cc31dSKevin Wolf
151a33cc31dSKevin Wolf# Leave out everything that isn't needed
152a33cc31dSKevin Wolfrun_qemu_img convert -O $IMGFMT -o help
153a33cc31dSKevin Wolfrun_qemu_img convert -o help
154a33cc31dSKevin Wolf
155a33cc31dSKevin Wolfecho
156a33cc31dSKevin Wolfecho === amend: Options specified more than once ===
157a33cc31dSKevin Wolf
158a33cc31dSKevin Wolf# Last -f should win
159a33cc31dSKevin Wolfrun_qemu_img amend -f foo -f $IMGFMT -o lazy_refcounts=on "$TEST_IMG"
160a33cc31dSKevin Wolfrun_qemu_img info "$TEST_IMG"
161a33cc31dSKevin Wolf
162a33cc31dSKevin Wolf# Multiple -o should be merged
163a33cc31dSKevin Wolfrun_qemu_img amend -f $IMGFMT -o size=130M -o lazy_refcounts=off "$TEST_IMG"
164a33cc31dSKevin Wolfrun_qemu_img info "$TEST_IMG"
165a33cc31dSKevin Wolf
166a33cc31dSKevin Wolf# If the same -o key is specified more than once, the last one wins
167a33cc31dSKevin Wolfrun_qemu_img amend -f $IMGFMT -o size=8M -o lazy_refcounts=on -o size=132M "$TEST_IMG"
168a33cc31dSKevin Wolfrun_qemu_img info "$TEST_IMG"
169a33cc31dSKevin Wolfrun_qemu_img amend -f $IMGFMT -o size=4M,size=148M "$TEST_IMG"
1701b53eab2SMax Reitz_img_info
171a33cc31dSKevin Wolf
172a33cc31dSKevin Wolfecho
173a33cc31dSKevin Wolfecho === amend: help for -o ===
174a33cc31dSKevin Wolf
175a33cc31dSKevin Wolf# Adding the help option to a command without other -o options
176a33cc31dSKevin Wolfrun_qemu_img amend -f $IMGFMT -o help "$TEST_IMG"
177a33cc31dSKevin Wolfrun_qemu_img amend -f $IMGFMT -o \? "$TEST_IMG"
178a33cc31dSKevin Wolf
179a33cc31dSKevin Wolf# Adding the help option to the same -o option
180a33cc31dSKevin Wolfrun_qemu_img amend -f $IMGFMT -o cluster_size=4k,help "$TEST_IMG"
181a33cc31dSKevin Wolfrun_qemu_img amend -f $IMGFMT -o cluster_size=4k,\? "$TEST_IMG"
182a33cc31dSKevin Wolfrun_qemu_img amend -f $IMGFMT -o help,cluster_size=4k "$TEST_IMG"
183a33cc31dSKevin Wolfrun_qemu_img amend -f $IMGFMT -o \?,cluster_size=4k "$TEST_IMG"
184a33cc31dSKevin Wolf
185a33cc31dSKevin Wolf# Adding the help option to a separate -o option
186a33cc31dSKevin Wolfrun_qemu_img amend -f $IMGFMT -o cluster_size=4k -o help "$TEST_IMG"
187a33cc31dSKevin Wolfrun_qemu_img amend -f $IMGFMT -o cluster_size=4k -o \? "$TEST_IMG"
188a33cc31dSKevin Wolf
189a33cc31dSKevin Wolf# Looks like a help option, but is part of the backing file name
190a33cc31dSKevin Wolfrun_qemu_img amend -f $IMGFMT -o backing_file="$TEST_IMG",,help "$TEST_IMG"
191a33cc31dSKevin Wolfrun_qemu_img rebase -u -b "" -f $IMGFMT "$TEST_IMG"
192a33cc31dSKevin Wolf
193a33cc31dSKevin Wolfrun_qemu_img amend -f $IMGFMT -o backing_file="$TEST_IMG",,\? "$TEST_IMG"
194a33cc31dSKevin Wolfrun_qemu_img rebase -u -b "" -f $IMGFMT "$TEST_IMG"
195a33cc31dSKevin Wolf
196a33cc31dSKevin Wolf# Try to trick qemu-img into creating escaped commas
197a33cc31dSKevin Wolfrun_qemu_img amend -f $IMGFMT -o backing_file="$TEST_IMG", -o help "$TEST_IMG"
198a33cc31dSKevin Wolfrun_qemu_img amend -f $IMGFMT -o backing_file="$TEST_IMG" -o ,help "$TEST_IMG"
199a33cc31dSKevin Wolfrun_qemu_img amend -f $IMGFMT -o backing_file="$TEST_IMG" -o ,, -o help "$TEST_IMG"
200a33cc31dSKevin Wolf
201a33cc31dSKevin Wolf# Leave out everything that isn't needed
202a33cc31dSKevin Wolfrun_qemu_img amend -f $IMGFMT -o help
203a33cc31dSKevin Wolfrun_qemu_img convert -o help
204a33cc31dSKevin Wolf
205a33cc31dSKevin Wolf# success, all done
206a33cc31dSKevin Wolfecho "*** done"
207a33cc31dSKevin Wolfrm -f $seq.full
208a33cc31dSKevin Wolfstatus=0
209