qapi/error: Check format string argument in error_*prepend()
[qemu/armbru.git] / tests / qemu-iotests / 028
blob5d043cef9289c3334f16b34746eaf7a8a80f040f
1 #!/usr/bin/env bash
3 # Test that backing files can be smaller than the image
5 # Copyright (C) 2010 IBM, Corp.
7 # Based on 017:
8 # Copyright (C) 2009 Red Hat, Inc.
10 # This program is free software; you can redistribute it and/or modify
11 # it under the terms of the GNU General Public License as published by
12 # the Free Software Foundation; either version 2 of the License, or
13 # (at your option) any later version.
15 # This program is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
20 # You should have received a copy of the GNU General Public License
21 # along with this program. If not, see <http://www.gnu.org/licenses/>.
24 # creator
25 owner=stefanha@linux.vnet.ibm.com
27 seq=`basename $0`
28 echo "QA output created by $seq"
30 status=1 # failure is the default!
32 _cleanup()
34 _cleanup_qemu
35 _rm_test_img "${TEST_IMG}.copy"
36 _cleanup_test_img
38 trap "_cleanup; exit \$status" 0 1 2 3 15
40 # get standard environment, filters and checks
41 . ./common.rc
42 . ./common.filter
43 . ./common.pattern
44 . ./common.qemu
46 # Any format supporting backing files except vmdk and qcow which do not support
47 # smaller backing files.
48 _supported_fmt qcow2 qed
49 _supported_proto file
50 _supported_os Linux
52 # Choose a size that is not necessarily a cluster size multiple for image
53 # formats that use clusters. This will ensure that the base image doesn't end
54 # precisely on a cluster boundary (the easy case).
55 image_size=$(( 4 * 1024 * 1024 * 1024 + 3 * 512 ))
57 # The base image is smaller than the image file
58 base_size=$(( image_size - 1024 * 1024 * 1024 ))
60 offset=$(( base_size - 32 * 1024 ))
62 TEST_IMG_SAVE="$TEST_IMG"
63 TEST_IMG="$TEST_IMG.base"
65 _make_test_img $base_size
67 echo "Filling base image"
68 echo
70 # Fill end of base image with a pattern, skipping every other sector
71 io writev $offset 512 1024 32
73 _check_test_img
75 echo "Creating test image with backing file"
76 echo
78 TEST_IMG="$TEST_IMG_SAVE"
79 _make_test_img -b "$TEST_IMG.base" -F $IMGFMT $image_size
81 echo "Filling test image"
82 echo
84 # Write every other sector around where the base image ends
85 io writev $(( offset + 512 )) 512 1024 64
87 _check_test_img
89 echo "Reading"
90 echo
92 # Base image sectors
93 io readv $(( offset )) 512 1024 32
95 # Image sectors
96 io readv $(( offset + 512 )) 512 1024 64
98 # Zero sectors beyond end of base image
99 io_zero readv $(( offset + 32 * 1024 )) 512 1024 32
101 _check_test_img
103 # Rebase it on top of its base image
104 $QEMU_IMG rebase -b "$TEST_IMG.base" -F $IMGFMT "$TEST_IMG"
106 echo
107 echo block-backup
108 echo
110 qemu_comm_method="monitor"
111 _launch_qemu -drive file="${TEST_IMG}",cache=${CACHEMODE},aio=${AIOMODE},id=disk
112 h=$QEMU_HANDLE
113 if [ "${VALGRIND_QEMU}" == "y" ]; then
114 QEMU_COMM_TIMEOUT=7
115 else
116 QEMU_COMM_TIMEOUT=1
119 # Silence output since it contains the disk image path and QEMU's readline
120 # character echoing makes it very hard to filter the output. Plus, there
121 # is no telling how many times the command will repeat before succeeding.
122 # (Note that creating the image results in a "Formatting..." message over
123 # stdout, which is the same channel the monitor uses. We cannot reliably
124 # wait for it because the monitor output may interact with it in such a
125 # way that _timed_wait_for cannot read it. However, once the block job is
126 # done, we know that the "Formatting..." message must have appeared
127 # already, so the output is still deterministic.)
128 silent=y _send_qemu_cmd $h "drive_backup disk ${TEST_IMG}.copy" "(qemu)"
129 silent=y qemu_cmd_repeat=20 _send_qemu_cmd $h "info block-jobs" "No active jobs"
130 _send_qemu_cmd $h "info block-jobs" "No active jobs"
131 _send_qemu_cmd $h 'quit' ""
133 # Base image sectors
134 TEST_IMG="${TEST_IMG}.copy" io readv $(( offset )) 512 1024 32
136 # Image sectors
137 TEST_IMG="${TEST_IMG}.copy" io readv $(( offset + 512 )) 512 1024 64
139 # Zero sectors beyond end of base image
140 TEST_IMG="${TEST_IMG}.copy" io_zero readv $(( offset + 32 * 1024 )) 512 1024 32
143 _check_test_img
145 # success, all done
146 echo "*** done"
147 rm -f $seq.full
148 status=0