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