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