xref: /openbmc/qemu/tests/qemu-iotests/232 (revision dd8d6a2d)
1#!/usr/bin/env bash
2#
3# Test for auto-read-only
4#
5# Copyright (C) 2018 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}
33trap "_cleanup; exit \$status" 0 1 2 3 15
34
35# get standard environment, filters and checks
36. ./common.rc
37. ./common.filter
38
39_supported_fmt generic
40_supported_proto file
41_supported_os Linux
42
43do_run_qemu()
44{
45    echo Testing: "$@"
46    (
47        if ! test -t 0; then
48            while read cmd; do
49                echo $cmd
50            done
51        fi
52        echo quit
53    ) | $QEMU -nographic -monitor stdio -nodefaults "$@"
54    echo
55}
56
57run_qemu()
58{
59    do_run_qemu "$@" 2>&1 | _filter_testdir | _filter_qemu | _filter_hmp |
60        _filter_generated_node_ids | _filter_imgfmt
61}
62
63run_qemu_info_block()
64{
65    echo "info block -n" | run_qemu "$@" | grep -e "(file" -e "QEMU_PROG"
66}
67
68size=128M
69
70_make_test_img $size
71
72if [ -n "$TEST_IMG_FILE" ]; then
73    TEST_IMG=$TEST_IMG_FILE
74fi
75
76echo
77echo "=== -drive with read-write image: read-only/auto-read-only combinations ==="
78echo
79
80run_qemu_info_block -drive driver=file,file="$TEST_IMG",if=none,read-only=on,auto-read-only=off
81run_qemu_info_block -drive driver=file,file="$TEST_IMG",if=none,read-only=on,auto-read-only=on
82run_qemu_info_block -drive driver=file,file="$TEST_IMG",if=none,read-only=on
83echo
84run_qemu_info_block -drive driver=file,file="$TEST_IMG",if=none,read-only=off,auto-read-only=off
85run_qemu_info_block -drive driver=file,file="$TEST_IMG",if=none,read-only=off,auto-read-only=on
86run_qemu_info_block -drive driver=file,file="$TEST_IMG",if=none,read-only=off
87echo
88run_qemu_info_block -drive driver=file,file="$TEST_IMG",if=none,auto-read-only=off
89run_qemu_info_block -drive driver=file,file="$TEST_IMG",if=none,auto-read-only=on
90run_qemu_info_block -drive driver=file,file="$TEST_IMG",if=none
91
92echo
93echo "=== -drive with read-only image: read-only/auto-read-only combinations ==="
94echo
95
96chmod a-w $TEST_IMG
97
98run_qemu_info_block -drive driver=file,file="$TEST_IMG",if=none,read-only=on,auto-read-only=off
99run_qemu_info_block -drive driver=file,file="$TEST_IMG",if=none,read-only=on,auto-read-only=on
100run_qemu_info_block -drive driver=file,file="$TEST_IMG",if=none,read-only=on
101echo
102run_qemu_info_block -drive driver=file,file="$TEST_IMG",if=none,read-only=off,auto-read-only=off
103run_qemu_info_block -drive driver=file,file="$TEST_IMG",if=none,read-only=off,auto-read-only=on
104run_qemu_info_block -drive driver=file,file="$TEST_IMG",if=none,read-only=off
105echo
106run_qemu_info_block -drive driver=file,file="$TEST_IMG",if=none,auto-read-only=off
107run_qemu_info_block -drive driver=file,file="$TEST_IMG",if=none,auto-read-only=on
108run_qemu_info_block -drive driver=file,file="$TEST_IMG",if=none
109
110echo
111echo "=== -blockdev with read-write image: read-only/auto-read-only combinations ==="
112echo
113
114chmod a+w $TEST_IMG
115
116run_qemu_info_block -blockdev driver=file,filename="$TEST_IMG",node-name=node0,read-only=on,auto-read-only=off
117run_qemu_info_block -blockdev driver=file,filename="$TEST_IMG",node-name=node0,read-only=on,auto-read-only=on
118run_qemu_info_block -blockdev driver=file,filename="$TEST_IMG",node-name=node0,read-only=on
119echo
120run_qemu_info_block -blockdev driver=file,filename="$TEST_IMG",node-name=node0,read-only=off,auto-read-only=off
121run_qemu_info_block -blockdev driver=file,filename="$TEST_IMG",node-name=node0,read-only=off,auto-read-only=on
122run_qemu_info_block -blockdev driver=file,filename="$TEST_IMG",node-name=node0,read-only=off
123echo
124run_qemu_info_block -blockdev driver=file,filename="$TEST_IMG",node-name=node0,auto-read-only=off
125run_qemu_info_block -blockdev driver=file,filename="$TEST_IMG",node-name=node0,auto-read-only=on
126run_qemu_info_block -blockdev driver=file,filename="$TEST_IMG",node-name=node0
127
128echo
129echo "=== -blockdev with read-only image: read-only/auto-read-only combinations ==="
130echo
131
132chmod a-w $TEST_IMG
133
134run_qemu_info_block -blockdev driver=file,filename="$TEST_IMG",node-name=node0,read-only=on,auto-read-only=off
135run_qemu_info_block -blockdev driver=file,filename="$TEST_IMG",node-name=node0,read-only=on,auto-read-only=on
136run_qemu_info_block -blockdev driver=file,filename="$TEST_IMG",node-name=node0,read-only=on
137echo
138run_qemu_info_block -blockdev driver=file,filename="$TEST_IMG",node-name=node0,read-only=off,auto-read-only=off
139run_qemu_info_block -blockdev driver=file,filename="$TEST_IMG",node-name=node0,read-only=off,auto-read-only=on
140run_qemu_info_block -blockdev driver=file,filename="$TEST_IMG",node-name=node0,read-only=off
141echo
142run_qemu_info_block -blockdev driver=file,filename="$TEST_IMG",node-name=node0,auto-read-only=off
143run_qemu_info_block -blockdev driver=file,filename="$TEST_IMG",node-name=node0,auto-read-only=on
144run_qemu_info_block -blockdev driver=file,filename="$TEST_IMG",node-name=node0
145
146# success, all done
147echo "*** done"
148rm -f $seq.full
149status=0
150