111a82d14SPhilippe Mathieu-Daudé#!/usr/bin/env bash 2c9bf278bSKevin Wolf# 3c9bf278bSKevin Wolf# Test floppy configuration 4c9bf278bSKevin Wolf# 5c9bf278bSKevin Wolf# Copyright (C) 2016 Red Hat, Inc. 6c9bf278bSKevin Wolf# 7c9bf278bSKevin Wolf# This program is free software; you can redistribute it and/or modify 8c9bf278bSKevin Wolf# it under the terms of the GNU General Public License as published by 9c9bf278bSKevin Wolf# the Free Software Foundation; either version 2 of the License, or 10c9bf278bSKevin Wolf# (at your option) any later version. 11c9bf278bSKevin Wolf# 12c9bf278bSKevin Wolf# This program is distributed in the hope that it will be useful, 13c9bf278bSKevin Wolf# but WITHOUT ANY WARRANTY; without even the implied warranty of 14c9bf278bSKevin Wolf# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15c9bf278bSKevin Wolf# GNU General Public License for more details. 16c9bf278bSKevin Wolf# 17c9bf278bSKevin Wolf# You should have received a copy of the GNU General Public License 18c9bf278bSKevin Wolf# along with this program. If not, see <http://www.gnu.org/licenses/>. 19c9bf278bSKevin Wolf# 20c9bf278bSKevin Wolf 21c9bf278bSKevin Wolf# creator 22c9bf278bSKevin Wolfowner=kwolf@redhat.com 23c9bf278bSKevin Wolf 24c9bf278bSKevin Wolfseq=`basename $0` 25c9bf278bSKevin Wolfecho "QA output created by $seq" 26c9bf278bSKevin Wolf 27c9bf278bSKevin Wolfstatus=1 # failure is the default! 28c9bf278bSKevin Wolf 29c9bf278bSKevin Wolf_cleanup() 30c9bf278bSKevin Wolf{ 31c9bf278bSKevin Wolf _cleanup_test_img 32f91ecbd7SMax Reitz _rm_test_img "$TEST_IMG.2" 33f91ecbd7SMax Reitz _rm_test_img "$TEST_IMG.3" 34c9bf278bSKevin Wolf} 35c9bf278bSKevin Wolftrap "_cleanup; exit \$status" 0 1 2 3 15 36c9bf278bSKevin Wolf 37c9bf278bSKevin Wolf# get standard environment, filters and checks 38c9bf278bSKevin Wolf. ./common.rc 39c9bf278bSKevin Wolf. ./common.filter 40c9bf278bSKevin Wolf 41c9bf278bSKevin Wolf_supported_fmt qcow2 42c9bf278bSKevin Wolf_supported_proto file 43c9bf278bSKevin Wolf_supported_os Linux 44c9bf278bSKevin Wolf 45c9bf278bSKevin Wolfif [ "$QEMU_DEFAULT_MACHINE" != "pc" ]; then 46c9bf278bSKevin Wolf _notrun "Requires a PC machine" 47c9bf278bSKevin Wolffi 48c9bf278bSKevin Wolf 498cedcffdSEric Blakedo_run_qemu() 50c9bf278bSKevin Wolf{ 51c9bf278bSKevin Wolf ( 52c9bf278bSKevin Wolf if ! test -t 0; then 53c9bf278bSKevin Wolf while read cmd; do 54c9bf278bSKevin Wolf echo $cmd 55c9bf278bSKevin Wolf done 56c9bf278bSKevin Wolf fi 57c9bf278bSKevin Wolf echo quit 58976e8c54SThomas Huth ) | $QEMU -accel qtest -nographic -monitor stdio -serial none "$@" 59c9bf278bSKevin Wolf echo 60c9bf278bSKevin Wolf} 61c9bf278bSKevin Wolf 628cedcffdSEric Blakecheck_floppy_qtree() 63c9bf278bSKevin Wolf{ 64c9bf278bSKevin Wolf echo 65c9bf278bSKevin Wolf echo Testing: "$@" | _filter_testdir 66c9bf278bSKevin Wolf 67c9bf278bSKevin Wolf # QEMU_OPTIONS contains -nodefaults, we don't want that here because the 68c9bf278bSKevin Wolf # defaults are part of what should be checked here. 69c9bf278bSKevin Wolf # 70c9bf278bSKevin Wolf # Apply the sed filter to stdout only, but keep the stderr output and 71c9bf278bSKevin Wolf # filter the qemu program name in it. 72*6a1a6433SMarkus Armbruster printf "info qtree\ninfo block\n" | 73c9bf278bSKevin Wolf (QEMU_OPTIONS="" do_run_qemu "$@" | 74*6a1a6433SMarkus Armbruster _filter_testdir |_filter_generated_node_ids | _filter_hmp | 75*6a1a6433SMarkus Armbruster sed -ne '/^ dev: isa-fdc/,/^ dev:/{x;p};/^[a-z][^ ]* (NODE_NAME):* /,/^(qemu)$/{p}') 2>&1 | 76c9bf278bSKevin Wolf _filter_win32 | _filter_qemu 77c9bf278bSKevin Wolf} 78c9bf278bSKevin Wolf 798cedcffdSEric Blakecheck_cache_mode() 80c9bf278bSKevin Wolf{ 81c9bf278bSKevin Wolf echo "info block none0" | 82c9bf278bSKevin Wolf QEMU_OPTIONS="" do_run_qemu -drive if=none,file="$TEST_IMG" "$@" | 83c9bf278bSKevin Wolf _filter_win32 | _filter_qemu | grep "Cache mode" 84c9bf278bSKevin Wolf} 85c9bf278bSKevin Wolf 86c9bf278bSKevin Wolf 87c9bf278bSKevin Wolfsize=720k 88c9bf278bSKevin Wolf 89c9bf278bSKevin Wolf_make_test_img $size 90c9bf278bSKevin Wolf 917ceb4fc1SFam ZhengTEST_IMG="$TEST_IMG.2" _make_test_img $size 927ceb4fc1SFam ZhengTEST_IMG="$TEST_IMG.3" _make_test_img $size 937ceb4fc1SFam Zheng 94c9bf278bSKevin Wolf# Default drive semantics: 95c9bf278bSKevin Wolf# 96c9bf278bSKevin Wolf# By default you get a single empty floppy drive. You can override it with 97c9bf278bSKevin Wolf# -drive and using the same index, but if you use -drive to add a floppy to a 98c9bf278bSKevin Wolf# different index, you get both of them. However, as soon as you use any 99c9bf278bSKevin Wolf# '-device floppy', even to a different slot, the default drive is disabled. 100c9bf278bSKevin Wolf 101c9bf278bSKevin Wolfecho 102c9bf278bSKevin Wolfecho 103c9bf278bSKevin Wolfecho === Default === 104c9bf278bSKevin Wolf 105c9bf278bSKevin Wolfcheck_floppy_qtree 106c9bf278bSKevin Wolf 107c9bf278bSKevin Wolfecho 108c9bf278bSKevin Wolfecho 109c9bf278bSKevin Wolfecho === Using -fda/-fdb options === 110c9bf278bSKevin Wolf 111c9bf278bSKevin Wolfcheck_floppy_qtree -fda "$TEST_IMG" 112c9bf278bSKevin Wolfcheck_floppy_qtree -fdb "$TEST_IMG" 1137ceb4fc1SFam Zhengcheck_floppy_qtree -fda "$TEST_IMG" -fdb "$TEST_IMG.2" 114c9bf278bSKevin Wolf 115c9bf278bSKevin Wolf 116c9bf278bSKevin Wolfecho 117c9bf278bSKevin Wolfecho 118c9bf278bSKevin Wolfecho === Using -drive options === 119c9bf278bSKevin Wolf 120c9bf278bSKevin Wolfcheck_floppy_qtree -drive if=floppy,file="$TEST_IMG" 121c9bf278bSKevin Wolfcheck_floppy_qtree -drive if=floppy,file="$TEST_IMG",index=1 1227ceb4fc1SFam Zhengcheck_floppy_qtree -drive if=floppy,file="$TEST_IMG" -drive if=floppy,file="$TEST_IMG.2",index=1 123c9bf278bSKevin Wolf 124c9bf278bSKevin Wolfecho 125c9bf278bSKevin Wolfecho 126c9bf278bSKevin Wolfecho === Using -drive if=none and -global === 127c9bf278bSKevin Wolf 128c9bf278bSKevin Wolfcheck_floppy_qtree -drive if=none,file="$TEST_IMG" -global isa-fdc.driveA=none0 129c9bf278bSKevin Wolfcheck_floppy_qtree -drive if=none,file="$TEST_IMG" -global isa-fdc.driveB=none0 1307ceb4fc1SFam Zhengcheck_floppy_qtree -drive if=none,file="$TEST_IMG" -drive if=none,file="$TEST_IMG.2" \ 131c9bf278bSKevin Wolf -global isa-fdc.driveA=none0 -global isa-fdc.driveB=none1 132c9bf278bSKevin Wolf 133c9bf278bSKevin Wolfecho 134c9bf278bSKevin Wolfecho 135c9bf278bSKevin Wolfecho === Using -drive if=none and -device === 136c9bf278bSKevin Wolf 137c9bf278bSKevin Wolfcheck_floppy_qtree -drive if=none,file="$TEST_IMG" -device floppy,drive=none0 138c9bf278bSKevin Wolfcheck_floppy_qtree -drive if=none,file="$TEST_IMG" -device floppy,drive=none0,unit=1 1397ceb4fc1SFam Zhengcheck_floppy_qtree -drive if=none,file="$TEST_IMG" -drive if=none,file="$TEST_IMG.2" \ 140c9bf278bSKevin Wolf -device floppy,drive=none0 -device floppy,drive=none1,unit=1 141c9bf278bSKevin Wolf 142c9bf278bSKevin Wolfecho 143c9bf278bSKevin Wolfecho 144c9bf278bSKevin Wolfecho === Mixing -fdX and -global === 145c9bf278bSKevin Wolf 146c9bf278bSKevin Wolf# Working 1477ceb4fc1SFam Zhengcheck_floppy_qtree -fda "$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -global isa-fdc.driveB=none0 1487ceb4fc1SFam Zhengcheck_floppy_qtree -fdb "$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -global isa-fdc.driveA=none0 149c9bf278bSKevin Wolf 150c9bf278bSKevin Wolf# Conflicting (-fdX wins) 1517ceb4fc1SFam Zhengcheck_floppy_qtree -fda "$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -global isa-fdc.driveA=none0 1527ceb4fc1SFam Zhengcheck_floppy_qtree -fdb "$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -global isa-fdc.driveB=none0 153c9bf278bSKevin Wolf 154c9bf278bSKevin Wolfecho 155c9bf278bSKevin Wolfecho 156c9bf278bSKevin Wolfecho === Mixing -fdX and -device === 157c9bf278bSKevin Wolf 158c9bf278bSKevin Wolf# Working 1597ceb4fc1SFam Zhengcheck_floppy_qtree -fda "$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -device floppy,drive=none0 1607ceb4fc1SFam Zhengcheck_floppy_qtree -fda "$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -device floppy,drive=none0,unit=1 161c9bf278bSKevin Wolf 1627ceb4fc1SFam Zhengcheck_floppy_qtree -fdb "$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -device floppy,drive=none0 1637ceb4fc1SFam Zhengcheck_floppy_qtree -fdb "$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -device floppy,drive=none0,unit=0 164c9bf278bSKevin Wolf 165c9bf278bSKevin Wolf# Conflicting 1667ceb4fc1SFam Zhengcheck_floppy_qtree -fda "$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -device floppy,drive=none0,unit=0 1677ceb4fc1SFam Zhengcheck_floppy_qtree -fdb "$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -device floppy,drive=none0,unit=1 168c9bf278bSKevin Wolf 169c9bf278bSKevin Wolfecho 170c9bf278bSKevin Wolfecho 171c9bf278bSKevin Wolfecho === Mixing -drive and -device === 172c9bf278bSKevin Wolf 173c9bf278bSKevin Wolf# Working 1747ceb4fc1SFam Zhengcheck_floppy_qtree -drive if=floppy,file="$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -device floppy,drive=none0 1757ceb4fc1SFam Zhengcheck_floppy_qtree -drive if=floppy,file="$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -device floppy,drive=none0,unit=1 176c9bf278bSKevin Wolf 177c9bf278bSKevin Wolf# Conflicting 1787ceb4fc1SFam Zhengcheck_floppy_qtree -drive if=floppy,file="$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -device floppy,drive=none0,unit=0 179c9bf278bSKevin Wolf 180c9bf278bSKevin Wolfecho 181c9bf278bSKevin Wolfecho 182c9bf278bSKevin Wolfecho === Mixing -global and -device === 183c9bf278bSKevin Wolf 184c9bf278bSKevin Wolf# Working 1857ceb4fc1SFam Zhengcheck_floppy_qtree -drive if=none,file="$TEST_IMG" -drive if=none,file="$TEST_IMG.2" \ 186c9bf278bSKevin Wolf -global isa-fdc.driveA=none0 -device floppy,drive=none1 1877ceb4fc1SFam Zhengcheck_floppy_qtree -drive if=none,file="$TEST_IMG" -drive if=none,file="$TEST_IMG.2" \ 188c9bf278bSKevin Wolf -global isa-fdc.driveA=none0 -device floppy,drive=none1,unit=1 189c9bf278bSKevin Wolf 1907ceb4fc1SFam Zhengcheck_floppy_qtree -drive if=none,file="$TEST_IMG" -drive if=none,file="$TEST_IMG.2" \ 191c9bf278bSKevin Wolf -global isa-fdc.driveB=none0 -device floppy,drive=none1 1927ceb4fc1SFam Zhengcheck_floppy_qtree -drive if=none,file="$TEST_IMG" -drive if=none,file="$TEST_IMG.2" \ 193c9bf278bSKevin Wolf -global isa-fdc.driveB=none0 -device floppy,drive=none1,unit=0 194c9bf278bSKevin Wolf 195c9bf278bSKevin Wolf# Conflicting 1967ceb4fc1SFam Zhengcheck_floppy_qtree -drive if=none,file="$TEST_IMG" -drive if=none,file="$TEST_IMG.2" \ 197c9bf278bSKevin Wolf -global isa-fdc.driveA=none0 -device floppy,drive=none1,unit=0 1987ceb4fc1SFam Zhengcheck_floppy_qtree -drive if=none,file="$TEST_IMG" -drive if=none,file="$TEST_IMG.2" \ 199c9bf278bSKevin Wolf -global isa-fdc.driveB=none0 -device floppy,drive=none1,unit=1 200c9bf278bSKevin Wolf 201c9bf278bSKevin Wolfecho 202c9bf278bSKevin Wolfecho 203c9bf278bSKevin Wolfecho === Too many floppy drives === 204c9bf278bSKevin Wolf 205c9bf278bSKevin Wolf# Working 206c9bf278bSKevin Wolfcheck_floppy_qtree -drive if=floppy,file="$TEST_IMG" \ 2077ceb4fc1SFam Zheng -drive if=none,file="$TEST_IMG.2" \ 2087ceb4fc1SFam Zheng -drive if=none,file="$TEST_IMG.3" \ 209c9bf278bSKevin Wolf -global isa-fdc.driveB=none0 \ 210c9bf278bSKevin Wolf -device floppy,drive=none1 211c9bf278bSKevin Wolf 212c9bf278bSKevin Wolfecho 213c9bf278bSKevin Wolfecho 214c9bf278bSKevin Wolfecho === Creating an empty drive with anonymous BB === 215c9bf278bSKevin Wolf 216c9bf278bSKevin Wolfcheck_floppy_qtree -device floppy 217c9bf278bSKevin Wolfcheck_floppy_qtree -device floppy,drive-type=120 218c9bf278bSKevin Wolfcheck_floppy_qtree -device floppy,drive-type=144 219c9bf278bSKevin Wolfcheck_floppy_qtree -device floppy,drive-type=288 220c9bf278bSKevin Wolf 221c9bf278bSKevin Wolfecho 222c9bf278bSKevin Wolfecho 223c9bf278bSKevin Wolfecho === Try passing different drive size with image === 224c9bf278bSKevin Wolf 225c9bf278bSKevin Wolfcheck_floppy_qtree -drive if=none,file="$TEST_IMG" -device floppy,drive=none0,drive-type=120 226c9bf278bSKevin Wolfcheck_floppy_qtree -drive if=none,file="$TEST_IMG" -device floppy,drive=none0,drive-type=288 227c9bf278bSKevin Wolf 228c9bf278bSKevin Wolfecho 229c9bf278bSKevin Wolfecho 230c9bf278bSKevin Wolfecho === Try passing different block sizes === 231c9bf278bSKevin Wolf 232c9bf278bSKevin Wolf# Explicitly setting the default is okay 233c9bf278bSKevin Wolfcheck_floppy_qtree -drive if=none,file="$TEST_IMG" -device floppy,drive=none0,logical_block_size=512 234c9bf278bSKevin Wolfcheck_floppy_qtree -drive if=none,file="$TEST_IMG" -device floppy,drive=none0,physical_block_size=512 235c9bf278bSKevin Wolf 236c9bf278bSKevin Wolf# Changing it is not 237c9bf278bSKevin Wolfcheck_floppy_qtree -drive if=none,file="$TEST_IMG" -device floppy,drive=none0,logical_block_size=4096 238c9bf278bSKevin Wolfcheck_floppy_qtree -drive if=none,file="$TEST_IMG" -device floppy,drive=none0,physical_block_size=1024 239c9bf278bSKevin Wolf 240c9bf278bSKevin Wolfecho 241c9bf278bSKevin Wolfecho 242c9bf278bSKevin Wolfecho === Writethrough caching === 243c9bf278bSKevin Wolf 244c9bf278bSKevin Wolfcheck_cache_mode -device floppy,drive=none0 245c9bf278bSKevin Wolfcheck_cache_mode -device floppy,drive=none0,write-cache=on 246c9bf278bSKevin Wolfcheck_cache_mode -device floppy,drive=none0,write-cache=off 247c9bf278bSKevin Wolf 248c9bf278bSKevin Wolf# success, all done 249c9bf278bSKevin Wolfecho "*** done" 250c9bf278bSKevin Wolfrm -f $seq.full 251c9bf278bSKevin Wolfstatus=0 252