Skip to content

Commit b6652c8

Browse files
committed
contest: hw: make sure we collect device info
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 1f8700f commit b6652c8

3 files changed

Lines changed: 60 additions & 1 deletion

File tree

contest/hw/hw_worker.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
130161
def 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}")

contest/hw/hwksft.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
parse_results, process_crashes, set_log_file,
2424
WaitResult, grab_hw_worker_journal, grab_sol_logs,
2525
reboot_machine, check_healthy_ssh,
26+
read_device_info,
2627
CRASH_SENTINEL, _journal_has_crash_sentinel)
2728

2829
# Config:
@@ -272,7 +273,12 @@ def test(binfo, rinfo, cbarg): # pylint: disable=unused-argument
272273
# 11. Copy back results
273274
fetch_results(machine_ips, reservation_id, results_path)
274275

275-
# 11. Parse results
276+
# Populate device info from hw_worker's devlink collection
277+
dev_info = read_device_info(results_path)
278+
if dev_info:
279+
rinfo['device'] = dev_info
280+
281+
# 12. Parse results
276282
cases = parse_results(results_path, link)
277283

278284
# 12. Post-process crashes: decode stack traces, extract fingerprints

contest/hw/lib/deployer.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,15 @@ def fetch_results(machine_ips, reservation_id, results_path):
437437
check=False)
438438

439439

440+
def read_device_info(results_path):
441+
"""Read device-info.json written by hw_worker, or return None."""
442+
path = os.path.join(results_path, 'test-outputs', 'device-info.json')
443+
if not os.path.exists(path):
444+
return None
445+
with open(path, encoding='utf-8') as fp:
446+
return json.load(fp)
447+
448+
440449
def parse_results(results_path, link):
441450
"""Parse fetched test output into a vmksft-p-style result list.
442451

0 commit comments

Comments
 (0)