xref: /openbmc/qemu/tests/qemu-iotests/084 (revision c5f7c0af473cadb8b0b5fc6d399e4ede1fc9408d)
11e7226f7SJeff Cody#!/bin/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 Codyhere=`pwd`
291e7226f7SJeff Codytmp=/tmp/$$
301e7226f7SJeff Codystatus=1	# failure is the default!
311e7226f7SJeff Cody
321e7226f7SJeff Cody_cleanup()
331e7226f7SJeff Cody{
341e7226f7SJeff Cody	_cleanup_test_img
351e7226f7SJeff Cody}
361e7226f7SJeff Codytrap "_cleanup; exit \$status" 0 1 2 3 15
371e7226f7SJeff Cody
381e7226f7SJeff Cody# get standard environment, filters and checks
391e7226f7SJeff Cody. ./common.rc
401e7226f7SJeff Cody. ./common.filter
411e7226f7SJeff Cody
421e7226f7SJeff Cody# This tests vdi-specific header fields
431e7226f7SJeff Cody_supported_fmt vdi
44*c5f7c0afSPeter Lieven_supported_proto file
451e7226f7SJeff Cody_supported_os Linux
461e7226f7SJeff Cody
4723d20b5bSJeff Codysize=64M
481e7226f7SJeff Codyds_offset=368  # disk image size field offset
491e7226f7SJeff Codybs_offset=376  # block size field offset
501e7226f7SJeff Codybii_offset=384 # block in image field offset
511e7226f7SJeff Cody
521e7226f7SJeff Codyecho
5323d20b5bSJeff Codyecho "=== Statically allocated image creation ==="
5423d20b5bSJeff Codyecho
5523d20b5bSJeff Cody_make_test_img $size -o static
5623d20b5bSJeff Cody_img_info
5723d20b5bSJeff Codystat -c"disk image file size in bytes: %s" "${TEST_IMG}"
5823d20b5bSJeff Cody_cleanup_test_img
5923d20b5bSJeff Cody
6023d20b5bSJeff Codyecho
611e7226f7SJeff Codyecho "=== Testing image size bounds ==="
621e7226f7SJeff Codyecho
6323d20b5bSJeff Cody_make_test_img $size
6423d20b5bSJeff Cody_img_info
6523d20b5bSJeff Codystat -c"disk image file size in bytes: %s" "${TEST_IMG}"
661e7226f7SJeff Cody
671e7226f7SJeff Cody# check for image size too large
681e7226f7SJeff Cody# poke max image size, and appropriate blocks_in_image value
691e7226f7SJeff Codyecho "Test 1: Maximum size (1024 TB):"
701e7226f7SJeff Codypoke_file "$TEST_IMG" "$ds_offset" "\x00\x00\xf0\xff\xff\xff\x03\x00"
711e7226f7SJeff Codypoke_file "$TEST_IMG" "$bii_offset" "\xff\xff\xff\x3f"
721e7226f7SJeff Cody_img_info
731e7226f7SJeff Cody
741e7226f7SJeff Codyecho
751e7226f7SJeff Codyecho "Test 2: Size too large (1024TB + 1)"
761e7226f7SJeff Cody# This should be too large (-EINVAL):
771e7226f7SJeff Codypoke_file "$TEST_IMG" "$ds_offset" "\x00\x00\xf1\xff\xff\xff\x03\x00"
781e7226f7SJeff Cody_img_info
791e7226f7SJeff Cody
801e7226f7SJeff Codyecho
811e7226f7SJeff Codyecho "Test 3: Size valid (64M), but Blocks In Image too small (63)"
821e7226f7SJeff Cody# This sets the size to 64M, but with a blocks_in_image size that is
831e7226f7SJeff Cody# too small
841e7226f7SJeff Codypoke_file "$TEST_IMG" "$ds_offset" "\x00\x00\x00\x04\x00\x00\x00\x00"
851e7226f7SJeff Cody# For a 64M image, we would need a blocks_in_image value of at least 64,
861e7226f7SJeff Cody# so 63 should be too small and give us -ENOTSUP
871e7226f7SJeff Codypoke_file "$TEST_IMG" "$bii_offset" "\x3f\x00\x00\x00"
881e7226f7SJeff Cody_img_info
891e7226f7SJeff Cody
901e7226f7SJeff Codyecho
911e7226f7SJeff Codyecho "Test 4: Size valid (64M), but Blocks In Image exceeds max allowed"
921e7226f7SJeff Cody# Now check the bounds of blocks_in_image - 0x3fffffff should be the max
931e7226f7SJeff Cody# value here, and we should get -ENOTSUP
941e7226f7SJeff Codypoke_file "$TEST_IMG" "$bii_offset" "\x00\x00\x00\x40"
951e7226f7SJeff Cody_img_info
961e7226f7SJeff Cody
971e7226f7SJeff Cody# Finally, 1MB is the only block size supported.  Verify that
981e7226f7SJeff Cody# a value != 1MB results in error, both smaller and larger
991e7226f7SJeff Codyecho
1001e7226f7SJeff Codyecho "Test 5: Valid Image: 64MB, Blocks In Image 64, Block Size 1MB"
1011e7226f7SJeff Codypoke_file "$TEST_IMG" "$bii_offset" "\x40\x00\x00\x00" # reset bii to valid
1021e7226f7SJeff Codypoke_file "$TEST_IMG" "$bs_offset" "\x00\x00\x10\x00"  # valid
1031e7226f7SJeff Cody_img_info
1041e7226f7SJeff Codyecho
1051e7226f7SJeff Codyecho "Test 6: Block Size != 1MB; too small test (1MB - 1)"
1061e7226f7SJeff Codypoke_file "$TEST_IMG" "$bs_offset" "\xff\xff\x0f\x00"  # invalid (too small)
1071e7226f7SJeff Cody_img_info
1081e7226f7SJeff Codyecho
1091e7226f7SJeff Codyecho "Test 7: Block Size != 1MB; too large test (1MB + 64KB)"
1101e7226f7SJeff Codypoke_file "$TEST_IMG" "$bs_offset" "\x00\x00\x11\x00"  # invalid (too large)
1111e7226f7SJeff Cody_img_info
1121e7226f7SJeff Cody# success, all done
1131e7226f7SJeff Codyecho
1141e7226f7SJeff Codyecho "*** done"
1151e7226f7SJeff Codyrm -f $seq.full
1161e7226f7SJeff Codystatus=0
117