1#!/bin/bash 2# 3# Test case for VDI header corruption; image too large, and too many blocks. 4# Also simple test for creating dynamic and static VDI images. 5# 6# Copyright (C) 2013 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 23owner=jcody@redhat.com 24 25seq=`basename $0` 26echo "QA output created by $seq" 27 28here=`pwd` 29tmp=/tmp/$$ 30status=1 # failure is the default! 31 32_cleanup() 33{ 34 _cleanup_test_img 35} 36trap "_cleanup; exit \$status" 0 1 2 3 15 37 38# get standard environment, filters and checks 39. ./common.rc 40. ./common.filter 41 42# This tests vdi-specific header fields 43_supported_fmt vdi 44_supported_proto generic 45_supported_os Linux 46 47size=64M 48ds_offset=368 # disk image size field offset 49bs_offset=376 # block size field offset 50bii_offset=384 # block in image field offset 51 52echo 53echo "=== Statically allocated image creation ===" 54echo 55_make_test_img $size -o static 56_img_info 57stat -c"disk image file size in bytes: %s" "${TEST_IMG}" 58_cleanup_test_img 59 60echo 61echo "=== Testing image size bounds ===" 62echo 63_make_test_img $size 64_img_info 65stat -c"disk image file size in bytes: %s" "${TEST_IMG}" 66 67# check for image size too large 68# poke max image size, and appropriate blocks_in_image value 69echo "Test 1: Maximum size (1024 TB):" 70poke_file "$TEST_IMG" "$ds_offset" "\x00\x00\xf0\xff\xff\xff\x03\x00" 71poke_file "$TEST_IMG" "$bii_offset" "\xff\xff\xff\x3f" 72_img_info 73 74echo 75echo "Test 2: Size too large (1024TB + 1)" 76# This should be too large (-EINVAL): 77poke_file "$TEST_IMG" "$ds_offset" "\x00\x00\xf1\xff\xff\xff\x03\x00" 78_img_info 79 80echo 81echo "Test 3: Size valid (64M), but Blocks In Image too small (63)" 82# This sets the size to 64M, but with a blocks_in_image size that is 83# too small 84poke_file "$TEST_IMG" "$ds_offset" "\x00\x00\x00\x04\x00\x00\x00\x00" 85# For a 64M image, we would need a blocks_in_image value of at least 64, 86# so 63 should be too small and give us -ENOTSUP 87poke_file "$TEST_IMG" "$bii_offset" "\x3f\x00\x00\x00" 88_img_info 89 90echo 91echo "Test 4: Size valid (64M), but Blocks In Image exceeds max allowed" 92# Now check the bounds of blocks_in_image - 0x3fffffff should be the max 93# value here, and we should get -ENOTSUP 94poke_file "$TEST_IMG" "$bii_offset" "\x00\x00\x00\x40" 95_img_info 96 97# Finally, 1MB is the only block size supported. Verify that 98# a value != 1MB results in error, both smaller and larger 99echo 100echo "Test 5: Valid Image: 64MB, Blocks In Image 64, Block Size 1MB" 101poke_file "$TEST_IMG" "$bii_offset" "\x40\x00\x00\x00" # reset bii to valid 102poke_file "$TEST_IMG" "$bs_offset" "\x00\x00\x10\x00" # valid 103_img_info 104echo 105echo "Test 6: Block Size != 1MB; too small test (1MB - 1)" 106poke_file "$TEST_IMG" "$bs_offset" "\xff\xff\x0f\x00" # invalid (too small) 107_img_info 108echo 109echo "Test 7: Block Size != 1MB; too large test (1MB + 64KB)" 110poke_file "$TEST_IMG" "$bs_offset" "\x00\x00\x11\x00" # invalid (too large) 111_img_info 112# success, all done 113echo 114echo "*** done" 115rm -f $seq.full 116status=0 117