@@ -105,3 +105,73 @@ def setUp(self):
105105 def test_parse_all_devices (self ):
106106 recs = self .parser .parse_items ()
107107 self .assertEqual (len (recs ), 171 )
108+
109+
110+ class TestSingleDeviceNNMMParse (unittest .TestCase ):
111+
112+ SAMPLE_DATA = '02:00.0 "Ethernet controller [0200]" "Broadcom Corporation [14e4]" "NetXtreme II BCM5716 Gigabit Ethernet [163b]" -r20 "Dell [1028]" "Device [02a3]'
113+
114+ DEVICE_REC = {
115+ 'pci_device_bus_id' : '02:00.0' ,
116+ 'pci_device_type_id' : '0200' ,
117+ 'pci_device_type_name' : 'Ethernet controller' ,
118+ 'pci_vendor_name' : 'Broadcom Corporation' ,
119+ 'pci_vendor_id' : '14e4' ,
120+ 'pci_device_id' : '163b' ,
121+ 'pci_device_name' : 'NetXtreme II BCM5716 Gigabit Ethernet' ,
122+ 'pci_subvendor_name' : 'Dell' ,
123+ 'pci_subvendor_id' : '1028' ,
124+ 'pci_subdevice_name' : 'Device' ,
125+ 'pci_subdevice_id' : '02a3' ,
126+ }
127+
128+ def setUp (self ):
129+ self .parser = LspciNNMMParser (self .SAMPLE_DATA )
130+ self .rec = self .parser .parse_items ()[0 ]
131+
132+ def _assert_rec_key (self , key ):
133+ self .assertEquals (self .rec [key ], self .DEVICE_REC [key ])
134+
135+ def test_pci_device_bus_id (self ):
136+ self ._assert_rec_key ('pci_device_bus_id' )
137+
138+ def test_pci_device_type_id (self ):
139+ self ._assert_rec_key ('pci_device_type_id' )
140+
141+ def test_pci_device_type_name (self ):
142+ self ._assert_rec_key ('pci_device_type_name' )
143+
144+ def test_pci_vendor_name (self ):
145+ self ._assert_rec_key ('pci_vendor_name' )
146+
147+ def test_pci_vendor_id (self ):
148+ self ._assert_rec_key ('pci_vendor_id' )
149+
150+ def test_pci_device_id (self ):
151+ self ._assert_rec_key ('pci_device_id' )
152+
153+ def test_pci_device_name (self ):
154+ self ._assert_rec_key ('pci_device_name' )
155+
156+ def test_pci_subvendor_name (self ):
157+ self ._assert_rec_key ('pci_subvendor_name' )
158+
159+ def test_pci_subdevice_name (self ):
160+ self ._assert_rec_key ('pci_subdevice_name' )
161+
162+ def test_pci_subdevice_id (self ):
163+ self ._assert_rec_key ('pci_subdevice_id' )
164+
165+ class TestMultiDeviceNNMMParse (unittest .TestCase ):
166+
167+ SAMPLE_FILE = '%s/lspci-nnmm' % DATA_DIR
168+
169+ def setUp (self ):
170+ fh = open (self .SAMPLE_FILE )
171+ data = fh .read ()
172+ fh .close ()
173+ self .parser = LspciNNMMParser (data )
174+
175+ def test_number_of_devices (self ):
176+ recs = self .parser .parse_items ()
177+ self .assertEqual (len (recs ), 37 )
0 commit comments