xref: /openbmc/qemu/tests/qemu-iotests/172 (revision 9b45a025)
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
23owner=kwolf@redhat.com
24
25seq=`basename $0`
26echo "QA output created by $seq"
27
28status=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}
36trap "_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
46if [ "$QEMU_DEFAULT_MACHINE" != "pc" ]; then
47    _notrun "Requires a PC machine"
48fi
49
50do_run_qemu()
51{
52    (
53        if ! test -t 0; then
54            while read cmd; do
55                echo $cmd
56            done
57        fi
58        echo quit
59    ) | $QEMU -accel qtest -nographic -monitor stdio -serial none "$@"
60    echo
61}
62
63check_floppy_qtree()
64{
65    echo
66    echo Testing: "$@" | _filter_testdir
67
68    # QEMU_OPTIONS contains -nodefaults, we don't want that here because the
69    # defaults are part of what should be checked here.
70    #
71    # Apply the sed filter to stdout only, but keep the stderr output and
72    # filter the qemu program name in it.
73    printf "info qtree\ninfo block\n" |
74    (QEMU_OPTIONS="" do_run_qemu "$@" |
75	_filter_testdir |_filter_generated_node_ids | _filter_hmp |
76        sed -ne '/^          dev: isa-fdc/,/^          dev:/{x;p};/^[a-z][^ ]* (NODE_NAME):* /,/^(qemu)$/{p}') 2>&1 |
77    _filter_win32 | _filter_qemu | _filter_qom_path
78}
79
80check_cache_mode()
81{
82    echo "info block none0" |
83    QEMU_OPTIONS="" do_run_qemu -drive if=none,file="$TEST_IMG" "$@" |
84    _filter_win32 | _filter_qemu | grep "Cache mode"
85}
86
87
88size=720k
89
90_make_test_img $size
91
92TEST_IMG="$TEST_IMG.2" _make_test_img $size
93TEST_IMG="$TEST_IMG.3" _make_test_img $size
94
95# Default drive semantics:
96#
97# By default you get a single empty floppy drive. You can override it with
98# -drive and using the same index, but if you use -drive to add a floppy to a
99# different index, you get both of them. However, as soon as you use any
100# '-device floppy', even to a different slot, the default drive is disabled.
101
102echo
103echo
104echo === Default ===
105
106check_floppy_qtree
107
108echo
109echo
110echo === Using -fda/-fdb options ===
111
112check_floppy_qtree -fda "$TEST_IMG"
113check_floppy_qtree -fdb "$TEST_IMG"
114check_floppy_qtree -fda "$TEST_IMG" -fdb "$TEST_IMG.2"
115check_floppy_qtree -fdb ""
116
117
118echo
119echo
120echo === Using -drive options ===
121
122check_floppy_qtree -drive if=floppy,file="$TEST_IMG"
123check_floppy_qtree -drive if=floppy,file="$TEST_IMG",index=1
124check_floppy_qtree -drive if=floppy,file="$TEST_IMG" -drive if=floppy,file="$TEST_IMG.2",index=1
125
126echo
127echo
128echo === Using -drive if=none and -global ===
129
130check_floppy_qtree -drive if=none,file="$TEST_IMG" -global isa-fdc.driveA=none0
131check_floppy_qtree -drive if=none,file="$TEST_IMG" -global isa-fdc.driveB=none0
132check_floppy_qtree -drive if=none,file="$TEST_IMG" -drive if=none,file="$TEST_IMG.2" \
133                   -global isa-fdc.driveA=none0 -global isa-fdc.driveB=none1
134
135echo
136echo
137echo === Using -drive if=none and -device ===
138
139check_floppy_qtree -drive if=none,file="$TEST_IMG" -device floppy,drive=none0
140check_floppy_qtree -drive if=none,file="$TEST_IMG" -device floppy,drive=none0,unit=1
141check_floppy_qtree -drive if=none,file="$TEST_IMG" -drive if=none,file="$TEST_IMG.2" \
142                   -device floppy,drive=none0 -device floppy,drive=none1,unit=1
143
144echo
145echo
146echo === Mixing -fdX and -global ===
147
148# Working
149check_floppy_qtree -fda "$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -global isa-fdc.driveB=none0
150check_floppy_qtree -fdb "$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -global isa-fdc.driveA=none0
151
152# Conflicting
153check_floppy_qtree -fda "$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -global isa-fdc.driveA=none0
154check_floppy_qtree -fdb "$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -global isa-fdc.driveB=none0
155# Conflicting, -fdX wins
156check_floppy_qtree -fda "$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -global floppy.drive=none0
157
158echo
159echo
160echo === Mixing -fdX and -device ===
161
162# Working
163check_floppy_qtree -fda "$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -device floppy,drive=none0
164check_floppy_qtree -fda "$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -device floppy,drive=none0,unit=1
165
166check_floppy_qtree -fdb "$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -device floppy,drive=none0
167check_floppy_qtree -fdb "$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -device floppy,drive=none0,unit=0
168
169# Conflicting
170check_floppy_qtree -fda "$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -device floppy,drive=none0,unit=0
171check_floppy_qtree -fdb "$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -device floppy,drive=none0,unit=1
172
173echo
174echo
175echo === Mixing -drive and -device ===
176
177# Working
178check_floppy_qtree -drive if=floppy,file="$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -device floppy,drive=none0
179check_floppy_qtree -drive if=floppy,file="$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -device floppy,drive=none0,unit=1
180
181# Conflicting
182check_floppy_qtree -drive if=floppy,file="$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -device floppy,drive=none0,unit=0
183
184echo
185echo
186echo === Mixing -global and -device ===
187
188# Working
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
191check_floppy_qtree -drive if=none,file="$TEST_IMG" -drive if=none,file="$TEST_IMG.2" \
192                   -global isa-fdc.driveA=none0 -device floppy,drive=none1,unit=1
193
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
196check_floppy_qtree -drive if=none,file="$TEST_IMG" -drive if=none,file="$TEST_IMG.2" \
197                   -global isa-fdc.driveB=none0 -device floppy,drive=none1,unit=0
198check_floppy_qtree -drive if=none,file="$TEST_IMG" \
199                   -global floppy.drive=none0 -device floppy,unit=0
200
201# Conflicting
202check_floppy_qtree -drive if=none,file="$TEST_IMG" -drive if=none,file="$TEST_IMG.2" \
203                   -global isa-fdc.driveA=none0 -device floppy,drive=none1,unit=0
204check_floppy_qtree -drive if=none,file="$TEST_IMG" -drive if=none,file="$TEST_IMG.2" \
205                   -global isa-fdc.driveB=none0 -device floppy,drive=none1,unit=1
206check_floppy_qtree -drive if=none,file="$TEST_IMG" -drive if=none,file="$TEST_IMG.2" \
207                   -global floppy.drive=none0 -device floppy,drive=none1,unit=0
208
209echo
210echo
211echo === Attempt to use drive twice ===
212
213# if=none
214check_floppy_qtree -drive if=none -device floppy,drive=none0 -device floppy -device floppy,drive=none0
215check_floppy_qtree -drive if=none -global floppy.drive=none0 -device floppy -device floppy
216# if=floppy
217check_floppy_qtree -fda "" -device floppy,drive=floppy0
218check_floppy_qtree -fda "" -global floppy.drive=floppy0
219# default if=floppy (not found, because it's created later)
220check_floppy_qtree -device floppy,drive=floppy0
221
222echo
223echo
224echo === Too many floppy drives ===
225
226# Working
227check_floppy_qtree -drive if=floppy,file="$TEST_IMG" \
228                   -drive if=none,file="$TEST_IMG.2" \
229                   -drive if=none,file="$TEST_IMG.3" \
230                   -global isa-fdc.driveB=none0 \
231                   -device floppy,drive=none1
232
233echo
234echo
235echo === Creating an empty drive with anonymous BB ===
236
237check_floppy_qtree -device floppy
238check_floppy_qtree -device floppy,drive-type=120
239check_floppy_qtree -device floppy,drive-type=144
240check_floppy_qtree -device floppy,drive-type=288
241
242echo
243echo
244echo === Try passing different drive size with image ===
245
246check_floppy_qtree -drive if=none,file="$TEST_IMG" -device floppy,drive=none0,drive-type=120
247check_floppy_qtree -drive if=none,file="$TEST_IMG" -device floppy,drive=none0,drive-type=288
248
249echo
250echo
251echo === Try passing different block sizes ===
252
253# Explicitly setting the default is okay
254check_floppy_qtree -drive if=none,file="$TEST_IMG" -device floppy,drive=none0,logical_block_size=512
255check_floppy_qtree -drive if=none,file="$TEST_IMG" -device floppy,drive=none0,physical_block_size=512
256
257# Changing it is not
258check_floppy_qtree -drive if=none,file="$TEST_IMG" -device floppy,drive=none0,logical_block_size=4096
259check_floppy_qtree -drive if=none,file="$TEST_IMG" -device floppy,drive=none0,physical_block_size=1024
260
261echo
262echo
263echo === Writethrough caching ===
264
265check_cache_mode -device floppy,drive=none0
266check_cache_mode -device floppy,drive=none0,write-cache=on
267check_cache_mode -device floppy,drive=none0,write-cache=off
268
269# success, all done
270echo "*** done"
271rm -f $seq.full
272status=0
273