xref: /openbmc/qemu/tests/qemu-iotests/082 (revision 0e324626)
111a82d14SPhilippe Mathieu-Daudé#!/usr/bin/env bash
2*9dd003a9SVladimir Sementsov-Ogievskiy# group: rw quick
3a33cc31dSKevin Wolf#
4a33cc31dSKevin Wolf# Test qemu-img command line parsing
5a33cc31dSKevin Wolf#
6a33cc31dSKevin Wolf# Copyright (C) 2014 Red Hat, Inc.
7a33cc31dSKevin Wolf#
8a33cc31dSKevin Wolf# This program is free software; you can redistribute it and/or modify
9a33cc31dSKevin Wolf# it under the terms of the GNU General Public License as published by
10a33cc31dSKevin Wolf# the Free Software Foundation; either version 2 of the License, or
11a33cc31dSKevin Wolf# (at your option) any later version.
12a33cc31dSKevin Wolf#
13a33cc31dSKevin Wolf# This program is distributed in the hope that it will be useful,
14a33cc31dSKevin Wolf# but WITHOUT ANY WARRANTY; without even the implied warranty of
15a33cc31dSKevin Wolf# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16a33cc31dSKevin Wolf# GNU General Public License for more details.
17a33cc31dSKevin Wolf#
18a33cc31dSKevin Wolf# You should have received a copy of the GNU General Public License
19a33cc31dSKevin Wolf# along with this program.  If not, see <http://www.gnu.org/licenses/>.
20a33cc31dSKevin Wolf#
21a33cc31dSKevin Wolf
22a33cc31dSKevin Wolf# creator
23a33cc31dSKevin Wolfowner=kwolf@redhat.com
24a33cc31dSKevin Wolf
25a33cc31dSKevin Wolfseq=`basename $0`
26a33cc31dSKevin Wolfecho "QA output created by $seq"
27a33cc31dSKevin Wolf
28a33cc31dSKevin Wolfstatus=1	# failure is the default!
29a33cc31dSKevin Wolf
30a33cc31dSKevin Wolf_cleanup()
31a33cc31dSKevin Wolf{
32a33cc31dSKevin Wolf	_cleanup_test_img
33a33cc31dSKevin Wolf}
34a33cc31dSKevin Wolftrap "_cleanup; exit \$status" 0 1 2 3 15
35a33cc31dSKevin Wolf
36a33cc31dSKevin Wolf# get standard environment, filters and checks
37a33cc31dSKevin Wolf. ./common.rc
38a33cc31dSKevin Wolf. ./common.filter
39a33cc31dSKevin Wolf
40a33cc31dSKevin Wolf_supported_fmt qcow2
41c5f7c0afSPeter Lieven_supported_proto file nfs
42f03a8c73SVladimir Sementsov-Ogievskiy_require_drivers bochs
43a33cc31dSKevin Wolf
448cedcffdSEric Blakerun_qemu_img()
45a33cc31dSKevin Wolf{
46a33cc31dSKevin Wolf    echo
47a33cc31dSKevin Wolf    echo Testing: "$@" | _filter_testdir
48a33cc31dSKevin Wolf    "$QEMU_IMG" "$@" 2>&1 | _filter_testdir
49a33cc31dSKevin Wolf}
50a33cc31dSKevin Wolf
51a33cc31dSKevin Wolfsize=128M
52a33cc31dSKevin Wolf
53a33cc31dSKevin Wolfecho
54a33cc31dSKevin Wolfecho === create: Options specified more than once ===
55a33cc31dSKevin Wolf
56a33cc31dSKevin Wolf# Last -f should win
57a33cc31dSKevin Wolfrun_qemu_img create -f foo -f $IMGFMT "$TEST_IMG" $size
581b53eab2SMax Reitz_img_info
59a33cc31dSKevin Wolf
60a33cc31dSKevin Wolf# Multiple -o should be merged
61a33cc31dSKevin Wolfrun_qemu_img create -f $IMGFMT -o cluster_size=4k -o lazy_refcounts=on "$TEST_IMG" $size
62d1103231SMichael Mueller_img_info --format-specific
63a33cc31dSKevin Wolf
64a33cc31dSKevin Wolf# If the same -o key is specified more than once, the last one wins
65a33cc31dSKevin Wolfrun_qemu_img create -f $IMGFMT -o cluster_size=4k -o lazy_refcounts=on -o cluster_size=8k "$TEST_IMG" $size
66d1103231SMichael Mueller_img_info --format-specific
67a33cc31dSKevin Wolfrun_qemu_img create -f $IMGFMT -o cluster_size=4k,cluster_size=8k "$TEST_IMG" $size
681b53eab2SMax Reitz_img_info
69a33cc31dSKevin Wolf
70a33cc31dSKevin Wolfecho
71a33cc31dSKevin Wolfecho === create: help for -o ===
72a33cc31dSKevin Wolf
73a33cc31dSKevin Wolf# Adding the help option to a command without other -o options
74a33cc31dSKevin Wolfrun_qemu_img create -f $IMGFMT -o help "$TEST_IMG" $size
75a33cc31dSKevin Wolfrun_qemu_img create -f $IMGFMT -o \? "$TEST_IMG" $size
76a33cc31dSKevin Wolf
77a33cc31dSKevin Wolf# Adding the help option to the same -o option
78a33cc31dSKevin Wolfrun_qemu_img create -f $IMGFMT -o cluster_size=4k,help "$TEST_IMG" $size
79a33cc31dSKevin Wolfrun_qemu_img create -f $IMGFMT -o cluster_size=4k,\? "$TEST_IMG" $size
80a33cc31dSKevin Wolfrun_qemu_img create -f $IMGFMT -o help,cluster_size=4k "$TEST_IMG" $size
81a33cc31dSKevin Wolfrun_qemu_img create -f $IMGFMT -o \?,cluster_size=4k "$TEST_IMG" $size
82a33cc31dSKevin Wolf
83a33cc31dSKevin Wolf# Adding the help option to a separate -o option
84a33cc31dSKevin Wolfrun_qemu_img create -f $IMGFMT -o cluster_size=4k -o help "$TEST_IMG" $size
85a33cc31dSKevin Wolfrun_qemu_img create -f $IMGFMT -o cluster_size=4k -o \? "$TEST_IMG" $size
86a33cc31dSKevin Wolf
87a33cc31dSKevin Wolf# Looks like a help option, but is part of the backing file name
88b66ff2c2SEric Blakerun_qemu_img create -f $IMGFMT -u -o backing_file="$TEST_IMG",,help \
89b66ff2c2SEric Blake    -F $IMGFMT "$TEST_IMG" $size
90b66ff2c2SEric Blakerun_qemu_img create -f $IMGFMT -u -o backing_file="$TEST_IMG",,\? \
91b66ff2c2SEric Blake    -F $IMGFMT "$TEST_IMG" $size
92a33cc31dSKevin Wolf
93a33cc31dSKevin Wolf# Try to trick qemu-img into creating escaped commas
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 ,help "$TEST_IMG" $size
96a33cc31dSKevin Wolfrun_qemu_img create -f $IMGFMT -o backing_file="$TEST_IMG" -o ,, -o help "$TEST_IMG" $size
97a33cc31dSKevin Wolf
98a33cc31dSKevin Wolf# Leave out everything that isn't needed
99a33cc31dSKevin Wolfrun_qemu_img create -f $IMGFMT -o help
100a33cc31dSKevin Wolfrun_qemu_img create -o help
101a33cc31dSKevin Wolf
102e53995ebSMax Reitz# Try help option for a format that does not support creation
103e53995ebSMax Reitzrun_qemu_img create -f bochs -o help
104e53995ebSMax Reitz
105a33cc31dSKevin Wolfecho
106a33cc31dSKevin Wolfecho === convert: Options specified more than once ===
107a33cc31dSKevin Wolf
108a33cc31dSKevin Wolf# We need a valid source image
109a33cc31dSKevin Wolfrun_qemu_img create -f $IMGFMT "$TEST_IMG" $size
110a33cc31dSKevin Wolf
111a33cc31dSKevin Wolf# Last -f should win
112a33cc31dSKevin Wolfrun_qemu_img convert -f foo -f $IMGFMT "$TEST_IMG" "$TEST_IMG".base
1131b53eab2SMax ReitzTEST_IMG="${TEST_IMG}.base" _img_info
114a33cc31dSKevin Wolf
115a33cc31dSKevin Wolf# Last -O should win
116a33cc31dSKevin Wolfrun_qemu_img convert -O foo -O $IMGFMT "$TEST_IMG" "$TEST_IMG".base
1171b53eab2SMax ReitzTEST_IMG="${TEST_IMG}.base" _img_info
118a33cc31dSKevin Wolf
119a33cc31dSKevin Wolf# Multiple -o should be merged
120a33cc31dSKevin Wolfrun_qemu_img convert -O $IMGFMT -o cluster_size=4k -o lazy_refcounts=on "$TEST_IMG" "$TEST_IMG".base
121d1103231SMichael MuellerTEST_IMG="${TEST_IMG}.base" _img_info --format-specific
122a33cc31dSKevin Wolf
123a33cc31dSKevin Wolf# If the same -o key is specified more than once, the last one wins
124a33cc31dSKevin Wolfrun_qemu_img convert -O $IMGFMT -o cluster_size=4k -o lazy_refcounts=on -o cluster_size=8k "$TEST_IMG" "$TEST_IMG".base
125d1103231SMichael MuellerTEST_IMG="${TEST_IMG}.base" _img_info --format-specific
126a33cc31dSKevin Wolfrun_qemu_img convert -O $IMGFMT -o cluster_size=4k,cluster_size=8k "$TEST_IMG" "$TEST_IMG".base
1271b53eab2SMax ReitzTEST_IMG="${TEST_IMG}.base" _img_info
128a33cc31dSKevin Wolf
129a33cc31dSKevin Wolfecho
130a33cc31dSKevin Wolfecho === convert: help for -o ===
131a33cc31dSKevin Wolf
132a33cc31dSKevin Wolf# Adding the help option to a command without other -o options
133a33cc31dSKevin Wolfrun_qemu_img convert -O $IMGFMT -o help "$TEST_IMG" "$TEST_IMG".base
134a33cc31dSKevin Wolfrun_qemu_img convert -O $IMGFMT -o \? "$TEST_IMG" "$TEST_IMG".base
135a33cc31dSKevin Wolf
136a33cc31dSKevin Wolf# Adding the help option to the same -o option
137a33cc31dSKevin Wolfrun_qemu_img convert -O $IMGFMT -o cluster_size=4k,help "$TEST_IMG" "$TEST_IMG".base
138a33cc31dSKevin Wolfrun_qemu_img convert -O $IMGFMT -o cluster_size=4k,\? "$TEST_IMG" "$TEST_IMG".base
139a33cc31dSKevin Wolfrun_qemu_img convert -O $IMGFMT -o help,cluster_size=4k "$TEST_IMG" "$TEST_IMG".base
140a33cc31dSKevin Wolfrun_qemu_img convert -O $IMGFMT -o \?,cluster_size=4k "$TEST_IMG" "$TEST_IMG".base
141a33cc31dSKevin Wolf
142a33cc31dSKevin Wolf# Adding the help option to a separate -o option
143a33cc31dSKevin Wolfrun_qemu_img convert -O $IMGFMT -o cluster_size=4k -o help "$TEST_IMG" "$TEST_IMG".base
144a33cc31dSKevin Wolfrun_qemu_img convert -O $IMGFMT -o cluster_size=4k -o \? "$TEST_IMG" "$TEST_IMG".base
145a33cc31dSKevin Wolf
146a33cc31dSKevin Wolf# Looks like a help option, but is part of the backing file name
147b66ff2c2SEric Blakerun_qemu_img convert -O $IMGFMT -o backing_fmt=$IMGFMT,backing_file="$TEST_IMG",,help "$TEST_IMG" "$TEST_IMG".base
148b66ff2c2SEric Blakerun_qemu_img convert -O $IMGFMT -o backing_fmt=$IMGFMT,backing_file="$TEST_IMG",,\? "$TEST_IMG" "$TEST_IMG".base
149a33cc31dSKevin Wolf
150a33cc31dSKevin Wolf# Try to trick qemu-img into creating escaped commas
151a33cc31dSKevin Wolfrun_qemu_img convert -O $IMGFMT -o backing_file="$TEST_IMG", -o help "$TEST_IMG" "$TEST_IMG".base
152a33cc31dSKevin Wolfrun_qemu_img convert -O $IMGFMT -o backing_file="$TEST_IMG" -o ,help "$TEST_IMG" "$TEST_IMG".base
153a33cc31dSKevin Wolfrun_qemu_img convert -O $IMGFMT -o backing_file="$TEST_IMG" -o ,, -o help "$TEST_IMG" "$TEST_IMG".base
154a33cc31dSKevin Wolf
155a33cc31dSKevin Wolf# Leave out everything that isn't needed
156a33cc31dSKevin Wolfrun_qemu_img convert -O $IMGFMT -o help
157a33cc31dSKevin Wolfrun_qemu_img convert -o help
158a33cc31dSKevin Wolf
159e53995ebSMax Reitz# Try help option for a format that does not support creation
160e53995ebSMax Reitzrun_qemu_img convert -O bochs -o help
161e53995ebSMax Reitz
162a33cc31dSKevin Wolfecho
1638ba4f10fSFam Zhengecho === convert: -C and other options ===
1648ba4f10fSFam Zheng
1658ba4f10fSFam Zheng# Adding the help option to a command without other -o options
1668ba4f10fSFam Zhengrun_qemu_img convert -C -S 4k -O $IMGFMT "$TEST_IMG" "$TEST_IMG".target
1678ba4f10fSFam Zhengrun_qemu_img convert -C -S 8k -O $IMGFMT "$TEST_IMG" "$TEST_IMG".target
1688ba4f10fSFam Zhengrun_qemu_img convert -C -c -O $IMGFMT "$TEST_IMG" "$TEST_IMG".target
16921c1ce59SMax Reitzrun_qemu_img convert -C --salvage -O $IMGFMT "$TEST_IMG" "$TEST_IMG".target
1708ba4f10fSFam Zheng
1718ba4f10fSFam Zhengecho
172a33cc31dSKevin Wolfecho === amend: Options specified more than once ===
173a33cc31dSKevin Wolf
174a33cc31dSKevin Wolf# Last -f should win
175a33cc31dSKevin Wolfrun_qemu_img amend -f foo -f $IMGFMT -o lazy_refcounts=on "$TEST_IMG"
176d1103231SMichael Mueller_img_info --format-specific
177a33cc31dSKevin Wolf
178a33cc31dSKevin Wolf# Multiple -o should be merged
179a33cc31dSKevin Wolfrun_qemu_img amend -f $IMGFMT -o size=130M -o lazy_refcounts=off "$TEST_IMG"
180d1103231SMichael Mueller_img_info --format-specific
181a33cc31dSKevin Wolf
182a33cc31dSKevin Wolf# If the same -o key is specified more than once, the last one wins
183a33cc31dSKevin Wolfrun_qemu_img amend -f $IMGFMT -o size=8M -o lazy_refcounts=on -o size=132M "$TEST_IMG"
184d1103231SMichael Mueller_img_info --format-specific
185a33cc31dSKevin Wolfrun_qemu_img amend -f $IMGFMT -o size=4M,size=148M "$TEST_IMG"
1861b53eab2SMax Reitz_img_info
187a33cc31dSKevin Wolf
188a33cc31dSKevin Wolfecho
189a33cc31dSKevin Wolfecho === amend: help for -o ===
190a33cc31dSKevin Wolf
191a33cc31dSKevin Wolf# Adding the help option to a command without other -o options
192a33cc31dSKevin Wolfrun_qemu_img amend -f $IMGFMT -o help "$TEST_IMG"
193a33cc31dSKevin Wolfrun_qemu_img amend -f $IMGFMT -o \? "$TEST_IMG"
194a33cc31dSKevin Wolf
195a33cc31dSKevin Wolf# Adding the help option to the same -o option
196a33cc31dSKevin Wolfrun_qemu_img amend -f $IMGFMT -o cluster_size=4k,help "$TEST_IMG"
197a33cc31dSKevin Wolfrun_qemu_img amend -f $IMGFMT -o cluster_size=4k,\? "$TEST_IMG"
198a33cc31dSKevin Wolfrun_qemu_img amend -f $IMGFMT -o help,cluster_size=4k "$TEST_IMG"
199a33cc31dSKevin Wolfrun_qemu_img amend -f $IMGFMT -o \?,cluster_size=4k "$TEST_IMG"
200a33cc31dSKevin Wolf
201a33cc31dSKevin Wolf# Adding the help option to a separate -o option
202a33cc31dSKevin Wolfrun_qemu_img amend -f $IMGFMT -o cluster_size=4k -o help "$TEST_IMG"
203a33cc31dSKevin Wolfrun_qemu_img amend -f $IMGFMT -o cluster_size=4k -o \? "$TEST_IMG"
204a33cc31dSKevin Wolf
205a33cc31dSKevin Wolf# Looks like a help option, but is part of the backing file name
206a33cc31dSKevin Wolfrun_qemu_img amend -f $IMGFMT -o backing_file="$TEST_IMG",,help "$TEST_IMG"
207a33cc31dSKevin Wolfrun_qemu_img rebase -u -b "" -f $IMGFMT "$TEST_IMG"
208a33cc31dSKevin Wolf
209a33cc31dSKevin Wolfrun_qemu_img amend -f $IMGFMT -o backing_file="$TEST_IMG",,\? "$TEST_IMG"
210a33cc31dSKevin Wolfrun_qemu_img rebase -u -b "" -f $IMGFMT "$TEST_IMG"
211a33cc31dSKevin Wolf
212a33cc31dSKevin Wolf# Try to trick qemu-img into creating escaped commas
213a33cc31dSKevin Wolfrun_qemu_img amend -f $IMGFMT -o backing_file="$TEST_IMG", -o help "$TEST_IMG"
214a33cc31dSKevin Wolfrun_qemu_img amend -f $IMGFMT -o backing_file="$TEST_IMG" -o ,help "$TEST_IMG"
215a33cc31dSKevin Wolfrun_qemu_img amend -f $IMGFMT -o backing_file="$TEST_IMG" -o ,, -o help "$TEST_IMG"
216a33cc31dSKevin Wolf
217a33cc31dSKevin Wolf# Leave out everything that isn't needed
218a33cc31dSKevin Wolfrun_qemu_img amend -f $IMGFMT -o help
2190ef5a8e6SMax Reitz
2200ef5a8e6SMax Reitz# amend requires specifying either a format explicitly, or a file
2210ef5a8e6SMax Reitz# which it can probe
2220ef5a8e6SMax Reitzrun_qemu_img amend -o help
223a33cc31dSKevin Wolf
224e53995ebSMax Reitz# Try help option for a format that does not support amendment
225e53995ebSMax Reitzrun_qemu_img amend -f bochs -o help
226e53995ebSMax Reitz
227a33cc31dSKevin Wolf# success, all done
228a33cc31dSKevin Wolfecho "*** done"
229a33cc31dSKevin Wolfrm -f $seq.full
230a33cc31dSKevin Wolfstatus=0
231