xref: /qemu/tests/qemu-iotests/157 (revision 42190dcc70b34d59c81d72f1f8ff884aa27dd851)
162ed9fa9SKevin Wolf#!/bin/bash
262ed9fa9SKevin Wolf#
362ed9fa9SKevin Wolf# Test command line configuration of block devices with qdev
462ed9fa9SKevin Wolf#
562ed9fa9SKevin Wolf# Copyright (C) 2016 Red Hat, Inc.
662ed9fa9SKevin Wolf#
762ed9fa9SKevin Wolf# This program is free software; you can redistribute it and/or modify
862ed9fa9SKevin Wolf# it under the terms of the GNU General Public License as published by
962ed9fa9SKevin Wolf# the Free Software Foundation; either version 2 of the License, or
1062ed9fa9SKevin Wolf# (at your option) any later version.
1162ed9fa9SKevin Wolf#
1262ed9fa9SKevin Wolf# This program is distributed in the hope that it will be useful,
1362ed9fa9SKevin Wolf# but WITHOUT ANY WARRANTY; without even the implied warranty of
1462ed9fa9SKevin Wolf# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1562ed9fa9SKevin Wolf# GNU General Public License for more details.
1662ed9fa9SKevin Wolf#
1762ed9fa9SKevin Wolf# You should have received a copy of the GNU General Public License
1862ed9fa9SKevin Wolf# along with this program.  If not, see <http://www.gnu.org/licenses/>.
1962ed9fa9SKevin Wolf#
2062ed9fa9SKevin Wolf
2162ed9fa9SKevin Wolf# creator
2262ed9fa9SKevin Wolfowner=kwolf@redhat.com
2362ed9fa9SKevin Wolf
2462ed9fa9SKevin Wolfseq="$(basename $0)"
2562ed9fa9SKevin Wolfecho "QA output created by $seq"
2662ed9fa9SKevin Wolf
2762ed9fa9SKevin Wolfhere="$PWD"
2862ed9fa9SKevin Wolfstatus=1	# failure is the default!
2962ed9fa9SKevin Wolf
3062ed9fa9SKevin Wolf_cleanup()
3162ed9fa9SKevin Wolf{
3262ed9fa9SKevin Wolf	_cleanup_test_img
3362ed9fa9SKevin Wolf}
3462ed9fa9SKevin Wolftrap "_cleanup; exit \$status" 0 1 2 3 15
3562ed9fa9SKevin Wolf
3662ed9fa9SKevin Wolf# get standard environment, filters and checks
3762ed9fa9SKevin Wolf. ./common.rc
3862ed9fa9SKevin Wolf. ./common.filter
3962ed9fa9SKevin Wolf
4062ed9fa9SKevin Wolf_supported_fmt generic
4162ed9fa9SKevin Wolf_supported_proto file
4262ed9fa9SKevin Wolf_supported_os Linux
4362ed9fa9SKevin Wolf
4462ed9fa9SKevin Wolffunction do_run_qemu()
4562ed9fa9SKevin Wolf{
4662ed9fa9SKevin Wolf    echo Testing: "$@"
4762ed9fa9SKevin Wolf    (
4862ed9fa9SKevin Wolf        if ! test -t 0; then
4962ed9fa9SKevin Wolf            while read cmd; do
5062ed9fa9SKevin Wolf                echo $cmd
5162ed9fa9SKevin Wolf            done
5262ed9fa9SKevin Wolf        fi
5362ed9fa9SKevin Wolf        echo quit
5462ed9fa9SKevin Wolf    ) | $QEMU -nodefaults -nographic -monitor stdio -serial none "$@"
5562ed9fa9SKevin Wolf    echo
5662ed9fa9SKevin Wolf}
5762ed9fa9SKevin Wolf
5862ed9fa9SKevin Wolffunction run_qemu()
5962ed9fa9SKevin Wolf{
60*42190dccSMax Reitz    do_run_qemu "$@" 2>&1 | _filter_testdir | _filter_imgfmt \
61*42190dccSMax Reitz                          | _filter_qemu | _filter_generated_node_ids
6262ed9fa9SKevin Wolf}
6362ed9fa9SKevin Wolf
6462ed9fa9SKevin Wolf
6562ed9fa9SKevin Wolfsize=128M
6662ed9fa9SKevin Wolfdrive="if=none,file=$TEST_IMG,driver=$IMGFMT"
6762ed9fa9SKevin Wolf
6862ed9fa9SKevin Wolf_make_test_img $size
6962ed9fa9SKevin Wolf
7062ed9fa9SKevin Wolfecho
7162ed9fa9SKevin Wolfecho "=== Setting WCE with qdev and with manually created BB ==="
7262ed9fa9SKevin Wolfecho
7362ed9fa9SKevin Wolf
7462ed9fa9SKevin Wolf# The qdev option takes precedence, but if it isn't given or 'auto', the BB
7562ed9fa9SKevin Wolf# option is used instead.
7662ed9fa9SKevin Wolf
7762ed9fa9SKevin Wolffor cache in "writeback" "writethrough"; do
7862ed9fa9SKevin Wolf    for wce in "" ",write-cache=auto" ",write-cache=on" ",write-cache=off"; do
7962ed9fa9SKevin Wolf        echo "info block" \
8062ed9fa9SKevin Wolf            | run_qemu -drive "$drive,cache=$cache" \
8162ed9fa9SKevin Wolf                       -device "virtio-blk,drive=none0$wce" \
8262ed9fa9SKevin Wolf            | grep -e "Testing" -e "Cache mode"
8362ed9fa9SKevin Wolf    done
8462ed9fa9SKevin Wolfdone
8562ed9fa9SKevin Wolf
8662ed9fa9SKevin Wolf# success, all done
8762ed9fa9SKevin Wolfecho "*** done"
8862ed9fa9SKevin Wolfrm -f $seq.full
8962ed9fa9SKevin Wolfstatus=0
90