Philippe Mathieu-Daudé | 11a82d1 | 2019-03-07 15:58:38 +0100 | [diff] [blame] | 1 | #!/usr/bin/env bash |
Kevin Wolf | 4dc9f9d | 2013-01-29 10:46:52 +0100 | [diff] [blame] | 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 |
| 22 | owner=kwolf@redhat.com |
| 23 | |
| 24 | seq=`basename $0` |
| 25 | echo "QA output created by $seq" |
| 26 | |
Kevin Wolf | 4dc9f9d | 2013-01-29 10:46:52 +0100 | [diff] [blame] | 27 | status=1 # failure is the default! |
| 28 | |
| 29 | _cleanup() |
| 30 | { |
| 31 | _cleanup_test_img |
| 32 | } |
| 33 | trap "_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 |
Kevin Wolf | 4dc9f9d | 2013-01-29 10:46:52 +0100 | [diff] [blame] | 41 | |
Eric Blake | 8cedcff | 2018-11-16 15:50:02 -0600 | [diff] [blame] | 42 | filter_test_dir() |
Kevin Wolf | 4dc9f9d | 2013-01-29 10:46:52 +0100 | [diff] [blame] | 43 | { |
| 44 | sed -e "s#$IMGPROTO:$TEST_DIR#TEST_DIR#g" \ |
| 45 | -e "s#$TEST_DIR#TEST_DIR#g" |
| 46 | } |
| 47 | |
Eric Blake | 8cedcff | 2018-11-16 15:50:02 -0600 | [diff] [blame] | 48 | test_qemu_img() |
Kevin Wolf | 4dc9f9d | 2013-01-29 10:46:52 +0100 | [diff] [blame] | 49 | { |
| 50 | echo qemu-img "$@" | filter_test_dir |
| 51 | $QEMU_IMG "$@" 2>&1 | filter_test_dir |
| 52 | echo |
| 53 | } |
| 54 | |
| 55 | echo "=== Check correct interpretation of suffixes for image size ===" |
| 56 | echo |
| 57 | sizes="1024 1024b 1k 1K 1M 1G 1T " |
| 58 | sizes+="1024.0 1024.0b 1.5k 1.5K 1.5M 1.5G 1.5T" |
| 59 | |
| 60 | echo "== 1. Traditional size parameter ==" |
| 61 | echo |
| 62 | for s in $sizes; do |
Jeff Cody | fef9c19 | 2013-09-25 08:12:22 -0400 | [diff] [blame] | 63 | test_qemu_img create -f $IMGFMT "$TEST_IMG" $s |
Kevin Wolf | 4dc9f9d | 2013-01-29 10:46:52 +0100 | [diff] [blame] | 64 | done |
| 65 | |
| 66 | echo "== 2. Specifying size via -o ==" |
| 67 | echo |
| 68 | for s in $sizes; do |
Jeff Cody | fef9c19 | 2013-09-25 08:12:22 -0400 | [diff] [blame] | 69 | test_qemu_img create -f $IMGFMT -o size=$s "$TEST_IMG" |
Kevin Wolf | 4dc9f9d | 2013-01-29 10:46:52 +0100 | [diff] [blame] | 70 | done |
| 71 | |
| 72 | echo "== 3. Invalid sizes ==" |
| 73 | echo |
| 74 | sizes="-1024 -1k 1kilobyte foobar" |
| 75 | |
| 76 | for s in $sizes; do |
Jeff Cody | fef9c19 | 2013-09-25 08:12:22 -0400 | [diff] [blame] | 77 | test_qemu_img create -f $IMGFMT "$TEST_IMG" -- $s |
| 78 | test_qemu_img create -f $IMGFMT -o size=$s "$TEST_IMG" |
Kevin Wolf | 4dc9f9d | 2013-01-29 10:46:52 +0100 | [diff] [blame] | 79 | done |
| 80 | |
Kevin Wolf | f6dc1c3 | 2019-11-26 16:45:49 +0100 | [diff] [blame] | 81 | echo "== 4. Specify size twice (-o and traditional parameter) ==" |
| 82 | echo |
| 83 | |
| 84 | test_qemu_img create -f $IMGFMT -o size=10M "$TEST_IMG" 20M |
| 85 | |
Kevin Wolf | 4dc9f9d | 2013-01-29 10:46:52 +0100 | [diff] [blame] | 86 | echo "== Check correct interpretation of suffixes for cluster size ==" |
| 87 | echo |
| 88 | sizes="1024 1024b 1k 1K 1M " |
| 89 | sizes+="1024.0 1024.0b 0.5k 0.5K 0.5M" |
| 90 | |
| 91 | for s in $sizes; do |
Jeff Cody | fef9c19 | 2013-09-25 08:12:22 -0400 | [diff] [blame] | 92 | test_qemu_img create -f $IMGFMT -o cluster_size=$s "$TEST_IMG" 64M |
Kevin Wolf | 4dc9f9d | 2013-01-29 10:46:52 +0100 | [diff] [blame] | 93 | done |
| 94 | |
| 95 | echo "== Check compat level option ==" |
| 96 | echo |
Jeff Cody | fef9c19 | 2013-09-25 08:12:22 -0400 | [diff] [blame] | 97 | test_qemu_img create -f $IMGFMT -o compat=0.10 "$TEST_IMG" 64M |
| 98 | test_qemu_img create -f $IMGFMT -o compat=1.1 "$TEST_IMG" 64M |
Kevin Wolf | 4dc9f9d | 2013-01-29 10:46:52 +0100 | [diff] [blame] | 99 | |
Jeff Cody | fef9c19 | 2013-09-25 08:12:22 -0400 | [diff] [blame] | 100 | test_qemu_img create -f $IMGFMT -o compat=0.42 "$TEST_IMG" 64M |
| 101 | test_qemu_img create -f $IMGFMT -o compat=foobar "$TEST_IMG" 64M |
Kevin Wolf | 4dc9f9d | 2013-01-29 10:46:52 +0100 | [diff] [blame] | 102 | |
| 103 | echo "== Check preallocation option ==" |
| 104 | echo |
Jeff Cody | fef9c19 | 2013-09-25 08:12:22 -0400 | [diff] [blame] | 105 | test_qemu_img create -f $IMGFMT -o preallocation=off "$TEST_IMG" 64M |
| 106 | test_qemu_img create -f $IMGFMT -o preallocation=metadata "$TEST_IMG" 64M |
| 107 | test_qemu_img create -f $IMGFMT -o preallocation=1234 "$TEST_IMG" 64M |
Kevin Wolf | 4dc9f9d | 2013-01-29 10:46:52 +0100 | [diff] [blame] | 108 | |
| 109 | echo "== Check encryption option ==" |
| 110 | echo |
Jeff Cody | fef9c19 | 2013-09-25 08:12:22 -0400 | [diff] [blame] | 111 | test_qemu_img create -f $IMGFMT -o encryption=off "$TEST_IMG" 64M |
Daniel P. Berrange | b25b387 | 2017-06-23 17:24:10 +0100 | [diff] [blame] | 112 | test_qemu_img create -f $IMGFMT --object secret,id=sec0,data=123456 -o encryption=on,encrypt.key-secret=sec0 "$TEST_IMG" 64M |
Kevin Wolf | 4dc9f9d | 2013-01-29 10:46:52 +0100 | [diff] [blame] | 113 | |
| 114 | echo "== Check lazy_refcounts option (only with v3) ==" |
| 115 | echo |
Jeff Cody | fef9c19 | 2013-09-25 08:12:22 -0400 | [diff] [blame] | 116 | test_qemu_img create -f $IMGFMT -o compat=1.1,lazy_refcounts=off "$TEST_IMG" 64M |
| 117 | test_qemu_img create -f $IMGFMT -o compat=1.1,lazy_refcounts=on "$TEST_IMG" 64M |
Kevin Wolf | 4dc9f9d | 2013-01-29 10:46:52 +0100 | [diff] [blame] | 118 | |
Jeff Cody | fef9c19 | 2013-09-25 08:12:22 -0400 | [diff] [blame] | 119 | test_qemu_img create -f $IMGFMT -o compat=0.10,lazy_refcounts=off "$TEST_IMG" 64M |
| 120 | test_qemu_img create -f $IMGFMT -o compat=0.10,lazy_refcounts=on "$TEST_IMG" 64M |
Kevin Wolf | 4dc9f9d | 2013-01-29 10:46:52 +0100 | [diff] [blame] | 121 | |
Connor Kuehl | 975a7bd | 2020-08-13 08:47:22 -0500 | [diff] [blame] | 122 | echo "== Expect error when backing file name is empty string ==" |
| 123 | echo |
| 124 | test_qemu_img create -f $IMGFMT -b '' $TEST_IMG 1M |
| 125 | |
Kevin Wolf | 4dc9f9d | 2013-01-29 10:46:52 +0100 | [diff] [blame] | 126 | # success, all done |
| 127 | echo "*** done" |
| 128 | rm -f $seq.full |
| 129 | status=0 |