Skip to content

Commit c4070e7

Browse files
committed
testscript: Add infrastructure for querying PCI devices with BDF
When evaluating PCI BDF assignment we need a way to query these information from a test VM. This commit adds a handy way to obtain all BDFs with their assigned devices. Signed-off-by: Pascal Scholz <pascal.scholz@cyberus-technology.de> On-behalf-of: SAP pascal.scholz@sap.com
1 parent 548b332 commit c4070e7

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

tests/testscript.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1367,6 +1367,29 @@ def number_of_storage_devices(machine):
13671367
return int(out)
13681368

13691369

1370+
def pci_devices_by_bdf(machine):
1371+
"""
1372+
Creates a dict of all PCI devices addressable by their BDF in the VM.
1373+
1374+
BDFs are keys, while the combination of vendor and device IDs form the
1375+
associated value.
1376+
1377+
:param machine: Host machine of the nested VM
1378+
:return: BDF mapped to devices, example: {'00:00.0': '8086:0d57'}
1379+
:rtype: dict[str, str]
1380+
"""
1381+
status, lines = ssh(
1382+
machine,
1383+
"lspci -n | awk '/^[0-9a-f]{2}:[0-9a-f]{2}\\.[0-9]/{bdf=$1}{class=$3} {print bdf \",\" class}'",
1384+
)
1385+
assert status == 0
1386+
out = {}
1387+
for line in lines.splitlines():
1388+
bdf, device_class = line.split(",")
1389+
out[bdf] = device_class
1390+
return out
1391+
1392+
13701393
runner = unittest.TextTestRunner()
13711394
if not runner.run(suite()).wasSuccessful():
13721395
raise Exception("Test Run unsuccessful")

0 commit comments

Comments
 (0)