xref: /qemu/tests/qemu-iotests/049 (revision 975a7bd2280db5a8db96a92ff0811e08431a64c7)
111a82d14SPhilippe Mathieu-Daudé#!/usr/bin/env bash
24dc9f9d6SKevin Wolf#
34dc9f9d6SKevin Wolf# Check qemu-img option parsing
44dc9f9d6SKevin Wolf#
54dc9f9d6SKevin Wolf# Copyright (C) 2013 Red Hat, Inc.
64dc9f9d6SKevin Wolf#
74dc9f9d6SKevin Wolf# This program is free software; you can redistribute it and/or modify
84dc9f9d6SKevin Wolf# it under the terms of the GNU General Public License as published by
94dc9f9d6SKevin Wolf# the Free Software Foundation; either version 2 of the License, or
104dc9f9d6SKevin Wolf# (at your option) any later version.
114dc9f9d6SKevin Wolf#
124dc9f9d6SKevin Wolf# This program is distributed in the hope that it will be useful,
134dc9f9d6SKevin Wolf# but WITHOUT ANY WARRANTY; without even the implied warranty of
144dc9f9d6SKevin Wolf# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
154dc9f9d6SKevin Wolf# GNU General Public License for more details.
164dc9f9d6SKevin Wolf#
174dc9f9d6SKevin Wolf# You should have received a copy of the GNU General Public License
184dc9f9d6SKevin Wolf# along with this program.  If not, see <http://www.gnu.org/licenses/>.
194dc9f9d6SKevin Wolf#
204dc9f9d6SKevin Wolf
214dc9f9d6SKevin Wolf# creator
224dc9f9d6SKevin Wolfowner=kwolf@redhat.com
234dc9f9d6SKevin Wolf
244dc9f9d6SKevin Wolfseq=`basename $0`
254dc9f9d6SKevin Wolfecho "QA output created by $seq"
264dc9f9d6SKevin Wolf
274dc9f9d6SKevin Wolfstatus=1	# failure is the default!
284dc9f9d6SKevin Wolf
294dc9f9d6SKevin Wolf_cleanup()
304dc9f9d6SKevin Wolf{
314dc9f9d6SKevin Wolf	_cleanup_test_img
324dc9f9d6SKevin Wolf}
334dc9f9d6SKevin Wolftrap "_cleanup; exit \$status" 0 1 2 3 15
344dc9f9d6SKevin Wolf
354dc9f9d6SKevin Wolf# get standard environment, filters and checks
364dc9f9d6SKevin Wolf. ./common.rc
374dc9f9d6SKevin Wolf. ./common.filter
384dc9f9d6SKevin Wolf
394dc9f9d6SKevin Wolf_supported_fmt qcow2
404dc9f9d6SKevin Wolf_supported_proto file
414dc9f9d6SKevin Wolf
428cedcffdSEric Blakefilter_test_dir()
434dc9f9d6SKevin Wolf{
444dc9f9d6SKevin Wolf    sed -e "s#$IMGPROTO:$TEST_DIR#TEST_DIR#g" \
454dc9f9d6SKevin Wolf        -e "s#$TEST_DIR#TEST_DIR#g"
464dc9f9d6SKevin Wolf}
474dc9f9d6SKevin Wolf
488cedcffdSEric Blaketest_qemu_img()
494dc9f9d6SKevin Wolf{
504dc9f9d6SKevin Wolf    echo qemu-img "$@" | filter_test_dir
514dc9f9d6SKevin Wolf    $QEMU_IMG "$@" 2>&1 | filter_test_dir
524dc9f9d6SKevin Wolf    echo
534dc9f9d6SKevin Wolf}
544dc9f9d6SKevin Wolf
554dc9f9d6SKevin Wolfecho "=== Check correct interpretation of suffixes for image size ==="
564dc9f9d6SKevin Wolfecho
574dc9f9d6SKevin Wolfsizes="1024 1024b 1k 1K 1M 1G 1T "
584dc9f9d6SKevin Wolfsizes+="1024.0 1024.0b 1.5k 1.5K 1.5M 1.5G 1.5T"
594dc9f9d6SKevin Wolf
604dc9f9d6SKevin Wolfecho "== 1. Traditional size parameter =="
614dc9f9d6SKevin Wolfecho
624dc9f9d6SKevin Wolffor s in $sizes; do
63fef9c191SJeff Cody    test_qemu_img create -f $IMGFMT "$TEST_IMG" $s
644dc9f9d6SKevin Wolfdone
654dc9f9d6SKevin Wolf
664dc9f9d6SKevin Wolfecho "== 2. Specifying size via -o =="
674dc9f9d6SKevin Wolfecho
684dc9f9d6SKevin Wolffor s in $sizes; do
69fef9c191SJeff Cody    test_qemu_img create -f $IMGFMT -o size=$s "$TEST_IMG"
704dc9f9d6SKevin Wolfdone
714dc9f9d6SKevin Wolf
724dc9f9d6SKevin Wolfecho "== 3. Invalid sizes =="
734dc9f9d6SKevin Wolfecho
744dc9f9d6SKevin Wolfsizes="-1024 -1k 1kilobyte foobar"
754dc9f9d6SKevin Wolf
764dc9f9d6SKevin Wolffor s in $sizes; do
77fef9c191SJeff Cody    test_qemu_img create -f $IMGFMT "$TEST_IMG" -- $s
78fef9c191SJeff Cody    test_qemu_img create -f $IMGFMT -o size=$s "$TEST_IMG"
794dc9f9d6SKevin Wolfdone
804dc9f9d6SKevin Wolf
81f6dc1c31SKevin Wolfecho "== 4. Specify size twice (-o and traditional parameter) =="
82f6dc1c31SKevin Wolfecho
83f6dc1c31SKevin Wolf
84f6dc1c31SKevin Wolftest_qemu_img create -f $IMGFMT -o size=10M "$TEST_IMG" 20M
85f6dc1c31SKevin Wolf
864dc9f9d6SKevin Wolfecho "== Check correct interpretation of suffixes for cluster size =="
874dc9f9d6SKevin Wolfecho
884dc9f9d6SKevin Wolfsizes="1024 1024b 1k 1K 1M "
894dc9f9d6SKevin Wolfsizes+="1024.0 1024.0b 0.5k 0.5K 0.5M"
904dc9f9d6SKevin Wolf
914dc9f9d6SKevin Wolffor s in $sizes; do
92fef9c191SJeff Cody    test_qemu_img create -f $IMGFMT -o cluster_size=$s "$TEST_IMG" 64M
934dc9f9d6SKevin Wolfdone
944dc9f9d6SKevin Wolf
954dc9f9d6SKevin Wolfecho "== Check compat level option =="
964dc9f9d6SKevin Wolfecho
97fef9c191SJeff Codytest_qemu_img create -f $IMGFMT -o compat=0.10 "$TEST_IMG" 64M
98fef9c191SJeff Codytest_qemu_img create -f $IMGFMT -o compat=1.1 "$TEST_IMG" 64M
994dc9f9d6SKevin Wolf
100fef9c191SJeff Codytest_qemu_img create -f $IMGFMT -o compat=0.42 "$TEST_IMG" 64M
101fef9c191SJeff Codytest_qemu_img create -f $IMGFMT -o compat=foobar "$TEST_IMG" 64M
1024dc9f9d6SKevin Wolf
1034dc9f9d6SKevin Wolfecho "== Check preallocation option =="
1044dc9f9d6SKevin Wolfecho
105fef9c191SJeff Codytest_qemu_img create -f $IMGFMT -o preallocation=off "$TEST_IMG" 64M
106fef9c191SJeff Codytest_qemu_img create -f $IMGFMT -o preallocation=metadata "$TEST_IMG" 64M
107fef9c191SJeff Codytest_qemu_img create -f $IMGFMT -o preallocation=1234 "$TEST_IMG" 64M
1084dc9f9d6SKevin Wolf
1094dc9f9d6SKevin Wolfecho "== Check encryption option =="
1104dc9f9d6SKevin Wolfecho
111fef9c191SJeff Codytest_qemu_img create -f $IMGFMT -o encryption=off "$TEST_IMG" 64M
112b25b387fSDaniel P. Berrangetest_qemu_img create -f $IMGFMT --object secret,id=sec0,data=123456 -o encryption=on,encrypt.key-secret=sec0 "$TEST_IMG" 64M
1134dc9f9d6SKevin Wolf
1144dc9f9d6SKevin Wolfecho "== Check lazy_refcounts option (only with v3) =="
1154dc9f9d6SKevin Wolfecho
116fef9c191SJeff Codytest_qemu_img create -f $IMGFMT -o compat=1.1,lazy_refcounts=off "$TEST_IMG" 64M
117fef9c191SJeff Codytest_qemu_img create -f $IMGFMT -o compat=1.1,lazy_refcounts=on "$TEST_IMG" 64M
1184dc9f9d6SKevin Wolf
119fef9c191SJeff Codytest_qemu_img create -f $IMGFMT -o compat=0.10,lazy_refcounts=off "$TEST_IMG" 64M
120fef9c191SJeff Codytest_qemu_img create -f $IMGFMT -o compat=0.10,lazy_refcounts=on "$TEST_IMG" 64M
1214dc9f9d6SKevin Wolf
122*975a7bd2SConnor Kuehlecho "== Expect error when backing file name is empty string =="
123*975a7bd2SConnor Kuehlecho
124*975a7bd2SConnor Kuehltest_qemu_img create -f $IMGFMT -b '' $TEST_IMG 1M
125*975a7bd2SConnor Kuehl
1264dc9f9d6SKevin Wolf# success, all done
1274dc9f9d6SKevin Wolfecho "*** done"
1284dc9f9d6SKevin Wolfrm -f $seq.full
1294dc9f9d6SKevin Wolfstatus=0
130