xref: /openbmc/qemu/tests/qemu-iotests/049 (revision 0e324626)
111a82d14SPhilippe Mathieu-Daudé#!/usr/bin/env bash
2*9dd003a9SVladimir Sementsov-Ogievskiy# group: rw auto
34dc9f9d6SKevin Wolf#
44dc9f9d6SKevin Wolf# Check qemu-img option parsing
54dc9f9d6SKevin Wolf#
64dc9f9d6SKevin Wolf# Copyright (C) 2013 Red Hat, Inc.
74dc9f9d6SKevin Wolf#
84dc9f9d6SKevin Wolf# This program is free software; you can redistribute it and/or modify
94dc9f9d6SKevin Wolf# it under the terms of the GNU General Public License as published by
104dc9f9d6SKevin Wolf# the Free Software Foundation; either version 2 of the License, or
114dc9f9d6SKevin Wolf# (at your option) any later version.
124dc9f9d6SKevin Wolf#
134dc9f9d6SKevin Wolf# This program is distributed in the hope that it will be useful,
144dc9f9d6SKevin Wolf# but WITHOUT ANY WARRANTY; without even the implied warranty of
154dc9f9d6SKevin Wolf# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
164dc9f9d6SKevin Wolf# GNU General Public License for more details.
174dc9f9d6SKevin Wolf#
184dc9f9d6SKevin Wolf# You should have received a copy of the GNU General Public License
194dc9f9d6SKevin Wolf# along with this program.  If not, see <http://www.gnu.org/licenses/>.
204dc9f9d6SKevin Wolf#
214dc9f9d6SKevin Wolf
224dc9f9d6SKevin Wolf# creator
234dc9f9d6SKevin Wolfowner=kwolf@redhat.com
244dc9f9d6SKevin Wolf
254dc9f9d6SKevin Wolfseq=`basename $0`
264dc9f9d6SKevin Wolfecho "QA output created by $seq"
274dc9f9d6SKevin Wolf
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
438cedcffdSEric Blakefilter_test_dir()
444dc9f9d6SKevin Wolf{
454dc9f9d6SKevin Wolf    sed -e "s#$IMGPROTO:$TEST_DIR#TEST_DIR#g" \
464dc9f9d6SKevin Wolf        -e "s#$TEST_DIR#TEST_DIR#g"
474dc9f9d6SKevin Wolf}
484dc9f9d6SKevin Wolf
498cedcffdSEric Blaketest_qemu_img()
504dc9f9d6SKevin Wolf{
514dc9f9d6SKevin Wolf    echo qemu-img "$@" | filter_test_dir
524dc9f9d6SKevin Wolf    $QEMU_IMG "$@" 2>&1 | filter_test_dir
534dc9f9d6SKevin Wolf    echo
544dc9f9d6SKevin Wolf}
554dc9f9d6SKevin Wolf
564dc9f9d6SKevin Wolfecho "=== Check correct interpretation of suffixes for image size ==="
574dc9f9d6SKevin Wolfecho
584dc9f9d6SKevin Wolfsizes="1024 1024b 1k 1K 1M 1G 1T "
594dc9f9d6SKevin Wolfsizes+="1024.0 1024.0b 1.5k 1.5K 1.5M 1.5G 1.5T"
604dc9f9d6SKevin Wolf
614dc9f9d6SKevin Wolfecho "== 1. Traditional size parameter =="
624dc9f9d6SKevin Wolfecho
634dc9f9d6SKevin Wolffor s in $sizes; do
64fef9c191SJeff Cody    test_qemu_img create -f $IMGFMT "$TEST_IMG" $s
654dc9f9d6SKevin Wolfdone
664dc9f9d6SKevin Wolf
674dc9f9d6SKevin Wolfecho "== 2. Specifying size via -o =="
684dc9f9d6SKevin Wolfecho
694dc9f9d6SKevin Wolffor s in $sizes; do
70fef9c191SJeff Cody    test_qemu_img create -f $IMGFMT -o size=$s "$TEST_IMG"
714dc9f9d6SKevin Wolfdone
724dc9f9d6SKevin Wolf
734dc9f9d6SKevin Wolfecho "== 3. Invalid sizes =="
744dc9f9d6SKevin Wolfecho
754dc9f9d6SKevin Wolfsizes="-1024 -1k 1kilobyte foobar"
764dc9f9d6SKevin Wolf
774dc9f9d6SKevin Wolffor s in $sizes; do
78fef9c191SJeff Cody    test_qemu_img create -f $IMGFMT "$TEST_IMG" -- $s
79fef9c191SJeff Cody    test_qemu_img create -f $IMGFMT -o size=$s "$TEST_IMG"
804dc9f9d6SKevin Wolfdone
814dc9f9d6SKevin Wolf
82f6dc1c31SKevin Wolfecho "== 4. Specify size twice (-o and traditional parameter) =="
83f6dc1c31SKevin Wolfecho
84f6dc1c31SKevin Wolf
85f6dc1c31SKevin Wolftest_qemu_img create -f $IMGFMT -o size=10M "$TEST_IMG" 20M
86f6dc1c31SKevin Wolf
874dc9f9d6SKevin Wolfecho "== Check correct interpretation of suffixes for cluster size =="
884dc9f9d6SKevin Wolfecho
894dc9f9d6SKevin Wolfsizes="1024 1024b 1k 1K 1M "
904dc9f9d6SKevin Wolfsizes+="1024.0 1024.0b 0.5k 0.5K 0.5M"
914dc9f9d6SKevin Wolf
924dc9f9d6SKevin Wolffor s in $sizes; do
93fef9c191SJeff Cody    test_qemu_img create -f $IMGFMT -o cluster_size=$s "$TEST_IMG" 64M
944dc9f9d6SKevin Wolfdone
954dc9f9d6SKevin Wolf
964dc9f9d6SKevin Wolfecho "== Check compat level option =="
974dc9f9d6SKevin Wolfecho
98fef9c191SJeff Codytest_qemu_img create -f $IMGFMT -o compat=0.10 "$TEST_IMG" 64M
99fef9c191SJeff Codytest_qemu_img create -f $IMGFMT -o compat=1.1 "$TEST_IMG" 64M
1004dc9f9d6SKevin Wolf
101fef9c191SJeff Codytest_qemu_img create -f $IMGFMT -o compat=0.42 "$TEST_IMG" 64M
102fef9c191SJeff Codytest_qemu_img create -f $IMGFMT -o compat=foobar "$TEST_IMG" 64M
1034dc9f9d6SKevin Wolf
1044dc9f9d6SKevin Wolfecho "== Check preallocation option =="
1054dc9f9d6SKevin Wolfecho
106fef9c191SJeff Codytest_qemu_img create -f $IMGFMT -o preallocation=off "$TEST_IMG" 64M
107fef9c191SJeff Codytest_qemu_img create -f $IMGFMT -o preallocation=metadata "$TEST_IMG" 64M
108fef9c191SJeff Codytest_qemu_img create -f $IMGFMT -o preallocation=1234 "$TEST_IMG" 64M
1094dc9f9d6SKevin Wolf
1104dc9f9d6SKevin Wolfecho "== Check encryption option =="
1114dc9f9d6SKevin Wolfecho
112fef9c191SJeff Codytest_qemu_img create -f $IMGFMT -o encryption=off "$TEST_IMG" 64M
113b25b387fSDaniel P. Berrangetest_qemu_img create -f $IMGFMT --object secret,id=sec0,data=123456 -o encryption=on,encrypt.key-secret=sec0 "$TEST_IMG" 64M
1144dc9f9d6SKevin Wolf
1154dc9f9d6SKevin Wolfecho "== Check lazy_refcounts option (only with v3) =="
1164dc9f9d6SKevin Wolfecho
117fef9c191SJeff Codytest_qemu_img create -f $IMGFMT -o compat=1.1,lazy_refcounts=off "$TEST_IMG" 64M
118fef9c191SJeff Codytest_qemu_img create -f $IMGFMT -o compat=1.1,lazy_refcounts=on "$TEST_IMG" 64M
1194dc9f9d6SKevin Wolf
120fef9c191SJeff Codytest_qemu_img create -f $IMGFMT -o compat=0.10,lazy_refcounts=off "$TEST_IMG" 64M
121fef9c191SJeff Codytest_qemu_img create -f $IMGFMT -o compat=0.10,lazy_refcounts=on "$TEST_IMG" 64M
1224dc9f9d6SKevin Wolf
123975a7bd2SConnor Kuehlecho "== Expect error when backing file name is empty string =="
124975a7bd2SConnor Kuehlecho
125975a7bd2SConnor Kuehltest_qemu_img create -f $IMGFMT -b '' $TEST_IMG 1M
126975a7bd2SConnor Kuehl
1274dc9f9d6SKevin Wolf# success, all done
1284dc9f9d6SKevin Wolfecho "*** done"
1294dc9f9d6SKevin Wolfrm -f $seq.full
1304dc9f9d6SKevin Wolfstatus=0
131