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