mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-07-30 05:43:53 -06:00

pci_devfn properties accept both integer and string values, but integer 1 and string '1' have different meanings: The integer value means device 0, function 1 whereas the string value '1' is short for '1.0' and means device 1, function 0. This test wants the string version so that the device actually becomes visible for the guest. device_add hides the problem because it goes through QemuOpts, which turns all properties into strings - this is a QEMU bug that we want to fix, but that cancelled out the bug in this test. Fix the test first so that device_add can be fixed afterwards. Signed-off-by: Kevin Wolf <kwolf@redhat.com> Message-ID: <20241122224042.149258-1-kwolf@redhat.com> Reviewed-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
69 lines
1.8 KiB
Python
69 lines
1.8 KiB
Python
# Functional test that hotplugs a virtio blk disk and checks it on a Linux
|
|
# guest
|
|
#
|
|
# Copyright (c) 2021 Red Hat, Inc.
|
|
# Copyright (c) Yandex
|
|
#
|
|
# This work is licensed under the terms of the GNU GPL, version 2 or
|
|
# later. See the COPYING file in the top-level directory.
|
|
|
|
import time
|
|
|
|
from avocado_qemu.linuxtest import LinuxTest
|
|
|
|
|
|
class HotPlug(LinuxTest):
|
|
def blockdev_add(self) -> None:
|
|
self.vm.cmd('blockdev-add', **{
|
|
'driver': 'null-co',
|
|
'size': 1073741824,
|
|
'node-name': 'disk'
|
|
})
|
|
|
|
def assert_vda(self) -> None:
|
|
self.ssh_command('test -e /sys/block/vda')
|
|
|
|
def assert_no_vda(self) -> None:
|
|
with self.assertRaises(AssertionError):
|
|
self.assert_vda()
|
|
|
|
def plug(self) -> None:
|
|
args = {
|
|
'driver': 'virtio-blk-pci',
|
|
'drive': 'disk',
|
|
'id': 'virtio-disk0',
|
|
'bus': 'pci.1',
|
|
'addr': '1',
|
|
}
|
|
|
|
self.assert_no_vda()
|
|
self.vm.cmd('device_add', args)
|
|
try:
|
|
self.assert_vda()
|
|
except AssertionError:
|
|
time.sleep(1)
|
|
self.assert_vda()
|
|
|
|
def unplug(self) -> None:
|
|
self.vm.cmd('device_del', id='virtio-disk0')
|
|
|
|
self.vm.event_wait('DEVICE_DELETED', 1.0,
|
|
match={'data': {'device': 'virtio-disk0'}})
|
|
|
|
self.assert_no_vda()
|
|
|
|
def test(self) -> None:
|
|
"""
|
|
:avocado: tags=arch:x86_64
|
|
:avocado: tags=machine:q35
|
|
:avocado: tags=accel:kvm
|
|
"""
|
|
self.require_accelerator('kvm')
|
|
self.vm.add_args('-accel', 'kvm')
|
|
self.vm.add_args('-device', 'pcie-pci-bridge,id=pci.1,bus=pcie.0')
|
|
|
|
self.launch_and_wait()
|
|
self.blockdev_add()
|
|
|
|
self.plug()
|
|
self.unplug()
|