|
6 | 6 | import json |
7 | 7 | import os |
8 | 8 | import subprocess |
| 9 | +import sys |
9 | 10 | import time |
10 | 11 |
|
11 | 12 | from lib.runner import find_newest_unseen, mark_all_seen, run_tests |
|
14 | 15 | TESTS_DIR = '/srv/hw-worker/tests' |
15 | 16 | RESULTS_DIR = '/srv/hw-worker/results' |
16 | 17 |
|
| 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 | + |
17 | 46 | # kselftest net.config keys (see drivers/net/README.rst) |
18 | 47 | _NET_CONFIG_KEYS = ['NETIF', 'LOCAL_V4', 'LOCAL_V6', 'REMOTE_V4', 'REMOTE_V6', |
19 | 48 | 'LOCAL_PREFIX_V6', 'REMOTE_TYPE', 'REMOTE_ARGS'] |
@@ -185,6 +214,8 @@ def setup_test_interfaces(test_dir): |
185 | 214 |
|
186 | 215 | def main(): |
187 | 216 | """Find pending tests, run them, and write results.""" |
| 217 | + sys.stdout = _TeeWriter(sys.stdout) |
| 218 | + |
188 | 219 | tests_dir = TESTS_DIR |
189 | 220 | results_base = RESULTS_DIR |
190 | 221 |
|
|
0 commit comments