Skip to content

Commit 0ea3460

Browse files
LixinGuoXnashif
authored andcommitted
twister: avoid monitor serial when flash error
Currently, twister keeps on monitoring serial output until timeout even if we have a flash error. And the error reason will be reported as 'No Console Output(Timeout)', which is not accurate. So add a flash_error flag to control if we need to monitor the output. Signed-off-by: Guo Lixin <[email protected]>
1 parent 8eead50 commit 0ea3460

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

scripts/pylib/twister/twisterlib/handlers.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,7 @@ def handle(self):
544544

545545
d_log = "{}/device.log".format(self.instance.build_dir)
546546
logger.debug('Flash command: %s', command)
547+
flash_error = False
547548
try:
548549
stdout = stderr = None
549550
with subprocess.Popen(command, stderr=subprocess.PIPE, stdout=subprocess.PIPE) as proc:
@@ -555,6 +556,7 @@ def handle(self):
555556
if proc.returncode != 0:
556557
self.instance.status = "error"
557558
self.instance.reason = "Device issue (Flash error?)"
559+
flash_error = True
558560
with open(d_log, "w") as dlog_fp:
559561
dlog_fp.write(stderr.decode())
560562
os.write(write_pipe, b'x') # halt the thread
@@ -564,6 +566,7 @@ def handle(self):
564566
(stdout, stderr) = proc.communicate()
565567
self.instance.status = "error"
566568
self.instance.reason = "Device issue (Timeout)"
569+
flash_error = True
567570

568571
with open(d_log, "w") as dlog_fp:
569572
dlog_fp.write(stderr.decode())
@@ -574,9 +577,10 @@ def handle(self):
574577
if post_flash_script:
575578
self.run_custom_script(post_flash_script, 30)
576579

577-
t.join(self.timeout)
578-
if t.is_alive():
579-
logger.debug("Timed out while monitoring serial output on {}".format(self.instance.platform.name))
580+
if not flash_error:
581+
t.join(self.timeout)
582+
if t.is_alive():
583+
logger.debug("Timed out while monitoring serial output on {}".format(self.instance.platform.name))
580584

581585
if ser.isOpen():
582586
ser.close()
@@ -599,14 +603,15 @@ def handle(self):
599603
self.instance.status = harness.state
600604
if harness.state == "failed":
601605
self.instance.reason = "Failed"
602-
else:
606+
elif not flash_error:
603607
self.instance.status = "error"
604608
self.instance.reason = "No Console Output(Timeout)"
605609

606610
if self.instance.status == "error":
607611
self.instance.add_missing_case_status("blocked", self.instance.reason)
608612

609-
self._final_handle_actions(harness, handler_time)
613+
if not flash_error:
614+
self._final_handle_actions(harness, handler_time)
610615

611616
if post_script:
612617
self.run_custom_script(post_script, 30)

0 commit comments

Comments
 (0)