xref: /qemu/tests/qemu-iotests/049 (revision b25b387fa5928e516cb2c9e7fde68e958bd7e50a)
14dc9f9d6SKevin Wolf#!/bin/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 Wolfhere=`pwd`
284dc9f9d6SKevin Wolfstatus=1	# failure is the default!
294dc9f9d6SKevin Wolf
304dc9f9d6SKevin Wolf_cleanup()
314dc9f9d6SKevin Wolf{
324dc9f9d6SKevin Wolf	_cleanup_test_img
334dc9f9d6SKevin Wolf}
344dc9f9d6SKevin Wolftrap "_cleanup; exit \$status" 0 1 2 3 15
354dc9f9d6SKevin Wolf
364dc9f9d6SKevin Wolf# get standard environment, filters and checks
374dc9f9d6SKevin Wolf. ./common.rc
384dc9f9d6SKevin Wolf. ./common.filter
394dc9f9d6SKevin Wolf
404dc9f9d6SKevin Wolf_supported_fmt qcow2
414dc9f9d6SKevin Wolf_supported_proto file
424dc9f9d6SKevin Wolf_supported_os Linux
434dc9f9d6SKevin Wolf
444dc9f9d6SKevin Wolffunction filter_test_dir()
454dc9f9d6SKevin Wolf{
464dc9f9d6SKevin Wolf    sed -e "s#$IMGPROTO:$TEST_DIR#TEST_DIR#g" \
474dc9f9d6SKevin Wolf        -e "s#$TEST_DIR#TEST_DIR#g"
484dc9f9d6SKevin Wolf}
494dc9f9d6SKevin Wolf
504dc9f9d6SKevin Wolffunction test_qemu_img()
514dc9f9d6SKevin Wolf{
524dc9f9d6SKevin Wolf    echo qemu-img "$@" | filter_test_dir
534dc9f9d6SKevin Wolf    $QEMU_IMG "$@" 2>&1 | filter_test_dir
544dc9f9d6SKevin Wolf    echo
554dc9f9d6SKevin Wolf}
564dc9f9d6SKevin Wolf
574dc9f9d6SKevin Wolfecho "=== Check correct interpretation of suffixes for image size ==="
584dc9f9d6SKevin Wolfecho
594dc9f9d6SKevin Wolfsizes="1024 1024b 1k 1K 1M 1G 1T "
604dc9f9d6SKevin Wolfsizes+="1024.0 1024.0b 1.5k 1.5K 1.5M 1.5G 1.5T"
614dc9f9d6SKevin Wolf
624dc9f9d6SKevin Wolfecho "== 1. Traditional size parameter =="
634dc9f9d6SKevin Wolfecho
644dc9f9d6SKevin Wolffor s in $sizes; do
65fef9c191SJeff Cody    test_qemu_img create -f $IMGFMT "$TEST_IMG" $s
664dc9f9d6SKevin Wolfdone
674dc9f9d6SKevin Wolf
684dc9f9d6SKevin Wolfecho "== 2. Specifying size via -o =="
694dc9f9d6SKevin Wolfecho
704dc9f9d6SKevin Wolffor s in $sizes; do
71fef9c191SJeff Cody    test_qemu_img create -f $IMGFMT -o size=$s "$TEST_IMG"
724dc9f9d6SKevin Wolfdone
734dc9f9d6SKevin Wolf
744dc9f9d6SKevin Wolfecho "== 3. Invalid sizes =="
754dc9f9d6SKevin Wolfecho
764dc9f9d6SKevin Wolfsizes="-1024 -1k 1kilobyte foobar"
774dc9f9d6SKevin Wolf
784dc9f9d6SKevin Wolffor s in $sizes; do
79fef9c191SJeff Cody    test_qemu_img create -f $IMGFMT "$TEST_IMG" -- $s
80fef9c191SJeff Cody    test_qemu_img create -f $IMGFMT -o size=$s "$TEST_IMG"
814dc9f9d6SKevin Wolfdone
824dc9f9d6SKevin Wolf
834dc9f9d6SKevin Wolfecho "== Check correct interpretation of suffixes for cluster size =="
844dc9f9d6SKevin Wolfecho
854dc9f9d6SKevin Wolfsizes="1024 1024b 1k 1K 1M "
864dc9f9d6SKevin Wolfsizes+="1024.0 1024.0b 0.5k 0.5K 0.5M"
874dc9f9d6SKevin Wolf
884dc9f9d6SKevin Wolffor s in $sizes; do
89fef9c191SJeff Cody    test_qemu_img create -f $IMGFMT -o cluster_size=$s "$TEST_IMG" 64M
904dc9f9d6SKevin Wolfdone
914dc9f9d6SKevin Wolf
924dc9f9d6SKevin Wolfecho "== Check compat level option =="
934dc9f9d6SKevin Wolfecho
94fef9c191SJeff Codytest_qemu_img create -f $IMGFMT -o compat=0.10 "$TEST_IMG" 64M
95fef9c191SJeff Codytest_qemu_img create -f $IMGFMT -o compat=1.1 "$TEST_IMG" 64M
964dc9f9d6SKevin Wolf
97fef9c191SJeff Codytest_qemu_img create -f $IMGFMT -o compat=0.42 "$TEST_IMG" 64M
98fef9c191SJeff Codytest_qemu_img create -f $IMGFMT -o compat=foobar "$TEST_IMG" 64M
994dc9f9d6SKevin Wolf
1004dc9f9d6SKevin Wolfecho "== Check preallocation option =="
1014dc9f9d6SKevin Wolfecho
102fef9c191SJeff Codytest_qemu_img create -f $IMGFMT -o preallocation=off "$TEST_IMG" 64M
103fef9c191SJeff Codytest_qemu_img create -f $IMGFMT -o preallocation=metadata "$TEST_IMG" 64M
104fef9c191SJeff Codytest_qemu_img create -f $IMGFMT -o preallocation=1234 "$TEST_IMG" 64M
1054dc9f9d6SKevin Wolf
1064dc9f9d6SKevin Wolfecho "== Check encryption option =="
1074dc9f9d6SKevin Wolfecho
108fef9c191SJeff Codytest_qemu_img create -f $IMGFMT -o encryption=off "$TEST_IMG" 64M
109*b25b387fSDaniel P. Berrangetest_qemu_img create -f $IMGFMT --object secret,id=sec0,data=123456 -o encryption=on,encrypt.key-secret=sec0 "$TEST_IMG" 64M
1104dc9f9d6SKevin Wolf
1114dc9f9d6SKevin Wolfecho "== Check lazy_refcounts option (only with v3) =="
1124dc9f9d6SKevin Wolfecho
113fef9c191SJeff Codytest_qemu_img create -f $IMGFMT -o compat=1.1,lazy_refcounts=off "$TEST_IMG" 64M
114fef9c191SJeff Codytest_qemu_img create -f $IMGFMT -o compat=1.1,lazy_refcounts=on "$TEST_IMG" 64M
1154dc9f9d6SKevin Wolf
116fef9c191SJeff Codytest_qemu_img create -f $IMGFMT -o compat=0.10,lazy_refcounts=off "$TEST_IMG" 64M
117fef9c191SJeff Codytest_qemu_img create -f $IMGFMT -o compat=0.10,lazy_refcounts=on "$TEST_IMG" 64M
1184dc9f9d6SKevin Wolf
1194dc9f9d6SKevin Wolf# success, all done
1204dc9f9d6SKevin Wolfecho "*** done"
1214dc9f9d6SKevin Wolfrm -f $seq.full
1224dc9f9d6SKevin Wolfstatus=0
123