xref: /qemu/tests/qemu-iotests/051 (revision 17b005f1d422d4581f8ce95b75d603deb081f4f3)
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
671ab39193SJeff Codycp "$TEST_IMG" "$TEST_IMG.orig"
681ab39193SJeff Codymv "$TEST_IMG" "$TEST_IMG.base"
691ab39193SJeff Cody_make_test_img -b "$TEST_IMG.base" $size
7047e5df21SKevin Wolf
7147e5df21SKevin Wolfecho
7247e5df21SKevin Wolfecho === Unknown option ===
7347e5df21SKevin Wolfecho
7447e5df21SKevin Wolf
75fef9c191SJeff Codyrun_qemu -drive file="$TEST_IMG",format=qcow2,unknown_opt=
76fef9c191SJeff Codyrun_qemu -drive file="$TEST_IMG",format=qcow2,unknown_opt=on
77fef9c191SJeff Codyrun_qemu -drive file="$TEST_IMG",format=qcow2,unknown_opt=1234
78fef9c191SJeff Codyrun_qemu -drive file="$TEST_IMG",format=qcow2,unknown_opt=foo
7947e5df21SKevin Wolf
804db9c980SFam Zhengecho
81eb909c7fSKevin Wolfecho === Unknown protocol option ===
82eb909c7fSKevin Wolfecho
83eb909c7fSKevin Wolf
84eb909c7fSKevin Wolfrun_qemu -drive file="$TEST_IMG",format=qcow2,file.unknown_opt=
85eb909c7fSKevin Wolfrun_qemu -drive file="$TEST_IMG",format=qcow2,file.unknown_opt=on
86eb909c7fSKevin Wolfrun_qemu -drive file="$TEST_IMG",format=qcow2,file.unknown_opt=1234
87eb909c7fSKevin Wolfrun_qemu -drive file="$TEST_IMG",format=qcow2,file.unknown_opt=foo
88eb909c7fSKevin Wolf
89eb909c7fSKevin Wolfecho
9006d22aa3SKevin Wolfecho === Invalid format ===
9106d22aa3SKevin Wolfecho
9206d22aa3SKevin Wolf
9306d22aa3SKevin Wolfrun_qemu -drive file="$TEST_IMG",format=foo
9406d22aa3SKevin Wolfrun_qemu -drive file="$TEST_IMG",driver=foo
95*17b005f1SKevin Wolfrun_qemu -drive file="$TEST_IMG",driver=raw,format=qcow2
9606d22aa3SKevin Wolf
9706d22aa3SKevin Wolfecho
984db9c980SFam Zhengecho === Overriding backing file ===
994db9c980SFam Zhengecho
1004db9c980SFam Zheng
1011ab39193SJeff Codyecho "info block" | run_qemu -drive file="$TEST_IMG",driver=qcow2,backing.file.filename="$TEST_IMG.orig" -nodefaults
10247e5df21SKevin Wolf
10347e5df21SKevin Wolfecho
10447e5df21SKevin Wolfecho === Enable and disable lazy refcounting on the command line, plus some invalid values ===
10547e5df21SKevin Wolfecho
10647e5df21SKevin Wolf
107fef9c191SJeff Codyrun_qemu -drive file="$TEST_IMG",format=qcow2,lazy-refcounts=on
108fef9c191SJeff Codyrun_qemu -drive file="$TEST_IMG",format=qcow2,lazy-refcounts=off
109fef9c191SJeff Codyrun_qemu -drive file="$TEST_IMG",format=qcow2,lazy-refcounts=
110fef9c191SJeff Codyrun_qemu -drive file="$TEST_IMG",format=qcow2,lazy-refcounts=42
111fef9c191SJeff Codyrun_qemu -drive file="$TEST_IMG",format=qcow2,lazy-refcounts=foo
11247e5df21SKevin Wolf
11347e5df21SKevin Wolf
11447e5df21SKevin Wolfecho
11547e5df21SKevin Wolfecho === With version 2 images enabling lazy refcounts must fail ===
11647e5df21SKevin Wolfecho
11747e5df21SKevin Wolf
11847e5df21SKevin Wolf_make_test_img -ocompat=0.10 $size
11947e5df21SKevin Wolf
120fef9c191SJeff Codyrun_qemu -drive file="$TEST_IMG",format=qcow2,lazy-refcounts=on
121fef9c191SJeff Codyrun_qemu -drive file="$TEST_IMG",format=qcow2,lazy-refcounts=off
12247e5df21SKevin Wolf
12347e5df21SKevin Wolfecho
12447e5df21SKevin Wolfecho === No medium ===
12547e5df21SKevin Wolfecho
12647e5df21SKevin Wolf
12747e5df21SKevin Wolfrun_qemu -drive if=floppy
12847e5df21SKevin Wolfrun_qemu -drive if=ide,media=cdrom
12947e5df21SKevin Wolfrun_qemu -drive if=scsi,media=cdrom
13047e5df21SKevin Wolf
13147e5df21SKevin Wolfrun_qemu -drive if=ide
13247e5df21SKevin Wolfrun_qemu -drive if=virtio
13347e5df21SKevin Wolfrun_qemu -drive if=scsi
13447e5df21SKevin Wolf
13547e5df21SKevin Wolfrun_qemu -drive if=none,id=disk -device ide-cd,drive=disk
13647e5df21SKevin Wolfrun_qemu -drive if=none,id=disk -device lsi53c895a -device scsi-cd,drive=disk
13747e5df21SKevin Wolf
13847e5df21SKevin Wolfrun_qemu -drive if=none,id=disk -device ide-drive,drive=disk
13947e5df21SKevin Wolfrun_qemu -drive if=none,id=disk -device ide-hd,drive=disk
14047e5df21SKevin Wolfrun_qemu -drive if=none,id=disk -device lsi53c895a -device scsi-disk,drive=disk
14147e5df21SKevin Wolfrun_qemu -drive if=none,id=disk -device lsi53c895a -device scsi-hd,drive=disk
14247e5df21SKevin Wolf
14347e5df21SKevin Wolfecho
14447e5df21SKevin Wolfecho === Read-only ===
14547e5df21SKevin Wolfecho
14647e5df21SKevin Wolf
147fef9c191SJeff Codyrun_qemu -drive file="$TEST_IMG",if=floppy,readonly=on
148fef9c191SJeff Codyrun_qemu -drive file="$TEST_IMG",if=ide,media=cdrom,readonly=on
149fef9c191SJeff Codyrun_qemu -drive file="$TEST_IMG",if=scsi,media=cdrom,readonly=on
15047e5df21SKevin Wolf
151fef9c191SJeff Codyrun_qemu -drive file="$TEST_IMG",if=ide,readonly=on
152fef9c191SJeff Codyrun_qemu -drive file="$TEST_IMG",if=virtio,readonly=on
153fef9c191SJeff Codyrun_qemu -drive file="$TEST_IMG",if=scsi,readonly=on
15447e5df21SKevin Wolf
155fef9c191SJeff Codyrun_qemu -drive file="$TEST_IMG",if=none,id=disk,readonly=on -device ide-cd,drive=disk
156fef9c191SJeff Codyrun_qemu -drive file="$TEST_IMG",if=none,id=disk,readonly=on -device lsi53c895a -device scsi-cd,drive=disk
15747e5df21SKevin Wolf
158fef9c191SJeff Codyrun_qemu -drive file="$TEST_IMG",if=none,id=disk,readonly=on -device ide-drive,drive=disk
159fef9c191SJeff Codyrun_qemu -drive file="$TEST_IMG",if=none,id=disk,readonly=on -device ide-hd,drive=disk
160fef9c191SJeff Codyrun_qemu -drive file="$TEST_IMG",if=none,id=disk,readonly=on -device lsi53c895a -device scsi-disk,drive=disk
161fef9c191SJeff Codyrun_qemu -drive file="$TEST_IMG",if=none,id=disk,readonly=on -device lsi53c895a -device scsi-hd,drive=disk
16247e5df21SKevin Wolf
16347e5df21SKevin Wolfecho
16447e5df21SKevin Wolfecho === Cache modes ===
16547e5df21SKevin Wolfecho
16647e5df21SKevin Wolf
16747e5df21SKevin Wolf# Cannot use the test image because cache=none might not work on the host FS
16847e5df21SKevin Wolf# Use cdrom so that we won't get errors about missing media
16947e5df21SKevin Wolf
17047e5df21SKevin Wolfrun_qemu -drive media=cdrom,cache=none
17147e5df21SKevin Wolfrun_qemu -drive media=cdrom,cache=directsync
17247e5df21SKevin Wolfrun_qemu -drive media=cdrom,cache=writeback
17347e5df21SKevin Wolfrun_qemu -drive media=cdrom,cache=writethrough
17447e5df21SKevin Wolfrun_qemu -drive media=cdrom,cache=unsafe
17547e5df21SKevin Wolfrun_qemu -drive media=cdrom,cache=invalid_value
17647e5df21SKevin Wolf
1772af5ef70SKevin Wolfecho
1782af5ef70SKevin Wolfecho === Specifying the protocol layer ===
1792af5ef70SKevin Wolfecho
1802af5ef70SKevin Wolf
181fef9c191SJeff Codyrun_qemu -drive file="$TEST_IMG",file.driver=file
182fef9c191SJeff Codyrun_qemu -drive file="$TEST_IMG",file.driver=qcow2
1832af5ef70SKevin Wolf
18498289620SKevin Wolfecho
185765003dbSKevin Wolfecho === Leaving out required options ===
186765003dbSKevin Wolfecho
187765003dbSKevin Wolf
188765003dbSKevin Wolfrun_qemu -drive driver=file
189765003dbSKevin Wolfrun_qemu -drive driver=nbd
190765003dbSKevin Wolfrun_qemu -drive driver=raw
191765003dbSKevin Wolfrun_qemu -drive file.driver=file
192765003dbSKevin Wolfrun_qemu -drive file.driver=nbd
193765003dbSKevin Wolfrun_qemu -drive file.driver=raw
194765003dbSKevin Wolfrun_qemu -drive foo=bar
195765003dbSKevin Wolf
196765003dbSKevin Wolfecho
19798289620SKevin Wolfecho === Parsing protocol from file name ===
19898289620SKevin Wolfecho
19998289620SKevin Wolf
20098289620SKevin Wolf# Protocol strings are supposed to be parsed from traditional option strings,
20198289620SKevin Wolf# but not when using driver-specific options. We can distinguish them by the
20298289620SKevin Wolf# error message for non-existing files.
20398289620SKevin Wolf
20498289620SKevin Wolfrun_qemu -hda foo:bar
20598289620SKevin Wolfrun_qemu -drive file=foo:bar
20698289620SKevin Wolfrun_qemu -drive file.filename=foo:bar
20798289620SKevin Wolf
208e3fa4bfaSKevin Wolfrun_qemu -hda "file:$TEST_IMG"
209e3fa4bfaSKevin Wolfrun_qemu -drive file="file:$TEST_IMG"
210e3fa4bfaSKevin Wolfrun_qemu -drive file.filename="file:$TEST_IMG"
211e3fa4bfaSKevin Wolf
212f32f988cSKevin Wolfecho
213f32f988cSKevin Wolfecho === Snapshot mode ===
214f32f988cSKevin Wolfecho
215f32f988cSKevin Wolf
216f32f988cSKevin Wolf$QEMU_IO -c "write -P 0x11 0 4k" "$TEST_IMG" | _filter_qemu_io
217f32f988cSKevin Wolf
218f32f988cSKevin Wolfecho 'qemu-io ide0-hd0 "write -P 0x22 0 4k"' | run_qemu -drive file="$TEST_IMG" -snapshot | _filter_qemu_io
219f32f988cSKevin Wolfecho 'qemu-io ide0-hd0 "write -P 0x22 0 4k"' | run_qemu -drive file="$TEST_IMG",snapshot=on | _filter_qemu_io
220f32f988cSKevin Wolfecho 'qemu-io ide0-hd0 "write -P 0x22 0 4k"' | run_qemu -drive file.filename="$TEST_IMG",driver=qcow2,snapshot=on | _filter_qemu_io
221f32f988cSKevin Wolfecho 'qemu-io ide0-hd0 "write -P 0x22 0 4k"' | run_qemu -drive file.filename="$TEST_IMG",driver=qcow2 -snapshot | _filter_qemu_io
222b998875dSKevin Wolfecho 'qemu-io ide0-hd0 "write -P 0x22 0 4k"' | run_qemu -drive file="file:$TEST_IMG" -snapshot | _filter_qemu_io
223b998875dSKevin Wolfecho 'qemu-io ide0-hd0 "write -P 0x22 0 4k"' | run_qemu -drive file="file:$TEST_IMG",snapshot=on | _filter_qemu_io
224b998875dSKevin Wolf
225b998875dSKevin Wolf# Opening a read-only file r/w with snapshot=on
226b998875dSKevin Wolfchmod u-w "$TEST_IMG"
227b998875dSKevin Wolfecho 'qemu-io ide0-hd0 "write -P 0x22 0 4k"' | run_qemu -drive file="$TEST_IMG" -snapshot | _filter_qemu_io
228b998875dSKevin Wolfecho 'qemu-io ide0-hd0 "write -P 0x22 0 4k"' | run_qemu -drive file="$TEST_IMG",snapshot=on | _filter_qemu_io
229b998875dSKevin Wolfchmod u+w "$TEST_IMG"
230f32f988cSKevin Wolf
231f32f988cSKevin Wolf$QEMU_IO -c "read -P 0x11 0 4k" "$TEST_IMG" | _filter_qemu_io
232f32f988cSKevin Wolf
233f32f988cSKevin Wolfecho 'qemu-io ide0-hd0 "write -P 0x22 0 4k"' | run_qemu -drive file="$TEST_IMG",snapshot=off | _filter_qemu_io
234f32f988cSKevin Wolf
235f32f988cSKevin Wolf$QEMU_IO -c "read -P 0x22 0 4k" "$TEST_IMG" | _filter_qemu_io
236f32f988cSKevin Wolf
237b1e6fc08SKevin Wolfecho -e 'qemu-io ide0-hd0 "write -P 0x33 0 4k"\ncommit ide0-hd0' | run_qemu -drive file="$TEST_IMG",snapshot=on | _filter_qemu_io
238b1e6fc08SKevin Wolf
239b1e6fc08SKevin Wolf$QEMU_IO -c "read -P 0x33 0 4k" "$TEST_IMG" | _filter_qemu_io
240b1e6fc08SKevin Wolf
24147e5df21SKevin Wolf# success, all done
24247e5df21SKevin Wolfecho "*** done"
24347e5df21SKevin Wolfrm -f $seq.full
24447e5df21SKevin Wolfstatus=0
245