Merge tag 'v9.0.0-rc3'
[qemu/ar7.git] / tests / qemu-iotests / tests / parallels-checks
blobb281246a423ac94ca620505e11b56d8e5470f23e
1 #!/usr/bin/env bash
2 # group: rw quick
4 # Test qemu-img check for parallels format
6 # Copyright (C) 2022 Virtuozzo International GmbH
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.
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.
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/>.
22 # creator
23 owner=alexander.ivanov@virtuozzo.com
25 seq=`basename $0`
26 echo "QA output created by $seq"
28 status=1 # failure is the default!
30 _cleanup()
32 _cleanup_test_img
34 trap "_cleanup; exit \$status" 0 1 2 3 15
36 # get standard environment, filters and checks
37 . ../common.rc
38 . ../common.filter
40 _supported_fmt parallels
41 _supported_proto file
42 _supported_os Linux
44 SIZE=$((4 * 1024 * 1024))
45 IMGFMT=parallels
46 CLUSTER_SIZE_OFFSET=28
47 DATA_OFF_OFFSET=48
48 BAT_OFFSET=64
50 _make_test_img $SIZE
52 CLUSTER_SIZE=$(peek_file_le $TEST_IMG $CLUSTER_SIZE_OFFSET 4)
53 CLUSTER_SIZE=$((CLUSTER_SIZE * 512))
54 LAST_CLUSTER_OFF=$((SIZE - CLUSTER_SIZE))
55 LAST_CLUSTER=$((LAST_CLUSTER_OFF/CLUSTER_SIZE))
57 echo "== TEST OUT OF IMAGE CHECK =="
59 echo "== write pattern =="
60 { $QEMU_IO -c "write -P 0x11 0 $SIZE" "$TEST_IMG"; } 2>&1 | _filter_qemu_io | _filter_testdir
62 echo "== corrupt image =="
63 cluster=$(($LAST_CLUSTER + 2))
64 poke_file "$TEST_IMG" "$BAT_OFFSET" "\x$cluster\x00\x00\x00"
66 echo "== read corrupted image with repairing =="
67 { $QEMU_IO -c "read -P 0x00 0 $CLUSTER_SIZE" "$TEST_IMG"; } 2>&1 | _filter_qemu_io | _filter_testdir
69 # Clear image
70 _make_test_img $SIZE
72 echo "== TEST LEAK CHECK =="
74 echo "== write pattern to last cluster =="
75 echo "write -P 0x11 $LAST_CLUSTER_OFF $CLUSTER_SIZE"
76 { $QEMU_IO -c "write -P 0x11 $LAST_CLUSTER_OFF $CLUSTER_SIZE" "$TEST_IMG"; } 2>&1 | _filter_qemu_io | _filter_testdir
78 file_size=`stat --printf="%s" "$TEST_IMG"`
79 echo "file size: $file_size"
81 echo "== extend image by 1 cluster =="
82 fallocate -xl $((file_size + CLUSTER_SIZE)) "$TEST_IMG"
84 file_size=`stat --printf="%s" "$TEST_IMG"`
85 echo "file size: $file_size"
87 echo "== repair image =="
88 _check_test_img -r all
90 file_size=`stat --printf="%s" "$TEST_IMG"`
91 echo "file size: $file_size"
93 echo "== check last cluster =="
94 { $QEMU_IO -r -c "read -P 0x11 $LAST_CLUSTER_OFF $CLUSTER_SIZE" "$TEST_IMG"; } 2>&1 | _filter_qemu_io | _filter_testdir
96 # Clear image
97 _make_test_img $SIZE
99 echo "== TEST DUPLICATION CHECK =="
101 echo "== write pattern to whole image =="
102 { $QEMU_IO -c "write -P 0x11 0 $SIZE" "$TEST_IMG"; } 2>&1 | _filter_qemu_io | _filter_testdir
104 echo "== write another pattern to second cluster =="
105 { $QEMU_IO -c "write -P 0x55 $CLUSTER_SIZE $CLUSTER_SIZE" "$TEST_IMG"; } 2>&1 | _filter_qemu_io | _filter_testdir
107 echo "== check second cluster =="
108 { $QEMU_IO -r -c "read -P 0x55 $CLUSTER_SIZE $CLUSTER_SIZE" "$TEST_IMG"; } 2>&1 | _filter_qemu_io | _filter_testdir
111 echo "== corrupt image =="
112 poke_file "$TEST_IMG" "$(($BAT_OFFSET + 4))" "\x01\x00\x00\x00"
114 echo "== check second cluster =="
115 { $QEMU_IO -r -c "read -P 0x11 $CLUSTER_SIZE $CLUSTER_SIZE" "$TEST_IMG"; } 2>&1 | _filter_qemu_io | _filter_testdir
117 echo "== repair image =="
118 _check_test_img -r all
120 echo "== check the first cluster =="
121 { $QEMU_IO -r -c "read -P 0x11 0 $CLUSTER_SIZE" "$TEST_IMG"; } 2>&1 | _filter_qemu_io | _filter_testdir
123 echo "== check second cluster =="
124 { $QEMU_IO -r -c "read -P 0x11 $CLUSTER_SIZE $CLUSTER_SIZE" "$TEST_IMG"; } 2>&1 | _filter_qemu_io | _filter_testdir
126 echo "== write another pattern to the first clusters =="
127 { $QEMU_IO -c "write -P 0x66 0 $CLUSTER_SIZE" "$TEST_IMG"; } 2>&1 | _filter_qemu_io | _filter_testdir
129 echo "== check the first cluster =="
130 { $QEMU_IO -r -c "read -P 0x66 0 $CLUSTER_SIZE" "$TEST_IMG"; } 2>&1 | _filter_qemu_io | _filter_testdir
132 echo "== check the second cluster (deduplicated) =="
133 { $QEMU_IO -r -c "read -P 0x11 $CLUSTER_SIZE $CLUSTER_SIZE" "$TEST_IMG"; } 2>&1 | _filter_qemu_io | _filter_testdir
135 # Clear image
136 _make_test_img $SIZE
138 echo "== TEST DUPLICATION SELF-CURE =="
140 echo "== write pattern to whole image =="
141 { $QEMU_IO -c "write -P 0x11 0 $SIZE" "$TEST_IMG"; } 2>&1 | _filter_qemu_io | _filter_testdir
143 echo "== write another pattern to second cluster =="
144 { $QEMU_IO -c "write -P 0x55 $CLUSTER_SIZE $CLUSTER_SIZE" "$TEST_IMG"; } 2>&1 | _filter_qemu_io | _filter_testdir
146 echo "== check second cluster =="
147 { $QEMU_IO -r -c "read -P 0x55 $CLUSTER_SIZE $CLUSTER_SIZE" "$TEST_IMG"; } 2>&1 | _filter_qemu_io | _filter_testdir
150 echo "== corrupt image =="
151 poke_file "$TEST_IMG" "$(($BAT_OFFSET + 4))" "\x01\x00\x00\x00"
153 echo "== check second cluster =="
154 { $QEMU_IO -r -c "read -P 0x11 $CLUSTER_SIZE $CLUSTER_SIZE" "$TEST_IMG"; } 2>&1 | _filter_qemu_io | _filter_testdir
156 echo "== check the first cluster with self-repair =="
157 { $QEMU_IO -c "read -P 0x11 0 $CLUSTER_SIZE" "$TEST_IMG"; } 2>&1 | _filter_qemu_io | _filter_testdir
159 echo "== check second cluster =="
160 { $QEMU_IO -r -c "read -P 0x11 $CLUSTER_SIZE $CLUSTER_SIZE" "$TEST_IMG"; } 2>&1 | _filter_qemu_io | _filter_testdir
162 echo "== write another pattern to the first clusters =="
163 { $QEMU_IO -c "write -P 0x66 0 $CLUSTER_SIZE" "$TEST_IMG"; } 2>&1 | _filter_qemu_io | _filter_testdir
165 echo "== check the first cluster =="
166 { $QEMU_IO -r -c "read -P 0x66 0 $CLUSTER_SIZE" "$TEST_IMG"; } 2>&1 | _filter_qemu_io | _filter_testdir
168 echo "== check the second cluster (deduplicated) =="
169 { $QEMU_IO -r -c "read -P 0x11 $CLUSTER_SIZE $CLUSTER_SIZE" "$TEST_IMG"; } 2>&1 | _filter_qemu_io | _filter_testdir
171 # Clear image
172 _make_test_img $SIZE
174 echo "== TEST DATA_OFF CHECK =="
176 echo "== write pattern to first cluster =="
177 { $QEMU_IO -c "write -P 0x55 0 $CLUSTER_SIZE" "$TEST_IMG"; } 2>&1 | _filter_qemu_io | _filter_testdir
179 echo "== spoil data_off field =="
180 poke_file "$TEST_IMG" "$DATA_OFF_OFFSET" "\xff\xff\xff\xff"
182 echo "== check first cluster =="
183 { $QEMU_IO -c "read -P 0x55 0 $CLUSTER_SIZE" "$TEST_IMG"; } 2>&1 | _filter_qemu_io | _filter_testdir
185 # Clear image
186 _make_test_img $SIZE
188 echo "== TEST DATA_OFF THROUGH REPAIR =="
190 echo "== write pattern to first cluster =="
191 { $QEMU_IO -c "write -P 0x55 0 $CLUSTER_SIZE" "$TEST_IMG"; } 2>&1 | _filter_qemu_io | _filter_testdir
193 echo "== spoil data_off field =="
194 poke_file "$TEST_IMG" "$DATA_OFF_OFFSET" "\xff\xff\xff\xff"
196 echo "== repair image =="
197 _check_test_img -r all
199 echo "== check first cluster =="
200 { $QEMU_IO -r -c "read -P 0x55 0 $CLUSTER_SIZE" "$TEST_IMG"; } 2>&1 | _filter_qemu_io | _filter_testdir
202 # success, all done
203 echo "*** done"
204 rm -f $seq.full
205 status=0