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>
This commit is contained in:
Benjamin Gwin 2022-08-11 15:42:15 -07:00 committed by Johan Hedberg
commit 723a8fcf36
2 changed files with 10 additions and 2 deletions

View file

@ -307,8 +307,9 @@ class BinaryHandler(Handler):
harness.run_robot_test(command, self)
return
with subprocess.Popen(command, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, cwd=self.build_dir, env=env) as proc:
stderr_log = "{}/handler_stderr.log".format(self.instance.build_dir)
with open(stderr_log, "w+") as stderr_log_fp, subprocess.Popen(command, stdout=subprocess.PIPE,
stderr=stderr_log_fp, cwd=self.build_dir, env=env) as proc:
logger.debug("Spawning BinaryHandler Thread for %s" % self.name)
t = threading.Thread(target=self._output_handler, args=(proc, harness,), daemon=True)
t.start()
@ -318,6 +319,9 @@ class BinaryHandler(Handler):
t.join()
proc.wait()
self.returncode = proc.returncode
if proc.returncode != 0:
self.instance.status = "error"
self.instance.reason = "BinaryHandler returned {}".format(proc.returncode)
self.try_kill_process_by_pid()
handler_time = time.time() - start_time

View file

@ -573,6 +573,7 @@ class ProjectBuilder(FilterBuilder):
def log_info_file(self, inline_logs):
build_dir = self.instance.build_dir
h_log = "{}/handler.log".format(build_dir)
he_log = "{}/handler_stderr.log".format(build_dir)
b_log = "{}/build.log".format(build_dir)
v_log = "{}/valgrind.log".format(build_dir)
d_log = "{}/device.log".format(build_dir)
@ -584,6 +585,8 @@ class ProjectBuilder(FilterBuilder):
self.log_info("{}".format(pytest_log), inline_logs, log_testcases=True)
elif os.path.exists(h_log) and os.path.getsize(h_log) > 0:
self.log_info("{}".format(h_log), inline_logs)
elif os.path.exists(he_log) and os.path.getsize(he_log) > 0:
self.log_info("{}".format(he_log), inline_logs)
elif os.path.exists(d_log) and os.path.getsize(d_log) > 0:
self.log_info("{}".format(d_log), inline_logs)
else:
@ -757,6 +760,7 @@ class ProjectBuilder(FilterBuilder):
allow = [
os.path.join('zephyr', '.config'),
'handler.log',
'handler_stderr.log',
'build.log',
'device.log',
'recording.csv',