Skip to content

Commit f050a99

Browse files
PerMacnashif
authored andcommitted
twister: Improve handling of errors while flashing device
The patch improves handling runners errors from flashing. It add thread termination in case of process returning non 0 exit code. Before, even though the error was returned, a thread was not terminated and test ended only after timeout termination. The patch also adds information about the failure reason to the reports Signed-off-by: Maciej Perkowski <[email protected]>
1 parent f062490 commit f050a99

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

scripts/pylib/twister/twisterlib.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -814,6 +814,8 @@ def handle(self):
814814
self.instance.reason = "Device issue (Flash?)"
815815
with open(d_log, "w") as dlog_fp:
816816
dlog_fp.write(stderr.decode())
817+
os.write(write_pipe, b'x') # halt the thread
818+
out_state = "flash_error"
817819
except subprocess.TimeoutExpired:
818820
proc.kill()
819821
(stdout, stderr) = proc.communicate()
@@ -846,12 +848,15 @@ def handle(self):
846848

847849
handler_time = time.time() - start_time
848850

849-
if out_state == "timeout":
851+
if out_state in ["timeout", "flash_error"]:
850852
for c in self.instance.testcase.cases:
851853
if c not in harness.tests:
852854
harness.tests[c] = "BLOCK"
853855

854-
self.instance.reason = "Timeout"
856+
if out_state == "timeout":
857+
self.instance.reason = "Timeout"
858+
elif out_state == "flash_error":
859+
self.instance.reason = "Flash error"
855860

856861
self.instance.results = harness.tests
857862

@@ -864,7 +869,7 @@ def handle(self):
864869

865870
if harness.state:
866871
self.set_state(harness.state, handler_time)
867-
if harness.state == "failed":
872+
if harness.state == "failed":
868873
self.instance.reason = "Failed"
869874
else:
870875
self.set_state(out_state, handler_time)
@@ -2415,7 +2420,7 @@ def report_out(self, results):
24152420
results.done += 1
24162421
instance = self.instance
24172422

2418-
if instance.status in ["error", "failed", "timeout"]:
2423+
if instance.status in ["error", "failed", "timeout", "flash_error"]:
24192424
if instance.status == "error":
24202425
results.error += 1
24212426
results.failed += 1
@@ -3381,7 +3386,7 @@ def xunit_report(self, filename, platform=None, full_report=False, append=False,
33813386
else:
33823387
fails += 1
33833388
else:
3384-
if instance.status in ["error", "failed", "timeout"]:
3389+
if instance.status in ["error", "failed", "timeout", "flash_error"]:
33853390
if instance.reason in ['build_error', 'handler_crash']:
33863391
errors += 1
33873392
else:
@@ -3467,7 +3472,7 @@ def xunit_report(self, filename, platform=None, full_report=False, append=False,
34673472
eleTestcase,
34683473
'error',
34693474
type="failure",
3470-
message="failed")
3475+
message=instance.reason)
34713476
log_root = os.path.join(self.outdir, instance.platform.name, instance.testcase.name)
34723477
log_file = os.path.join(log_root, "handler.log")
34733478
el.text = self.process_log(log_file)
@@ -3498,7 +3503,7 @@ def xunit_report(self, filename, platform=None, full_report=False, append=False,
34983503
name="%s" % (instance.testcase.name),
34993504
time="%f" % handler_time)
35003505

3501-
if instance.status in ["error", "failed", "timeout"]:
3506+
if instance.status in ["error", "failed", "timeout", "flash_error"]:
35023507
failure = ET.SubElement(
35033508
eleTestcase,
35043509
'failure',

0 commit comments

Comments
 (0)