Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
iotests: Add out-of-image check test for parallels format
Fill the image with a pattern to generate entries in the BAT, set the first
BAT entry outside the image, try to read the corrupted image. At the image
opening it should be repaired, check for zeroes in the first cluster.

Signed-off-by: Alexander Ivanov <alexander.ivanov@virtuozzo.com>
Reviewed-by: Denis V. Lunev <den@openvz.org>
Signed-off-by: Denis V. Lunev <den@openvz.org>
  • Loading branch information
AlexanderIvanov-Virtuozzo authored and Denis V. Lunev committed Sep 6, 2023
1 parent c89d436 commit ab8e1f4
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 0 deletions.
71 changes: 71 additions & 0 deletions tests/qemu-iotests/tests/parallels-checks
@@ -0,0 +1,71 @@
#!/usr/bin/env bash
# group: rw quick
#
# Test qemu-img check for parallels format
#
# Copyright (C) 2022 Virtuozzo International GmbH
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#

# creator
owner=alexander.ivanov@virtuozzo.com

seq=`basename $0`
echo "QA output created by $seq"

status=1 # failure is the default!

_cleanup()
{
_cleanup_test_img
}
trap "_cleanup; exit \$status" 0 1 2 3 15

# get standard environment, filters and checks
. ../common.rc
. ../common.filter

_supported_fmt parallels
_supported_proto file
_supported_os Linux

SIZE=$((4 * 1024 * 1024))
IMGFMT=parallels
CLUSTER_SIZE_OFFSET=28
BAT_OFFSET=64

_make_test_img $SIZE

CLUSTER_SIZE=$(peek_file_le $TEST_IMG $CLUSTER_SIZE_OFFSET 4)
CLUSTER_SIZE=$((CLUSTER_SIZE * 512))
LAST_CLUSTER_OFF=$((SIZE - CLUSTER_SIZE))
LAST_CLUSTER=$((LAST_CLUSTER_OFF/CLUSTER_SIZE))

echo "== TEST OUT OF IMAGE CHECK =="

echo "== write pattern =="
{ $QEMU_IO -c "write -P 0x11 0 $SIZE" "$TEST_IMG"; } 2>&1 | _filter_qemu_io | _filter_testdir

echo "== corrupt image =="
cluster=$(($LAST_CLUSTER + 2))
poke_file "$TEST_IMG" "$BAT_OFFSET" "\x$cluster\x00\x00\x00"

echo "== read corrupted image with repairing =="
{ $QEMU_IO -c "read -P 0x00 0 $CLUSTER_SIZE" "$TEST_IMG"; } 2>&1 | _filter_qemu_io | _filter_testdir

# success, all done
echo "*** done"
rm -f $seq.full
status=0
12 changes: 12 additions & 0 deletions tests/qemu-iotests/tests/parallels-checks.out
@@ -0,0 +1,12 @@
QA output created by parallels-checks
Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=4194304
== TEST OUT OF IMAGE CHECK ==
== write pattern ==
wrote 4194304/4194304 bytes at offset 0
4 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
== corrupt image ==
== read corrupted image with repairing ==
Repairing cluster 0 is outside image
read 1048576/1048576 bytes at offset 0
1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
*** done

0 comments on commit ab8e1f4

Please sign in to comment.