Skip to content

Commit c2bc207

Browse files
committed
contest: hw: make hw_worker output to serial
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 5a66cc7 commit c2bc207

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

contest/hw/hw_worker.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import json
77
import os
88
import subprocess
9+
import sys
910
import time
1011

1112
from lib.runner import find_newest_unseen, mark_all_seen, run_tests
@@ -14,6 +15,34 @@
1415
TESTS_DIR = '/srv/hw-worker/tests'
1516
RESULTS_DIR = '/srv/hw-worker/results'
1617

18+
19+
class _TeeWriter:
20+
"""Write to both the original stream and /dev/kmsg."""
21+
22+
def __init__(self, original):
23+
self._original = original
24+
try:
25+
self._kmsg = open('/dev/kmsg', 'w', encoding='utf-8',
26+
errors='ignore')
27+
except (PermissionError, FileNotFoundError, OSError):
28+
self._kmsg = None
29+
30+
def write(self, text):
31+
self._original.write(text)
32+
if self._kmsg and text.strip():
33+
# kmsg prepends its own priority/timestamp, just send the text
34+
try:
35+
self._kmsg.write(f'nipa-hw-worker: {text}')
36+
self._kmsg.flush()
37+
except OSError:
38+
pass
39+
40+
def flush(self):
41+
self._original.flush()
42+
43+
def __getattr__(self, name):
44+
return getattr(self._original, name)
45+
1746
# kselftest net.config keys (see drivers/net/README.rst)
1847
_NET_CONFIG_KEYS = ['NETIF', 'LOCAL_V4', 'LOCAL_V6', 'REMOTE_V4', 'REMOTE_V6',
1948
'LOCAL_PREFIX_V6', 'REMOTE_TYPE', 'REMOTE_ARGS']
@@ -185,6 +214,8 @@ def setup_test_interfaces(test_dir):
185214

186215
def main():
187216
"""Find pending tests, run them, and write results."""
217+
sys.stdout = _TeeWriter(sys.stdout)
218+
188219
tests_dir = TESTS_DIR
189220
results_base = RESULTS_DIR
190221

0 commit comments

Comments
 (0)