Skip to content

Commit 6996436

Browse files
hakehuangkartben
authored andcommitted
tests: twister: add quit-on-failure option
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]>
1 parent 557f7f9 commit 6996436

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

scripts/pylib/twister/twisterlib/environment.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -668,6 +668,12 @@ def add_parse_arguments(parser = None) -> argparse.ArgumentParser:
668668
help="Use the list of test scenarios under quarantine and run them"
669669
"to verify their current status.")
670670

671+
parser.add_argument(
672+
"--quit-on-failure",
673+
action="store_true",
674+
help="""quit twister once there is build / run failure
675+
""")
676+
671677
parser.add_argument(
672678
"--report-name",
673679
help="""Create a report with a custom name.

scripts/pylib/twister/twisterlib/runner.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1927,6 +1927,11 @@ def pipeline_mgr(self, pipeline, done_queue, lock, results):
19271927
pb = ProjectBuilder(instance, self.env, self.jobserver)
19281928
pb.duts = self.duts
19291929
pb.process(pipeline, done_queue, task, lock, results)
1930+
if self.env.options.quit_on_failure and \
1931+
pb.instance.status in [TwisterStatus.FAIL, TwisterStatus.ERROR]:
1932+
with pipeline.mutex:
1933+
pipeline.queue.clear()
1934+
break
19301935

19311936
return True
19321937
else:
@@ -1940,6 +1945,11 @@ def pipeline_mgr(self, pipeline, done_queue, lock, results):
19401945
pb = ProjectBuilder(instance, self.env, self.jobserver)
19411946
pb.duts = self.duts
19421947
pb.process(pipeline, done_queue, task, lock, results)
1948+
if self.env.options.quit_on_failure and \
1949+
pb.instance.status in [TwisterStatus.FAIL, TwisterStatus.ERROR]:
1950+
with pipeline.mutex:
1951+
pipeline.queue.clear()
1952+
break
19431953
return True
19441954
except Exception as e:
19451955
logger.error(f"General exception: {e}")

scripts/pylib/twister/twisterlib/twister_main.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,13 +238,17 @@ def main(options: argparse.Namespace, default_options: argparse.Namespace):
238238
artifacts = Artifacts(env)
239239
artifacts.package()
240240

241-
logger.info("Run completed")
242241
if (
243242
runner.results.failed
244243
or runner.results.error
245244
or (tplan.warnings and options.warnings_as_errors)
246245
or (options.coverage and not coverage_completed)
247246
):
247+
if env.options.quit_on_failure:
248+
logger.info("twister aborted because of a failure/error")
249+
else:
250+
logger.info("Run completed")
248251
return 1
249252

253+
logger.info("Run completed")
250254
return 0

0 commit comments

Comments
 (0)