xref: /qemu/tests/qemu-iotests/172 (revision 02b83f7d7c0828bb03fe0324c0ec8388d7e711d4)
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
22owner=kwolf@redhat.com
23
24seq=`basename $0`
25echo "QA output created by $seq"
26
27status=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}
35trap "_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
45if [ "$QEMU_DEFAULT_MACHINE" != "pc" ]; then
46    _notrun "Requires a PC machine"
47fi
48
49do_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
62check_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
79check_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
87size=720k
88
89_make_test_img $size
90
91TEST_IMG="$TEST_IMG.2" _make_test_img $size
92TEST_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
101echo
102echo
103echo === Default ===
104
105check_floppy_qtree
106
107echo
108echo
109echo === Using -fda/-fdb options ===
110
111check_floppy_qtree -fda "$TEST_IMG"
112check_floppy_qtree -fdb "$TEST_IMG"
113check_floppy_qtree -fda "$TEST_IMG" -fdb "$TEST_IMG.2"
114check_floppy_qtree -fdb ""
115
116
117echo
118echo
119echo === Using -drive options ===
120
121check_floppy_qtree -drive if=floppy,file="$TEST_IMG"
122check_floppy_qtree -drive if=floppy,file="$TEST_IMG",index=1
123check_floppy_qtree -drive if=floppy,file="$TEST_IMG" -drive if=floppy,file="$TEST_IMG.2",index=1
124
125echo
126echo
127echo === Using -drive if=none and -global ===
128
129check_floppy_qtree -drive if=none,file="$TEST_IMG" -global isa-fdc.driveA=none0
130check_floppy_qtree -drive if=none,file="$TEST_IMG" -global isa-fdc.driveB=none0
131check_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
134echo
135echo
136echo === Using -drive if=none and -device ===
137
138check_floppy_qtree -drive if=none,file="$TEST_IMG" -device floppy,drive=none0
139check_floppy_qtree -drive if=none,file="$TEST_IMG" -device floppy,drive=none0,unit=1
140check_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
143echo
144echo
145echo === Mixing -fdX and -global ===
146
147# Working
148check_floppy_qtree -fda "$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -global isa-fdc.driveB=none0
149check_floppy_qtree -fdb "$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -global isa-fdc.driveA=none0
150
151# Conflicting (-fdX wins)
152check_floppy_qtree -fda "$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -global isa-fdc.driveA=none0
153check_floppy_qtree -fdb "$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -global isa-fdc.driveB=none0
154check_floppy_qtree -fda "$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -global floppy.drive=none0
155
156echo
157echo
158echo === Mixing -fdX and -device ===
159
160# Working
161check_floppy_qtree -fda "$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -device floppy,drive=none0
162check_floppy_qtree -fda "$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -device floppy,drive=none0,unit=1
163
164check_floppy_qtree -fdb "$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -device floppy,drive=none0
165check_floppy_qtree -fdb "$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -device floppy,drive=none0,unit=0
166
167# Conflicting
168check_floppy_qtree -fda "$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -device floppy,drive=none0,unit=0
169check_floppy_qtree -fdb "$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -device floppy,drive=none0,unit=1
170
171echo
172echo
173echo === Mixing -drive and -device ===
174
175# Working
176check_floppy_qtree -drive if=floppy,file="$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -device floppy,drive=none0
177check_floppy_qtree -drive if=floppy,file="$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -device floppy,drive=none0,unit=1
178
179# Conflicting
180check_floppy_qtree -drive if=floppy,file="$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -device floppy,drive=none0,unit=0
181
182echo
183echo
184echo === Mixing -global and -device ===
185
186# Working
187check_floppy_qtree -drive if=none,file="$TEST_IMG" -drive if=none,file="$TEST_IMG.2" \
188                   -global isa-fdc.driveA=none0 -device floppy,drive=none1
189check_floppy_qtree -drive if=none,file="$TEST_IMG" -drive if=none,file="$TEST_IMG.2" \
190                   -global isa-fdc.driveA=none0 -device floppy,drive=none1,unit=1
191
192check_floppy_qtree -drive if=none,file="$TEST_IMG" -drive if=none,file="$TEST_IMG.2" \
193                   -global isa-fdc.driveB=none0 -device floppy,drive=none1
194check_floppy_qtree -drive if=none,file="$TEST_IMG" -drive if=none,file="$TEST_IMG.2" \
195                   -global isa-fdc.driveB=none0 -device floppy,drive=none1,unit=0
196check_floppy_qtree -drive if=none,file="$TEST_IMG" \
197                   -global floppy.drive=none0 -device floppy,unit=0
198
199# Conflicting
200check_floppy_qtree -drive if=none,file="$TEST_IMG" -drive if=none,file="$TEST_IMG.2" \
201                   -global isa-fdc.driveA=none0 -device floppy,drive=none1,unit=0
202check_floppy_qtree -drive if=none,file="$TEST_IMG" -drive if=none,file="$TEST_IMG.2" \
203                   -global isa-fdc.driveB=none0 -device floppy,drive=none1,unit=1
204check_floppy_qtree -drive if=none,file="$TEST_IMG" -drive if=none,file="$TEST_IMG.2" \
205                   -global floppy.drive=none0 -device floppy,drive=none1,unit=0
206
207echo
208echo
209echo === Attempt to use drive twice ===
210
211# if=none
212check_floppy_qtree -drive if=none -device floppy,drive=none0 -device floppy -device floppy,drive=none0
213check_floppy_qtree -drive if=none -global floppy.drive=none0 -device floppy -device floppy
214# if=floppy
215check_floppy_qtree -fda "" -device floppy,drive=floppy0
216check_floppy_qtree -fda "" -global floppy.drive=floppy0
217# default if=floppy (not found, because it's created later)
218check_floppy_qtree -device floppy,drive=floppy0
219
220echo
221echo
222echo === Too many floppy drives ===
223
224# Working
225check_floppy_qtree -drive if=floppy,file="$TEST_IMG" \
226                   -drive if=none,file="$TEST_IMG.2" \
227                   -drive if=none,file="$TEST_IMG.3" \
228                   -global isa-fdc.driveB=none0 \
229                   -device floppy,drive=none1
230
231echo
232echo
233echo === Creating an empty drive with anonymous BB ===
234
235check_floppy_qtree -device floppy
236check_floppy_qtree -device floppy,drive-type=120
237check_floppy_qtree -device floppy,drive-type=144
238check_floppy_qtree -device floppy,drive-type=288
239
240echo
241echo
242echo === Try passing different drive size with image ===
243
244check_floppy_qtree -drive if=none,file="$TEST_IMG" -device floppy,drive=none0,drive-type=120
245check_floppy_qtree -drive if=none,file="$TEST_IMG" -device floppy,drive=none0,drive-type=288
246
247echo
248echo
249echo === Try passing different block sizes ===
250
251# Explicitly setting the default is okay
252check_floppy_qtree -drive if=none,file="$TEST_IMG" -device floppy,drive=none0,logical_block_size=512
253check_floppy_qtree -drive if=none,file="$TEST_IMG" -device floppy,drive=none0,physical_block_size=512
254
255# Changing it is not
256check_floppy_qtree -drive if=none,file="$TEST_IMG" -device floppy,drive=none0,logical_block_size=4096
257check_floppy_qtree -drive if=none,file="$TEST_IMG" -device floppy,drive=none0,physical_block_size=1024
258
259echo
260echo
261echo === Writethrough caching ===
262
263check_cache_mode -device floppy,drive=none0
264check_cache_mode -device floppy,drive=none0,write-cache=on
265check_cache_mode -device floppy,drive=none0,write-cache=off
266
267# success, all done
268echo "*** done"
269rm -f $seq.full
270status=0
271