xref: /qemu/tests/qemu-iotests/049 (revision 4dc9f9d67dbf5d062d8db188b81cef435f291dd8)
1*4dc9f9d6SKevin Wolf#!/bin/bash
2*4dc9f9d6SKevin Wolf#
3*4dc9f9d6SKevin Wolf# Check qemu-img option parsing
4*4dc9f9d6SKevin Wolf#
5*4dc9f9d6SKevin Wolf# Copyright (C) 2013 Red Hat, Inc.
6*4dc9f9d6SKevin Wolf#
7*4dc9f9d6SKevin Wolf# This program is free software; you can redistribute it and/or modify
8*4dc9f9d6SKevin Wolf# it under the terms of the GNU General Public License as published by
9*4dc9f9d6SKevin Wolf# the Free Software Foundation; either version 2 of the License, or
10*4dc9f9d6SKevin Wolf# (at your option) any later version.
11*4dc9f9d6SKevin Wolf#
12*4dc9f9d6SKevin Wolf# This program is distributed in the hope that it will be useful,
13*4dc9f9d6SKevin Wolf# but WITHOUT ANY WARRANTY; without even the implied warranty of
14*4dc9f9d6SKevin Wolf# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15*4dc9f9d6SKevin Wolf# GNU General Public License for more details.
16*4dc9f9d6SKevin Wolf#
17*4dc9f9d6SKevin Wolf# You should have received a copy of the GNU General Public License
18*4dc9f9d6SKevin Wolf# along with this program.  If not, see <http://www.gnu.org/licenses/>.
19*4dc9f9d6SKevin Wolf#
20*4dc9f9d6SKevin Wolf
21*4dc9f9d6SKevin Wolf# creator
22*4dc9f9d6SKevin Wolfowner=kwolf@redhat.com
23*4dc9f9d6SKevin Wolf
24*4dc9f9d6SKevin Wolfseq=`basename $0`
25*4dc9f9d6SKevin Wolfecho "QA output created by $seq"
26*4dc9f9d6SKevin Wolf
27*4dc9f9d6SKevin Wolfhere=`pwd`
28*4dc9f9d6SKevin Wolftmp=/tmp/$$
29*4dc9f9d6SKevin Wolfstatus=1	# failure is the default!
30*4dc9f9d6SKevin Wolf
31*4dc9f9d6SKevin Wolf_cleanup()
32*4dc9f9d6SKevin Wolf{
33*4dc9f9d6SKevin Wolf	_cleanup_test_img
34*4dc9f9d6SKevin Wolf}
35*4dc9f9d6SKevin Wolftrap "_cleanup; exit \$status" 0 1 2 3 15
36*4dc9f9d6SKevin Wolf
37*4dc9f9d6SKevin Wolf# get standard environment, filters and checks
38*4dc9f9d6SKevin Wolf. ./common.rc
39*4dc9f9d6SKevin Wolf. ./common.filter
40*4dc9f9d6SKevin Wolf
41*4dc9f9d6SKevin Wolf_supported_fmt qcow2
42*4dc9f9d6SKevin Wolf_supported_proto file
43*4dc9f9d6SKevin Wolf_supported_os Linux
44*4dc9f9d6SKevin Wolf
45*4dc9f9d6SKevin Wolffunction filter_test_dir()
46*4dc9f9d6SKevin Wolf{
47*4dc9f9d6SKevin Wolf    sed -e "s#$IMGPROTO:$TEST_DIR#TEST_DIR#g" \
48*4dc9f9d6SKevin Wolf        -e "s#$TEST_DIR#TEST_DIR#g"
49*4dc9f9d6SKevin Wolf}
50*4dc9f9d6SKevin Wolf
51*4dc9f9d6SKevin Wolffunction test_qemu_img()
52*4dc9f9d6SKevin Wolf{
53*4dc9f9d6SKevin Wolf    echo qemu-img "$@" | filter_test_dir
54*4dc9f9d6SKevin Wolf    $QEMU_IMG "$@" 2>&1 | filter_test_dir
55*4dc9f9d6SKevin Wolf    echo
56*4dc9f9d6SKevin Wolf}
57*4dc9f9d6SKevin Wolf
58*4dc9f9d6SKevin Wolfecho "=== Check correct interpretation of suffixes for image size ==="
59*4dc9f9d6SKevin Wolfecho
60*4dc9f9d6SKevin Wolfsizes="1024 1024b 1k 1K 1M 1G 1T "
61*4dc9f9d6SKevin Wolfsizes+="1024.0 1024.0b 1.5k 1.5K 1.5M 1.5G 1.5T"
62*4dc9f9d6SKevin Wolf
63*4dc9f9d6SKevin Wolfecho "== 1. Traditional size parameter =="
64*4dc9f9d6SKevin Wolfecho
65*4dc9f9d6SKevin Wolffor s in $sizes; do
66*4dc9f9d6SKevin Wolf    test_qemu_img create -f $IMGFMT $TEST_IMG $s
67*4dc9f9d6SKevin Wolfdone
68*4dc9f9d6SKevin Wolf
69*4dc9f9d6SKevin Wolfecho "== 2. Specifying size via -o =="
70*4dc9f9d6SKevin Wolfecho
71*4dc9f9d6SKevin Wolffor s in $sizes; do
72*4dc9f9d6SKevin Wolf    test_qemu_img create -f $IMGFMT -o size=$s $TEST_IMG
73*4dc9f9d6SKevin Wolfdone
74*4dc9f9d6SKevin Wolf
75*4dc9f9d6SKevin Wolfecho "== 3. Invalid sizes =="
76*4dc9f9d6SKevin Wolfecho
77*4dc9f9d6SKevin Wolfsizes="-1024 -1k 1kilobyte foobar"
78*4dc9f9d6SKevin Wolf
79*4dc9f9d6SKevin Wolffor s in $sizes; do
80*4dc9f9d6SKevin Wolf    test_qemu_img create -f $IMGFMT $TEST_IMG -- $s
81*4dc9f9d6SKevin Wolf    test_qemu_img create -f $IMGFMT -o size=$s $TEST_IMG
82*4dc9f9d6SKevin Wolfdone
83*4dc9f9d6SKevin Wolf
84*4dc9f9d6SKevin Wolfecho "== Check correct interpretation of suffixes for cluster size =="
85*4dc9f9d6SKevin Wolfecho
86*4dc9f9d6SKevin Wolfsizes="1024 1024b 1k 1K 1M "
87*4dc9f9d6SKevin Wolfsizes+="1024.0 1024.0b 0.5k 0.5K 0.5M"
88*4dc9f9d6SKevin Wolf
89*4dc9f9d6SKevin Wolffor s in $sizes; do
90*4dc9f9d6SKevin Wolf    test_qemu_img create -f $IMGFMT -o cluster_size=$s $TEST_IMG 64M
91*4dc9f9d6SKevin Wolfdone
92*4dc9f9d6SKevin Wolf
93*4dc9f9d6SKevin Wolfecho "== Check compat level option =="
94*4dc9f9d6SKevin Wolfecho
95*4dc9f9d6SKevin Wolftest_qemu_img create -f $IMGFMT -o compat=0.10 $TEST_IMG 64M
96*4dc9f9d6SKevin Wolftest_qemu_img create -f $IMGFMT -o compat=1.1 $TEST_IMG 64M
97*4dc9f9d6SKevin Wolf
98*4dc9f9d6SKevin Wolftest_qemu_img create -f $IMGFMT -o compat=0.42 $TEST_IMG 64M
99*4dc9f9d6SKevin Wolftest_qemu_img create -f $IMGFMT -o compat=foobar $TEST_IMG 64M
100*4dc9f9d6SKevin Wolf
101*4dc9f9d6SKevin Wolfecho "== Check preallocation option =="
102*4dc9f9d6SKevin Wolfecho
103*4dc9f9d6SKevin Wolftest_qemu_img create -f $IMGFMT -o preallocation=off $TEST_IMG 64M
104*4dc9f9d6SKevin Wolftest_qemu_img create -f $IMGFMT -o preallocation=metadata $TEST_IMG 64M
105*4dc9f9d6SKevin Wolftest_qemu_img create -f $IMGFMT -o preallocation=1234 $TEST_IMG 64M
106*4dc9f9d6SKevin Wolf
107*4dc9f9d6SKevin Wolfecho "== Check encryption option =="
108*4dc9f9d6SKevin Wolfecho
109*4dc9f9d6SKevin Wolftest_qemu_img create -f $IMGFMT -o encryption=off $TEST_IMG 64M
110*4dc9f9d6SKevin Wolftest_qemu_img create -f $IMGFMT -o encryption=on $TEST_IMG 64M
111*4dc9f9d6SKevin Wolf
112*4dc9f9d6SKevin Wolfecho "== Check lazy_refcounts option (only with v3) =="
113*4dc9f9d6SKevin Wolfecho
114*4dc9f9d6SKevin Wolftest_qemu_img create -f $IMGFMT -o compat=1.1,lazy_refcounts=off $TEST_IMG 64M
115*4dc9f9d6SKevin Wolftest_qemu_img create -f $IMGFMT -o compat=1.1,lazy_refcounts=on $TEST_IMG 64M
116*4dc9f9d6SKevin Wolf
117*4dc9f9d6SKevin Wolftest_qemu_img create -f $IMGFMT -o compat=0.10,lazy_refcounts=off $TEST_IMG 64M
118*4dc9f9d6SKevin Wolftest_qemu_img create -f $IMGFMT -o compat=0.10,lazy_refcounts=on $TEST_IMG 64M
119*4dc9f9d6SKevin Wolf
120*4dc9f9d6SKevin Wolf# success, all done
121*4dc9f9d6SKevin Wolfecho "*** done"
122*4dc9f9d6SKevin Wolfrm -f $seq.full
123*4dc9f9d6SKevin Wolfstatus=0
124