xref: /openbmc/qemu/tests/qemu-iotests/049 (revision fef9c19139f4d69a080d99b8cbade163d0bbf0fc)
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 Wolftmp=/tmp/$$
294dc9f9d6SKevin Wolfstatus=1	# failure is the default!
304dc9f9d6SKevin Wolf
314dc9f9d6SKevin Wolf_cleanup()
324dc9f9d6SKevin Wolf{
334dc9f9d6SKevin Wolf	_cleanup_test_img
344dc9f9d6SKevin Wolf}
354dc9f9d6SKevin Wolftrap "_cleanup; exit \$status" 0 1 2 3 15
364dc9f9d6SKevin Wolf
374dc9f9d6SKevin Wolf# get standard environment, filters and checks
384dc9f9d6SKevin Wolf. ./common.rc
394dc9f9d6SKevin Wolf. ./common.filter
404dc9f9d6SKevin Wolf
414dc9f9d6SKevin Wolf_supported_fmt qcow2
424dc9f9d6SKevin Wolf_supported_proto file
434dc9f9d6SKevin Wolf_supported_os Linux
444dc9f9d6SKevin Wolf
454dc9f9d6SKevin Wolffunction filter_test_dir()
464dc9f9d6SKevin Wolf{
474dc9f9d6SKevin Wolf    sed -e "s#$IMGPROTO:$TEST_DIR#TEST_DIR#g" \
484dc9f9d6SKevin Wolf        -e "s#$TEST_DIR#TEST_DIR#g"
494dc9f9d6SKevin Wolf}
504dc9f9d6SKevin Wolf
514dc9f9d6SKevin Wolffunction test_qemu_img()
524dc9f9d6SKevin Wolf{
534dc9f9d6SKevin Wolf    echo qemu-img "$@" | filter_test_dir
544dc9f9d6SKevin Wolf    $QEMU_IMG "$@" 2>&1 | filter_test_dir
554dc9f9d6SKevin Wolf    echo
564dc9f9d6SKevin Wolf}
574dc9f9d6SKevin Wolf
584dc9f9d6SKevin Wolfecho "=== Check correct interpretation of suffixes for image size ==="
594dc9f9d6SKevin Wolfecho
604dc9f9d6SKevin Wolfsizes="1024 1024b 1k 1K 1M 1G 1T "
614dc9f9d6SKevin Wolfsizes+="1024.0 1024.0b 1.5k 1.5K 1.5M 1.5G 1.5T"
624dc9f9d6SKevin Wolf
634dc9f9d6SKevin Wolfecho "== 1. Traditional size parameter =="
644dc9f9d6SKevin Wolfecho
654dc9f9d6SKevin Wolffor s in $sizes; do
66*fef9c191SJeff Cody    test_qemu_img create -f $IMGFMT "$TEST_IMG" $s
674dc9f9d6SKevin Wolfdone
684dc9f9d6SKevin Wolf
694dc9f9d6SKevin Wolfecho "== 2. Specifying size via -o =="
704dc9f9d6SKevin Wolfecho
714dc9f9d6SKevin Wolffor s in $sizes; do
72*fef9c191SJeff Cody    test_qemu_img create -f $IMGFMT -o size=$s "$TEST_IMG"
734dc9f9d6SKevin Wolfdone
744dc9f9d6SKevin Wolf
754dc9f9d6SKevin Wolfecho "== 3. Invalid sizes =="
764dc9f9d6SKevin Wolfecho
774dc9f9d6SKevin Wolfsizes="-1024 -1k 1kilobyte foobar"
784dc9f9d6SKevin Wolf
794dc9f9d6SKevin Wolffor s in $sizes; do
80*fef9c191SJeff Cody    test_qemu_img create -f $IMGFMT "$TEST_IMG" -- $s
81*fef9c191SJeff Cody    test_qemu_img create -f $IMGFMT -o size=$s "$TEST_IMG"
824dc9f9d6SKevin Wolfdone
834dc9f9d6SKevin Wolf
844dc9f9d6SKevin Wolfecho "== Check correct interpretation of suffixes for cluster size =="
854dc9f9d6SKevin Wolfecho
864dc9f9d6SKevin Wolfsizes="1024 1024b 1k 1K 1M "
874dc9f9d6SKevin Wolfsizes+="1024.0 1024.0b 0.5k 0.5K 0.5M"
884dc9f9d6SKevin Wolf
894dc9f9d6SKevin Wolffor s in $sizes; do
90*fef9c191SJeff Cody    test_qemu_img create -f $IMGFMT -o cluster_size=$s "$TEST_IMG" 64M
914dc9f9d6SKevin Wolfdone
924dc9f9d6SKevin Wolf
934dc9f9d6SKevin Wolfecho "== Check compat level option =="
944dc9f9d6SKevin Wolfecho
95*fef9c191SJeff Codytest_qemu_img create -f $IMGFMT -o compat=0.10 "$TEST_IMG" 64M
96*fef9c191SJeff Codytest_qemu_img create -f $IMGFMT -o compat=1.1 "$TEST_IMG" 64M
974dc9f9d6SKevin Wolf
98*fef9c191SJeff Codytest_qemu_img create -f $IMGFMT -o compat=0.42 "$TEST_IMG" 64M
99*fef9c191SJeff Codytest_qemu_img create -f $IMGFMT -o compat=foobar "$TEST_IMG" 64M
1004dc9f9d6SKevin Wolf
1014dc9f9d6SKevin Wolfecho "== Check preallocation option =="
1024dc9f9d6SKevin Wolfecho
103*fef9c191SJeff Codytest_qemu_img create -f $IMGFMT -o preallocation=off "$TEST_IMG" 64M
104*fef9c191SJeff Codytest_qemu_img create -f $IMGFMT -o preallocation=metadata "$TEST_IMG" 64M
105*fef9c191SJeff Codytest_qemu_img create -f $IMGFMT -o preallocation=1234 "$TEST_IMG" 64M
1064dc9f9d6SKevin Wolf
1074dc9f9d6SKevin Wolfecho "== Check encryption option =="
1084dc9f9d6SKevin Wolfecho
109*fef9c191SJeff Codytest_qemu_img create -f $IMGFMT -o encryption=off "$TEST_IMG" 64M
110*fef9c191SJeff Codytest_qemu_img create -f $IMGFMT -o encryption=on "$TEST_IMG" 64M
1114dc9f9d6SKevin Wolf
1124dc9f9d6SKevin Wolfecho "== Check lazy_refcounts option (only with v3) =="
1134dc9f9d6SKevin Wolfecho
114*fef9c191SJeff Codytest_qemu_img create -f $IMGFMT -o compat=1.1,lazy_refcounts=off "$TEST_IMG" 64M
115*fef9c191SJeff Codytest_qemu_img create -f $IMGFMT -o compat=1.1,lazy_refcounts=on "$TEST_IMG" 64M
1164dc9f9d6SKevin Wolf
117*fef9c191SJeff Codytest_qemu_img create -f $IMGFMT -o compat=0.10,lazy_refcounts=off "$TEST_IMG" 64M
118*fef9c191SJeff Codytest_qemu_img create -f $IMGFMT -o compat=0.10,lazy_refcounts=on "$TEST_IMG" 64M
1194dc9f9d6SKevin Wolf
1204dc9f9d6SKevin Wolf# success, all done
1214dc9f9d6SKevin Wolfecho "*** done"
1224dc9f9d6SKevin Wolfrm -f $seq.full
1234dc9f9d6SKevin Wolfstatus=0
124