Skip to content

Commit 723a8fc

Browse files
Benjamin Gwinjhedberg
authored andcommitted
twister: Add logging of stderr for BinaryHandlers
In the case where a test causes the test executor to crash, the stderr is currently lost, making it hard to debug failures. This changes it so that the process' stderr gets captured to 'handler_stderr.log' for inspection. Signed-off-by: Benjamin Gwin <bgwin@google.com>
1 parent 0ca7ef7 commit 723a8fc

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

scripts/pylib/twister/twisterlib/handlers.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,8 +307,9 @@ def handle(self, harness):
307307
harness.run_robot_test(command, self)
308308
return
309309

310-
with subprocess.Popen(command, stdout=subprocess.PIPE,
311-
stderr=subprocess.PIPE, cwd=self.build_dir, env=env) as proc:
310+
stderr_log = "{}/handler_stderr.log".format(self.instance.build_dir)
311+
with open(stderr_log, "w+") as stderr_log_fp, subprocess.Popen(command, stdout=subprocess.PIPE,
312+
stderr=stderr_log_fp, cwd=self.build_dir, env=env) as proc:
312313
logger.debug("Spawning BinaryHandler Thread for %s" % self.name)
313314
t = threading.Thread(target=self._output_handler, args=(proc, harness,), daemon=True)
314315
t.start()
@@ -318,6 +319,9 @@ def handle(self, harness):
318319
t.join()
319320
proc.wait()
320321
self.returncode = proc.returncode
322+
if proc.returncode != 0:
323+
self.instance.status = "error"
324+
self.instance.reason = "BinaryHandler returned {}".format(proc.returncode)
321325
self.try_kill_process_by_pid()
322326

323327
handler_time = time.time() - start_time

scripts/pylib/twister/twisterlib/runner.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,7 @@ def log_info(self, filename, inline_logs, log_testcases=False):
573573
def log_info_file(self, inline_logs):
574574
build_dir = self.instance.build_dir
575575
h_log = "{}/handler.log".format(build_dir)
576+
he_log = "{}/handler_stderr.log".format(build_dir)
576577
b_log = "{}/build.log".format(build_dir)
577578
v_log = "{}/valgrind.log".format(build_dir)
578579
d_log = "{}/device.log".format(build_dir)
@@ -584,6 +585,8 @@ def log_info_file(self, inline_logs):
584585
self.log_info("{}".format(pytest_log), inline_logs, log_testcases=True)
585586
elif os.path.exists(h_log) and os.path.getsize(h_log) > 0:
586587
self.log_info("{}".format(h_log), inline_logs)
588+
elif os.path.exists(he_log) and os.path.getsize(he_log) > 0:
589+
self.log_info("{}".format(he_log), inline_logs)
587590
elif os.path.exists(d_log) and os.path.getsize(d_log) > 0:
588591
self.log_info("{}".format(d_log), inline_logs)
589592
else:
@@ -757,6 +760,7 @@ def cleanup_artifacts(self, additional_keep: List[str] = []):
757760
allow = [
758761
os.path.join('zephyr', '.config'),
759762
'handler.log',
763+
'handler_stderr.log',
760764
'build.log',
761765
'device.log',
762766
'recording.csv',

0 commit comments

Comments
 (0)