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