Skip to content

Commit fd15760

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 <[email protected]> On-behalf-of: SAP [email protected]
1 parent e826b17 commit fd15760

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
}
@@ -495,6 +502,14 @@ in
495502
})}";
496503
};
497504
};
505+
"/etc/domain-chv-static-bdf-with-function.xml" = {
506+
"C+" = {
507+
argument = "${pkgs.writeText "domain-chv-static-bdf-with-function.xml" (virsh_ch_xml {
508+
all_static_bdf = true;
509+
use_bdf_function = true;
510+
})}";
511+
};
512+
};
498513
"/etc/new_interface.xml" = {
499514
"C+" = {
500515
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
@@ -1793,6 +1793,29 @@ def test_bdf_invalid_device_id(self):
17931793
)
17941794
assert number_of_devices(controllerVM) == num_before_expected_failure
17951795

1796+
def test_bdf_valid_device_id_with_function_id(self):
1797+
"""
1798+
Test that a BDFs containing a function ID leads to errors.
1799+
"""
1800+
# We don't support multi function devices currently
1801+
controllerVM.fail("virsh define /etc/domain-chv-static-bdf-with-function.xml")
1802+
# Using define + start creates a "persistent" domain rather than a transient
1803+
controllerVM.succeed("virsh define /etc/domain-chv.xml")
1804+
controllerVM.succeed("virsh start testvm")
1805+
1806+
assert wait_for_ssh(controllerVM)
1807+
1808+
num_before_expected_failure = number_of_devices(controllerVM)
1809+
# Add a persistent disk.
1810+
controllerVM.succeed(
1811+
"qemu-img create -f raw /var/lib/libvirt/storage-pools/nfs-share/vdb.img 5M"
1812+
)
1813+
# Attach to BDF 0:04.0
1814+
controllerVM.wait_until_fails(
1815+
"virsh attach-disk --domain testvm --target vdb --source /var/lib/libvirt/storage-pools/nfs-share/vdb.img --persistent --address pci:0.0.1f.5"
1816+
)
1817+
assert number_of_devices(controllerVM) == num_before_expected_failure
1818+
17961819

17971820
def suite():
17981821
# Test cases in alphabetical order
@@ -1801,6 +1824,7 @@ def suite():
18011824
LibvirtTests.test_bdf_explicit_assignment,
18021825
LibvirtTests.test_bdf_implicit_assignment,
18031826
LibvirtTests.test_bdf_invalid_device_id,
1827+
LibvirtTests.test_bdf_valid_device_id_with_function_id,
18041828
LibvirtTests.test_disk_is_locked,
18051829
LibvirtTests.test_disk_resize_qcow2,
18061830
LibvirtTests.test_disk_resize_raw,

0 commit comments

Comments
 (0)