1*a33cc31dSKevin Wolf#!/bin/bash 2*a33cc31dSKevin Wolf# 3*a33cc31dSKevin Wolf# Test qemu-img command line parsing 4*a33cc31dSKevin Wolf# 5*a33cc31dSKevin Wolf# Copyright (C) 2014 Red Hat, Inc. 6*a33cc31dSKevin Wolf# 7*a33cc31dSKevin Wolf# This program is free software; you can redistribute it and/or modify 8*a33cc31dSKevin Wolf# it under the terms of the GNU General Public License as published by 9*a33cc31dSKevin Wolf# the Free Software Foundation; either version 2 of the License, or 10*a33cc31dSKevin Wolf# (at your option) any later version. 11*a33cc31dSKevin Wolf# 12*a33cc31dSKevin Wolf# This program is distributed in the hope that it will be useful, 13*a33cc31dSKevin Wolf# but WITHOUT ANY WARRANTY; without even the implied warranty of 14*a33cc31dSKevin Wolf# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15*a33cc31dSKevin Wolf# GNU General Public License for more details. 16*a33cc31dSKevin Wolf# 17*a33cc31dSKevin Wolf# You should have received a copy of the GNU General Public License 18*a33cc31dSKevin Wolf# along with this program. If not, see <http://www.gnu.org/licenses/>. 19*a33cc31dSKevin Wolf# 20*a33cc31dSKevin Wolf 21*a33cc31dSKevin Wolf# creator 22*a33cc31dSKevin Wolfowner=kwolf@redhat.com 23*a33cc31dSKevin Wolf 24*a33cc31dSKevin Wolfseq=`basename $0` 25*a33cc31dSKevin Wolfecho "QA output created by $seq" 26*a33cc31dSKevin Wolf 27*a33cc31dSKevin Wolfhere=`pwd` 28*a33cc31dSKevin Wolftmp=/tmp/$$ 29*a33cc31dSKevin Wolfstatus=1 # failure is the default! 30*a33cc31dSKevin Wolf 31*a33cc31dSKevin Wolf_cleanup() 32*a33cc31dSKevin Wolf{ 33*a33cc31dSKevin Wolf _cleanup_test_img 34*a33cc31dSKevin Wolf} 35*a33cc31dSKevin Wolftrap "_cleanup; exit \$status" 0 1 2 3 15 36*a33cc31dSKevin Wolf 37*a33cc31dSKevin Wolf# get standard environment, filters and checks 38*a33cc31dSKevin Wolf. ./common.rc 39*a33cc31dSKevin Wolf. ./common.filter 40*a33cc31dSKevin Wolf 41*a33cc31dSKevin Wolf_supported_fmt qcow2 42*a33cc31dSKevin Wolf_supported_proto file 43*a33cc31dSKevin Wolf_supported_os Linux 44*a33cc31dSKevin Wolf 45*a33cc31dSKevin Wolffunction run_qemu_img() 46*a33cc31dSKevin Wolf{ 47*a33cc31dSKevin Wolf echo 48*a33cc31dSKevin Wolf echo Testing: "$@" | _filter_testdir 49*a33cc31dSKevin Wolf "$QEMU_IMG" "$@" 2>&1 | _filter_testdir 50*a33cc31dSKevin Wolf} 51*a33cc31dSKevin Wolf 52*a33cc31dSKevin Wolfsize=128M 53*a33cc31dSKevin Wolf 54*a33cc31dSKevin Wolfecho 55*a33cc31dSKevin Wolfecho === create: Options specified more than once === 56*a33cc31dSKevin Wolf 57*a33cc31dSKevin Wolf# Last -f should win 58*a33cc31dSKevin Wolfrun_qemu_img create -f foo -f $IMGFMT "$TEST_IMG" $size 59*a33cc31dSKevin Wolfrun_qemu_img info "$TEST_IMG" 60*a33cc31dSKevin Wolf 61*a33cc31dSKevin Wolf# Multiple -o should be merged 62*a33cc31dSKevin Wolfrun_qemu_img create -f $IMGFMT -o cluster_size=4k -o lazy_refcounts=on "$TEST_IMG" $size 63*a33cc31dSKevin Wolfrun_qemu_img info "$TEST_IMG" 64*a33cc31dSKevin Wolf 65*a33cc31dSKevin Wolf# If the same -o key is specified more than once, the last one wins 66*a33cc31dSKevin Wolfrun_qemu_img create -f $IMGFMT -o cluster_size=4k -o lazy_refcounts=on -o cluster_size=8k "$TEST_IMG" $size 67*a33cc31dSKevin Wolfrun_qemu_img info "$TEST_IMG" 68*a33cc31dSKevin Wolfrun_qemu_img create -f $IMGFMT -o cluster_size=4k,cluster_size=8k "$TEST_IMG" $size 69*a33cc31dSKevin Wolfrun_qemu_img info "$TEST_IMG" 70*a33cc31dSKevin Wolf 71*a33cc31dSKevin Wolfecho 72*a33cc31dSKevin Wolfecho === create: help for -o === 73*a33cc31dSKevin Wolf 74*a33cc31dSKevin Wolf# Adding the help option to a command without other -o options 75*a33cc31dSKevin Wolfrun_qemu_img create -f $IMGFMT -o help "$TEST_IMG" $size 76*a33cc31dSKevin Wolfrun_qemu_img create -f $IMGFMT -o \? "$TEST_IMG" $size 77*a33cc31dSKevin Wolf 78*a33cc31dSKevin Wolf# Adding the help option to the same -o option 79*a33cc31dSKevin Wolfrun_qemu_img create -f $IMGFMT -o cluster_size=4k,help "$TEST_IMG" $size 80*a33cc31dSKevin Wolfrun_qemu_img create -f $IMGFMT -o cluster_size=4k,\? "$TEST_IMG" $size 81*a33cc31dSKevin Wolfrun_qemu_img create -f $IMGFMT -o help,cluster_size=4k "$TEST_IMG" $size 82*a33cc31dSKevin Wolfrun_qemu_img create -f $IMGFMT -o \?,cluster_size=4k "$TEST_IMG" $size 83*a33cc31dSKevin Wolf 84*a33cc31dSKevin Wolf# Adding the help option to a separate -o option 85*a33cc31dSKevin Wolfrun_qemu_img create -f $IMGFMT -o cluster_size=4k -o help "$TEST_IMG" $size 86*a33cc31dSKevin Wolfrun_qemu_img create -f $IMGFMT -o cluster_size=4k -o \? "$TEST_IMG" $size 87*a33cc31dSKevin Wolf 88*a33cc31dSKevin Wolf# Looks like a help option, but is part of the backing file name 89*a33cc31dSKevin Wolfrun_qemu_img create -f $IMGFMT -o backing_file="$TEST_IMG",,help "$TEST_IMG" $size 90*a33cc31dSKevin Wolfrun_qemu_img create -f $IMGFMT -o backing_file="$TEST_IMG",,\? "$TEST_IMG" $size 91*a33cc31dSKevin Wolf 92*a33cc31dSKevin Wolf# Try to trick qemu-img into creating escaped commas 93*a33cc31dSKevin Wolfrun_qemu_img create -f $IMGFMT -o backing_file="$TEST_IMG", -o help "$TEST_IMG" $size 94*a33cc31dSKevin Wolfrun_qemu_img create -f $IMGFMT -o backing_file="$TEST_IMG" -o ,help "$TEST_IMG" $size 95*a33cc31dSKevin Wolfrun_qemu_img create -f $IMGFMT -o backing_file="$TEST_IMG" -o ,, -o help "$TEST_IMG" $size 96*a33cc31dSKevin Wolf 97*a33cc31dSKevin Wolf# Leave out everything that isn't needed 98*a33cc31dSKevin Wolfrun_qemu_img create -f $IMGFMT -o help 99*a33cc31dSKevin Wolfrun_qemu_img create -o help 100*a33cc31dSKevin Wolf 101*a33cc31dSKevin Wolfecho 102*a33cc31dSKevin Wolfecho === convert: Options specified more than once === 103*a33cc31dSKevin Wolf 104*a33cc31dSKevin Wolf# We need a valid source image 105*a33cc31dSKevin Wolfrun_qemu_img create -f $IMGFMT "$TEST_IMG" $size 106*a33cc31dSKevin Wolf 107*a33cc31dSKevin Wolf# Last -f should win 108*a33cc31dSKevin Wolfrun_qemu_img convert -f foo -f $IMGFMT "$TEST_IMG" "$TEST_IMG".base 109*a33cc31dSKevin Wolfrun_qemu_img info "$TEST_IMG".base 110*a33cc31dSKevin Wolf 111*a33cc31dSKevin Wolf# Last -O should win 112*a33cc31dSKevin Wolfrun_qemu_img convert -O foo -O $IMGFMT "$TEST_IMG" "$TEST_IMG".base 113*a33cc31dSKevin Wolfrun_qemu_img info "$TEST_IMG".base 114*a33cc31dSKevin Wolf 115*a33cc31dSKevin Wolf# Multiple -o should be merged 116*a33cc31dSKevin Wolfrun_qemu_img convert -O $IMGFMT -o cluster_size=4k -o lazy_refcounts=on "$TEST_IMG" "$TEST_IMG".base 117*a33cc31dSKevin Wolfrun_qemu_img info "$TEST_IMG".base 118*a33cc31dSKevin Wolf 119*a33cc31dSKevin Wolf# If the same -o key is specified more than once, the last one wins 120*a33cc31dSKevin Wolfrun_qemu_img convert -O $IMGFMT -o cluster_size=4k -o lazy_refcounts=on -o cluster_size=8k "$TEST_IMG" "$TEST_IMG".base 121*a33cc31dSKevin Wolfrun_qemu_img info "$TEST_IMG".base 122*a33cc31dSKevin Wolfrun_qemu_img convert -O $IMGFMT -o cluster_size=4k,cluster_size=8k "$TEST_IMG" "$TEST_IMG".base 123*a33cc31dSKevin Wolfrun_qemu_img info "$TEST_IMG".base 124*a33cc31dSKevin Wolf 125*a33cc31dSKevin Wolfecho 126*a33cc31dSKevin Wolfecho === convert: help for -o === 127*a33cc31dSKevin Wolf 128*a33cc31dSKevin Wolf# Adding the help option to a command without other -o options 129*a33cc31dSKevin Wolfrun_qemu_img convert -O $IMGFMT -o help "$TEST_IMG" "$TEST_IMG".base 130*a33cc31dSKevin Wolfrun_qemu_img convert -O $IMGFMT -o \? "$TEST_IMG" "$TEST_IMG".base 131*a33cc31dSKevin Wolf 132*a33cc31dSKevin Wolf# Adding the help option to the same -o option 133*a33cc31dSKevin Wolfrun_qemu_img convert -O $IMGFMT -o cluster_size=4k,help "$TEST_IMG" "$TEST_IMG".base 134*a33cc31dSKevin Wolfrun_qemu_img convert -O $IMGFMT -o cluster_size=4k,\? "$TEST_IMG" "$TEST_IMG".base 135*a33cc31dSKevin Wolfrun_qemu_img convert -O $IMGFMT -o help,cluster_size=4k "$TEST_IMG" "$TEST_IMG".base 136*a33cc31dSKevin Wolfrun_qemu_img convert -O $IMGFMT -o \?,cluster_size=4k "$TEST_IMG" "$TEST_IMG".base 137*a33cc31dSKevin Wolf 138*a33cc31dSKevin Wolf# Adding the help option to a separate -o option 139*a33cc31dSKevin Wolfrun_qemu_img convert -O $IMGFMT -o cluster_size=4k -o help "$TEST_IMG" "$TEST_IMG".base 140*a33cc31dSKevin Wolfrun_qemu_img convert -O $IMGFMT -o cluster_size=4k -o \? "$TEST_IMG" "$TEST_IMG".base 141*a33cc31dSKevin Wolf 142*a33cc31dSKevin Wolf# Looks like a help option, but is part of the backing file name 143*a33cc31dSKevin Wolfrun_qemu_img convert -O $IMGFMT -o backing_file="$TEST_IMG",,help "$TEST_IMG" "$TEST_IMG".base 144*a33cc31dSKevin Wolfrun_qemu_img convert -O $IMGFMT -o backing_file="$TEST_IMG",,\? "$TEST_IMG" "$TEST_IMG".base 145*a33cc31dSKevin Wolf 146*a33cc31dSKevin Wolf# Try to trick qemu-img into creating escaped commas 147*a33cc31dSKevin Wolfrun_qemu_img convert -O $IMGFMT -o backing_file="$TEST_IMG", -o help "$TEST_IMG" "$TEST_IMG".base 148*a33cc31dSKevin Wolfrun_qemu_img convert -O $IMGFMT -o backing_file="$TEST_IMG" -o ,help "$TEST_IMG" "$TEST_IMG".base 149*a33cc31dSKevin Wolfrun_qemu_img convert -O $IMGFMT -o backing_file="$TEST_IMG" -o ,, -o help "$TEST_IMG" "$TEST_IMG".base 150*a33cc31dSKevin Wolf 151*a33cc31dSKevin Wolf# Leave out everything that isn't needed 152*a33cc31dSKevin Wolfrun_qemu_img convert -O $IMGFMT -o help 153*a33cc31dSKevin Wolfrun_qemu_img convert -o help 154*a33cc31dSKevin Wolf 155*a33cc31dSKevin Wolfecho 156*a33cc31dSKevin Wolfecho === amend: Options specified more than once === 157*a33cc31dSKevin Wolf 158*a33cc31dSKevin Wolf# Last -f should win 159*a33cc31dSKevin Wolfrun_qemu_img amend -f foo -f $IMGFMT -o lazy_refcounts=on "$TEST_IMG" 160*a33cc31dSKevin Wolfrun_qemu_img info "$TEST_IMG" 161*a33cc31dSKevin Wolf 162*a33cc31dSKevin Wolf# Multiple -o should be merged 163*a33cc31dSKevin Wolfrun_qemu_img amend -f $IMGFMT -o size=130M -o lazy_refcounts=off "$TEST_IMG" 164*a33cc31dSKevin Wolfrun_qemu_img info "$TEST_IMG" 165*a33cc31dSKevin Wolf 166*a33cc31dSKevin Wolf# If the same -o key is specified more than once, the last one wins 167*a33cc31dSKevin Wolfrun_qemu_img amend -f $IMGFMT -o size=8M -o lazy_refcounts=on -o size=132M "$TEST_IMG" 168*a33cc31dSKevin Wolfrun_qemu_img info "$TEST_IMG" 169*a33cc31dSKevin Wolfrun_qemu_img amend -f $IMGFMT -o size=4M,size=148M "$TEST_IMG" 170*a33cc31dSKevin Wolfrun_qemu_img info "$TEST_IMG" 171*a33cc31dSKevin Wolf 172*a33cc31dSKevin Wolfecho 173*a33cc31dSKevin Wolfecho === amend: help for -o === 174*a33cc31dSKevin Wolf 175*a33cc31dSKevin Wolf# Adding the help option to a command without other -o options 176*a33cc31dSKevin Wolfrun_qemu_img amend -f $IMGFMT -o help "$TEST_IMG" 177*a33cc31dSKevin Wolfrun_qemu_img amend -f $IMGFMT -o \? "$TEST_IMG" 178*a33cc31dSKevin Wolf 179*a33cc31dSKevin Wolf# Adding the help option to the same -o option 180*a33cc31dSKevin Wolfrun_qemu_img amend -f $IMGFMT -o cluster_size=4k,help "$TEST_IMG" 181*a33cc31dSKevin Wolfrun_qemu_img amend -f $IMGFMT -o cluster_size=4k,\? "$TEST_IMG" 182*a33cc31dSKevin Wolfrun_qemu_img amend -f $IMGFMT -o help,cluster_size=4k "$TEST_IMG" 183*a33cc31dSKevin Wolfrun_qemu_img amend -f $IMGFMT -o \?,cluster_size=4k "$TEST_IMG" 184*a33cc31dSKevin Wolf 185*a33cc31dSKevin Wolf# Adding the help option to a separate -o option 186*a33cc31dSKevin Wolfrun_qemu_img amend -f $IMGFMT -o cluster_size=4k -o help "$TEST_IMG" 187*a33cc31dSKevin Wolfrun_qemu_img amend -f $IMGFMT -o cluster_size=4k -o \? "$TEST_IMG" 188*a33cc31dSKevin Wolf 189*a33cc31dSKevin Wolf# Looks like a help option, but is part of the backing file name 190*a33cc31dSKevin Wolfrun_qemu_img amend -f $IMGFMT -o backing_file="$TEST_IMG",,help "$TEST_IMG" 191*a33cc31dSKevin Wolfrun_qemu_img rebase -u -b "" -f $IMGFMT "$TEST_IMG" 192*a33cc31dSKevin Wolf 193*a33cc31dSKevin Wolfrun_qemu_img amend -f $IMGFMT -o backing_file="$TEST_IMG",,\? "$TEST_IMG" 194*a33cc31dSKevin Wolfrun_qemu_img rebase -u -b "" -f $IMGFMT "$TEST_IMG" 195*a33cc31dSKevin Wolf 196*a33cc31dSKevin Wolf# Try to trick qemu-img into creating escaped commas 197*a33cc31dSKevin Wolfrun_qemu_img amend -f $IMGFMT -o backing_file="$TEST_IMG", -o help "$TEST_IMG" 198*a33cc31dSKevin Wolfrun_qemu_img amend -f $IMGFMT -o backing_file="$TEST_IMG" -o ,help "$TEST_IMG" 199*a33cc31dSKevin Wolfrun_qemu_img amend -f $IMGFMT -o backing_file="$TEST_IMG" -o ,, -o help "$TEST_IMG" 200*a33cc31dSKevin Wolf 201*a33cc31dSKevin Wolf# Leave out everything that isn't needed 202*a33cc31dSKevin Wolfrun_qemu_img amend -f $IMGFMT -o help 203*a33cc31dSKevin Wolfrun_qemu_img convert -o help 204*a33cc31dSKevin Wolf 205*a33cc31dSKevin Wolf# success, all done 206*a33cc31dSKevin Wolfecho "*** done" 207*a33cc31dSKevin Wolfrm -f $seq.full 208*a33cc31dSKevin Wolfstatus=0 209