From 6996436ed6c247950652ae58e1ecb41905a4d389 Mon Sep 17 00:00:00 2001 From: Hake Huang Date: Tue, 20 Aug 2024 01:22:52 +0800 Subject: [PATCH] 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 --- scripts/pylib/twister/twisterlib/environment.py | 6 ++++++ scripts/pylib/twister/twisterlib/runner.py | 10 ++++++++++ scripts/pylib/twister/twisterlib/twister_main.py | 6 +++++- 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/scripts/pylib/twister/twisterlib/environment.py b/scripts/pylib/twister/twisterlib/environment.py index b161096d562..ad2f619056a 100644 --- a/scripts/pylib/twister/twisterlib/environment.py +++ b/scripts/pylib/twister/twisterlib/environment.py @@ -668,6 +668,12 @@ structure in the main Zephyr tree: boards///""") 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. diff --git a/scripts/pylib/twister/twisterlib/runner.py b/scripts/pylib/twister/twisterlib/runner.py index 287069f47d8..cf496225aa3 100644 --- a/scripts/pylib/twister/twisterlib/runner.py +++ b/scripts/pylib/twister/twisterlib/runner.py @@ -1927,6 +1927,11 @@ class TwisterRunner: 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 and \ + pb.instance.status in [TwisterStatus.FAIL, TwisterStatus.ERROR]: + with pipeline.mutex: + pipeline.queue.clear() + break return True else: @@ -1940,6 +1945,11 @@ class TwisterRunner: 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 and \ + 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}") diff --git a/scripts/pylib/twister/twisterlib/twister_main.py b/scripts/pylib/twister/twisterlib/twister_main.py index 5644b981131..1fbd2ffac4d 100644 --- a/scripts/pylib/twister/twisterlib/twister_main.py +++ b/scripts/pylib/twister/twisterlib/twister_main.py @@ -238,13 +238,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