cachepc-qemu

Fork of AMDESE/qemu with changes for cachepc side-channel attack
git clone https://git.sinitax.com/sinitax/cachepc-qemu
Log | Files | Refs | Submodules | LICENSE | sfeed.txt

237 (7185B)


      1#!/usr/bin/env python3
      2# group: rw quick
      3#
      4# Test vmdk and file image creation
      5#
      6# Copyright (C) 2018 Red Hat, Inc.
      7#
      8# Creator/Owner: Kevin Wolf <kwolf@redhat.com>
      9#
     10# This program is free software; you can redistribute it and/or modify
     11# it under the terms of the GNU General Public License as published by
     12# the Free Software Foundation; either version 2 of the License, or
     13# (at your option) any later version.
     14#
     15# This program is distributed in the hope that it will be useful,
     16# but WITHOUT ANY WARRANTY; without even the implied warranty of
     17# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     18# GNU General Public License for more details.
     19#
     20# You should have received a copy of the GNU General Public License
     21# along with this program.  If not, see <http://www.gnu.org/licenses/>.
     22#
     23
     24import math
     25import iotests
     26from iotests import imgfmt
     27
     28iotests.script_initialize(supported_fmts=['vmdk'])
     29
     30with iotests.FilePath('t.vmdk') as disk_path, \
     31     iotests.FilePath('t.vmdk.1') as extent1_path, \
     32     iotests.FilePath('t.vmdk.2') as extent2_path, \
     33     iotests.FilePath('t.vmdk.3') as extent3_path, \
     34     iotests.VM() as vm:
     35
     36    #
     37    # Successful image creation (defaults)
     38    #
     39    iotests.log("=== Successful image creation (defaults) ===")
     40    iotests.log("")
     41
     42    size = 5 * 1024 * 1024 * 1024
     43
     44    vm.launch()
     45    vm.blockdev_create({ 'driver': 'file',
     46                         'filename': disk_path,
     47                         'size': 0 })
     48
     49    vm.qmp_log('blockdev-add', driver='file', filename=disk_path,
     50               node_name='imgfile', filters=[iotests.filter_qmp_testfiles])
     51
     52    vm.blockdev_create({ 'driver': imgfmt,
     53                         'file': 'imgfile',
     54                         'size': size })
     55    vm.shutdown()
     56
     57    iotests.img_info_log(disk_path)
     58
     59    #
     60    # Successful image creation (inline blockdev-add, explicit defaults)
     61    #
     62    iotests.log("=== Successful image creation (inline blockdev-add, explicit defaults) ===")
     63    iotests.log("")
     64
     65    # Choose a different size to show that we got a new image
     66    size = 64 * 1024 * 1024
     67
     68    vm.launch()
     69    vm.blockdev_create({ 'driver': 'file',
     70                         'filename': disk_path,
     71                         'size': 0 })
     72
     73    vm.blockdev_create({ 'driver': imgfmt,
     74                         'file': {
     75                             'driver': 'file',
     76                             'filename': disk_path,
     77                         },
     78                         'size': size,
     79                         'extents': [],
     80                         'subformat': 'monolithicSparse',
     81                         'adapter-type': 'ide',
     82                         'hwversion': '4',
     83                         'zeroed-grain': False })
     84    vm.shutdown()
     85
     86    iotests.img_info_log(disk_path)
     87
     88    #
     89    # Successful image creation (non-default options)
     90    #
     91    iotests.log("=== Successful image creation (with non-default options) ===")
     92    iotests.log("")
     93
     94    # Choose a different size to show that we got a new image
     95    size = 32 * 1024 * 1024
     96
     97    vm.launch()
     98    vm.blockdev_create({ 'driver': 'file',
     99                         'filename': disk_path,
    100                         'size': 0 })
    101
    102    vm.blockdev_create({ 'driver': imgfmt,
    103                         'file': {
    104                             'driver': 'file',
    105                             'filename': disk_path,
    106                         },
    107                         'size': size,
    108                         'extents': [],
    109                         'subformat': 'monolithicSparse',
    110                         'adapter-type': 'buslogic',
    111                         'zeroed-grain': True })
    112    vm.shutdown()
    113
    114    iotests.img_info_log(disk_path)
    115
    116    #
    117    # Invalid BlockdevRef
    118    #
    119    iotests.log("=== Invalid BlockdevRef ===")
    120    iotests.log("")
    121
    122    vm.launch()
    123    vm.blockdev_create({ 'driver': imgfmt,
    124                         'file': "this doesn't exist",
    125                         'size': size })
    126    vm.shutdown()
    127
    128    #
    129    # Adapter types
    130    #
    131
    132    iotests.log("=== Adapter types ===")
    133    iotests.log("")
    134
    135    vm.add_blockdev('driver=file,filename=%s,node-name=node0' % (disk_path))
    136
    137    # Valid
    138    iotests.log("== Valid adapter types ==")
    139    iotests.log("")
    140
    141    vm.launch()
    142    for adapter_type in [ 'ide', 'buslogic', 'lsilogic', 'legacyESX' ]:
    143        vm.blockdev_create({ 'driver': imgfmt,
    144                             'file': 'node0',
    145                             'size': size,
    146                             'adapter-type': adapter_type })
    147    vm.shutdown()
    148
    149    # Invalid
    150    iotests.log("== Invalid adapter types ==")
    151    iotests.log("")
    152
    153    vm.launch()
    154    for adapter_type in [ 'foo', 'IDE', 'legacyesx', 1 ]:
    155        vm.blockdev_create({ 'driver': imgfmt,
    156                             'file': 'node0',
    157                             'size': size,
    158                             'adapter-type': adapter_type })
    159    vm.shutdown()
    160
    161    #
    162    # Other subformats
    163    #
    164    iotests.log("=== Other subformats ===")
    165    iotests.log("")
    166
    167    for path in [ extent1_path, extent2_path, extent3_path ]:
    168        msg = iotests.qemu_img_pipe('create', '-f', imgfmt, path, '0')
    169        iotests.log(msg, [iotests.filter_testfiles])
    170
    171    vm.add_blockdev('driver=file,filename=%s,node-name=ext1' % (extent1_path))
    172    vm.add_blockdev('driver=file,filename=%s,node-name=ext2' % (extent2_path))
    173    vm.add_blockdev('driver=file,filename=%s,node-name=ext3' % (extent3_path))
    174
    175    # Missing extent
    176    iotests.log("== Missing extent ==")
    177    iotests.log("")
    178
    179    vm.launch()
    180    vm.blockdev_create({ 'driver': imgfmt,
    181                         'file': 'node0',
    182                         'size': size,
    183                         'subformat': 'monolithicFlat' })
    184    vm.shutdown()
    185
    186    # Correct extent
    187    iotests.log("== Correct extent ==")
    188    iotests.log("")
    189
    190    vm.launch()
    191    vm.blockdev_create({ 'driver': imgfmt,
    192                         'file': 'node0',
    193                         'size': size,
    194                         'subformat': 'monolithicFlat',
    195                         'extents': ['ext1'] })
    196    vm.shutdown()
    197
    198    # Extra extent
    199    iotests.log("== Extra extent ==")
    200    iotests.log("")
    201
    202    vm.launch()
    203    vm.blockdev_create({ 'driver': imgfmt,
    204                         'file': 'node0',
    205                         'size': 512,
    206                         'subformat': 'monolithicFlat',
    207                         'extents': ['ext1', 'ext2', 'ext3'] })
    208    vm.shutdown()
    209
    210    # Split formats
    211    iotests.log("== Split formats ==")
    212    iotests.log("")
    213
    214    for size in [ 512, 1073741824, 2147483648, 5368709120 ]:
    215        for subfmt in [ 'twoGbMaxExtentFlat', 'twoGbMaxExtentSparse' ]:
    216            iotests.log("= %s %d =" % (subfmt, size))
    217            iotests.log("")
    218
    219            num_extents = int(math.ceil(size / 2.0**31))
    220            extents = [ "ext%d" % (i) for i in range(1, num_extents + 1) ]
    221
    222            vm.launch()
    223            vm.blockdev_create({ 'driver': imgfmt,
    224                                 'file': 'node0',
    225                                 'size': size,
    226                                 'subformat': subfmt,
    227                                 'extents': extents })
    228            vm.shutdown()
    229
    230            iotests.img_info_log(disk_path)