111a82d14SPhilippe Mathieu-Daudé#!/usr/bin/env bash 29dd003a9SVladimir Sementsov-Ogievskiy# group: auto 3c9bf278bSKevin Wolf# 4c9bf278bSKevin Wolf# Test floppy configuration 5c9bf278bSKevin Wolf# 6c9bf278bSKevin Wolf# Copyright (C) 2016 Red Hat, Inc. 7c9bf278bSKevin Wolf# 8c9bf278bSKevin Wolf# This program is free software; you can redistribute it and/or modify 9c9bf278bSKevin Wolf# it under the terms of the GNU General Public License as published by 10c9bf278bSKevin Wolf# the Free Software Foundation; either version 2 of the License, or 11c9bf278bSKevin Wolf# (at your option) any later version. 12c9bf278bSKevin Wolf# 13c9bf278bSKevin Wolf# This program is distributed in the hope that it will be useful, 14c9bf278bSKevin Wolf# but WITHOUT ANY WARRANTY; without even the implied warranty of 15c9bf278bSKevin Wolf# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16c9bf278bSKevin Wolf# GNU General Public License for more details. 17c9bf278bSKevin Wolf# 18c9bf278bSKevin Wolf# You should have received a copy of the GNU General Public License 19c9bf278bSKevin Wolf# along with this program. If not, see <http://www.gnu.org/licenses/>. 20c9bf278bSKevin Wolf# 21c9bf278bSKevin Wolf 22c9bf278bSKevin Wolf# creator 23c9bf278bSKevin Wolfowner=kwolf@redhat.com 24c9bf278bSKevin Wolf 25c9bf278bSKevin Wolfseq=`basename $0` 26c9bf278bSKevin Wolfecho "QA output created by $seq" 27c9bf278bSKevin Wolf 28c9bf278bSKevin Wolfstatus=1 # failure is the default! 29c9bf278bSKevin Wolf 30c9bf278bSKevin Wolf_cleanup() 31c9bf278bSKevin Wolf{ 32c9bf278bSKevin Wolf _cleanup_test_img 33f91ecbd7SMax Reitz _rm_test_img "$TEST_IMG.2" 34f91ecbd7SMax Reitz _rm_test_img "$TEST_IMG.3" 35c9bf278bSKevin Wolf} 36c9bf278bSKevin Wolftrap "_cleanup; exit \$status" 0 1 2 3 15 37c9bf278bSKevin Wolf 38c9bf278bSKevin Wolf# get standard environment, filters and checks 39c9bf278bSKevin Wolf. ./common.rc 40c9bf278bSKevin Wolf. ./common.filter 41c9bf278bSKevin Wolf 42c9bf278bSKevin Wolf_supported_fmt qcow2 43c9bf278bSKevin Wolf_supported_proto file 44c9bf278bSKevin Wolf_supported_os Linux 45c9bf278bSKevin Wolf 46c9bf278bSKevin Wolfif [ "$QEMU_DEFAULT_MACHINE" != "pc" ]; then 47c9bf278bSKevin Wolf _notrun "Requires a PC machine" 48c9bf278bSKevin Wolffi 49c9bf278bSKevin Wolf 508cedcffdSEric Blakedo_run_qemu() 51c9bf278bSKevin Wolf{ 52c9bf278bSKevin Wolf ( 53c9bf278bSKevin Wolf if ! test -t 0; then 54c9bf278bSKevin Wolf while read cmd; do 55c9bf278bSKevin Wolf echo $cmd 56c9bf278bSKevin Wolf done 57c9bf278bSKevin Wolf fi 58c9bf278bSKevin Wolf echo quit 59*2feae891SThomas Huth ) | $QEMU -accel qtest -nographic -monitor stdio -serial none -vga none -nic none "$@" 60c9bf278bSKevin Wolf echo 61c9bf278bSKevin Wolf} 62c9bf278bSKevin Wolf 638cedcffdSEric Blakecheck_floppy_qtree() 64c9bf278bSKevin Wolf{ 65c9bf278bSKevin Wolf echo 66c9bf278bSKevin Wolf echo Testing: "$@" | _filter_testdir 67c9bf278bSKevin Wolf 68c9bf278bSKevin Wolf # QEMU_OPTIONS contains -nodefaults, we don't want that here because the 69c9bf278bSKevin Wolf # defaults are part of what should be checked here. 70c9bf278bSKevin Wolf # 71c9bf278bSKevin Wolf # Apply the sed filter to stdout only, but keep the stderr output and 72c9bf278bSKevin Wolf # filter the qemu program name in it. 736a1a6433SMarkus Armbruster printf "info qtree\ninfo block\n" | 74c9bf278bSKevin Wolf (QEMU_OPTIONS="" do_run_qemu "$@" | 756a1a6433SMarkus Armbruster _filter_testdir |_filter_generated_node_ids | _filter_hmp | 766a1a6433SMarkus Armbruster sed -ne '/^ dev: isa-fdc/,/^ dev:/{x;p};/^[a-z][^ ]* (NODE_NAME):* /,/^(qemu)$/{p}') 2>&1 | 771a351101SVladimir Sementsov-Ogievskiy _filter_win32 | _filter_qemu | _filter_qom_path 78c9bf278bSKevin Wolf} 79c9bf278bSKevin Wolf 808cedcffdSEric Blakecheck_cache_mode() 81c9bf278bSKevin Wolf{ 82c9bf278bSKevin Wolf echo "info block none0" | 83c9bf278bSKevin Wolf QEMU_OPTIONS="" do_run_qemu -drive if=none,file="$TEST_IMG" "$@" | 84c9bf278bSKevin Wolf _filter_win32 | _filter_qemu | grep "Cache mode" 85c9bf278bSKevin Wolf} 86c9bf278bSKevin Wolf 87c9bf278bSKevin Wolf 88c9bf278bSKevin Wolfsize=720k 89c9bf278bSKevin Wolf 90c9bf278bSKevin Wolf_make_test_img $size 91c9bf278bSKevin Wolf 927ceb4fc1SFam ZhengTEST_IMG="$TEST_IMG.2" _make_test_img $size 937ceb4fc1SFam ZhengTEST_IMG="$TEST_IMG.3" _make_test_img $size 947ceb4fc1SFam Zheng 95c9bf278bSKevin Wolf# Default drive semantics: 96c9bf278bSKevin Wolf# 97c9bf278bSKevin Wolf# By default you get a single empty floppy drive. You can override it with 98c9bf278bSKevin Wolf# -drive and using the same index, but if you use -drive to add a floppy to a 99c9bf278bSKevin Wolf# different index, you get both of them. However, as soon as you use any 100c9bf278bSKevin Wolf# '-device floppy', even to a different slot, the default drive is disabled. 101c9bf278bSKevin Wolf 102c9bf278bSKevin Wolfecho 103c9bf278bSKevin Wolfecho 104c9bf278bSKevin Wolfecho === Default === 105c9bf278bSKevin Wolf 106c9bf278bSKevin Wolfcheck_floppy_qtree 107c9bf278bSKevin Wolf 108c9bf278bSKevin Wolfecho 109c9bf278bSKevin Wolfecho 110c9bf278bSKevin Wolfecho === Using -fda/-fdb options === 111c9bf278bSKevin Wolf 112c9bf278bSKevin Wolfcheck_floppy_qtree -fda "$TEST_IMG" 113c9bf278bSKevin Wolfcheck_floppy_qtree -fdb "$TEST_IMG" 1147ceb4fc1SFam Zhengcheck_floppy_qtree -fda "$TEST_IMG" -fdb "$TEST_IMG.2" 11520171739SMarkus Armbrustercheck_floppy_qtree -fdb "" 116c9bf278bSKevin Wolf 117c9bf278bSKevin Wolf 118c9bf278bSKevin Wolfecho 119c9bf278bSKevin Wolfecho 120c9bf278bSKevin Wolfecho === Using -drive options === 121c9bf278bSKevin Wolf 122c9bf278bSKevin Wolfcheck_floppy_qtree -drive if=floppy,file="$TEST_IMG" 123c9bf278bSKevin Wolfcheck_floppy_qtree -drive if=floppy,file="$TEST_IMG",index=1 1247ceb4fc1SFam Zhengcheck_floppy_qtree -drive if=floppy,file="$TEST_IMG" -drive if=floppy,file="$TEST_IMG.2",index=1 125c9bf278bSKevin Wolf 126c9bf278bSKevin Wolfecho 127c9bf278bSKevin Wolfecho 128c9bf278bSKevin Wolfecho === Using -drive if=none and -device === 129c9bf278bSKevin Wolf 130c9bf278bSKevin Wolfcheck_floppy_qtree -drive if=none,file="$TEST_IMG" -device floppy,drive=none0 131c9bf278bSKevin Wolfcheck_floppy_qtree -drive if=none,file="$TEST_IMG" -device floppy,drive=none0,unit=1 1327ceb4fc1SFam Zhengcheck_floppy_qtree -drive if=none,file="$TEST_IMG" -drive if=none,file="$TEST_IMG.2" \ 133c9bf278bSKevin Wolf -device floppy,drive=none0 -device floppy,drive=none1,unit=1 134c9bf278bSKevin Wolf 135c9bf278bSKevin Wolfecho 136c9bf278bSKevin Wolfecho 137c9bf278bSKevin Wolfecho === Mixing -fdX and -global === 138c9bf278bSKevin Wolf 1396172e067SMarkus Armbruster# Conflicting, -fdX wins 14002b83f7dSMarkus Armbrustercheck_floppy_qtree -fda "$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -global floppy.drive=none0 141c9bf278bSKevin Wolf 142c9bf278bSKevin Wolfecho 143c9bf278bSKevin Wolfecho 144c9bf278bSKevin Wolfecho === Mixing -fdX and -device === 145c9bf278bSKevin Wolf 146c9bf278bSKevin Wolf# Working 1477ceb4fc1SFam Zhengcheck_floppy_qtree -fda "$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -device floppy,drive=none0 1487ceb4fc1SFam Zhengcheck_floppy_qtree -fda "$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -device floppy,drive=none0,unit=1 149c9bf278bSKevin Wolf 1507ceb4fc1SFam Zhengcheck_floppy_qtree -fdb "$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -device floppy,drive=none0 1517ceb4fc1SFam Zhengcheck_floppy_qtree -fdb "$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -device floppy,drive=none0,unit=0 152c9bf278bSKevin Wolf 153c9bf278bSKevin Wolf# Conflicting 1547ceb4fc1SFam Zhengcheck_floppy_qtree -fda "$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -device floppy,drive=none0,unit=0 1557ceb4fc1SFam Zhengcheck_floppy_qtree -fdb "$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -device floppy,drive=none0,unit=1 156c9bf278bSKevin Wolf 157c9bf278bSKevin Wolfecho 158c9bf278bSKevin Wolfecho 159c9bf278bSKevin Wolfecho === Mixing -drive and -device === 160c9bf278bSKevin Wolf 161c9bf278bSKevin Wolf# Working 1627ceb4fc1SFam Zhengcheck_floppy_qtree -drive if=floppy,file="$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -device floppy,drive=none0 1637ceb4fc1SFam Zhengcheck_floppy_qtree -drive if=floppy,file="$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -device floppy,drive=none0,unit=1 164c9bf278bSKevin Wolf 165c9bf278bSKevin Wolf# Conflicting 1667ceb4fc1SFam Zhengcheck_floppy_qtree -drive if=floppy,file="$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -device floppy,drive=none0,unit=0 167c9bf278bSKevin Wolf 168c9bf278bSKevin Wolfecho 169c9bf278bSKevin Wolfecho 170c9bf278bSKevin Wolfecho === Mixing -global and -device === 171c9bf278bSKevin Wolf 172c9bf278bSKevin Wolf# Working 17302b83f7dSMarkus Armbrustercheck_floppy_qtree -drive if=none,file="$TEST_IMG" \ 17402b83f7dSMarkus Armbruster -global floppy.drive=none0 -device floppy,unit=0 175c9bf278bSKevin Wolf 176c9bf278bSKevin Wolf# Conflicting 1777ceb4fc1SFam Zhengcheck_floppy_qtree -drive if=none,file="$TEST_IMG" -drive if=none,file="$TEST_IMG.2" \ 17802b83f7dSMarkus Armbruster -global floppy.drive=none0 -device floppy,drive=none1,unit=0 179c9bf278bSKevin Wolf 180c9bf278bSKevin Wolfecho 181c9bf278bSKevin Wolfecho 18220171739SMarkus Armbrusterecho === Attempt to use drive twice === 18320171739SMarkus Armbruster 18420171739SMarkus Armbruster# if=none 18520171739SMarkus Armbrustercheck_floppy_qtree -drive if=none -device floppy,drive=none0 -device floppy -device floppy,drive=none0 18602b83f7dSMarkus Armbrustercheck_floppy_qtree -drive if=none -global floppy.drive=none0 -device floppy -device floppy 18720171739SMarkus Armbruster# if=floppy 18820171739SMarkus Armbrustercheck_floppy_qtree -fda "" -device floppy,drive=floppy0 18902b83f7dSMarkus Armbrustercheck_floppy_qtree -fda "" -global floppy.drive=floppy0 19020171739SMarkus Armbruster# default if=floppy (not found, because it's created later) 19120171739SMarkus Armbrustercheck_floppy_qtree -device floppy,drive=floppy0 19220171739SMarkus Armbruster 19320171739SMarkus Armbrusterecho 19420171739SMarkus Armbrusterecho 195c9bf278bSKevin Wolfecho === Too many floppy drives === 196c9bf278bSKevin Wolf 197c9bf278bSKevin Wolf# Working 198c9bf278bSKevin Wolfcheck_floppy_qtree -drive if=floppy,file="$TEST_IMG" \ 1997ceb4fc1SFam Zheng -drive if=none,file="$TEST_IMG.2" \ 2007ceb4fc1SFam Zheng -drive if=none,file="$TEST_IMG.3" \ 20136585e2bSMarkus Armbruster -device floppy,drive=none0 \ 202c9bf278bSKevin Wolf -device floppy,drive=none1 203c9bf278bSKevin Wolf 204c9bf278bSKevin Wolfecho 205c9bf278bSKevin Wolfecho 206c9bf278bSKevin Wolfecho === Creating an empty drive with anonymous BB === 207c9bf278bSKevin Wolf 208c9bf278bSKevin Wolfcheck_floppy_qtree -device floppy 209c9bf278bSKevin Wolfcheck_floppy_qtree -device floppy,drive-type=120 210c9bf278bSKevin Wolfcheck_floppy_qtree -device floppy,drive-type=144 211c9bf278bSKevin Wolfcheck_floppy_qtree -device floppy,drive-type=288 212c9bf278bSKevin Wolf 213c9bf278bSKevin Wolfecho 214c9bf278bSKevin Wolfecho 215c9bf278bSKevin Wolfecho === Try passing different drive size with image === 216c9bf278bSKevin Wolf 217c9bf278bSKevin Wolfcheck_floppy_qtree -drive if=none,file="$TEST_IMG" -device floppy,drive=none0,drive-type=120 218c9bf278bSKevin Wolfcheck_floppy_qtree -drive if=none,file="$TEST_IMG" -device floppy,drive=none0,drive-type=288 219c9bf278bSKevin Wolf 220c9bf278bSKevin Wolfecho 221c9bf278bSKevin Wolfecho 222c9bf278bSKevin Wolfecho === Try passing different block sizes === 223c9bf278bSKevin Wolf 224c9bf278bSKevin Wolf# Explicitly setting the default is okay 225c9bf278bSKevin Wolfcheck_floppy_qtree -drive if=none,file="$TEST_IMG" -device floppy,drive=none0,logical_block_size=512 226c9bf278bSKevin Wolfcheck_floppy_qtree -drive if=none,file="$TEST_IMG" -device floppy,drive=none0,physical_block_size=512 227c9bf278bSKevin Wolf 228c9bf278bSKevin Wolf# Changing it is not 229c9bf278bSKevin Wolfcheck_floppy_qtree -drive if=none,file="$TEST_IMG" -device floppy,drive=none0,logical_block_size=4096 230c9bf278bSKevin Wolfcheck_floppy_qtree -drive if=none,file="$TEST_IMG" -device floppy,drive=none0,physical_block_size=1024 231c9bf278bSKevin Wolf 232c9bf278bSKevin Wolfecho 233c9bf278bSKevin Wolfecho 234c9bf278bSKevin Wolfecho === Writethrough caching === 235c9bf278bSKevin Wolf 236c9bf278bSKevin Wolfcheck_cache_mode -device floppy,drive=none0 237c9bf278bSKevin Wolfcheck_cache_mode -device floppy,drive=none0,write-cache=on 238c9bf278bSKevin Wolfcheck_cache_mode -device floppy,drive=none0,write-cache=off 239c9bf278bSKevin Wolf 240c9bf278bSKevin Wolf# success, all done 241c9bf278bSKevin Wolfecho "*** done" 242c9bf278bSKevin Wolfrm -f $seq.full 243c9bf278bSKevin Wolfstatus=0 244