111a82d14SPhilippe Mathieu-Daudé#!/usr/bin/env bash 29dd003a9SVladimir Sementsov-Ogievskiy# group: quick 362ed9fa9SKevin Wolf# 462ed9fa9SKevin Wolf# Test command line configuration of block devices with qdev 562ed9fa9SKevin Wolf# 662ed9fa9SKevin Wolf# Copyright (C) 2016 Red Hat, Inc. 762ed9fa9SKevin Wolf# 862ed9fa9SKevin Wolf# This program is free software; you can redistribute it and/or modify 962ed9fa9SKevin Wolf# it under the terms of the GNU General Public License as published by 1062ed9fa9SKevin Wolf# the Free Software Foundation; either version 2 of the License, or 1162ed9fa9SKevin Wolf# (at your option) any later version. 1262ed9fa9SKevin Wolf# 1362ed9fa9SKevin Wolf# This program is distributed in the hope that it will be useful, 1462ed9fa9SKevin Wolf# but WITHOUT ANY WARRANTY; without even the implied warranty of 1562ed9fa9SKevin Wolf# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1662ed9fa9SKevin Wolf# GNU General Public License for more details. 1762ed9fa9SKevin Wolf# 1862ed9fa9SKevin Wolf# You should have received a copy of the GNU General Public License 1962ed9fa9SKevin Wolf# along with this program. If not, see <http://www.gnu.org/licenses/>. 2062ed9fa9SKevin Wolf# 2162ed9fa9SKevin Wolf 2262ed9fa9SKevin Wolf# creator 2362ed9fa9SKevin Wolfowner=kwolf@redhat.com 2462ed9fa9SKevin Wolf 2562ed9fa9SKevin Wolfseq="$(basename $0)" 2662ed9fa9SKevin Wolfecho "QA output created by $seq" 2762ed9fa9SKevin Wolf 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 43*d9e40706SThomas Huth_require_devices virtio-blk 44*d9e40706SThomas Huth 458cedcffdSEric Blakedo_run_qemu() 4662ed9fa9SKevin Wolf{ 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 588cedcffdSEric Blakerun_qemu() 5962ed9fa9SKevin Wolf{ 6042190dccSMax Reitz do_run_qemu "$@" 2>&1 | _filter_testdir | _filter_imgfmt \ 6142190dccSMax Reitz | _filter_qemu | _filter_generated_node_ids 6262ed9fa9SKevin Wolf} 6362ed9fa9SKevin Wolf 6462ed9fa9SKevin Wolf 6562ed9fa9SKevin Wolfsize=128M 6613a1d4a7SDaniel P. Berrangeif test "$IMGOPTSSYNTAX" = "true" 6713a1d4a7SDaniel P. Berrangethen 6813a1d4a7SDaniel P. Berrange SYSEMU_DRIVE_ARG=if=none,$TEST_IMG 6913a1d4a7SDaniel P. Berrange SYSEMU_EXTRA_ARGS="" 7013a1d4a7SDaniel P. Berrange if [ -n "$IMGKEYSECRET" ]; then 7113a1d4a7SDaniel P. Berrange SECRET_ARG="secret,id=keysec0,data=$IMGKEYSECRET" 7213a1d4a7SDaniel P. Berrange SYSEMU_EXTRA_ARGS="-object $SECRET_ARG" 7313a1d4a7SDaniel P. Berrange fi 7413a1d4a7SDaniel P. Berrangeelse 7513a1d4a7SDaniel P. Berrange SYSEMU_DRIVE_ARG=if=none,file="$TEST_IMG",driver=$IMGFMT 7613a1d4a7SDaniel P. Berrange SYSEMU_EXTRA_ARGS="" 7713a1d4a7SDaniel P. Berrangefi 7862ed9fa9SKevin Wolf 7962ed9fa9SKevin Wolf_make_test_img $size 8062ed9fa9SKevin Wolf 8162ed9fa9SKevin Wolfecho 8262ed9fa9SKevin Wolfecho "=== Setting WCE with qdev and with manually created BB ===" 8362ed9fa9SKevin Wolfecho 8462ed9fa9SKevin Wolf 8562ed9fa9SKevin Wolf# The qdev option takes precedence, but if it isn't given or 'auto', the BB 8662ed9fa9SKevin Wolf# option is used instead. 8762ed9fa9SKevin Wolf 8862ed9fa9SKevin Wolffor cache in "writeback" "writethrough"; do 8962ed9fa9SKevin Wolf for wce in "" ",write-cache=auto" ",write-cache=on" ",write-cache=off"; do 9013a1d4a7SDaniel P. Berrange echo "Testing: cache='$cache' wce='$wce'" 9162ed9fa9SKevin Wolf echo "info block" \ 9213a1d4a7SDaniel P. Berrange | run_qemu $SYSEMU_EXTRA_ARGS -drive "$SYSEMU_DRIVE_ARG,cache=$cache" \ 9362ed9fa9SKevin Wolf -device "virtio-blk,drive=none0$wce" \ 9462ed9fa9SKevin Wolf | grep -e "Testing" -e "Cache mode" 9562ed9fa9SKevin Wolf done 9662ed9fa9SKevin Wolfdone 9762ed9fa9SKevin Wolf 9862ed9fa9SKevin Wolf# success, all done 9962ed9fa9SKevin Wolfecho "*** done" 10062ed9fa9SKevin Wolfrm -f $seq.full 10162ed9fa9SKevin Wolfstatus=0 102