Skip to content

Commit 43b9216

Browse files
Merge pull request #6294 from saijanani-c/accelerator-class-check
Adding a method to check for accelerators
2 parents 9aaeff1 + 39678db commit 43b9216

1 file changed

Lines changed: 16 additions & 1 deletion

File tree

avocado/utils/pci.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
Module for all PCI devices related functions.
2121
"""
2222

23-
2423
import errno
2524
import os
2625
import re
@@ -697,3 +696,19 @@ def get_cfg(dom_pci_address):
697696
device_subvendor = re.search(r"([0-9a-e]{8})", cfg_dic["Description"])
698697
cfg_dic["subvendor_device"] = device_subvendor.group()
699698
return cfg_dic
699+
700+
701+
def is_accelerator():
702+
"""
703+
Checks if any PCI device is of class 'accelerator'.
704+
705+
:return: True if an accelerator device is found, False otherwise.
706+
:rtype: bool
707+
"""
708+
for dev in os.listdir("/sys/bus/pci/devices"):
709+
try:
710+
if get_pci_class_name(dev) == "accelerator":
711+
return True
712+
except ValueError:
713+
continue
714+
return False

0 commit comments

Comments
 (0)