blob: ed12fa49d7f5dfeb253d095a301eb56a280fa7b3 [file] [log] [blame]
Philippe Mathieu-Daudé11a82d12019-03-07 15:58:38 +01001#!/usr/bin/env bash
Vladimir Sementsov-Ogievskiy9dd003a2021-01-16 16:44:19 +03002# group: rw auto
Kevin Wolf4dc9f9d2013-01-29 10:46:52 +01003#
4# Check qemu-img option parsing
5#
6# Copyright (C) 2013 Red Hat, Inc.
7#
8# This program is free software; you can redistribute it and/or modify
9# it under the terms of the GNU General Public License as published by
10# the Free Software Foundation; either version 2 of the License, or
11# (at your option) any later version.
12#
13# This program is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16# GNU General Public License for more details.
17#
18# You should have received a copy of the GNU General Public License
19# along with this program. If not, see <http://www.gnu.org/licenses/>.
20#
21
22# creator
23owner=kwolf@redhat.com
24
25seq=`basename $0`
26echo "QA output created by $seq"
27
Kevin Wolf4dc9f9d2013-01-29 10:46:52 +010028status=1 # failure is the default!
29
30_cleanup()
31{
32 _cleanup_test_img
33}
34trap "_cleanup; exit \$status" 0 1 2 3 15
35
36# get standard environment, filters and checks
37. ./common.rc
38. ./common.filter
39
40_supported_fmt qcow2
41_supported_proto file
Kevin Wolf4dc9f9d2013-01-29 10:46:52 +010042
Eric Blake8cedcff2018-11-16 15:50:02 -060043filter_test_dir()
Kevin Wolf4dc9f9d2013-01-29 10:46:52 +010044{
45 sed -e "s#$IMGPROTO:$TEST_DIR#TEST_DIR#g" \
46 -e "s#$TEST_DIR#TEST_DIR#g"
47}
48
Eric Blake8cedcff2018-11-16 15:50:02 -060049test_qemu_img()
Kevin Wolf4dc9f9d2013-01-29 10:46:52 +010050{
51 echo qemu-img "$@" | filter_test_dir
52 $QEMU_IMG "$@" 2>&1 | filter_test_dir
53 echo
54}
55
56echo "=== Check correct interpretation of suffixes for image size ==="
57echo
58sizes="1024 1024b 1k 1K 1M 1G 1T "
59sizes+="1024.0 1024.0b 1.5k 1.5K 1.5M 1.5G 1.5T"
60
61echo "== 1. Traditional size parameter =="
62echo
63for s in $sizes; do
Jeff Codyfef9c192013-09-25 08:12:22 -040064 test_qemu_img create -f $IMGFMT "$TEST_IMG" $s
Kevin Wolf4dc9f9d2013-01-29 10:46:52 +010065done
66
67echo "== 2. Specifying size via -o =="
68echo
69for s in $sizes; do
Jeff Codyfef9c192013-09-25 08:12:22 -040070 test_qemu_img create -f $IMGFMT -o size=$s "$TEST_IMG"
Kevin Wolf4dc9f9d2013-01-29 10:46:52 +010071done
72
73echo "== 3. Invalid sizes =="
74echo
75sizes="-1024 -1k 1kilobyte foobar"
76
77for s in $sizes; do
Jeff Codyfef9c192013-09-25 08:12:22 -040078 test_qemu_img create -f $IMGFMT "$TEST_IMG" -- $s
79 test_qemu_img create -f $IMGFMT -o size=$s "$TEST_IMG"
Kevin Wolf4dc9f9d2013-01-29 10:46:52 +010080done
81
Kevin Wolff6dc1c32019-11-26 16:45:49 +010082echo "== 4. Specify size twice (-o and traditional parameter) =="
83echo
84
85test_qemu_img create -f $IMGFMT -o size=10M "$TEST_IMG" 20M
86
Kevin Wolf4dc9f9d2013-01-29 10:46:52 +010087echo "== Check correct interpretation of suffixes for cluster size =="
88echo
89sizes="1024 1024b 1k 1K 1M "
90sizes+="1024.0 1024.0b 0.5k 0.5K 0.5M"
91
92for s in $sizes; do
Jeff Codyfef9c192013-09-25 08:12:22 -040093 test_qemu_img create -f $IMGFMT -o cluster_size=$s "$TEST_IMG" 64M
Kevin Wolf4dc9f9d2013-01-29 10:46:52 +010094done
95
96echo "== Check compat level option =="
97echo
Jeff Codyfef9c192013-09-25 08:12:22 -040098test_qemu_img create -f $IMGFMT -o compat=0.10 "$TEST_IMG" 64M
99test_qemu_img create -f $IMGFMT -o compat=1.1 "$TEST_IMG" 64M
Kevin Wolf4dc9f9d2013-01-29 10:46:52 +0100100
Jeff Codyfef9c192013-09-25 08:12:22 -0400101test_qemu_img create -f $IMGFMT -o compat=0.42 "$TEST_IMG" 64M
102test_qemu_img create -f $IMGFMT -o compat=foobar "$TEST_IMG" 64M
Kevin Wolf4dc9f9d2013-01-29 10:46:52 +0100103
104echo "== Check preallocation option =="
105echo
Jeff Codyfef9c192013-09-25 08:12:22 -0400106test_qemu_img create -f $IMGFMT -o preallocation=off "$TEST_IMG" 64M
107test_qemu_img create -f $IMGFMT -o preallocation=metadata "$TEST_IMG" 64M
108test_qemu_img create -f $IMGFMT -o preallocation=1234 "$TEST_IMG" 64M
Kevin Wolf4dc9f9d2013-01-29 10:46:52 +0100109
110echo "== Check encryption option =="
111echo
Jeff Codyfef9c192013-09-25 08:12:22 -0400112test_qemu_img create -f $IMGFMT -o encryption=off "$TEST_IMG" 64M
Daniel P. Berrangeb25b3872017-06-23 17:24:10 +0100113test_qemu_img create -f $IMGFMT --object secret,id=sec0,data=123456 -o encryption=on,encrypt.key-secret=sec0 "$TEST_IMG" 64M
Kevin Wolf4dc9f9d2013-01-29 10:46:52 +0100114
115echo "== Check lazy_refcounts option (only with v3) =="
116echo
Jeff Codyfef9c192013-09-25 08:12:22 -0400117test_qemu_img create -f $IMGFMT -o compat=1.1,lazy_refcounts=off "$TEST_IMG" 64M
118test_qemu_img create -f $IMGFMT -o compat=1.1,lazy_refcounts=on "$TEST_IMG" 64M
Kevin Wolf4dc9f9d2013-01-29 10:46:52 +0100119
Jeff Codyfef9c192013-09-25 08:12:22 -0400120test_qemu_img create -f $IMGFMT -o compat=0.10,lazy_refcounts=off "$TEST_IMG" 64M
121test_qemu_img create -f $IMGFMT -o compat=0.10,lazy_refcounts=on "$TEST_IMG" 64M
Kevin Wolf4dc9f9d2013-01-29 10:46:52 +0100122
Connor Kuehl975a7bd2020-08-13 08:47:22 -0500123echo "== Expect error when backing file name is empty string =="
124echo
125test_qemu_img create -f $IMGFMT -b '' $TEST_IMG 1M
126
Kevin Wolf4dc9f9d2013-01-29 10:46:52 +0100127# success, all done
128echo "*** done"
129rm -f $seq.full
130status=0