1*11a82d14SPhilippe 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_supported_os Linux 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 824dc9f9d6SKevin Wolfecho "== Check correct interpretation of suffixes for cluster size ==" 834dc9f9d6SKevin Wolfecho 844dc9f9d6SKevin Wolfsizes="1024 1024b 1k 1K 1M " 854dc9f9d6SKevin Wolfsizes+="1024.0 1024.0b 0.5k 0.5K 0.5M" 864dc9f9d6SKevin Wolf 874dc9f9d6SKevin Wolffor s in $sizes; do 88fef9c191SJeff Cody test_qemu_img create -f $IMGFMT -o cluster_size=$s "$TEST_IMG" 64M 894dc9f9d6SKevin Wolfdone 904dc9f9d6SKevin Wolf 914dc9f9d6SKevin Wolfecho "== Check compat level option ==" 924dc9f9d6SKevin Wolfecho 93fef9c191SJeff Codytest_qemu_img create -f $IMGFMT -o compat=0.10 "$TEST_IMG" 64M 94fef9c191SJeff Codytest_qemu_img create -f $IMGFMT -o compat=1.1 "$TEST_IMG" 64M 954dc9f9d6SKevin Wolf 96fef9c191SJeff Codytest_qemu_img create -f $IMGFMT -o compat=0.42 "$TEST_IMG" 64M 97fef9c191SJeff Codytest_qemu_img create -f $IMGFMT -o compat=foobar "$TEST_IMG" 64M 984dc9f9d6SKevin Wolf 994dc9f9d6SKevin Wolfecho "== Check preallocation option ==" 1004dc9f9d6SKevin Wolfecho 101fef9c191SJeff Codytest_qemu_img create -f $IMGFMT -o preallocation=off "$TEST_IMG" 64M 102fef9c191SJeff Codytest_qemu_img create -f $IMGFMT -o preallocation=metadata "$TEST_IMG" 64M 103fef9c191SJeff Codytest_qemu_img create -f $IMGFMT -o preallocation=1234 "$TEST_IMG" 64M 1044dc9f9d6SKevin Wolf 1054dc9f9d6SKevin Wolfecho "== Check encryption option ==" 1064dc9f9d6SKevin Wolfecho 107fef9c191SJeff Codytest_qemu_img create -f $IMGFMT -o encryption=off "$TEST_IMG" 64M 108b25b387fSDaniel P. Berrangetest_qemu_img create -f $IMGFMT --object secret,id=sec0,data=123456 -o encryption=on,encrypt.key-secret=sec0 "$TEST_IMG" 64M 1094dc9f9d6SKevin Wolf 1104dc9f9d6SKevin Wolfecho "== Check lazy_refcounts option (only with v3) ==" 1114dc9f9d6SKevin Wolfecho 112fef9c191SJeff Codytest_qemu_img create -f $IMGFMT -o compat=1.1,lazy_refcounts=off "$TEST_IMG" 64M 113fef9c191SJeff Codytest_qemu_img create -f $IMGFMT -o compat=1.1,lazy_refcounts=on "$TEST_IMG" 64M 1144dc9f9d6SKevin Wolf 115fef9c191SJeff Codytest_qemu_img create -f $IMGFMT -o compat=0.10,lazy_refcounts=off "$TEST_IMG" 64M 116fef9c191SJeff Codytest_qemu_img create -f $IMGFMT -o compat=0.10,lazy_refcounts=on "$TEST_IMG" 64M 1174dc9f9d6SKevin Wolf 1184dc9f9d6SKevin Wolf# success, all done 1194dc9f9d6SKevin Wolfecho "*** done" 1204dc9f9d6SKevin Wolfrm -f $seq.full 1214dc9f9d6SKevin Wolfstatus=0 122