xref: /openbmc/qemu/tests/qemu-iotests/049 (revision c00506aa)
1#!/usr/bin/env bash
2#
3# Check qemu-img option parsing
4#
5# Copyright (C) 2013 Red Hat, Inc.
6#
7# This program is free software; you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by
9# the Free Software Foundation; either version 2 of the License, or
10# (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15# GNU General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License
18# along with this program.  If not, see <http://www.gnu.org/licenses/>.
19#
20
21# creator
22owner=kwolf@redhat.com
23
24seq=`basename $0`
25echo "QA output created by $seq"
26
27status=1	# failure is the default!
28
29_cleanup()
30{
31	_cleanup_test_img
32}
33trap "_cleanup; exit \$status" 0 1 2 3 15
34
35# get standard environment, filters and checks
36. ./common.rc
37. ./common.filter
38
39_supported_fmt qcow2
40_supported_proto file
41
42filter_test_dir()
43{
44    sed -e "s#$IMGPROTO:$TEST_DIR#TEST_DIR#g" \
45        -e "s#$TEST_DIR#TEST_DIR#g"
46}
47
48test_qemu_img()
49{
50    echo qemu-img "$@" | filter_test_dir
51    $QEMU_IMG "$@" 2>&1 | filter_test_dir
52    echo
53}
54
55echo "=== Check correct interpretation of suffixes for image size ==="
56echo
57sizes="1024 1024b 1k 1K 1M 1G 1T "
58sizes+="1024.0 1024.0b 1.5k 1.5K 1.5M 1.5G 1.5T"
59
60echo "== 1. Traditional size parameter =="
61echo
62for s in $sizes; do
63    test_qemu_img create -f $IMGFMT "$TEST_IMG" $s
64done
65
66echo "== 2. Specifying size via -o =="
67echo
68for s in $sizes; do
69    test_qemu_img create -f $IMGFMT -o size=$s "$TEST_IMG"
70done
71
72echo "== 3. Invalid sizes =="
73echo
74sizes="-1024 -1k 1kilobyte foobar"
75
76for s in $sizes; do
77    test_qemu_img create -f $IMGFMT "$TEST_IMG" -- $s
78    test_qemu_img create -f $IMGFMT -o size=$s "$TEST_IMG"
79done
80
81echo "== 4. Specify size twice (-o and traditional parameter) =="
82echo
83
84test_qemu_img create -f $IMGFMT -o size=10M "$TEST_IMG" 20M
85
86echo "== Check correct interpretation of suffixes for cluster size =="
87echo
88sizes="1024 1024b 1k 1K 1M "
89sizes+="1024.0 1024.0b 0.5k 0.5K 0.5M"
90
91for s in $sizes; do
92    test_qemu_img create -f $IMGFMT -o cluster_size=$s "$TEST_IMG" 64M
93done
94
95echo "== Check compat level option =="
96echo
97test_qemu_img create -f $IMGFMT -o compat=0.10 "$TEST_IMG" 64M
98test_qemu_img create -f $IMGFMT -o compat=1.1 "$TEST_IMG" 64M
99
100test_qemu_img create -f $IMGFMT -o compat=0.42 "$TEST_IMG" 64M
101test_qemu_img create -f $IMGFMT -o compat=foobar "$TEST_IMG" 64M
102
103echo "== Check preallocation option =="
104echo
105test_qemu_img create -f $IMGFMT -o preallocation=off "$TEST_IMG" 64M
106test_qemu_img create -f $IMGFMT -o preallocation=metadata "$TEST_IMG" 64M
107test_qemu_img create -f $IMGFMT -o preallocation=1234 "$TEST_IMG" 64M
108
109echo "== Check encryption option =="
110echo
111test_qemu_img create -f $IMGFMT -o encryption=off "$TEST_IMG" 64M
112test_qemu_img create -f $IMGFMT --object secret,id=sec0,data=123456 -o encryption=on,encrypt.key-secret=sec0 "$TEST_IMG" 64M
113
114echo "== Check lazy_refcounts option (only with v3) =="
115echo
116test_qemu_img create -f $IMGFMT -o compat=1.1,lazy_refcounts=off "$TEST_IMG" 64M
117test_qemu_img create -f $IMGFMT -o compat=1.1,lazy_refcounts=on "$TEST_IMG" 64M
118
119test_qemu_img create -f $IMGFMT -o compat=0.10,lazy_refcounts=off "$TEST_IMG" 64M
120test_qemu_img create -f $IMGFMT -o compat=0.10,lazy_refcounts=on "$TEST_IMG" 64M
121
122echo "== Expect error when backing file name is empty string =="
123echo
124test_qemu_img create -f $IMGFMT -b '' $TEST_IMG 1M
125
126# success, all done
127echo "*** done"
128rm -f $seq.full
129status=0
130