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 ( 4762ed9fa9SKevin Wolf if ! test -t 0; then 4862ed9fa9SKevin Wolf while read cmd; do 4962ed9fa9SKevin Wolf echo $cmd 5062ed9fa9SKevin Wolf done 5162ed9fa9SKevin Wolf fi 5262ed9fa9SKevin Wolf echo quit 5362ed9fa9SKevin Wolf ) | $QEMU -nodefaults -nographic -monitor stdio -serial none "$@" 5462ed9fa9SKevin Wolf echo 5562ed9fa9SKevin Wolf} 5662ed9fa9SKevin Wolf 5762ed9fa9SKevin Wolffunction run_qemu() 5862ed9fa9SKevin Wolf{ 5942190dccSMax Reitz do_run_qemu "$@" 2>&1 | _filter_testdir | _filter_imgfmt \ 6042190dccSMax Reitz | _filter_qemu | _filter_generated_node_ids 6162ed9fa9SKevin Wolf} 6262ed9fa9SKevin Wolf 6362ed9fa9SKevin Wolf 6462ed9fa9SKevin Wolfsize=128M 65*13a1d4a7SDaniel P. Berrangeif test "$IMGOPTSSYNTAX" = "true" 66*13a1d4a7SDaniel P. Berrangethen 67*13a1d4a7SDaniel P. Berrange SYSEMU_DRIVE_ARG=if=none,$TEST_IMG 68*13a1d4a7SDaniel P. Berrange SYSEMU_EXTRA_ARGS="" 69*13a1d4a7SDaniel P. Berrange if [ -n "$IMGKEYSECRET" ]; then 70*13a1d4a7SDaniel P. Berrange SECRET_ARG="secret,id=keysec0,data=$IMGKEYSECRET" 71*13a1d4a7SDaniel P. Berrange SYSEMU_EXTRA_ARGS="-object $SECRET_ARG" 72*13a1d4a7SDaniel P. Berrange fi 73*13a1d4a7SDaniel P. Berrangeelse 74*13a1d4a7SDaniel P. Berrange SYSEMU_DRIVE_ARG=if=none,file="$TEST_IMG",driver=$IMGFMT 75*13a1d4a7SDaniel P. Berrange SYSEMU_EXTRA_ARGS="" 76*13a1d4a7SDaniel P. Berrangefi 7762ed9fa9SKevin Wolf 7862ed9fa9SKevin Wolf_make_test_img $size 7962ed9fa9SKevin Wolf 8062ed9fa9SKevin Wolfecho 8162ed9fa9SKevin Wolfecho "=== Setting WCE with qdev and with manually created BB ===" 8262ed9fa9SKevin Wolfecho 8362ed9fa9SKevin Wolf 8462ed9fa9SKevin Wolf# The qdev option takes precedence, but if it isn't given or 'auto', the BB 8562ed9fa9SKevin Wolf# option is used instead. 8662ed9fa9SKevin Wolf 8762ed9fa9SKevin Wolffor cache in "writeback" "writethrough"; do 8862ed9fa9SKevin Wolf for wce in "" ",write-cache=auto" ",write-cache=on" ",write-cache=off"; do 89*13a1d4a7SDaniel P. Berrange echo "Testing: cache='$cache' wce='$wce'" 9062ed9fa9SKevin Wolf echo "info block" \ 91*13a1d4a7SDaniel P. Berrange | run_qemu $SYSEMU_EXTRA_ARGS -drive "$SYSEMU_DRIVE_ARG,cache=$cache" \ 9262ed9fa9SKevin Wolf -device "virtio-blk,drive=none0$wce" \ 9362ed9fa9SKevin Wolf | grep -e "Testing" -e "Cache mode" 9462ed9fa9SKevin Wolf done 9562ed9fa9SKevin Wolfdone 9662ed9fa9SKevin Wolf 9762ed9fa9SKevin Wolf# success, all done 9862ed9fa9SKevin Wolfecho "*** done" 9962ed9fa9SKevin Wolfrm -f $seq.full 10062ed9fa9SKevin Wolfstatus=0 101