111a82d14SPhilippe Mathieu-Daudé#!/usr/bin/env bash 2*9dd003a9SVladimir 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 59976e8c54SThomas Huth ) | $QEMU -accel qtest -nographic -monitor stdio -serial 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 -global === 129c9bf278bSKevin Wolf 130c9bf278bSKevin Wolfcheck_floppy_qtree -drive if=none,file="$TEST_IMG" -global isa-fdc.driveA=none0 131c9bf278bSKevin Wolfcheck_floppy_qtree -drive if=none,file="$TEST_IMG" -global isa-fdc.driveB=none0 1327ceb4fc1SFam Zhengcheck_floppy_qtree -drive if=none,file="$TEST_IMG" -drive if=none,file="$TEST_IMG.2" \ 133c9bf278bSKevin Wolf -global isa-fdc.driveA=none0 -global isa-fdc.driveB=none1 134c9bf278bSKevin Wolf 135c9bf278bSKevin Wolfecho 136c9bf278bSKevin Wolfecho 137c9bf278bSKevin Wolfecho === Using -drive if=none and -device === 138c9bf278bSKevin Wolf 139c9bf278bSKevin Wolfcheck_floppy_qtree -drive if=none,file="$TEST_IMG" -device floppy,drive=none0 140c9bf278bSKevin Wolfcheck_floppy_qtree -drive if=none,file="$TEST_IMG" -device floppy,drive=none0,unit=1 1417ceb4fc1SFam Zhengcheck_floppy_qtree -drive if=none,file="$TEST_IMG" -drive if=none,file="$TEST_IMG.2" \ 142c9bf278bSKevin Wolf -device floppy,drive=none0 -device floppy,drive=none1,unit=1 143c9bf278bSKevin Wolf 144c9bf278bSKevin Wolfecho 145c9bf278bSKevin Wolfecho 146c9bf278bSKevin Wolfecho === Mixing -fdX and -global === 147c9bf278bSKevin Wolf 148c9bf278bSKevin Wolf# Working 1497ceb4fc1SFam Zhengcheck_floppy_qtree -fda "$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -global isa-fdc.driveB=none0 1507ceb4fc1SFam Zhengcheck_floppy_qtree -fdb "$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -global isa-fdc.driveA=none0 151c9bf278bSKevin Wolf 1526172e067SMarkus Armbruster# Conflicting 1537ceb4fc1SFam Zhengcheck_floppy_qtree -fda "$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -global isa-fdc.driveA=none0 1547ceb4fc1SFam Zhengcheck_floppy_qtree -fdb "$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -global isa-fdc.driveB=none0 1556172e067SMarkus Armbruster# Conflicting, -fdX wins 15602b83f7dSMarkus Armbrustercheck_floppy_qtree -fda "$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -global floppy.drive=none0 157c9bf278bSKevin Wolf 158c9bf278bSKevin Wolfecho 159c9bf278bSKevin Wolfecho 160c9bf278bSKevin Wolfecho === Mixing -fdX and -device === 161c9bf278bSKevin Wolf 162c9bf278bSKevin Wolf# Working 1637ceb4fc1SFam Zhengcheck_floppy_qtree -fda "$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -device floppy,drive=none0 1647ceb4fc1SFam Zhengcheck_floppy_qtree -fda "$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -device floppy,drive=none0,unit=1 165c9bf278bSKevin Wolf 1667ceb4fc1SFam Zhengcheck_floppy_qtree -fdb "$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -device floppy,drive=none0 1677ceb4fc1SFam Zhengcheck_floppy_qtree -fdb "$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -device floppy,drive=none0,unit=0 168c9bf278bSKevin Wolf 169c9bf278bSKevin Wolf# Conflicting 1707ceb4fc1SFam Zhengcheck_floppy_qtree -fda "$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -device floppy,drive=none0,unit=0 1717ceb4fc1SFam Zhengcheck_floppy_qtree -fdb "$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -device floppy,drive=none0,unit=1 172c9bf278bSKevin Wolf 173c9bf278bSKevin Wolfecho 174c9bf278bSKevin Wolfecho 175c9bf278bSKevin Wolfecho === Mixing -drive and -device === 176c9bf278bSKevin Wolf 177c9bf278bSKevin Wolf# Working 1787ceb4fc1SFam Zhengcheck_floppy_qtree -drive if=floppy,file="$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -device floppy,drive=none0 1797ceb4fc1SFam Zhengcheck_floppy_qtree -drive if=floppy,file="$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -device floppy,drive=none0,unit=1 180c9bf278bSKevin Wolf 181c9bf278bSKevin Wolf# Conflicting 1827ceb4fc1SFam Zhengcheck_floppy_qtree -drive if=floppy,file="$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -device floppy,drive=none0,unit=0 183c9bf278bSKevin Wolf 184c9bf278bSKevin Wolfecho 185c9bf278bSKevin Wolfecho 186c9bf278bSKevin Wolfecho === Mixing -global and -device === 187c9bf278bSKevin Wolf 188c9bf278bSKevin Wolf# Working 1897ceb4fc1SFam Zhengcheck_floppy_qtree -drive if=none,file="$TEST_IMG" -drive if=none,file="$TEST_IMG.2" \ 190c9bf278bSKevin Wolf -global isa-fdc.driveA=none0 -device floppy,drive=none1 1917ceb4fc1SFam Zhengcheck_floppy_qtree -drive if=none,file="$TEST_IMG" -drive if=none,file="$TEST_IMG.2" \ 192c9bf278bSKevin Wolf -global isa-fdc.driveA=none0 -device floppy,drive=none1,unit=1 193c9bf278bSKevin Wolf 1947ceb4fc1SFam Zhengcheck_floppy_qtree -drive if=none,file="$TEST_IMG" -drive if=none,file="$TEST_IMG.2" \ 195c9bf278bSKevin Wolf -global isa-fdc.driveB=none0 -device floppy,drive=none1 1967ceb4fc1SFam Zhengcheck_floppy_qtree -drive if=none,file="$TEST_IMG" -drive if=none,file="$TEST_IMG.2" \ 197c9bf278bSKevin Wolf -global isa-fdc.driveB=none0 -device floppy,drive=none1,unit=0 19802b83f7dSMarkus Armbrustercheck_floppy_qtree -drive if=none,file="$TEST_IMG" \ 19902b83f7dSMarkus Armbruster -global floppy.drive=none0 -device floppy,unit=0 200c9bf278bSKevin Wolf 201c9bf278bSKevin Wolf# Conflicting 2027ceb4fc1SFam Zhengcheck_floppy_qtree -drive if=none,file="$TEST_IMG" -drive if=none,file="$TEST_IMG.2" \ 203c9bf278bSKevin Wolf -global isa-fdc.driveA=none0 -device floppy,drive=none1,unit=0 2047ceb4fc1SFam Zhengcheck_floppy_qtree -drive if=none,file="$TEST_IMG" -drive if=none,file="$TEST_IMG.2" \ 205c9bf278bSKevin Wolf -global isa-fdc.driveB=none0 -device floppy,drive=none1,unit=1 20602b83f7dSMarkus Armbrustercheck_floppy_qtree -drive if=none,file="$TEST_IMG" -drive if=none,file="$TEST_IMG.2" \ 20702b83f7dSMarkus Armbruster -global floppy.drive=none0 -device floppy,drive=none1,unit=0 208c9bf278bSKevin Wolf 209c9bf278bSKevin Wolfecho 210c9bf278bSKevin Wolfecho 21120171739SMarkus Armbrusterecho === Attempt to use drive twice === 21220171739SMarkus Armbruster 21320171739SMarkus Armbruster# if=none 21420171739SMarkus Armbrustercheck_floppy_qtree -drive if=none -device floppy,drive=none0 -device floppy -device floppy,drive=none0 21502b83f7dSMarkus Armbrustercheck_floppy_qtree -drive if=none -global floppy.drive=none0 -device floppy -device floppy 21620171739SMarkus Armbruster# if=floppy 21720171739SMarkus Armbrustercheck_floppy_qtree -fda "" -device floppy,drive=floppy0 21802b83f7dSMarkus Armbrustercheck_floppy_qtree -fda "" -global floppy.drive=floppy0 21920171739SMarkus Armbruster# default if=floppy (not found, because it's created later) 22020171739SMarkus Armbrustercheck_floppy_qtree -device floppy,drive=floppy0 22120171739SMarkus Armbruster 22220171739SMarkus Armbrusterecho 22320171739SMarkus Armbrusterecho 224c9bf278bSKevin Wolfecho === Too many floppy drives === 225c9bf278bSKevin Wolf 226c9bf278bSKevin Wolf# Working 227c9bf278bSKevin Wolfcheck_floppy_qtree -drive if=floppy,file="$TEST_IMG" \ 2287ceb4fc1SFam Zheng -drive if=none,file="$TEST_IMG.2" \ 2297ceb4fc1SFam Zheng -drive if=none,file="$TEST_IMG.3" \ 230c9bf278bSKevin Wolf -global isa-fdc.driveB=none0 \ 231c9bf278bSKevin Wolf -device floppy,drive=none1 232c9bf278bSKevin Wolf 233c9bf278bSKevin Wolfecho 234c9bf278bSKevin Wolfecho 235c9bf278bSKevin Wolfecho === Creating an empty drive with anonymous BB === 236c9bf278bSKevin Wolf 237c9bf278bSKevin Wolfcheck_floppy_qtree -device floppy 238c9bf278bSKevin Wolfcheck_floppy_qtree -device floppy,drive-type=120 239c9bf278bSKevin Wolfcheck_floppy_qtree -device floppy,drive-type=144 240c9bf278bSKevin Wolfcheck_floppy_qtree -device floppy,drive-type=288 241c9bf278bSKevin Wolf 242c9bf278bSKevin Wolfecho 243c9bf278bSKevin Wolfecho 244c9bf278bSKevin Wolfecho === Try passing different drive size with image === 245c9bf278bSKevin Wolf 246c9bf278bSKevin Wolfcheck_floppy_qtree -drive if=none,file="$TEST_IMG" -device floppy,drive=none0,drive-type=120 247c9bf278bSKevin Wolfcheck_floppy_qtree -drive if=none,file="$TEST_IMG" -device floppy,drive=none0,drive-type=288 248c9bf278bSKevin Wolf 249c9bf278bSKevin Wolfecho 250c9bf278bSKevin Wolfecho 251c9bf278bSKevin Wolfecho === Try passing different block sizes === 252c9bf278bSKevin Wolf 253c9bf278bSKevin Wolf# Explicitly setting the default is okay 254c9bf278bSKevin Wolfcheck_floppy_qtree -drive if=none,file="$TEST_IMG" -device floppy,drive=none0,logical_block_size=512 255c9bf278bSKevin Wolfcheck_floppy_qtree -drive if=none,file="$TEST_IMG" -device floppy,drive=none0,physical_block_size=512 256c9bf278bSKevin Wolf 257c9bf278bSKevin Wolf# Changing it is not 258c9bf278bSKevin Wolfcheck_floppy_qtree -drive if=none,file="$TEST_IMG" -device floppy,drive=none0,logical_block_size=4096 259c9bf278bSKevin Wolfcheck_floppy_qtree -drive if=none,file="$TEST_IMG" -device floppy,drive=none0,physical_block_size=1024 260c9bf278bSKevin Wolf 261c9bf278bSKevin Wolfecho 262c9bf278bSKevin Wolfecho 263c9bf278bSKevin Wolfecho === Writethrough caching === 264c9bf278bSKevin Wolf 265c9bf278bSKevin Wolfcheck_cache_mode -device floppy,drive=none0 266c9bf278bSKevin Wolfcheck_cache_mode -device floppy,drive=none0,write-cache=on 267c9bf278bSKevin Wolfcheck_cache_mode -device floppy,drive=none0,write-cache=off 268c9bf278bSKevin Wolf 269c9bf278bSKevin Wolf# success, all done 270c9bf278bSKevin Wolfecho "*** done" 271c9bf278bSKevin Wolfrm -f $seq.full 272c9bf278bSKevin Wolfstatus=0 273