pc: hack for migration compatibility from QEMU 2.0
[qemu/ar7.git] / tests / qemu-iotests / 084
blobcb4d7b729e7deade87c4252fe98292cbc6c9acef
1 #!/bin/bash
3 # Test case for VDI header corruption; image too large, and too many blocks
5 # Copyright (C) 2013 Red Hat, Inc.
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
21 # creator
22 owner=jcody@redhat.com
24 seq=`basename $0`
25 echo "QA output created by $seq"
27 here=`pwd`
28 tmp=/tmp/$$
29 status=1 # failure is the default!
31 _cleanup()
33 _cleanup_test_img
35 trap "_cleanup; exit \$status" 0 1 2 3 15
37 # get standard environment, filters and checks
38 . ./common.rc
39 . ./common.filter
41 # This tests vdi-specific header fields
42 _supported_fmt vdi
43 _supported_proto generic
44 _supported_os Linux
46 ds_offset=368 # disk image size field offset
47 bs_offset=376 # block size field offset
48 bii_offset=384 # block in image field offset
50 echo
51 echo "=== Testing image size bounds ==="
52 echo
53 _make_test_img 64M
55 # check for image size too large
56 # poke max image size, and appropriate blocks_in_image value
57 echo "Test 1: Maximum size (1024 TB):"
58 poke_file "$TEST_IMG" "$ds_offset" "\x00\x00\xf0\xff\xff\xff\x03\x00"
59 poke_file "$TEST_IMG" "$bii_offset" "\xff\xff\xff\x3f"
60 _img_info
62 echo
63 echo "Test 2: Size too large (1024TB + 1)"
64 # This should be too large (-EINVAL):
65 poke_file "$TEST_IMG" "$ds_offset" "\x00\x00\xf1\xff\xff\xff\x03\x00"
66 _img_info
68 echo
69 echo "Test 3: Size valid (64M), but Blocks In Image too small (63)"
70 # This sets the size to 64M, but with a blocks_in_image size that is
71 # too small
72 poke_file "$TEST_IMG" "$ds_offset" "\x00\x00\x00\x04\x00\x00\x00\x00"
73 # For a 64M image, we would need a blocks_in_image value of at least 64,
74 # so 63 should be too small and give us -ENOTSUP
75 poke_file "$TEST_IMG" "$bii_offset" "\x3f\x00\x00\x00"
76 _img_info
78 echo
79 echo "Test 4: Size valid (64M), but Blocks In Image exceeds max allowed"
80 # Now check the bounds of blocks_in_image - 0x3fffffff should be the max
81 # value here, and we should get -ENOTSUP
82 poke_file "$TEST_IMG" "$bii_offset" "\x00\x00\x00\x40"
83 _img_info
85 # Finally, 1MB is the only block size supported. Verify that
86 # a value != 1MB results in error, both smaller and larger
87 echo
88 echo "Test 5: Valid Image: 64MB, Blocks In Image 64, Block Size 1MB"
89 poke_file "$TEST_IMG" "$bii_offset" "\x40\x00\x00\x00" # reset bii to valid
90 poke_file "$TEST_IMG" "$bs_offset" "\x00\x00\x10\x00" # valid
91 _img_info
92 echo
93 echo "Test 6: Block Size != 1MB; too small test (1MB - 1)"
94 poke_file "$TEST_IMG" "$bs_offset" "\xff\xff\x0f\x00" # invalid (too small)
95 _img_info
96 echo
97 echo "Test 7: Block Size != 1MB; too large test (1MB + 64KB)"
98 poke_file "$TEST_IMG" "$bs_offset" "\x00\x00\x11\x00" # invalid (too large)
99 _img_info
100 # success, all done
101 echo
102 echo "*** done"
103 rm -f $seq.full
104 status=0