Skip to content

Commit

Permalink
tests: twister: add quit-on-failure option
Browse files Browse the repository at this point in the history
in CI, we may need to quit if there is any failure
to save time, so add this --quit-on-failure so that
any failure will quit the test.

Signed-off-by: Hake Huang <[email protected]>
  • Loading branch information
hakehuang committed Nov 28, 2024
1 parent 184c0f9 commit e526c52
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
6 changes: 6 additions & 0 deletions scripts/pylib/twister/twisterlib/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,12 @@ def add_parse_arguments(parser = None) -> argparse.ArgumentParser:
help="Use the list of test scenarios under quarantine and run them"
"to verify their current status.")

parser.add_argument(
"--quit-on-failure",
action="store_true",
help="""quit twister once there is build / run failure
""")

parser.add_argument(
"--report-name",
help="""Create a report with a custom name.
Expand Down
12 changes: 11 additions & 1 deletion scripts/pylib/twister/twisterlib/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -1095,7 +1095,7 @@ def demangle(self, symbol_name):
if symbol_name[:2] == '_Z':
try:
cpp_filt = subprocess.run('c++filt', input=symbol_name, text=True, check=True,
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
capture_output=True)
if self.trace:
logger.debug(f"Demangle: '{symbol_name}'==>'{cpp_filt.stdout}'")
return cpp_filt.stdout.strip()
Expand Down Expand Up @@ -1796,6 +1796,11 @@ def pipeline_mgr(self, pipeline, done_queue, lock, results):
pb = ProjectBuilder(instance, self.env, self.jobserver)
pb.duts = self.duts
pb.process(pipeline, done_queue, task, lock, results)
if self.env.options.quit_on_failure:
if pb.instance.status in [TwisterStatus.FAIL, TwisterStatus.ERROR]:
with pipeline.mutex:
pipeline.queue.clear()
break

return True
else:
Expand All @@ -1809,6 +1814,11 @@ def pipeline_mgr(self, pipeline, done_queue, lock, results):
pb = ProjectBuilder(instance, self.env, self.jobserver)
pb.duts = self.duts
pb.process(pipeline, done_queue, task, lock, results)
if self.env.options.quit_on_failure:
if pb.instance.status in [TwisterStatus.FAIL, TwisterStatus.ERROR]:
with pipeline.mutex:
pipeline.queue.clear()
break
return True
except Exception as e:
logger.error(f"General exception: {e}")
Expand Down
8 changes: 6 additions & 2 deletions scripts/pylib/twister/twisterlib/twister_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ def main(options: argparse.Namespace, default_options: argparse.Namespace):

if options.dry_run:
duration = time.time() - start_time
logger.info("Completed in %d seconds" % (duration))
logger.info(f"Completed in {duration} seconds")
return 0

if options.short_build_path:
Expand Down Expand Up @@ -239,13 +239,17 @@ def main(options: argparse.Namespace, default_options: argparse.Namespace):
artifacts = Artifacts(env)
artifacts.package()

logger.info("Run completed")
if (
runner.results.failed
or runner.results.error
or (tplan.warnings and options.warnings_as_errors)
or (options.coverage and not coverage_completed)
):
if env.options.quit_on_failure:
logger.info("twister aborted because of a failure/error")
else:
logger.info("Run completed")
return 1

logger.info("Run completed")
return 0

0 comments on commit e526c52

Please sign in to comment.