Philippe Mathieu-Daudé | 11a82d1 | 2019-03-07 15:58:38 +0100 | [diff] [blame] | 1 | #!/usr/bin/env bash |
Vladimir Sementsov-Ogievskiy | 9dd003a | 2021-01-16 16:44:19 +0300 | [diff] [blame] | 2 | # group: img quick |
Jeff Cody | 1e7226f | 2014-03-28 11:42:25 -0400 | [diff] [blame] | 3 | # |
Jeff Cody | 23d20b5 | 2014-07-23 17:23:01 -0400 | [diff] [blame] | 4 | # Test case for VDI header corruption; image too large, and too many blocks. |
| 5 | # Also simple test for creating dynamic and static VDI images. |
Jeff Cody | 1e7226f | 2014-03-28 11:42:25 -0400 | [diff] [blame] | 6 | # |
| 7 | # Copyright (C) 2013 Red Hat, Inc. |
| 8 | # |
| 9 | # This program is free software; you can redistribute it and/or modify |
| 10 | # it under the terms of the GNU General Public License as published by |
| 11 | # the Free Software Foundation; either version 2 of the License, or |
| 12 | # (at your option) any later version. |
| 13 | # |
| 14 | # This program is distributed in the hope that it will be useful, |
| 15 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | # GNU General Public License for more details. |
| 18 | # |
| 19 | # You should have received a copy of the GNU General Public License |
| 20 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 21 | # |
| 22 | |
| 23 | # creator |
John Snow | 42a5009 | 2022-03-22 13:42:12 -0400 | [diff] [blame] | 24 | owner=codyprime@gmail.com |
Jeff Cody | 1e7226f | 2014-03-28 11:42:25 -0400 | [diff] [blame] | 25 | |
| 26 | seq=`basename $0` |
| 27 | echo "QA output created by $seq" |
| 28 | |
Jeff Cody | 1e7226f | 2014-03-28 11:42:25 -0400 | [diff] [blame] | 29 | status=1 # failure is the default! |
| 30 | |
| 31 | _cleanup() |
| 32 | { |
| 33 | _cleanup_test_img |
| 34 | } |
| 35 | trap "_cleanup; exit \$status" 0 1 2 3 15 |
| 36 | |
| 37 | # get standard environment, filters and checks |
| 38 | . ./common.rc |
| 39 | . ./common.filter |
| 40 | |
| 41 | # This tests vdi-specific header fields |
| 42 | _supported_fmt vdi |
Peter Lieven | c5f7c0a | 2014-10-20 13:47:11 +0200 | [diff] [blame] | 43 | _supported_proto file |
Jeff Cody | 1e7226f | 2014-03-28 11:42:25 -0400 | [diff] [blame] | 44 | _supported_os Linux |
| 45 | |
Jeff Cody | 23d20b5 | 2014-07-23 17:23:01 -0400 | [diff] [blame] | 46 | size=64M |
Jeff Cody | 1e7226f | 2014-03-28 11:42:25 -0400 | [diff] [blame] | 47 | ds_offset=368 # disk image size field offset |
| 48 | bs_offset=376 # block size field offset |
| 49 | bii_offset=384 # block in image field offset |
| 50 | |
| 51 | echo |
Jeff Cody | 23d20b5 | 2014-07-23 17:23:01 -0400 | [diff] [blame] | 52 | echo "=== Statically allocated image creation ===" |
| 53 | echo |
| 54 | _make_test_img $size -o static |
| 55 | _img_info |
| 56 | stat -c"disk image file size in bytes: %s" "${TEST_IMG}" |
| 57 | _cleanup_test_img |
| 58 | |
| 59 | echo |
Jeff Cody | 1e7226f | 2014-03-28 11:42:25 -0400 | [diff] [blame] | 60 | echo "=== Testing image size bounds ===" |
| 61 | echo |
Jeff Cody | 23d20b5 | 2014-07-23 17:23:01 -0400 | [diff] [blame] | 62 | _make_test_img $size |
| 63 | _img_info |
| 64 | stat -c"disk image file size in bytes: %s" "${TEST_IMG}" |
Jeff Cody | 1e7226f | 2014-03-28 11:42:25 -0400 | [diff] [blame] | 65 | |
| 66 | # check for image size too large |
| 67 | # poke max image size, and appropriate blocks_in_image value |
Max Reitz | d20418e | 2014-10-28 11:12:32 +0100 | [diff] [blame] | 68 | echo "Test 1: Maximum size (512 TB - 128 MB):" |
| 69 | poke_file "$TEST_IMG" "$ds_offset" "\x00\x00\x00\xf8\xff\xff\x01\x00" |
| 70 | poke_file "$TEST_IMG" "$bii_offset" "\x80\xff\xff\x1f" |
Jeff Cody | 1e7226f | 2014-03-28 11:42:25 -0400 | [diff] [blame] | 71 | _img_info |
| 72 | |
| 73 | echo |
Max Reitz | d20418e | 2014-10-28 11:12:32 +0100 | [diff] [blame] | 74 | echo "Test 2: Size too large (512 TB - 128 MB + 64 kB)" |
Jeff Cody | 1e7226f | 2014-03-28 11:42:25 -0400 | [diff] [blame] | 75 | # This should be too large (-EINVAL): |
Max Reitz | d20418e | 2014-10-28 11:12:32 +0100 | [diff] [blame] | 76 | poke_file "$TEST_IMG" "$ds_offset" "\x00\x00\x01\xf8\xff\xff\x01\x00" |
Jeff Cody | 1e7226f | 2014-03-28 11:42:25 -0400 | [diff] [blame] | 77 | _img_info |
| 78 | |
| 79 | echo |
| 80 | echo "Test 3: Size valid (64M), but Blocks In Image too small (63)" |
| 81 | # This sets the size to 64M, but with a blocks_in_image size that is |
| 82 | # too small |
| 83 | poke_file "$TEST_IMG" "$ds_offset" "\x00\x00\x00\x04\x00\x00\x00\x00" |
| 84 | # For a 64M image, we would need a blocks_in_image value of at least 64, |
| 85 | # so 63 should be too small and give us -ENOTSUP |
| 86 | poke_file "$TEST_IMG" "$bii_offset" "\x3f\x00\x00\x00" |
| 87 | _img_info |
| 88 | |
| 89 | echo |
| 90 | echo "Test 4: Size valid (64M), but Blocks In Image exceeds max allowed" |
Max Reitz | d20418e | 2014-10-28 11:12:32 +0100 | [diff] [blame] | 91 | # Now check the bounds of blocks_in_image - 0x1fffff80 should be the max |
Jeff Cody | 1e7226f | 2014-03-28 11:42:25 -0400 | [diff] [blame] | 92 | # value here, and we should get -ENOTSUP |
Max Reitz | d20418e | 2014-10-28 11:12:32 +0100 | [diff] [blame] | 93 | poke_file "$TEST_IMG" "$bii_offset" "\x81\xff\xff\x1f" |
Jeff Cody | 1e7226f | 2014-03-28 11:42:25 -0400 | [diff] [blame] | 94 | _img_info |
| 95 | |
| 96 | # Finally, 1MB is the only block size supported. Verify that |
| 97 | # a value != 1MB results in error, both smaller and larger |
| 98 | echo |
| 99 | echo "Test 5: Valid Image: 64MB, Blocks In Image 64, Block Size 1MB" |
| 100 | poke_file "$TEST_IMG" "$bii_offset" "\x40\x00\x00\x00" # reset bii to valid |
| 101 | poke_file "$TEST_IMG" "$bs_offset" "\x00\x00\x10\x00" # valid |
| 102 | _img_info |
| 103 | echo |
| 104 | echo "Test 6: Block Size != 1MB; too small test (1MB - 1)" |
| 105 | poke_file "$TEST_IMG" "$bs_offset" "\xff\xff\x0f\x00" # invalid (too small) |
| 106 | _img_info |
| 107 | echo |
| 108 | echo "Test 7: Block Size != 1MB; too large test (1MB + 64KB)" |
| 109 | poke_file "$TEST_IMG" "$bs_offset" "\x00\x00\x11\x00" # invalid (too large) |
| 110 | _img_info |
| 111 | # success, all done |
| 112 | echo |
| 113 | echo "*** done" |
| 114 | rm -f $seq.full |
| 115 | status=0 |