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