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