147e5df21SKevin Wolf#!/bin/bash 247e5df21SKevin Wolf# 347e5df21SKevin Wolf# Test command line configuration of block devices and driver-specific options 447e5df21SKevin Wolf# 547e5df21SKevin Wolf# Copyright (C) 2013 Red Hat, Inc. 647e5df21SKevin Wolf# 747e5df21SKevin Wolf# This program is free software; you can redistribute it and/or modify 847e5df21SKevin Wolf# it under the terms of the GNU General Public License as published by 947e5df21SKevin Wolf# the Free Software Foundation; either version 2 of the License, or 1047e5df21SKevin Wolf# (at your option) any later version. 1147e5df21SKevin Wolf# 1247e5df21SKevin Wolf# This program is distributed in the hope that it will be useful, 1347e5df21SKevin Wolf# but WITHOUT ANY WARRANTY; without even the implied warranty of 1447e5df21SKevin Wolf# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1547e5df21SKevin Wolf# GNU General Public License for more details. 1647e5df21SKevin Wolf# 1747e5df21SKevin Wolf# You should have received a copy of the GNU General Public License 1847e5df21SKevin Wolf# along with this program. If not, see <http://www.gnu.org/licenses/>. 1947e5df21SKevin Wolf# 2047e5df21SKevin Wolf 2147e5df21SKevin Wolf# creator 2247e5df21SKevin Wolfowner=kwolf@redhat.com 2347e5df21SKevin Wolf 2447e5df21SKevin Wolfseq=`basename $0` 2547e5df21SKevin Wolfecho "QA output created by $seq" 2647e5df21SKevin Wolf 2747e5df21SKevin Wolfhere=`pwd` 2847e5df21SKevin Wolftmp=/tmp/$$ 2947e5df21SKevin Wolfstatus=1 # failure is the default! 3047e5df21SKevin Wolf 3147e5df21SKevin Wolf_cleanup() 3247e5df21SKevin Wolf{ 3347e5df21SKevin Wolf _cleanup_test_img 3447e5df21SKevin Wolf} 3547e5df21SKevin Wolftrap "_cleanup; exit \$status" 0 1 2 3 15 3647e5df21SKevin Wolf 3747e5df21SKevin Wolf# get standard environment, filters and checks 3847e5df21SKevin Wolf. ./common.rc 3947e5df21SKevin Wolf. ./common.filter 4047e5df21SKevin Wolf 4147e5df21SKevin Wolf_supported_fmt qcow2 4247e5df21SKevin Wolf_supported_proto file 4347e5df21SKevin Wolf_supported_os Linux 4447e5df21SKevin Wolf 4547e5df21SKevin Wolffunction do_run_qemu() 4647e5df21SKevin Wolf{ 4747e5df21SKevin Wolf echo Testing: "$@" 484db9c980SFam Zheng ( 494db9c980SFam Zheng if ! test -t 0; then 504db9c980SFam Zheng while read cmd; do 514db9c980SFam Zheng echo $cmd 524db9c980SFam Zheng done 534db9c980SFam Zheng fi 544db9c980SFam Zheng echo quit 554db9c980SFam Zheng ) | $QEMU -nographic -monitor stdio -serial none "$@" 5647e5df21SKevin Wolf echo 5747e5df21SKevin Wolf} 5847e5df21SKevin Wolf 5947e5df21SKevin Wolffunction run_qemu() 6047e5df21SKevin Wolf{ 61c09b437bSStefan Hajnoczi do_run_qemu "$@" 2>&1 | _filter_testdir | _filter_qemu 6247e5df21SKevin Wolf} 6347e5df21SKevin Wolf 6447e5df21SKevin Wolfsize=128M 6547e5df21SKevin Wolf 6647e5df21SKevin Wolf_make_test_img $size 674db9c980SFam Zhengcp $TEST_IMG $TEST_IMG.orig 684db9c980SFam Zhengmv $TEST_IMG $TEST_IMG.base 694db9c980SFam Zheng_make_test_img -b $TEST_IMG.base $size 7047e5df21SKevin Wolf 7147e5df21SKevin Wolfecho 7247e5df21SKevin Wolfecho === Unknown option === 7347e5df21SKevin Wolfecho 7447e5df21SKevin Wolf 75*fef9c191SJeff Codyrun_qemu -drive file="$TEST_IMG",format=qcow2,unknown_opt= 76*fef9c191SJeff Codyrun_qemu -drive file="$TEST_IMG",format=qcow2,unknown_opt=on 77*fef9c191SJeff Codyrun_qemu -drive file="$TEST_IMG",format=qcow2,unknown_opt=1234 78*fef9c191SJeff Codyrun_qemu -drive file="$TEST_IMG",format=qcow2,unknown_opt=foo 7947e5df21SKevin Wolf 804db9c980SFam Zhengecho 814db9c980SFam Zhengecho === Overriding backing file === 824db9c980SFam Zhengecho 834db9c980SFam Zheng 844db9c980SFam Zhengecho "info block" | run_qemu -drive file=$TEST_IMG,driver=qcow2,backing.file.filename=$TEST_IMG.orig -nodefaults 8547e5df21SKevin Wolf 8647e5df21SKevin Wolfecho 8747e5df21SKevin Wolfecho === Enable and disable lazy refcounting on the command line, plus some invalid values === 8847e5df21SKevin Wolfecho 8947e5df21SKevin Wolf 90*fef9c191SJeff Codyrun_qemu -drive file="$TEST_IMG",format=qcow2,lazy-refcounts=on 91*fef9c191SJeff Codyrun_qemu -drive file="$TEST_IMG",format=qcow2,lazy-refcounts=off 92*fef9c191SJeff Codyrun_qemu -drive file="$TEST_IMG",format=qcow2,lazy-refcounts= 93*fef9c191SJeff Codyrun_qemu -drive file="$TEST_IMG",format=qcow2,lazy-refcounts=42 94*fef9c191SJeff Codyrun_qemu -drive file="$TEST_IMG",format=qcow2,lazy-refcounts=foo 9547e5df21SKevin Wolf 9647e5df21SKevin Wolf 9747e5df21SKevin Wolfecho 9847e5df21SKevin Wolfecho === With version 2 images enabling lazy refcounts must fail === 9947e5df21SKevin Wolfecho 10047e5df21SKevin Wolf 10147e5df21SKevin Wolf_make_test_img -ocompat=0.10 $size 10247e5df21SKevin Wolf 103*fef9c191SJeff Codyrun_qemu -drive file="$TEST_IMG",format=qcow2,lazy-refcounts=on 104*fef9c191SJeff Codyrun_qemu -drive file="$TEST_IMG",format=qcow2,lazy-refcounts=off 10547e5df21SKevin Wolf 10647e5df21SKevin Wolfecho 10747e5df21SKevin Wolfecho === No medium === 10847e5df21SKevin Wolfecho 10947e5df21SKevin Wolf 11047e5df21SKevin Wolfrun_qemu -drive if=floppy 11147e5df21SKevin Wolfrun_qemu -drive if=ide,media=cdrom 11247e5df21SKevin Wolfrun_qemu -drive if=scsi,media=cdrom 11347e5df21SKevin Wolf 11447e5df21SKevin Wolfrun_qemu -drive if=ide 11547e5df21SKevin Wolfrun_qemu -drive if=virtio 11647e5df21SKevin Wolfrun_qemu -drive if=scsi 11747e5df21SKevin Wolf 11847e5df21SKevin Wolfrun_qemu -drive if=none,id=disk -device ide-cd,drive=disk 11947e5df21SKevin Wolfrun_qemu -drive if=none,id=disk -device lsi53c895a -device scsi-cd,drive=disk 12047e5df21SKevin Wolf 12147e5df21SKevin Wolfrun_qemu -drive if=none,id=disk -device ide-drive,drive=disk 12247e5df21SKevin Wolfrun_qemu -drive if=none,id=disk -device ide-hd,drive=disk 12347e5df21SKevin Wolfrun_qemu -drive if=none,id=disk -device lsi53c895a -device scsi-disk,drive=disk 12447e5df21SKevin Wolfrun_qemu -drive if=none,id=disk -device lsi53c895a -device scsi-hd,drive=disk 12547e5df21SKevin Wolf 12647e5df21SKevin Wolfecho 12747e5df21SKevin Wolfecho === Read-only === 12847e5df21SKevin Wolfecho 12947e5df21SKevin Wolf 130*fef9c191SJeff Codyrun_qemu -drive file="$TEST_IMG",if=floppy,readonly=on 131*fef9c191SJeff Codyrun_qemu -drive file="$TEST_IMG",if=ide,media=cdrom,readonly=on 132*fef9c191SJeff Codyrun_qemu -drive file="$TEST_IMG",if=scsi,media=cdrom,readonly=on 13347e5df21SKevin Wolf 134*fef9c191SJeff Codyrun_qemu -drive file="$TEST_IMG",if=ide,readonly=on 135*fef9c191SJeff Codyrun_qemu -drive file="$TEST_IMG",if=virtio,readonly=on 136*fef9c191SJeff Codyrun_qemu -drive file="$TEST_IMG",if=scsi,readonly=on 13747e5df21SKevin Wolf 138*fef9c191SJeff Codyrun_qemu -drive file="$TEST_IMG",if=none,id=disk,readonly=on -device ide-cd,drive=disk 139*fef9c191SJeff Codyrun_qemu -drive file="$TEST_IMG",if=none,id=disk,readonly=on -device lsi53c895a -device scsi-cd,drive=disk 14047e5df21SKevin Wolf 141*fef9c191SJeff Codyrun_qemu -drive file="$TEST_IMG",if=none,id=disk,readonly=on -device ide-drive,drive=disk 142*fef9c191SJeff Codyrun_qemu -drive file="$TEST_IMG",if=none,id=disk,readonly=on -device ide-hd,drive=disk 143*fef9c191SJeff Codyrun_qemu -drive file="$TEST_IMG",if=none,id=disk,readonly=on -device lsi53c895a -device scsi-disk,drive=disk 144*fef9c191SJeff Codyrun_qemu -drive file="$TEST_IMG",if=none,id=disk,readonly=on -device lsi53c895a -device scsi-hd,drive=disk 14547e5df21SKevin Wolf 14647e5df21SKevin Wolfecho 14747e5df21SKevin Wolfecho === Cache modes === 14847e5df21SKevin Wolfecho 14947e5df21SKevin Wolf 15047e5df21SKevin Wolf# Cannot use the test image because cache=none might not work on the host FS 15147e5df21SKevin Wolf# Use cdrom so that we won't get errors about missing media 15247e5df21SKevin Wolf 15347e5df21SKevin Wolfrun_qemu -drive media=cdrom,cache=none 15447e5df21SKevin Wolfrun_qemu -drive media=cdrom,cache=directsync 15547e5df21SKevin Wolfrun_qemu -drive media=cdrom,cache=writeback 15647e5df21SKevin Wolfrun_qemu -drive media=cdrom,cache=writethrough 15747e5df21SKevin Wolfrun_qemu -drive media=cdrom,cache=unsafe 15847e5df21SKevin Wolfrun_qemu -drive media=cdrom,cache=invalid_value 15947e5df21SKevin Wolf 1602af5ef70SKevin Wolfecho 1612af5ef70SKevin Wolfecho === Specifying the protocol layer === 1622af5ef70SKevin Wolfecho 1632af5ef70SKevin Wolf 164*fef9c191SJeff Codyrun_qemu -drive file="$TEST_IMG",file.driver=file 165*fef9c191SJeff Codyrun_qemu -drive file="$TEST_IMG",file.driver=qcow2 1662af5ef70SKevin Wolf 16798289620SKevin Wolfecho 16898289620SKevin Wolfecho === Parsing protocol from file name === 16998289620SKevin Wolfecho 17098289620SKevin Wolf 17198289620SKevin Wolf# Protocol strings are supposed to be parsed from traditional option strings, 17298289620SKevin Wolf# but not when using driver-specific options. We can distinguish them by the 17398289620SKevin Wolf# error message for non-existing files. 17498289620SKevin Wolf 17598289620SKevin Wolfrun_qemu -hda foo:bar 17698289620SKevin Wolfrun_qemu -drive file=foo:bar 17798289620SKevin Wolfrun_qemu -drive file.filename=foo:bar 17898289620SKevin Wolf 17947e5df21SKevin Wolf# success, all done 18047e5df21SKevin Wolfecho "*** done" 18147e5df21SKevin Wolfrm -f $seq.full 18247e5df21SKevin Wolfstatus=0 183