From 87e59d58623b5430e658e75b66e789514edf3ac4 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 | 12 +++++++++++- scripts/pylib/twister/twisterlib/twister_main.py | 8 ++++++-- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/scripts/pylib/twister/twisterlib/environment.py b/scripts/pylib/twister/twisterlib/environment.py index 7d55c0f8d27fdc2..60fef8944887514 100644 --- a/scripts/pylib/twister/twisterlib/environment.py +++ b/scripts/pylib/twister/twisterlib/environment.py @@ -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. diff --git a/scripts/pylib/twister/twisterlib/runner.py b/scripts/pylib/twister/twisterlib/runner.py index 172add5367edf07..6b40621b4ed58af 100644 --- a/scripts/pylib/twister/twisterlib/runner.py +++ b/scripts/pylib/twister/twisterlib/runner.py @@ -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() @@ -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: @@ -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}") diff --git a/scripts/pylib/twister/twisterlib/twister_main.py b/scripts/pylib/twister/twisterlib/twister_main.py index 310cdc7bfdde138..3317ff6a6655adb 100644 --- a/scripts/pylib/twister/twisterlib/twister_main.py +++ b/scripts/pylib/twister/twisterlib/twister_main.py @@ -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: @@ -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