Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions hwinfo/pci/lspci.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,16 @@ class LspciNParser(CommandParser):
'pci_vendor_id',
'pci_device_type_id',
]

class LspciNNMMParser(CommandParser):
"""Parser object for the output of lspci -nnmm"""

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

ITEM_REGEXS = [
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})\]"' \
+ 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})\]"' \
+ 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})\]'
]

ITEM_SEPERATOR = "\n"
70 changes: 70 additions & 0 deletions hwinfo/pci/tests/lspci_tests.py → hwinfo/pci/tests/test_lspci.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,73 @@ def setUp(self):
def test_parse_all_devices(self):
recs = self.parser.parse_items()
self.assertEqual(len(recs), 171)


class TestSingleDeviceNNMMParse(unittest.TestCase):

SAMPLE_DATA = '02:00.0 "Ethernet controller [0200]" "Broadcom Corporation [14e4]" "NetXtreme II BCM5716 Gigabit Ethernet [163b]" -r20 "Dell [1028]" "Device [02a3]'

DEVICE_REC = {
'pci_device_bus_id': '02:00.0',
'pci_device_type_id': '0200',
'pci_device_type_name': 'Ethernet controller',
'pci_vendor_name': 'Broadcom Corporation',
'pci_vendor_id': '14e4',
'pci_device_id': '163b',
'pci_device_name': 'NetXtreme II BCM5716 Gigabit Ethernet',
'pci_subvendor_name': 'Dell',
'pci_subvendor_id': '1028',
'pci_subdevice_name': 'Device',
'pci_subdevice_id': '02a3',
}

def setUp(self):
self.parser = LspciNNMMParser(self.SAMPLE_DATA)
self.rec = self.parser.parse_items()[0]

def _assert_rec_key(self, key):
self.assertEquals(self.rec[key], self.DEVICE_REC[key])

def test_pci_device_bus_id(self):
self._assert_rec_key('pci_device_bus_id')

def test_pci_device_type_id(self):
self._assert_rec_key('pci_device_type_id')

def test_pci_device_type_name(self):
self._assert_rec_key('pci_device_type_name')

def test_pci_vendor_name(self):
self._assert_rec_key('pci_vendor_name')

def test_pci_vendor_id(self):
self._assert_rec_key('pci_vendor_id')

def test_pci_device_id(self):
self._assert_rec_key('pci_device_id')

def test_pci_device_name(self):
self._assert_rec_key('pci_device_name')

def test_pci_subvendor_name(self):
self._assert_rec_key('pci_subvendor_name')

def test_pci_subdevice_name(self):
self._assert_rec_key('pci_subdevice_name')

def test_pci_subdevice_id(self):
self._assert_rec_key('pci_subdevice_id')

class TestMultiDeviceNNMMParse(unittest.TestCase):

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

def setUp(self):
fh = open(self.SAMPLE_FILE)
data = fh.read()
fh.close()
self.parser = LspciNNMMParser(data)

def test_number_of_devices(self):
recs = self.parser.parse_items()
self.assertEqual(len(recs), 37)