xref: /openbmc/qemu/tests/qemu-iotests/138 (revision 11a82d14293cd66f428f535741717ff338c0722b)
1*11a82d14SPhilippe Mathieu-Daudé#!/usr/bin/env bash
2097b500cSMax Reitz#
3097b500cSMax Reitz# General test case for qcow2's image check
4097b500cSMax Reitz#
5097b500cSMax Reitz# Copyright (C) 2015 Red Hat, Inc.
6097b500cSMax Reitz#
7097b500cSMax Reitz# This program is free software; you can redistribute it and/or modify
8097b500cSMax Reitz# it under the terms of the GNU General Public License as published by
9097b500cSMax Reitz# the Free Software Foundation; either version 2 of the License, or
10097b500cSMax Reitz# (at your option) any later version.
11097b500cSMax Reitz#
12097b500cSMax Reitz# This program is distributed in the hope that it will be useful,
13097b500cSMax Reitz# but WITHOUT ANY WARRANTY; without even the implied warranty of
14097b500cSMax Reitz# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15097b500cSMax Reitz# GNU General Public License for more details.
16097b500cSMax Reitz#
17097b500cSMax Reitz# You should have received a copy of the GNU General Public License
18097b500cSMax Reitz# along with this program.  If not, see <http://www.gnu.org/licenses/>.
19097b500cSMax Reitz#
20097b500cSMax Reitz
21097b500cSMax Reitz# creator
22097b500cSMax Reitzowner=mreitz@redhat.com
23097b500cSMax Reitz
24097b500cSMax Reitzseq="$(basename $0)"
25097b500cSMax Reitzecho "QA output created by $seq"
26097b500cSMax Reitz
27097b500cSMax Reitzstatus=1	# failure is the default!
28097b500cSMax Reitz
29097b500cSMax Reitz_cleanup()
30097b500cSMax Reitz{
31097b500cSMax Reitz	_cleanup_test_img
32097b500cSMax Reitz}
33097b500cSMax Reitztrap "_cleanup; exit \$status" 0 1 2 3 15
34097b500cSMax Reitz
35097b500cSMax Reitz# get standard environment, filters and checks
36097b500cSMax Reitz. ./common.rc
37097b500cSMax Reitz. ./common.filter
38097b500cSMax Reitz
39097b500cSMax Reitz# This tests qocw2-specific low-level functionality
40097b500cSMax Reitz_supported_fmt qcow2
41097b500cSMax Reitz_supported_proto file
42097b500cSMax Reitz_supported_os Linux
43097b500cSMax Reitz
44097b500cSMax Reitzecho
45097b500cSMax Reitzecho '=== Check on an image with a multiple of 2^32 clusters ==='
46097b500cSMax Reitzecho
47097b500cSMax Reitz
48097b500cSMax ReitzIMGOPTS=$(_optstr_add "$IMGOPTS" "cluster_size=512") \
49097b500cSMax Reitz    _make_test_img 512
50097b500cSMax Reitz
51097b500cSMax Reitz# Allocate L2 table
52097b500cSMax Reitz$QEMU_IO -c 'write 0 512' "$TEST_IMG" | _filter_qemu_io
53097b500cSMax Reitz
54097b500cSMax Reitz# Put the data cluster at a multiple of 2 TB, resulting in the image apparently
55097b500cSMax Reitz# having a multiple of 2^32 clusters
56097b500cSMax Reitz# (To be more specific: It is at 32 PB)
57097b500cSMax Reitzpoke_file "$TEST_IMG" 2048 "\x80\x80\x00\x00\x00\x00\x00\x00"
58097b500cSMax Reitz
59097b500cSMax Reitz# An offset of 32 PB results in qemu-img check having to allocate an in-memory
60097b500cSMax Reitz# refcount table of 128 TB (16 bit refcounts, 512 byte clusters).
61097b500cSMax Reitz# This should be generally too much for any system and thus fail.
62097b500cSMax Reitz# What this test is checking is that the qcow2 driver actually tries to allocate
63097b500cSMax Reitz# such a large amount of memory (and is consequently aborting) instead of having
64097b500cSMax Reitz# truncated the cluster count somewhere (which would result in much less memory
65097b500cSMax Reitz# being allocated and then a segfault occurring).
66097b500cSMax Reitz_check_test_img
67097b500cSMax Reitz
68097b500cSMax Reitz# success, all done
69097b500cSMax Reitzecho "*** done"
70097b500cSMax Reitzrm -f $seq.full
71097b500cSMax Reitzstatus=0
72