1 #!/usr/bin/env bash 2 # 3 # Test floppy configuration 4 # 5 # Copyright (C) 2016 Red Hat, Inc. 6 # 7 # This program is free software; you can redistribute it and/or modify 8 # it under the terms of the GNU General Public License as published by 9 # the Free Software Foundation; either version 2 of the License, or 10 # (at your option) any later version. 11 # 12 # This program is distributed in the hope that it will be useful, 13 # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 # GNU General Public License for more details. 16 # 17 # You should have received a copy of the GNU General Public License 18 # along with this program. If not, see <http://www.gnu.org/licenses/>. 19 # 20 21 # creator 22 owner=kwolf@redhat.com 23 24 seq=`basename $0` 25 echo "QA output created by $seq" 26 27 status=1 # failure is the default! 28 29 _cleanup() 30 { 31 _cleanup_test_img 32 _rm_test_img "$TEST_IMG.2" 33 _rm_test_img "$TEST_IMG.3" 34 } 35 trap "_cleanup; exit \$status" 0 1 2 3 15 36 37 # get standard environment, filters and checks 38 . ./common.rc 39 . ./common.filter 40 41 _supported_fmt qcow2 42 _supported_proto file 43 _supported_os Linux 44 45 if [ "$QEMU_DEFAULT_MACHINE" != "pc" ]; then 46 _notrun "Requires a PC machine" 47 fi 48 49 do_run_qemu() 50 { 51 ( 52 if ! test -t 0; then 53 while read cmd; do 54 echo $cmd 55 done 56 fi 57 echo quit 58 ) | $QEMU -accel qtest -nographic -monitor stdio -serial none "$@" 59 echo 60 } 61 62 check_floppy_qtree() 63 { 64 echo 65 echo Testing: "$@" | _filter_testdir 66 67 # QEMU_OPTIONS contains -nodefaults, we don't want that here because the 68 # defaults are part of what should be checked here. 69 # 70 # Apply the sed filter to stdout only, but keep the stderr output and 71 # filter the qemu program name in it. 72 printf "info qtree\ninfo block\n" | 73 (QEMU_OPTIONS="" do_run_qemu "$@" | 74 _filter_testdir |_filter_generated_node_ids | _filter_hmp | 75 sed -ne '/^ dev: isa-fdc/,/^ dev:/{x;p};/^[a-z][^ ]* (NODE_NAME):* /,/^(qemu)$/{p}') 2>&1 | 76 _filter_win32 | _filter_qemu 77 } 78 79 check_cache_mode() 80 { 81 echo "info block none0" | 82 QEMU_OPTIONS="" do_run_qemu -drive if=none,file="$TEST_IMG" "$@" | 83 _filter_win32 | _filter_qemu | grep "Cache mode" 84 } 85 86 87 size=720k 88 89 _make_test_img $size 90 91 TEST_IMG="$TEST_IMG.2" _make_test_img $size 92 TEST_IMG="$TEST_IMG.3" _make_test_img $size 93 94 # Default drive semantics: 95 # 96 # By default you get a single empty floppy drive. You can override it with 97 # -drive and using the same index, but if you use -drive to add a floppy to a 98 # different index, you get both of them. However, as soon as you use any 99 # '-device floppy', even to a different slot, the default drive is disabled. 100 101 echo 102 echo 103 echo === Default === 104 105 check_floppy_qtree 106 107 echo 108 echo 109 echo === Using -fda/-fdb options === 110 111 check_floppy_qtree -fda "$TEST_IMG" 112 check_floppy_qtree -fdb "$TEST_IMG" 113 check_floppy_qtree -fda "$TEST_IMG" -fdb "$TEST_IMG.2" 114 check_floppy_qtree -fdb "" 115 116 117 echo 118 echo 119 echo === Using -drive options === 120 121 check_floppy_qtree -drive if=floppy,file="$TEST_IMG" 122 check_floppy_qtree -drive if=floppy,file="$TEST_IMG",index=1 123 check_floppy_qtree -drive if=floppy,file="$TEST_IMG" -drive if=floppy,file="$TEST_IMG.2",index=1 124 125 echo 126 echo 127 echo === Using -drive if=none and -global === 128 129 check_floppy_qtree -drive if=none,file="$TEST_IMG" -global isa-fdc.driveA=none0 130 check_floppy_qtree -drive if=none,file="$TEST_IMG" -global isa-fdc.driveB=none0 131 check_floppy_qtree -drive if=none,file="$TEST_IMG" -drive if=none,file="$TEST_IMG.2" \ 132 -global isa-fdc.driveA=none0 -global isa-fdc.driveB=none1 133 134 echo 135 echo 136 echo === Using -drive if=none and -device === 137 138 check_floppy_qtree -drive if=none,file="$TEST_IMG" -device floppy,drive=none0 139 check_floppy_qtree -drive if=none,file="$TEST_IMG" -device floppy,drive=none0,unit=1 140 check_floppy_qtree -drive if=none,file="$TEST_IMG" -drive if=none,file="$TEST_IMG.2" \ 141 -device floppy,drive=none0 -device floppy,drive=none1,unit=1 142 143 echo 144 echo 145 echo === Mixing -fdX and -global === 146 147 # Working 148 check_floppy_qtree -fda "$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -global isa-fdc.driveB=none0 149 check_floppy_qtree -fdb "$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -global isa-fdc.driveA=none0 150 151 # Conflicting 152 check_floppy_qtree -fda "$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -global isa-fdc.driveA=none0 153 check_floppy_qtree -fdb "$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -global isa-fdc.driveB=none0 154 # Conflicting, -fdX wins 155 check_floppy_qtree -fda "$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -global floppy.drive=none0 156 157 echo 158 echo 159 echo === Mixing -fdX and -device === 160 161 # Working 162 check_floppy_qtree -fda "$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -device floppy,drive=none0 163 check_floppy_qtree -fda "$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -device floppy,drive=none0,unit=1 164 165 check_floppy_qtree -fdb "$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -device floppy,drive=none0 166 check_floppy_qtree -fdb "$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -device floppy,drive=none0,unit=0 167 168 # Conflicting 169 check_floppy_qtree -fda "$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -device floppy,drive=none0,unit=0 170 check_floppy_qtree -fdb "$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -device floppy,drive=none0,unit=1 171 172 echo 173 echo 174 echo === Mixing -drive and -device === 175 176 # Working 177 check_floppy_qtree -drive if=floppy,file="$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -device floppy,drive=none0 178 check_floppy_qtree -drive if=floppy,file="$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -device floppy,drive=none0,unit=1 179 180 # Conflicting 181 check_floppy_qtree -drive if=floppy,file="$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -device floppy,drive=none0,unit=0 182 183 echo 184 echo 185 echo === Mixing -global and -device === 186 187 # Working 188 check_floppy_qtree -drive if=none,file="$TEST_IMG" -drive if=none,file="$TEST_IMG.2" \ 189 -global isa-fdc.driveA=none0 -device floppy,drive=none1 190 check_floppy_qtree -drive if=none,file="$TEST_IMG" -drive if=none,file="$TEST_IMG.2" \ 191 -global isa-fdc.driveA=none0 -device floppy,drive=none1,unit=1 192 193 check_floppy_qtree -drive if=none,file="$TEST_IMG" -drive if=none,file="$TEST_IMG.2" \ 194 -global isa-fdc.driveB=none0 -device floppy,drive=none1 195 check_floppy_qtree -drive if=none,file="$TEST_IMG" -drive if=none,file="$TEST_IMG.2" \ 196 -global isa-fdc.driveB=none0 -device floppy,drive=none1,unit=0 197 check_floppy_qtree -drive if=none,file="$TEST_IMG" \ 198 -global floppy.drive=none0 -device floppy,unit=0 199 200 # Conflicting 201 check_floppy_qtree -drive if=none,file="$TEST_IMG" -drive if=none,file="$TEST_IMG.2" \ 202 -global isa-fdc.driveA=none0 -device floppy,drive=none1,unit=0 203 check_floppy_qtree -drive if=none,file="$TEST_IMG" -drive if=none,file="$TEST_IMG.2" \ 204 -global isa-fdc.driveB=none0 -device floppy,drive=none1,unit=1 205 check_floppy_qtree -drive if=none,file="$TEST_IMG" -drive if=none,file="$TEST_IMG.2" \ 206 -global floppy.drive=none0 -device floppy,drive=none1,unit=0 207 208 echo 209 echo 210 echo === Attempt to use drive twice === 211 212 # if=none 213 check_floppy_qtree -drive if=none -device floppy,drive=none0 -device floppy -device floppy,drive=none0 214 check_floppy_qtree -drive if=none -global floppy.drive=none0 -device floppy -device floppy 215 # if=floppy 216 check_floppy_qtree -fda "" -device floppy,drive=floppy0 217 check_floppy_qtree -fda "" -global floppy.drive=floppy0 218 # default if=floppy (not found, because it's created later) 219 check_floppy_qtree -device floppy,drive=floppy0 220 221 echo 222 echo 223 echo === Too many floppy drives === 224 225 # Working 226 check_floppy_qtree -drive if=floppy,file="$TEST_IMG" \ 227 -drive if=none,file="$TEST_IMG.2" \ 228 -drive if=none,file="$TEST_IMG.3" \ 229 -global isa-fdc.driveB=none0 \ 230 -device floppy,drive=none1 231 232 echo 233 echo 234 echo === Creating an empty drive with anonymous BB === 235 236 check_floppy_qtree -device floppy 237 check_floppy_qtree -device floppy,drive-type=120 238 check_floppy_qtree -device floppy,drive-type=144 239 check_floppy_qtree -device floppy,drive-type=288 240 241 echo 242 echo 243 echo === Try passing different drive size with image === 244 245 check_floppy_qtree -drive if=none,file="$TEST_IMG" -device floppy,drive=none0,drive-type=120 246 check_floppy_qtree -drive if=none,file="$TEST_IMG" -device floppy,drive=none0,drive-type=288 247 248 echo 249 echo 250 echo === Try passing different block sizes === 251 252 # Explicitly setting the default is okay 253 check_floppy_qtree -drive if=none,file="$TEST_IMG" -device floppy,drive=none0,logical_block_size=512 254 check_floppy_qtree -drive if=none,file="$TEST_IMG" -device floppy,drive=none0,physical_block_size=512 255 256 # Changing it is not 257 check_floppy_qtree -drive if=none,file="$TEST_IMG" -device floppy,drive=none0,logical_block_size=4096 258 check_floppy_qtree -drive if=none,file="$TEST_IMG" -device floppy,drive=none0,physical_block_size=1024 259 260 echo 261 echo 262 echo === Writethrough caching === 263 264 check_cache_mode -device floppy,drive=none0 265 check_cache_mode -device floppy,drive=none0,write-cache=on 266 check_cache_mode -device floppy,drive=none0,write-cache=off 267 268 # success, all done 269 echo "*** done" 270 rm -f $seq.full 271 status=0 272