Skip to content

Commit d955b3c

Browse files
committed
testscript: Test that setting a function ID in a BDF fails
We need a negative test that shows, that adding a function ID when entering a BDF result in libvirt generating a failure and CHV not crashing. Signed-off-by: Pascal Scholz <pascal.scholz@cyberus-technology.de> On-behalf-of: SAP pascal.scholz@sap.com
1 parent 1185185 commit d955b3c

File tree

2 files changed

+42
-3
lines changed

2 files changed

+42
-3
lines changed

tests/common.nix

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ let
2525
serial ? "pty",
2626
# Whether all device will be assigned a static BDF through the XML or only some
2727
all_static_bdf ? false,
28+
# Whether we add a function ID to specific BDFs or not
29+
use_bdf_function ? false,
2830
}:
2931
''
3032
<domain type='kvm' id='21050'>
@@ -134,9 +136,14 @@ let
134136
${
135137
# Assign a fixed BDF that would normally be acquired by the implicit RNG device
136138
if all_static_bdf then
137-
''
138-
<address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x0'/>
139-
''
139+
if use_bdf_function then
140+
''
141+
<address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/>
142+
''
143+
else
144+
''
145+
<address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x0'/>
146+
''
140147
else
141148
""
142149
}
@@ -496,6 +503,14 @@ in
496503
})}";
497504
};
498505
};
506+
"/etc/domain-chv-static-bdf-with-function.xml" = {
507+
"C+" = {
508+
argument = "${pkgs.writeText "domain-chv-static-bdf-with-function.xml" (virsh_ch_xml {
509+
all_static_bdf = true;
510+
use_bdf_function = true;
511+
})}";
512+
};
513+
};
499514
"/etc/new_interface.xml" = {
500515
"C+" = {
501516
argument = "${pkgs.writeText "new_interface.xml" (new_interface { })}";

tests/testscript.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1809,6 +1809,29 @@ def test_bdf_invalid_device_id(self):
18091809
)
18101810
assert number_of_devices(controllerVM) == num_before_expected_failure
18111811

1812+
def test_bdf_valid_device_id_with_function_id(self):
1813+
"""
1814+
Test that a BDFs containing a function ID leads to errors.
1815+
"""
1816+
# We don't support multi function devices currently
1817+
controllerVM.fail("virsh define /etc/domain-chv-static-bdf-with-function.xml")
1818+
# Using define + start creates a "persistent" domain rather than a transient
1819+
controllerVM.succeed("virsh define /etc/domain-chv.xml")
1820+
controllerVM.succeed("virsh start testvm")
1821+
1822+
assert wait_for_ssh(controllerVM)
1823+
1824+
num_before_expected_failure = number_of_devices(controllerVM)
1825+
# Add a persistent disk.
1826+
controllerVM.succeed(
1827+
"qemu-img create -f raw /var/lib/libvirt/storage-pools/nfs-share/vdb.img 5M"
1828+
)
1829+
# Attach to BDF 0:04.0
1830+
controllerVM.wait_until_fails(
1831+
"virsh attach-disk --domain testvm --target vdb --source /var/lib/libvirt/storage-pools/nfs-share/vdb.img --persistent --address pci:0.0.1f.5"
1832+
)
1833+
assert number_of_devices(controllerVM) == num_before_expected_failure
1834+
18121835

18131836
def suite():
18141837
# Test cases in alphabetical order
@@ -1817,6 +1840,7 @@ def suite():
18171840
LibvirtTests.test_bdf_explicit_assignment,
18181841
LibvirtTests.test_bdf_implicit_assignment,
18191842
LibvirtTests.test_bdf_invalid_device_id,
1843+
LibvirtTests.test_bdf_valid_device_id_with_function_id,
18201844
LibvirtTests.test_disk_is_locked,
18211845
LibvirtTests.test_disk_resize_qcow2,
18221846
LibvirtTests.test_disk_resize_raw,

0 commit comments

Comments
 (0)