xref: /openbmc/qemu/tests/qemu-iotests/172 (revision f91ecbd7)
111a82d14SPhilippe Mathieu-Daudé#!/usr/bin/env bash
2c9bf278bSKevin Wolf#
3c9bf278bSKevin Wolf# Test floppy configuration
4c9bf278bSKevin Wolf#
5c9bf278bSKevin Wolf# Copyright (C) 2016 Red Hat, Inc.
6c9bf278bSKevin Wolf#
7c9bf278bSKevin Wolf# This program is free software; you can redistribute it and/or modify
8c9bf278bSKevin Wolf# it under the terms of the GNU General Public License as published by
9c9bf278bSKevin Wolf# the Free Software Foundation; either version 2 of the License, or
10c9bf278bSKevin Wolf# (at your option) any later version.
11c9bf278bSKevin Wolf#
12c9bf278bSKevin Wolf# This program is distributed in the hope that it will be useful,
13c9bf278bSKevin Wolf# but WITHOUT ANY WARRANTY; without even the implied warranty of
14c9bf278bSKevin Wolf# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15c9bf278bSKevin Wolf# GNU General Public License for more details.
16c9bf278bSKevin Wolf#
17c9bf278bSKevin Wolf# You should have received a copy of the GNU General Public License
18c9bf278bSKevin Wolf# along with this program.  If not, see <http://www.gnu.org/licenses/>.
19c9bf278bSKevin Wolf#
20c9bf278bSKevin Wolf
21c9bf278bSKevin Wolf# creator
22c9bf278bSKevin Wolfowner=kwolf@redhat.com
23c9bf278bSKevin Wolf
24c9bf278bSKevin Wolfseq=`basename $0`
25c9bf278bSKevin Wolfecho "QA output created by $seq"
26c9bf278bSKevin Wolf
27c9bf278bSKevin Wolfstatus=1	# failure is the default!
28c9bf278bSKevin Wolf
29c9bf278bSKevin Wolf_cleanup()
30c9bf278bSKevin Wolf{
31c9bf278bSKevin Wolf    _cleanup_test_img
32*f91ecbd7SMax Reitz    _rm_test_img "$TEST_IMG.2"
33*f91ecbd7SMax Reitz    _rm_test_img "$TEST_IMG.3"
34c9bf278bSKevin Wolf}
35c9bf278bSKevin Wolftrap "_cleanup; exit \$status" 0 1 2 3 15
36c9bf278bSKevin Wolf
37c9bf278bSKevin Wolf# get standard environment, filters and checks
38c9bf278bSKevin Wolf. ./common.rc
39c9bf278bSKevin Wolf. ./common.filter
40c9bf278bSKevin Wolf
41c9bf278bSKevin Wolf_supported_fmt qcow2
42c9bf278bSKevin Wolf_supported_proto file
43c9bf278bSKevin Wolf_supported_os Linux
44c9bf278bSKevin Wolf
45c9bf278bSKevin Wolfif [ "$QEMU_DEFAULT_MACHINE" != "pc" ]; then
46c9bf278bSKevin Wolf    _notrun "Requires a PC machine"
47c9bf278bSKevin Wolffi
48c9bf278bSKevin Wolf
498cedcffdSEric Blakedo_run_qemu()
50c9bf278bSKevin Wolf{
51c9bf278bSKevin Wolf    (
52c9bf278bSKevin Wolf        if ! test -t 0; then
53c9bf278bSKevin Wolf            while read cmd; do
54c9bf278bSKevin Wolf                echo $cmd
55c9bf278bSKevin Wolf            done
56c9bf278bSKevin Wolf        fi
57c9bf278bSKevin Wolf        echo quit
58976e8c54SThomas Huth    ) | $QEMU -accel qtest -nographic -monitor stdio -serial none "$@"
59c9bf278bSKevin Wolf    echo
60c9bf278bSKevin Wolf}
61c9bf278bSKevin Wolf
628cedcffdSEric Blakecheck_floppy_qtree()
63c9bf278bSKevin Wolf{
64c9bf278bSKevin Wolf    echo
65c9bf278bSKevin Wolf    echo Testing: "$@" | _filter_testdir
66c9bf278bSKevin Wolf
67c9bf278bSKevin Wolf    # QEMU_OPTIONS contains -nodefaults, we don't want that here because the
68c9bf278bSKevin Wolf    # defaults are part of what should be checked here.
69c9bf278bSKevin Wolf    #
70c9bf278bSKevin Wolf    # Apply the sed filter to stdout only, but keep the stderr output and
71c9bf278bSKevin Wolf    # filter the qemu program name in it.
72c9bf278bSKevin Wolf    echo "info qtree" |
73c9bf278bSKevin Wolf    (QEMU_OPTIONS="" do_run_qemu "$@" |
74c9bf278bSKevin Wolf        sed -ne '/^          dev: isa-fdc/,/^          dev:/{x;p}' ) 2>&1 |
75c9bf278bSKevin Wolf    _filter_win32 | _filter_qemu
76c9bf278bSKevin Wolf}
77c9bf278bSKevin Wolf
788cedcffdSEric Blakecheck_cache_mode()
79c9bf278bSKevin Wolf{
80c9bf278bSKevin Wolf    echo "info block none0" |
81c9bf278bSKevin Wolf    QEMU_OPTIONS="" do_run_qemu -drive if=none,file="$TEST_IMG" "$@" |
82c9bf278bSKevin Wolf    _filter_win32 | _filter_qemu | grep "Cache mode"
83c9bf278bSKevin Wolf}
84c9bf278bSKevin Wolf
85c9bf278bSKevin Wolf
86c9bf278bSKevin Wolfsize=720k
87c9bf278bSKevin Wolf
88c9bf278bSKevin Wolf_make_test_img $size
89c9bf278bSKevin Wolf
907ceb4fc1SFam ZhengTEST_IMG="$TEST_IMG.2" _make_test_img $size
917ceb4fc1SFam ZhengTEST_IMG="$TEST_IMG.3" _make_test_img $size
927ceb4fc1SFam Zheng
93c9bf278bSKevin Wolf# Default drive semantics:
94c9bf278bSKevin Wolf#
95c9bf278bSKevin Wolf# By default you get a single empty floppy drive. You can override it with
96c9bf278bSKevin Wolf# -drive and using the same index, but if you use -drive to add a floppy to a
97c9bf278bSKevin Wolf# different index, you get both of them. However, as soon as you use any
98c9bf278bSKevin Wolf# '-device floppy', even to a different slot, the default drive is disabled.
99c9bf278bSKevin Wolf
100c9bf278bSKevin Wolfecho
101c9bf278bSKevin Wolfecho
102c9bf278bSKevin Wolfecho === Default ===
103c9bf278bSKevin Wolf
104c9bf278bSKevin Wolfcheck_floppy_qtree
105c9bf278bSKevin Wolf
106c9bf278bSKevin Wolfecho
107c9bf278bSKevin Wolfecho
108c9bf278bSKevin Wolfecho === Using -fda/-fdb options ===
109c9bf278bSKevin Wolf
110c9bf278bSKevin Wolfcheck_floppy_qtree -fda "$TEST_IMG"
111c9bf278bSKevin Wolfcheck_floppy_qtree -fdb "$TEST_IMG"
1127ceb4fc1SFam Zhengcheck_floppy_qtree -fda "$TEST_IMG" -fdb "$TEST_IMG.2"
113c9bf278bSKevin Wolf
114c9bf278bSKevin Wolf
115c9bf278bSKevin Wolfecho
116c9bf278bSKevin Wolfecho
117c9bf278bSKevin Wolfecho === Using -drive options ===
118c9bf278bSKevin Wolf
119c9bf278bSKevin Wolfcheck_floppy_qtree -drive if=floppy,file="$TEST_IMG"
120c9bf278bSKevin Wolfcheck_floppy_qtree -drive if=floppy,file="$TEST_IMG",index=1
1217ceb4fc1SFam Zhengcheck_floppy_qtree -drive if=floppy,file="$TEST_IMG" -drive if=floppy,file="$TEST_IMG.2",index=1
122c9bf278bSKevin Wolf
123c9bf278bSKevin Wolfecho
124c9bf278bSKevin Wolfecho
125c9bf278bSKevin Wolfecho === Using -drive if=none and -global ===
126c9bf278bSKevin Wolf
127c9bf278bSKevin Wolfcheck_floppy_qtree -drive if=none,file="$TEST_IMG" -global isa-fdc.driveA=none0
128c9bf278bSKevin Wolfcheck_floppy_qtree -drive if=none,file="$TEST_IMG" -global isa-fdc.driveB=none0
1297ceb4fc1SFam Zhengcheck_floppy_qtree -drive if=none,file="$TEST_IMG" -drive if=none,file="$TEST_IMG.2" \
130c9bf278bSKevin Wolf                   -global isa-fdc.driveA=none0 -global isa-fdc.driveB=none1
131c9bf278bSKevin Wolf
132c9bf278bSKevin Wolfecho
133c9bf278bSKevin Wolfecho
134c9bf278bSKevin Wolfecho === Using -drive if=none and -device ===
135c9bf278bSKevin Wolf
136c9bf278bSKevin Wolfcheck_floppy_qtree -drive if=none,file="$TEST_IMG" -device floppy,drive=none0
137c9bf278bSKevin Wolfcheck_floppy_qtree -drive if=none,file="$TEST_IMG" -device floppy,drive=none0,unit=1
1387ceb4fc1SFam Zhengcheck_floppy_qtree -drive if=none,file="$TEST_IMG" -drive if=none,file="$TEST_IMG.2" \
139c9bf278bSKevin Wolf                   -device floppy,drive=none0 -device floppy,drive=none1,unit=1
140c9bf278bSKevin Wolf
141c9bf278bSKevin Wolfecho
142c9bf278bSKevin Wolfecho
143c9bf278bSKevin Wolfecho === Mixing -fdX and -global ===
144c9bf278bSKevin Wolf
145c9bf278bSKevin Wolf# Working
1467ceb4fc1SFam Zhengcheck_floppy_qtree -fda "$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -global isa-fdc.driveB=none0
1477ceb4fc1SFam Zhengcheck_floppy_qtree -fdb "$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -global isa-fdc.driveA=none0
148c9bf278bSKevin Wolf
149c9bf278bSKevin Wolf# Conflicting (-fdX wins)
1507ceb4fc1SFam Zhengcheck_floppy_qtree -fda "$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -global isa-fdc.driveA=none0
1517ceb4fc1SFam Zhengcheck_floppy_qtree -fdb "$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -global isa-fdc.driveB=none0
152c9bf278bSKevin Wolf
153c9bf278bSKevin Wolfecho
154c9bf278bSKevin Wolfecho
155c9bf278bSKevin Wolfecho === Mixing -fdX and -device ===
156c9bf278bSKevin Wolf
157c9bf278bSKevin Wolf# Working
1587ceb4fc1SFam Zhengcheck_floppy_qtree -fda "$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -device floppy,drive=none0
1597ceb4fc1SFam Zhengcheck_floppy_qtree -fda "$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -device floppy,drive=none0,unit=1
160c9bf278bSKevin Wolf
1617ceb4fc1SFam Zhengcheck_floppy_qtree -fdb "$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -device floppy,drive=none0
1627ceb4fc1SFam Zhengcheck_floppy_qtree -fdb "$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -device floppy,drive=none0,unit=0
163c9bf278bSKevin Wolf
164c9bf278bSKevin Wolf# Conflicting
1657ceb4fc1SFam Zhengcheck_floppy_qtree -fda "$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -device floppy,drive=none0,unit=0
1667ceb4fc1SFam Zhengcheck_floppy_qtree -fdb "$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -device floppy,drive=none0,unit=1
167c9bf278bSKevin Wolf
168c9bf278bSKevin Wolfecho
169c9bf278bSKevin Wolfecho
170c9bf278bSKevin Wolfecho === Mixing -drive and -device ===
171c9bf278bSKevin Wolf
172c9bf278bSKevin Wolf# Working
1737ceb4fc1SFam Zhengcheck_floppy_qtree -drive if=floppy,file="$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -device floppy,drive=none0
1747ceb4fc1SFam Zhengcheck_floppy_qtree -drive if=floppy,file="$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -device floppy,drive=none0,unit=1
175c9bf278bSKevin Wolf
176c9bf278bSKevin Wolf# Conflicting
1777ceb4fc1SFam Zhengcheck_floppy_qtree -drive if=floppy,file="$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -device floppy,drive=none0,unit=0
178c9bf278bSKevin Wolf
179c9bf278bSKevin Wolfecho
180c9bf278bSKevin Wolfecho
181c9bf278bSKevin Wolfecho === Mixing -global and -device ===
182c9bf278bSKevin Wolf
183c9bf278bSKevin Wolf# Working
1847ceb4fc1SFam Zhengcheck_floppy_qtree -drive if=none,file="$TEST_IMG" -drive if=none,file="$TEST_IMG.2" \
185c9bf278bSKevin Wolf                   -global isa-fdc.driveA=none0 -device floppy,drive=none1
1867ceb4fc1SFam Zhengcheck_floppy_qtree -drive if=none,file="$TEST_IMG" -drive if=none,file="$TEST_IMG.2" \
187c9bf278bSKevin Wolf                   -global isa-fdc.driveA=none0 -device floppy,drive=none1,unit=1
188c9bf278bSKevin Wolf
1897ceb4fc1SFam Zhengcheck_floppy_qtree -drive if=none,file="$TEST_IMG" -drive if=none,file="$TEST_IMG.2" \
190c9bf278bSKevin Wolf                   -global isa-fdc.driveB=none0 -device floppy,drive=none1
1917ceb4fc1SFam Zhengcheck_floppy_qtree -drive if=none,file="$TEST_IMG" -drive if=none,file="$TEST_IMG.2" \
192c9bf278bSKevin Wolf                   -global isa-fdc.driveB=none0 -device floppy,drive=none1,unit=0
193c9bf278bSKevin Wolf
194c9bf278bSKevin Wolf# Conflicting
1957ceb4fc1SFam Zhengcheck_floppy_qtree -drive if=none,file="$TEST_IMG" -drive if=none,file="$TEST_IMG.2" \
196c9bf278bSKevin Wolf                   -global isa-fdc.driveA=none0 -device floppy,drive=none1,unit=0
1977ceb4fc1SFam Zhengcheck_floppy_qtree -drive if=none,file="$TEST_IMG" -drive if=none,file="$TEST_IMG.2" \
198c9bf278bSKevin Wolf                   -global isa-fdc.driveB=none0 -device floppy,drive=none1,unit=1
199c9bf278bSKevin Wolf
200c9bf278bSKevin Wolfecho
201c9bf278bSKevin Wolfecho
202c9bf278bSKevin Wolfecho === Too many floppy drives ===
203c9bf278bSKevin Wolf
204c9bf278bSKevin Wolf# Working
205c9bf278bSKevin Wolfcheck_floppy_qtree -drive if=floppy,file="$TEST_IMG" \
2067ceb4fc1SFam Zheng                   -drive if=none,file="$TEST_IMG.2" \
2077ceb4fc1SFam Zheng                   -drive if=none,file="$TEST_IMG.3" \
208c9bf278bSKevin Wolf                   -global isa-fdc.driveB=none0 \
209c9bf278bSKevin Wolf                   -device floppy,drive=none1
210c9bf278bSKevin Wolf
211c9bf278bSKevin Wolfecho
212c9bf278bSKevin Wolfecho
213c9bf278bSKevin Wolfecho === Creating an empty drive with anonymous BB ===
214c9bf278bSKevin Wolf
215c9bf278bSKevin Wolfcheck_floppy_qtree -device floppy
216c9bf278bSKevin Wolfcheck_floppy_qtree -device floppy,drive-type=120
217c9bf278bSKevin Wolfcheck_floppy_qtree -device floppy,drive-type=144
218c9bf278bSKevin Wolfcheck_floppy_qtree -device floppy,drive-type=288
219c9bf278bSKevin Wolf
220c9bf278bSKevin Wolfecho
221c9bf278bSKevin Wolfecho
222c9bf278bSKevin Wolfecho === Try passing different drive size with image ===
223c9bf278bSKevin Wolf
224c9bf278bSKevin Wolfcheck_floppy_qtree -drive if=none,file="$TEST_IMG" -device floppy,drive=none0,drive-type=120
225c9bf278bSKevin Wolfcheck_floppy_qtree -drive if=none,file="$TEST_IMG" -device floppy,drive=none0,drive-type=288
226c9bf278bSKevin Wolf
227c9bf278bSKevin Wolfecho
228c9bf278bSKevin Wolfecho
229c9bf278bSKevin Wolfecho === Try passing different block sizes ===
230c9bf278bSKevin Wolf
231c9bf278bSKevin Wolf# Explicitly setting the default is okay
232c9bf278bSKevin Wolfcheck_floppy_qtree -drive if=none,file="$TEST_IMG" -device floppy,drive=none0,logical_block_size=512
233c9bf278bSKevin Wolfcheck_floppy_qtree -drive if=none,file="$TEST_IMG" -device floppy,drive=none0,physical_block_size=512
234c9bf278bSKevin Wolf
235c9bf278bSKevin Wolf# Changing it is not
236c9bf278bSKevin Wolfcheck_floppy_qtree -drive if=none,file="$TEST_IMG" -device floppy,drive=none0,logical_block_size=4096
237c9bf278bSKevin Wolfcheck_floppy_qtree -drive if=none,file="$TEST_IMG" -device floppy,drive=none0,physical_block_size=1024
238c9bf278bSKevin Wolf
239c9bf278bSKevin Wolfecho
240c9bf278bSKevin Wolfecho
241c9bf278bSKevin Wolfecho === Writethrough caching ===
242c9bf278bSKevin Wolf
243c9bf278bSKevin Wolfcheck_cache_mode -device floppy,drive=none0
244c9bf278bSKevin Wolfcheck_cache_mode -device floppy,drive=none0,write-cache=on
245c9bf278bSKevin Wolfcheck_cache_mode -device floppy,drive=none0,write-cache=off
246c9bf278bSKevin Wolf
247c9bf278bSKevin Wolf# success, all done
248c9bf278bSKevin Wolfecho "*** done"
249c9bf278bSKevin Wolfrm -f $seq.full
250c9bf278bSKevin Wolfstatus=0
251