@@ -127,6 +127,37 @@ def _ensure_addr(ifname, addr, **kwargs):
127127 _ip (f'addr add { addr } dev { ifname } ' , ** kwargs )
128128
129129
130+ def _collect_device_info (ifname ):
131+ """Collect devlink device info for the test interface.
132+
133+ Returns a dict matching ``devlink -j dev info $dev | jq '.[][]'``
134+ or None if the info cannot be obtained.
135+ """
136+ # Find PCI address via ip link
137+ ret = subprocess .run (['ip' , '-d' , '-j' , 'link' , 'show' , 'dev' , ifname ],
138+ capture_output = True , timeout = 10 , check = False )
139+ if ret .returncode != 0 :
140+ return None
141+ try :
142+ pci_addr = json .loads (ret .stdout )[0 ].get ('parentdev' )
143+ except (json .JSONDecodeError , IndexError ):
144+ return None
145+ if not pci_addr :
146+ return None
147+
148+ devlink_dev = f'pci/{ pci_addr } '
149+ ret = subprocess .run (['devlink' , '-j' , 'dev' , 'info' , devlink_dev ],
150+ capture_output = True , timeout = 10 , check = False )
151+ if ret .returncode != 0 :
152+ return None
153+ try :
154+ data = json .loads (ret .stdout )
155+ # Strip outer nests: {"info":{"pci/...": {actual data}}}
156+ return data ['info' ][devlink_dev ]
157+ except (json .JSONDecodeError , KeyError ):
158+ return None
159+
160+
130161def setup_test_interfaces (test_dir ):
131162 """Configure test NICs and write net.config from nic-test.env.
132163
@@ -252,6 +283,19 @@ def main():
252283 results_dir = os .path .join (results_base , reservation_id )
253284 os .makedirs (results_dir , exist_ok = True )
254285
286+ # Collect devlink device info for the test NIC
287+ env = _parse_env_file (os .path .join (test_dir , 'nic-test.env' ))
288+ netif = env .get ('NETIF' )
289+ if netif :
290+ dev_info = _collect_device_info (netif )
291+ if dev_info :
292+ with open (os .path .join (results_dir , 'device-info.json' ), 'w' ,
293+ encoding = 'utf-8' ) as fp :
294+ json .dump (dev_info , fp )
295+ print (f"Collected device info for { netif } " )
296+ else :
297+ print (f"Warning: could not collect device info for { netif } " )
298+
255299 crashed = run_tests (test_dir , results_dir )
256300
257301 print (f"Completed, results in { results_dir } " )
0 commit comments