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