1*11a82d14SPhilippe Mathieu-Daudé#!/usr/bin/env 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 Wolfstatus=1 # failure is the default! 2862ed9fa9SKevin Wolf 2962ed9fa9SKevin Wolf_cleanup() 3062ed9fa9SKevin Wolf{ 3162ed9fa9SKevin Wolf _cleanup_test_img 3262ed9fa9SKevin Wolf} 3362ed9fa9SKevin Wolftrap "_cleanup; exit \$status" 0 1 2 3 15 3462ed9fa9SKevin Wolf 3562ed9fa9SKevin Wolf# get standard environment, filters and checks 3662ed9fa9SKevin Wolf. ./common.rc 3762ed9fa9SKevin Wolf. ./common.filter 3862ed9fa9SKevin Wolf 3962ed9fa9SKevin Wolf_supported_fmt generic 4062ed9fa9SKevin Wolf_supported_proto file 4162ed9fa9SKevin Wolf_supported_os Linux 4262ed9fa9SKevin Wolf 438cedcffdSEric Blakedo_run_qemu() 4462ed9fa9SKevin Wolf{ 4562ed9fa9SKevin Wolf ( 4662ed9fa9SKevin Wolf if ! test -t 0; then 4762ed9fa9SKevin Wolf while read cmd; do 4862ed9fa9SKevin Wolf echo $cmd 4962ed9fa9SKevin Wolf done 5062ed9fa9SKevin Wolf fi 5162ed9fa9SKevin Wolf echo quit 5262ed9fa9SKevin Wolf ) | $QEMU -nodefaults -nographic -monitor stdio -serial none "$@" 5362ed9fa9SKevin Wolf echo 5462ed9fa9SKevin Wolf} 5562ed9fa9SKevin Wolf 568cedcffdSEric Blakerun_qemu() 5762ed9fa9SKevin Wolf{ 5842190dccSMax Reitz do_run_qemu "$@" 2>&1 | _filter_testdir | _filter_imgfmt \ 5942190dccSMax Reitz | _filter_qemu | _filter_generated_node_ids 6062ed9fa9SKevin Wolf} 6162ed9fa9SKevin Wolf 6262ed9fa9SKevin Wolf 6362ed9fa9SKevin Wolfsize=128M 6413a1d4a7SDaniel P. Berrangeif test "$IMGOPTSSYNTAX" = "true" 6513a1d4a7SDaniel P. Berrangethen 6613a1d4a7SDaniel P. Berrange SYSEMU_DRIVE_ARG=if=none,$TEST_IMG 6713a1d4a7SDaniel P. Berrange SYSEMU_EXTRA_ARGS="" 6813a1d4a7SDaniel P. Berrange if [ -n "$IMGKEYSECRET" ]; then 6913a1d4a7SDaniel P. Berrange SECRET_ARG="secret,id=keysec0,data=$IMGKEYSECRET" 7013a1d4a7SDaniel P. Berrange SYSEMU_EXTRA_ARGS="-object $SECRET_ARG" 7113a1d4a7SDaniel P. Berrange fi 7213a1d4a7SDaniel P. Berrangeelse 7313a1d4a7SDaniel P. Berrange SYSEMU_DRIVE_ARG=if=none,file="$TEST_IMG",driver=$IMGFMT 7413a1d4a7SDaniel P. Berrange SYSEMU_EXTRA_ARGS="" 7513a1d4a7SDaniel P. Berrangefi 7662ed9fa9SKevin Wolf 7762ed9fa9SKevin Wolf_make_test_img $size 7862ed9fa9SKevin Wolf 7962ed9fa9SKevin Wolfecho 8062ed9fa9SKevin Wolfecho "=== Setting WCE with qdev and with manually created BB ===" 8162ed9fa9SKevin Wolfecho 8262ed9fa9SKevin Wolf 8362ed9fa9SKevin Wolf# The qdev option takes precedence, but if it isn't given or 'auto', the BB 8462ed9fa9SKevin Wolf# option is used instead. 8562ed9fa9SKevin Wolf 8662ed9fa9SKevin Wolffor cache in "writeback" "writethrough"; do 8762ed9fa9SKevin Wolf for wce in "" ",write-cache=auto" ",write-cache=on" ",write-cache=off"; do 8813a1d4a7SDaniel P. Berrange echo "Testing: cache='$cache' wce='$wce'" 8962ed9fa9SKevin Wolf echo "info block" \ 9013a1d4a7SDaniel P. Berrange | run_qemu $SYSEMU_EXTRA_ARGS -drive "$SYSEMU_DRIVE_ARG,cache=$cache" \ 9162ed9fa9SKevin Wolf -device "virtio-blk,drive=none0$wce" \ 9262ed9fa9SKevin Wolf | grep -e "Testing" -e "Cache mode" 9362ed9fa9SKevin Wolf done 9462ed9fa9SKevin Wolfdone 9562ed9fa9SKevin Wolf 9662ed9fa9SKevin Wolf# success, all done 9762ed9fa9SKevin Wolfecho "*** done" 9862ed9fa9SKevin Wolfrm -f $seq.full 9962ed9fa9SKevin Wolfstatus=0 100