Skip to content

Commit e3a3ffd

Browse files
committed
Adding a couple of extra device tests and improving REGEX to cope with '/' as well as refector the label/code expressions to make future updates simpler.
Signed-off-by: Rob Dobson <rob.dobson@citrix.com>
1 parent a36ba6b commit e3a3ffd

3 files changed

Lines changed: 50 additions & 4 deletions

File tree

hwinfo/pci/__init__.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ def __init__(self, record):
66
self.rec = record
77

88
def lookup_value(self, k):
9-
return self.rec[k]
9+
if k in self.rec:
10+
return self.rec[k]
11+
else:
12+
return "Unknown"
1013

1114
def get_device_name(self):
1215
name = self.lookup_value('pci_device_name')
@@ -60,3 +63,5 @@ def get_info(self):
6063

6164
if self.is_subdevice():
6265
return "%s %s (%s %s)" % (self.get_subvendor_name(), self.get_subdevice_name(), self.get_vendor_name(), self.get_device_name())
66+
else:
67+
return "%s %s" % (self.get_vendor_name(), self.get_device_name())

hwinfo/pci/lspci.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,19 @@ class LspciNParser(CommandParser):
3939
'pci_device_type_id',
4040
]
4141

42+
43+
LABEL_REGEX = r'[\w+\ \.\-\/]+'
44+
CODE_REGEX = r'[0-9a-fA-F]{4}'
45+
4246
class LspciNNMMParser(CommandParser):
4347
"""Parser object for the output of lspci -nnmm"""
4448

4549
#02:00.1 "Ethernet controller [0200]" "Broadcom Corporation [14e4]" "NetXtreme II BCM5716 Gigabit Ethernet [163b]" -r20 "Dell [1028]" "Device [02a3]"
4650

4751
ITEM_REGEXS = [
48-
r'(?P<pci_device_bus_id>([0-9a-fA-F]{2}:[0-9a-fA-F]{2}\.[0-9a-fA-F]))\ "(?P<pci_device_type_name>[\w+\ \.\-]+)\ \[(?P<pci_device_type_id>[0-9a-fA-F]{4})\]"' \
49-
+ r'\ "(?P<pci_vendor_name>[\w+\ \.\-]+)\ \[(?P<pci_vendor_id>[0-9a-fA-F]{4})\]"\ "(?P<pci_device_name>[\w+\ \.\-]+)\ \[(?P<pci_device_id>[0-9a-fA-F]{4})\]"' \
50-
+ r'\ .*\ "((?P<pci_subvendor_name>[\w+\ \.\-]+)\ \[(?P<pci_subvendor_id>[0-9a-fA-F]{4})\])*"\ "((?P<pci_subdevice_name>[\w+\ \.\-]+)\ \[(?P<pci_subdevice_id>[0-9a-fA-F]{4})\])*',
52+
r'(?P<pci_device_bus_id>([0-9a-fA-F]{2}:[0-9a-fA-F]{2}\.[0-9a-fA-F]))\ "(?P<pci_device_type_name>' + LABEL_REGEX + r')\ \[(?P<pci_device_type_id>' + CODE_REGEX + r')\]"' \
53+
+ r'\ "(?P<pci_vendor_name>' + LABEL_REGEX + r')\ \[(?P<pci_vendor_id>' + CODE_REGEX + r')\]"\ "(?P<pci_device_name>' + LABEL_REGEX + r')\ \[(?P<pci_device_id>' + CODE_REGEX + r')\]"' \
54+
+ r'\ .*\ "((?P<pci_subvendor_name>' + LABEL_REGEX + r')\ \[(?P<pci_subvendor_id>' + CODE_REGEX + r')\])*"\ "((?P<pci_subdevice_name>' + LABEL_REGEX + r')\ \[(?P<pci_subdevice_id>' + CODE_REGEX + r')\])*',
5155
]
5256

5357
ITEM_SEPERATOR = "\n"

hwinfo/pci/tests/test_lspci.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,43 @@ def test_pci_subdevice_name(self):
162162
def test_pci_subdevice_id(self):
163163
self._assert_rec_key('pci_subdevice_id')
164164

165+
class LsiDeviceParse(TestSingleDeviceNNMMParse):
166+
167+
SAMPLE_DATA = '03:00.0 "SCSI storage controller [0100]" "LSI Logic / Symbios Logic [1000]" "SAS1068E PCI-Express Fusion-MPT SAS [0058]" -r08 "Dell [1028]" "SAS 6/iR Integrated Blades RAID Controller [1f0f]"'
168+
169+
DEVICE_REC = {
170+
'pci_device_bus_id': '03:00.0',
171+
'pci_device_type_id': '0100',
172+
'pci_device_type_name': 'SCSI storage controller',
173+
'pci_vendor_name': 'LSI Logic / Symbios Logic',
174+
'pci_vendor_id': '1000',
175+
'pci_device_id': '0058',
176+
'pci_device_name': 'SAS1068E PCI-Express Fusion-MPT SAS',
177+
'pci_subvendor_name': 'Dell',
178+
'pci_subvendor_id': '1028',
179+
'pci_subdevice_name': 'SAS 6/iR Integrated Blades RAID Controller',
180+
'pci_subdevice_id': '1f0f',
181+
}
182+
183+
184+
class IntelUSBControllerDeviceParse(TestSingleDeviceNNMMParse):
185+
186+
SAMPLE_DATA = '00:1d.0 "USB controller [0c03]" "Intel Corporation [8086]" "5 Series/3400 Series Chipset USB2 Enhanced Host Controller [3b34]" -r05 -p20 "Dell [1028]" "Device [02a3]"'
187+
188+
DEVICE_REC = {
189+
'pci_device_bus_id': '00:1d.0',
190+
'pci_device_type_id': '0c03',
191+
'pci_device_type_name': 'USB controller',
192+
'pci_vendor_name': 'Intel Corporation',
193+
'pci_vendor_id': '8086',
194+
'pci_device_id': '3b34',
195+
'pci_device_name': '5 Series/3400 Series Chipset USB2 Enhanced Host Controller',
196+
'pci_subvendor_name': 'Dell',
197+
'pci_subvendor_id': '1028',
198+
'pci_subdevice_name': 'Device',
199+
'pci_subdevice_id': '02a3',
200+
}
201+
165202
class TestMultiDeviceNNMMParse(unittest.TestCase):
166203

167204
SAMPLE_FILE = '%s/lspci-nnmm' % DATA_DIR

0 commit comments

Comments
 (0)