xref: /openbmc/qemu/tests/qemu-iotests/212 (revision fef80ea073c4862bc9eaddb6ddb0ed970b8ad7c4)
17c477526SPhilippe Mathieu-Daudé#!/usr/bin/env python3
2*9dd003a9SVladimir Sementsov-Ogievskiy# group: rw quick
3e8f6ea6fSKevin Wolf#
4e8f6ea6fSKevin Wolf# Test parallels and file image creation
5e8f6ea6fSKevin Wolf#
6e8f6ea6fSKevin Wolf# Copyright (C) 2018 Red Hat, Inc.
7e8f6ea6fSKevin Wolf#
82d7abfbeSKevin Wolf# Creator/Owner: Kevin Wolf <kwolf@redhat.com>
92d7abfbeSKevin Wolf#
10e8f6ea6fSKevin Wolf# This program is free software; you can redistribute it and/or modify
11e8f6ea6fSKevin Wolf# it under the terms of the GNU General Public License as published by
12e8f6ea6fSKevin Wolf# the Free Software Foundation; either version 2 of the License, or
13e8f6ea6fSKevin Wolf# (at your option) any later version.
14e8f6ea6fSKevin Wolf#
15e8f6ea6fSKevin Wolf# This program is distributed in the hope that it will be useful,
16e8f6ea6fSKevin Wolf# but WITHOUT ANY WARRANTY; without even the implied warranty of
17e8f6ea6fSKevin Wolf# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18e8f6ea6fSKevin Wolf# GNU General Public License for more details.
19e8f6ea6fSKevin Wolf#
20e8f6ea6fSKevin Wolf# You should have received a copy of the GNU General Public License
21e8f6ea6fSKevin Wolf# along with this program.  If not, see <http://www.gnu.org/licenses/>.
22e8f6ea6fSKevin Wolf#
23e8f6ea6fSKevin Wolf
242d7abfbeSKevin Wolfimport iotests
252d7abfbeSKevin Wolffrom iotests import imgfmt
26e8f6ea6fSKevin Wolf
277d814059SJohn Snowiotests.script_initialize(
287d814059SJohn Snow    supported_fmts=['parallels'],
297d814059SJohn Snow    supported_protocols=['file'],
307d814059SJohn Snow)
31e8f6ea6fSKevin Wolf
322d7abfbeSKevin Wolfwith iotests.FilePath('t.parallels') as disk_path, \
332d7abfbeSKevin Wolf     iotests.VM() as vm:
34e8f6ea6fSKevin Wolf
352d7abfbeSKevin Wolf    #
362d7abfbeSKevin Wolf    # Successful image creation (defaults)
372d7abfbeSKevin Wolf    #
382d7abfbeSKevin Wolf    iotests.log("=== Successful image creation (defaults) ===")
392d7abfbeSKevin Wolf    iotests.log("")
40e8f6ea6fSKevin Wolf
412d7abfbeSKevin Wolf    size = 128 * 1024 * 1024
42e8f6ea6fSKevin Wolf
432d7abfbeSKevin Wolf    vm.launch()
4408b17138SKevin Wolf    vm.blockdev_create({ 'driver': 'file',
452d7abfbeSKevin Wolf                         'filename': disk_path,
462d7abfbeSKevin Wolf                         'size': 0 })
47e8f6ea6fSKevin Wolf
482d7abfbeSKevin Wolf    vm.qmp_log('blockdev-add', driver='file', filename=disk_path,
49250c04f5SMax Reitz               node_name='imgfile', filters=[iotests.filter_qmp_testfiles])
50e8f6ea6fSKevin Wolf
5108b17138SKevin Wolf    vm.blockdev_create({ 'driver': imgfmt,
522d7abfbeSKevin Wolf                         'file': 'imgfile',
532d7abfbeSKevin Wolf                         'size': size })
542d7abfbeSKevin Wolf    vm.shutdown()
55e8f6ea6fSKevin Wolf
562d7abfbeSKevin Wolf    iotests.img_info_log(disk_path)
57e8f6ea6fSKevin Wolf
582d7abfbeSKevin Wolf    #
592d7abfbeSKevin Wolf    # Successful image creation (explicit defaults)
602d7abfbeSKevin Wolf    #
612d7abfbeSKevin Wolf    iotests.log("=== Successful image creation (explicit defaults) ===")
622d7abfbeSKevin Wolf    iotests.log("")
63e8f6ea6fSKevin Wolf
64e8f6ea6fSKevin Wolf    # Choose a different size to show that we got a new image
652d7abfbeSKevin Wolf    size = 64 * 1024 * 1024
66e8f6ea6fSKevin Wolf
672d7abfbeSKevin Wolf    vm.launch()
6808b17138SKevin Wolf    vm.blockdev_create({ 'driver': 'file',
692d7abfbeSKevin Wolf                         'filename': disk_path,
702d7abfbeSKevin Wolf                         'size': 0 })
7108b17138SKevin Wolf    vm.blockdev_create({ 'driver': imgfmt,
722d7abfbeSKevin Wolf                         'file': {
732d7abfbeSKevin Wolf                             'driver': 'file',
742d7abfbeSKevin Wolf                             'filename': disk_path,
75e8f6ea6fSKevin Wolf                         },
762d7abfbeSKevin Wolf                         'size': size,
772d7abfbeSKevin Wolf                         'cluster-size': 1048576 })
782d7abfbeSKevin Wolf    vm.shutdown()
79e8f6ea6fSKevin Wolf
802d7abfbeSKevin Wolf    iotests.img_info_log(disk_path)
81e8f6ea6fSKevin Wolf
822d7abfbeSKevin Wolf    #
832d7abfbeSKevin Wolf    # Successful image creation (with non-default options)
842d7abfbeSKevin Wolf    #
852d7abfbeSKevin Wolf    iotests.log("=== Successful image creation (with non-default options) ===")
862d7abfbeSKevin Wolf    iotests.log("")
87e8f6ea6fSKevin Wolf
88e8f6ea6fSKevin Wolf    # Choose a different size to show that we got a new image
892d7abfbeSKevin Wolf    size = 32 * 1024 * 1024
90e8f6ea6fSKevin Wolf
912d7abfbeSKevin Wolf    vm.launch()
9208b17138SKevin Wolf    vm.blockdev_create({ 'driver': 'file',
932d7abfbeSKevin Wolf                         'filename': disk_path,
942d7abfbeSKevin Wolf                         'size': 0 })
9508b17138SKevin Wolf    vm.blockdev_create({ 'driver': imgfmt,
962d7abfbeSKevin Wolf                         'file': {
972d7abfbeSKevin Wolf                             'driver': 'file',
982d7abfbeSKevin Wolf                             'filename': disk_path,
99e8f6ea6fSKevin Wolf                         },
1002d7abfbeSKevin Wolf                         'size': size,
1012d7abfbeSKevin Wolf                         'cluster-size': 65536 })
1022d7abfbeSKevin Wolf    vm.shutdown()
103e8f6ea6fSKevin Wolf
1042d7abfbeSKevin Wolf    iotests.img_info_log(disk_path)
105e8f6ea6fSKevin Wolf
1062d7abfbeSKevin Wolf    #
1072d7abfbeSKevin Wolf    # Invalid BlockdevRef
1082d7abfbeSKevin Wolf    #
1092d7abfbeSKevin Wolf    iotests.log("=== Invalid BlockdevRef ===")
1102d7abfbeSKevin Wolf    iotests.log("")
111e8f6ea6fSKevin Wolf
1122d7abfbeSKevin Wolf    vm.launch()
11308b17138SKevin Wolf    vm.blockdev_create({ 'driver': imgfmt,
1142d7abfbeSKevin Wolf                         'file': "this doesn't exist",
1152d7abfbeSKevin Wolf                         'size': size })
1162d7abfbeSKevin Wolf    vm.shutdown()
117e8f6ea6fSKevin Wolf
1182d7abfbeSKevin Wolf    #
1192d7abfbeSKevin Wolf    # Zero size
1202d7abfbeSKevin Wolf    #
1212d7abfbeSKevin Wolf    iotests.log("=== Zero size ===")
1222d7abfbeSKevin Wolf    iotests.log("")
123e8f6ea6fSKevin Wolf
1242d7abfbeSKevin Wolf    vm.add_blockdev('driver=file,filename=%s,node-name=node0' % (disk_path))
1252d7abfbeSKevin Wolf    vm.launch()
12608b17138SKevin Wolf    vm.blockdev_create({ 'driver': imgfmt,
1272d7abfbeSKevin Wolf                         'file': 'node0',
1282d7abfbeSKevin Wolf                         'size': 0 })
1292d7abfbeSKevin Wolf    vm.shutdown()
130e8f6ea6fSKevin Wolf
1312d7abfbeSKevin Wolf    iotests.img_info_log(disk_path)
132e8f6ea6fSKevin Wolf
1332d7abfbeSKevin Wolf    #
1342d7abfbeSKevin Wolf    # Maximum size
1352d7abfbeSKevin Wolf    #
1362d7abfbeSKevin Wolf    iotests.log("=== Maximum size ===")
1372d7abfbeSKevin Wolf    iotests.log("")
138e8f6ea6fSKevin Wolf
1392d7abfbeSKevin Wolf    vm.launch()
14008b17138SKevin Wolf    vm.blockdev_create({ 'driver': imgfmt,
1412d7abfbeSKevin Wolf                         'file': 'node0',
1422d7abfbeSKevin Wolf                         'size': 4503599627369984})
1432d7abfbeSKevin Wolf    vm.shutdown()
144e8f6ea6fSKevin Wolf
1452d7abfbeSKevin Wolf    iotests.img_info_log(disk_path)
146e8f6ea6fSKevin Wolf
1472d7abfbeSKevin Wolf    #
1482d7abfbeSKevin Wolf    # Invalid sizes
1492d7abfbeSKevin Wolf    #
150e8f6ea6fSKevin Wolf
151e8f6ea6fSKevin Wolf    # TODO Negative image sizes aren't handled correctly, but this is a problem
1522d7abfbeSKevin Wolf    # with QAPI's implementation of the 'size' type and affects other commands
1532d7abfbeSKevin Wolf    # as well. Once this is fixed, we may want to add a test case here.
154e8f6ea6fSKevin Wolf
155e8f6ea6fSKevin Wolf    # 1. Misaligned image size
156e8f6ea6fSKevin Wolf    # 2. 2^64 - 512
157e8f6ea6fSKevin Wolf    # 3. 2^63 = 8 EB (qemu-img enforces image sizes less than this)
158e8f6ea6fSKevin Wolf    # 4. 2^63 - 512 (generally valid, but with the image header the file will
159e8f6ea6fSKevin Wolf    #                exceed 63 bits)
160e8f6ea6fSKevin Wolf    # 5. 2^52 (512 bytes more than maximum image size)
161e8f6ea6fSKevin Wolf
1622d7abfbeSKevin Wolf    iotests.log("=== Invalid sizes ===")
1632d7abfbeSKevin Wolf    iotests.log("")
164e8f6ea6fSKevin Wolf
1652d7abfbeSKevin Wolf    vm.launch()
1662d7abfbeSKevin Wolf    for size in [ 1234, 18446744073709551104, 9223372036854775808,
1672d7abfbeSKevin Wolf                  9223372036854775296, 4503599627370497 ]:
16808b17138SKevin Wolf        vm.blockdev_create({ 'driver': imgfmt,
1692d7abfbeSKevin Wolf                             'file': 'node0',
1702d7abfbeSKevin Wolf                             'size': size })
1712d7abfbeSKevin Wolf    vm.shutdown()
172e8f6ea6fSKevin Wolf
1732d7abfbeSKevin Wolf    #
1742d7abfbeSKevin Wolf    # Invalid cluster size
1752d7abfbeSKevin Wolf    #
1762d7abfbeSKevin Wolf    iotests.log("=== Invalid cluster size ===")
1772d7abfbeSKevin Wolf    iotests.log("")
178e8f6ea6fSKevin Wolf
1792d7abfbeSKevin Wolf    vm.launch()
1802d7abfbeSKevin Wolf    for csize in [ 1234, 128, 4294967296, 9223372036854775808,
1812d7abfbeSKevin Wolf                   18446744073709551104, 0 ]:
18208b17138SKevin Wolf        vm.blockdev_create({ 'driver': imgfmt,
1832d7abfbeSKevin Wolf                             'file': 'node0',
1842d7abfbeSKevin Wolf                             'size': 67108864,
1852d7abfbeSKevin Wolf                             'cluster-size': csize })
18608b17138SKevin Wolf    vm.blockdev_create({ 'driver': imgfmt,
1872d7abfbeSKevin Wolf                         'file': 'node0',
1882d7abfbeSKevin Wolf                         'size': 281474976710656,
1892d7abfbeSKevin Wolf                         'cluster-size': 512 })
1902d7abfbeSKevin Wolf    vm.shutdown()
191