xref: /qemu/tests/qemu-iotests/232 (revision 36f808fa15f85a894c2f6cce9df46d27e8f0f129)
1*36f808faSKevin Wolf#!/bin/bash
2*36f808faSKevin Wolf#
3*36f808faSKevin Wolf# Test for auto-read-only
4*36f808faSKevin Wolf#
5*36f808faSKevin Wolf# Copyright (C) 2018 Red Hat, Inc.
6*36f808faSKevin Wolf#
7*36f808faSKevin Wolf# This program is free software; you can redistribute it and/or modify
8*36f808faSKevin Wolf# it under the terms of the GNU General Public License as published by
9*36f808faSKevin Wolf# the Free Software Foundation; either version 2 of the License, or
10*36f808faSKevin Wolf# (at your option) any later version.
11*36f808faSKevin Wolf#
12*36f808faSKevin Wolf# This program is distributed in the hope that it will be useful,
13*36f808faSKevin Wolf# but WITHOUT ANY WARRANTY; without even the implied warranty of
14*36f808faSKevin Wolf# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15*36f808faSKevin Wolf# GNU General Public License for more details.
16*36f808faSKevin Wolf#
17*36f808faSKevin Wolf# You should have received a copy of the GNU General Public License
18*36f808faSKevin Wolf# along with this program.  If not, see <http://www.gnu.org/licenses/>.
19*36f808faSKevin Wolf#
20*36f808faSKevin Wolf
21*36f808faSKevin Wolf# creator
22*36f808faSKevin Wolfowner=kwolf@redhat.com
23*36f808faSKevin Wolf
24*36f808faSKevin Wolfseq=`basename $0`
25*36f808faSKevin Wolfecho "QA output created by $seq"
26*36f808faSKevin Wolf
27*36f808faSKevin Wolfhere=`pwd`
28*36f808faSKevin Wolfstatus=1	# failure is the default!
29*36f808faSKevin Wolf
30*36f808faSKevin Wolf_cleanup()
31*36f808faSKevin Wolf{
32*36f808faSKevin Wolf    _cleanup_test_img
33*36f808faSKevin Wolf    rm -f $TEST_IMG.snap
34*36f808faSKevin Wolf}
35*36f808faSKevin Wolftrap "_cleanup; exit \$status" 0 1 2 3 15
36*36f808faSKevin Wolf
37*36f808faSKevin Wolf# get standard environment, filters and checks
38*36f808faSKevin Wolf. ./common.rc
39*36f808faSKevin Wolf. ./common.filter
40*36f808faSKevin Wolf
41*36f808faSKevin Wolf_supported_fmt generic
42*36f808faSKevin Wolf_supported_proto file
43*36f808faSKevin Wolf_supported_os Linux
44*36f808faSKevin Wolf
45*36f808faSKevin Wolffunction do_run_qemu()
46*36f808faSKevin Wolf{
47*36f808faSKevin Wolf    echo Testing: "$@"
48*36f808faSKevin Wolf    (
49*36f808faSKevin Wolf        if ! test -t 0; then
50*36f808faSKevin Wolf            while read cmd; do
51*36f808faSKevin Wolf                echo $cmd
52*36f808faSKevin Wolf            done
53*36f808faSKevin Wolf        fi
54*36f808faSKevin Wolf        echo quit
55*36f808faSKevin Wolf    ) | $QEMU -nographic -monitor stdio -nodefaults "$@"
56*36f808faSKevin Wolf    echo
57*36f808faSKevin Wolf}
58*36f808faSKevin Wolf
59*36f808faSKevin Wolffunction run_qemu()
60*36f808faSKevin Wolf{
61*36f808faSKevin Wolf    do_run_qemu "$@" 2>&1 | _filter_testdir | _filter_qemu | _filter_hmp |
62*36f808faSKevin Wolf        _filter_generated_node_ids | _filter_imgfmt
63*36f808faSKevin Wolf}
64*36f808faSKevin Wolf
65*36f808faSKevin Wolffunction run_qemu_info_block()
66*36f808faSKevin Wolf{
67*36f808faSKevin Wolf    echo "info block -n" | run_qemu "$@" | grep -e "(file" -e "QEMU_PROG"
68*36f808faSKevin Wolf}
69*36f808faSKevin Wolf
70*36f808faSKevin Wolfsize=128M
71*36f808faSKevin Wolf
72*36f808faSKevin Wolf_make_test_img $size
73*36f808faSKevin Wolf
74*36f808faSKevin Wolfecho
75*36f808faSKevin Wolfecho "=== -drive with read-write image: read-only/auto-read-only combinations ==="
76*36f808faSKevin Wolfecho
77*36f808faSKevin Wolf
78*36f808faSKevin Wolfrun_qemu_info_block -drive driver=file,file="$TEST_IMG",if=none,read-only=on,auto-read-only=off
79*36f808faSKevin Wolfrun_qemu_info_block -drive driver=file,file="$TEST_IMG",if=none,read-only=on,auto-read-only=on
80*36f808faSKevin Wolfrun_qemu_info_block -drive driver=file,file="$TEST_IMG",if=none,read-only=on
81*36f808faSKevin Wolfecho
82*36f808faSKevin Wolfrun_qemu_info_block -drive driver=file,file="$TEST_IMG",if=none,read-only=off,auto-read-only=off
83*36f808faSKevin Wolfrun_qemu_info_block -drive driver=file,file="$TEST_IMG",if=none,read-only=off,auto-read-only=on
84*36f808faSKevin Wolfrun_qemu_info_block -drive driver=file,file="$TEST_IMG",if=none,read-only=off
85*36f808faSKevin Wolfecho
86*36f808faSKevin Wolfrun_qemu_info_block -drive driver=file,file="$TEST_IMG",if=none,auto-read-only=off
87*36f808faSKevin Wolfrun_qemu_info_block -drive driver=file,file="$TEST_IMG",if=none,auto-read-only=on
88*36f808faSKevin Wolfrun_qemu_info_block -drive driver=file,file="$TEST_IMG",if=none
89*36f808faSKevin Wolf
90*36f808faSKevin Wolfecho
91*36f808faSKevin Wolfecho "=== -drive with read-only image: read-only/auto-read-only combinations ==="
92*36f808faSKevin Wolfecho
93*36f808faSKevin Wolf
94*36f808faSKevin Wolfchmod a-w $TEST_IMG
95*36f808faSKevin Wolf
96*36f808faSKevin Wolfrun_qemu_info_block -drive driver=file,file="$TEST_IMG",if=none,read-only=on,auto-read-only=off
97*36f808faSKevin Wolfrun_qemu_info_block -drive driver=file,file="$TEST_IMG",if=none,read-only=on,auto-read-only=on
98*36f808faSKevin Wolfrun_qemu_info_block -drive driver=file,file="$TEST_IMG",if=none,read-only=on
99*36f808faSKevin Wolfecho
100*36f808faSKevin Wolfrun_qemu_info_block -drive driver=file,file="$TEST_IMG",if=none,read-only=off,auto-read-only=off
101*36f808faSKevin Wolfrun_qemu_info_block -drive driver=file,file="$TEST_IMG",if=none,read-only=off,auto-read-only=on
102*36f808faSKevin Wolfrun_qemu_info_block -drive driver=file,file="$TEST_IMG",if=none,read-only=off
103*36f808faSKevin Wolfecho
104*36f808faSKevin Wolfrun_qemu_info_block -drive driver=file,file="$TEST_IMG",if=none,auto-read-only=off
105*36f808faSKevin Wolfrun_qemu_info_block -drive driver=file,file="$TEST_IMG",if=none,auto-read-only=on
106*36f808faSKevin Wolfrun_qemu_info_block -drive driver=file,file="$TEST_IMG",if=none
107*36f808faSKevin Wolf
108*36f808faSKevin Wolfecho
109*36f808faSKevin Wolfecho "=== -blockdev with read-write image: read-only/auto-read-only combinations ==="
110*36f808faSKevin Wolfecho
111*36f808faSKevin Wolf
112*36f808faSKevin Wolfchmod a+w $TEST_IMG
113*36f808faSKevin Wolf
114*36f808faSKevin Wolfrun_qemu_info_block -blockdev driver=file,filename="$TEST_IMG",node-name=node0,read-only=on,auto-read-only=off
115*36f808faSKevin Wolfrun_qemu_info_block -blockdev driver=file,filename="$TEST_IMG",node-name=node0,read-only=on,auto-read-only=on
116*36f808faSKevin Wolfrun_qemu_info_block -blockdev driver=file,filename="$TEST_IMG",node-name=node0,read-only=on
117*36f808faSKevin Wolfecho
118*36f808faSKevin Wolfrun_qemu_info_block -blockdev driver=file,filename="$TEST_IMG",node-name=node0,read-only=off,auto-read-only=off
119*36f808faSKevin Wolfrun_qemu_info_block -blockdev driver=file,filename="$TEST_IMG",node-name=node0,read-only=off,auto-read-only=on
120*36f808faSKevin Wolfrun_qemu_info_block -blockdev driver=file,filename="$TEST_IMG",node-name=node0,read-only=off
121*36f808faSKevin Wolfecho
122*36f808faSKevin Wolfrun_qemu_info_block -blockdev driver=file,filename="$TEST_IMG",node-name=node0,auto-read-only=off
123*36f808faSKevin Wolfrun_qemu_info_block -blockdev driver=file,filename="$TEST_IMG",node-name=node0,auto-read-only=on
124*36f808faSKevin Wolfrun_qemu_info_block -blockdev driver=file,filename="$TEST_IMG",node-name=node0
125*36f808faSKevin Wolf
126*36f808faSKevin Wolfecho
127*36f808faSKevin Wolfecho "=== -blockdev with read-only image: read-only/auto-read-only combinations ==="
128*36f808faSKevin Wolfecho
129*36f808faSKevin Wolf
130*36f808faSKevin Wolfchmod a-w $TEST_IMG
131*36f808faSKevin Wolf
132*36f808faSKevin Wolfrun_qemu_info_block -blockdev driver=file,filename="$TEST_IMG",node-name=node0,read-only=on,auto-read-only=off
133*36f808faSKevin Wolfrun_qemu_info_block -blockdev driver=file,filename="$TEST_IMG",node-name=node0,read-only=on,auto-read-only=on
134*36f808faSKevin Wolfrun_qemu_info_block -blockdev driver=file,filename="$TEST_IMG",node-name=node0,read-only=on
135*36f808faSKevin Wolfecho
136*36f808faSKevin Wolfrun_qemu_info_block -blockdev driver=file,filename="$TEST_IMG",node-name=node0,read-only=off,auto-read-only=off
137*36f808faSKevin Wolfrun_qemu_info_block -blockdev driver=file,filename="$TEST_IMG",node-name=node0,read-only=off,auto-read-only=on
138*36f808faSKevin Wolfrun_qemu_info_block -blockdev driver=file,filename="$TEST_IMG",node-name=node0,read-only=off
139*36f808faSKevin Wolfecho
140*36f808faSKevin Wolfrun_qemu_info_block -blockdev driver=file,filename="$TEST_IMG",node-name=node0,auto-read-only=off
141*36f808faSKevin Wolfrun_qemu_info_block -blockdev driver=file,filename="$TEST_IMG",node-name=node0,auto-read-only=on
142*36f808faSKevin Wolfrun_qemu_info_block -blockdev driver=file,filename="$TEST_IMG",node-name=node0
143*36f808faSKevin Wolf
144*36f808faSKevin Wolf# success, all done
145*36f808faSKevin Wolfecho "*** done"
146*36f808faSKevin Wolfrm -f $seq.full
147*36f808faSKevin Wolfstatus=0
148