xref: /openbmc/qemu/tests/qemu-iotests/172 (revision 04a37d4c)
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 | _filter_qom_path
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
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
154# Conflicting, -fdX wins
155check_floppy_qtree -fda "$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -global floppy.drive=none0
156
157echo
158echo
159echo === Mixing -fdX and -device ===
160
161# Working
162check_floppy_qtree -fda "$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -device floppy,drive=none0
163check_floppy_qtree -fda "$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -device floppy,drive=none0,unit=1
164
165check_floppy_qtree -fdb "$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -device floppy,drive=none0
166check_floppy_qtree -fdb "$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -device floppy,drive=none0,unit=0
167
168# Conflicting
169check_floppy_qtree -fda "$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -device floppy,drive=none0,unit=0
170check_floppy_qtree -fdb "$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -device floppy,drive=none0,unit=1
171
172echo
173echo
174echo === Mixing -drive and -device ===
175
176# Working
177check_floppy_qtree -drive if=floppy,file="$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -device floppy,drive=none0
178check_floppy_qtree -drive if=floppy,file="$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -device floppy,drive=none0,unit=1
179
180# Conflicting
181check_floppy_qtree -drive if=floppy,file="$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -device floppy,drive=none0,unit=0
182
183echo
184echo
185echo === Mixing -global and -device ===
186
187# Working
188check_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
190check_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
193check_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
195check_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
197check_floppy_qtree -drive if=none,file="$TEST_IMG" \
198                   -global floppy.drive=none0 -device floppy,unit=0
199
200# Conflicting
201check_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
203check_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
205check_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
208echo
209echo
210echo === Attempt to use drive twice ===
211
212# if=none
213check_floppy_qtree -drive if=none -device floppy,drive=none0 -device floppy -device floppy,drive=none0
214check_floppy_qtree -drive if=none -global floppy.drive=none0 -device floppy -device floppy
215# if=floppy
216check_floppy_qtree -fda "" -device floppy,drive=floppy0
217check_floppy_qtree -fda "" -global floppy.drive=floppy0
218# default if=floppy (not found, because it's created later)
219check_floppy_qtree -device floppy,drive=floppy0
220
221echo
222echo
223echo === Too many floppy drives ===
224
225# Working
226check_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
232echo
233echo
234echo === Creating an empty drive with anonymous BB ===
235
236check_floppy_qtree -device floppy
237check_floppy_qtree -device floppy,drive-type=120
238check_floppy_qtree -device floppy,drive-type=144
239check_floppy_qtree -device floppy,drive-type=288
240
241echo
242echo
243echo === Try passing different drive size with image ===
244
245check_floppy_qtree -drive if=none,file="$TEST_IMG" -device floppy,drive=none0,drive-type=120
246check_floppy_qtree -drive if=none,file="$TEST_IMG" -device floppy,drive=none0,drive-type=288
247
248echo
249echo
250echo === Try passing different block sizes ===
251
252# Explicitly setting the default is okay
253check_floppy_qtree -drive if=none,file="$TEST_IMG" -device floppy,drive=none0,logical_block_size=512
254check_floppy_qtree -drive if=none,file="$TEST_IMG" -device floppy,drive=none0,physical_block_size=512
255
256# Changing it is not
257check_floppy_qtree -drive if=none,file="$TEST_IMG" -device floppy,drive=none0,logical_block_size=4096
258check_floppy_qtree -drive if=none,file="$TEST_IMG" -device floppy,drive=none0,physical_block_size=1024
259
260echo
261echo
262echo === Writethrough caching ===
263
264check_cache_mode -device floppy,drive=none0
265check_cache_mode -device floppy,drive=none0,write-cache=on
266check_cache_mode -device floppy,drive=none0,write-cache=off
267
268# success, all done
269echo "*** done"
270rm -f $seq.full
271status=0
272