xref: /openbmc/qemu/tests/qemu-iotests/084 (revision 11a82d14293cd66f428f535741717ff338c0722b)
1*11a82d14SPhilippe Mathieu-Daudé#!/usr/bin/env bash
21e7226f7SJeff Cody#
323d20b5bSJeff Cody# Test case for VDI header corruption; image too large, and too many blocks.
423d20b5bSJeff Cody# Also simple test for creating dynamic and static VDI images.
51e7226f7SJeff Cody#
61e7226f7SJeff Cody# Copyright (C) 2013 Red Hat, Inc.
71e7226f7SJeff Cody#
81e7226f7SJeff Cody# This program is free software; you can redistribute it and/or modify
91e7226f7SJeff Cody# it under the terms of the GNU General Public License as published by
101e7226f7SJeff Cody# the Free Software Foundation; either version 2 of the License, or
111e7226f7SJeff Cody# (at your option) any later version.
121e7226f7SJeff Cody#
131e7226f7SJeff Cody# This program is distributed in the hope that it will be useful,
141e7226f7SJeff Cody# but WITHOUT ANY WARRANTY; without even the implied warranty of
151e7226f7SJeff Cody# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
161e7226f7SJeff Cody# GNU General Public License for more details.
171e7226f7SJeff Cody#
181e7226f7SJeff Cody# You should have received a copy of the GNU General Public License
191e7226f7SJeff Cody# along with this program.  If not, see <http://www.gnu.org/licenses/>.
201e7226f7SJeff Cody#
211e7226f7SJeff Cody
221e7226f7SJeff Cody# creator
231e7226f7SJeff Codyowner=jcody@redhat.com
241e7226f7SJeff Cody
251e7226f7SJeff Codyseq=`basename $0`
261e7226f7SJeff Codyecho "QA output created by $seq"
271e7226f7SJeff Cody
281e7226f7SJeff Codystatus=1	# failure is the default!
291e7226f7SJeff Cody
301e7226f7SJeff Cody_cleanup()
311e7226f7SJeff Cody{
321e7226f7SJeff Cody	_cleanup_test_img
331e7226f7SJeff Cody}
341e7226f7SJeff Codytrap "_cleanup; exit \$status" 0 1 2 3 15
351e7226f7SJeff Cody
361e7226f7SJeff Cody# get standard environment, filters and checks
371e7226f7SJeff Cody. ./common.rc
381e7226f7SJeff Cody. ./common.filter
391e7226f7SJeff Cody
401e7226f7SJeff Cody# This tests vdi-specific header fields
411e7226f7SJeff Cody_supported_fmt vdi
42c5f7c0afSPeter Lieven_supported_proto file
431e7226f7SJeff Cody_supported_os Linux
441e7226f7SJeff Cody
4523d20b5bSJeff Codysize=64M
461e7226f7SJeff Codyds_offset=368  # disk image size field offset
471e7226f7SJeff Codybs_offset=376  # block size field offset
481e7226f7SJeff Codybii_offset=384 # block in image field offset
491e7226f7SJeff Cody
501e7226f7SJeff Codyecho
5123d20b5bSJeff Codyecho "=== Statically allocated image creation ==="
5223d20b5bSJeff Codyecho
5323d20b5bSJeff Cody_make_test_img $size -o static
5423d20b5bSJeff Cody_img_info
5523d20b5bSJeff Codystat -c"disk image file size in bytes: %s" "${TEST_IMG}"
5623d20b5bSJeff Cody_cleanup_test_img
5723d20b5bSJeff Cody
5823d20b5bSJeff Codyecho
591e7226f7SJeff Codyecho "=== Testing image size bounds ==="
601e7226f7SJeff Codyecho
6123d20b5bSJeff Cody_make_test_img $size
6223d20b5bSJeff Cody_img_info
6323d20b5bSJeff Codystat -c"disk image file size in bytes: %s" "${TEST_IMG}"
641e7226f7SJeff Cody
651e7226f7SJeff Cody# check for image size too large
661e7226f7SJeff Cody# poke max image size, and appropriate blocks_in_image value
67d20418eeSMax Reitzecho "Test 1: Maximum size (512 TB - 128 MB):"
68d20418eeSMax Reitzpoke_file "$TEST_IMG" "$ds_offset" "\x00\x00\x00\xf8\xff\xff\x01\x00"
69d20418eeSMax Reitzpoke_file "$TEST_IMG" "$bii_offset" "\x80\xff\xff\x1f"
701e7226f7SJeff Cody_img_info
711e7226f7SJeff Cody
721e7226f7SJeff Codyecho
73d20418eeSMax Reitzecho "Test 2: Size too large (512 TB - 128 MB + 64 kB)"
741e7226f7SJeff Cody# This should be too large (-EINVAL):
75d20418eeSMax Reitzpoke_file "$TEST_IMG" "$ds_offset" "\x00\x00\x01\xf8\xff\xff\x01\x00"
761e7226f7SJeff Cody_img_info
771e7226f7SJeff Cody
781e7226f7SJeff Codyecho
791e7226f7SJeff Codyecho "Test 3: Size valid (64M), but Blocks In Image too small (63)"
801e7226f7SJeff Cody# This sets the size to 64M, but with a blocks_in_image size that is
811e7226f7SJeff Cody# too small
821e7226f7SJeff Codypoke_file "$TEST_IMG" "$ds_offset" "\x00\x00\x00\x04\x00\x00\x00\x00"
831e7226f7SJeff Cody# For a 64M image, we would need a blocks_in_image value of at least 64,
841e7226f7SJeff Cody# so 63 should be too small and give us -ENOTSUP
851e7226f7SJeff Codypoke_file "$TEST_IMG" "$bii_offset" "\x3f\x00\x00\x00"
861e7226f7SJeff Cody_img_info
871e7226f7SJeff Cody
881e7226f7SJeff Codyecho
891e7226f7SJeff Codyecho "Test 4: Size valid (64M), but Blocks In Image exceeds max allowed"
90d20418eeSMax Reitz# Now check the bounds of blocks_in_image - 0x1fffff80 should be the max
911e7226f7SJeff Cody# value here, and we should get -ENOTSUP
92d20418eeSMax Reitzpoke_file "$TEST_IMG" "$bii_offset" "\x81\xff\xff\x1f"
931e7226f7SJeff Cody_img_info
941e7226f7SJeff Cody
951e7226f7SJeff Cody# Finally, 1MB is the only block size supported.  Verify that
961e7226f7SJeff Cody# a value != 1MB results in error, both smaller and larger
971e7226f7SJeff Codyecho
981e7226f7SJeff Codyecho "Test 5: Valid Image: 64MB, Blocks In Image 64, Block Size 1MB"
991e7226f7SJeff Codypoke_file "$TEST_IMG" "$bii_offset" "\x40\x00\x00\x00" # reset bii to valid
1001e7226f7SJeff Codypoke_file "$TEST_IMG" "$bs_offset" "\x00\x00\x10\x00"  # valid
1011e7226f7SJeff Cody_img_info
1021e7226f7SJeff Codyecho
1031e7226f7SJeff Codyecho "Test 6: Block Size != 1MB; too small test (1MB - 1)"
1041e7226f7SJeff Codypoke_file "$TEST_IMG" "$bs_offset" "\xff\xff\x0f\x00"  # invalid (too small)
1051e7226f7SJeff Cody_img_info
1061e7226f7SJeff Codyecho
1071e7226f7SJeff Codyecho "Test 7: Block Size != 1MB; too large test (1MB + 64KB)"
1081e7226f7SJeff Codypoke_file "$TEST_IMG" "$bs_offset" "\x00\x00\x11\x00"  # invalid (too large)
1091e7226f7SJeff Cody_img_info
1101e7226f7SJeff Cody# success, all done
1111e7226f7SJeff Codyecho
1121e7226f7SJeff Codyecho "*** done"
1131e7226f7SJeff Codyrm -f $seq.full
1141e7226f7SJeff Codystatus=0
115