From 765941ef6aaf46e71f7c23cc7d764516d2ce8bca 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. Due to multi-process running, some process will still processed. Signed-off-by: Hake Huang --- samples/hello_world/src/main.c | 1 - .../pylib/twister/twisterlib/environment.py | 6 +++++ scripts/pylib/twister/twisterlib/runner.py | 24 ++++++++++++++++++- 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/samples/hello_world/src/main.c b/samples/hello_world/src/main.c index c550ab461cb356c..9386c4c6a20ea6f 100644 --- a/samples/hello_world/src/main.c +++ b/samples/hello_world/src/main.c @@ -9,6 +9,5 @@ int main(void) { printf("Hello World! %s\n", CONFIG_BOARD_TARGET); - return 0; } diff --git a/scripts/pylib/twister/twisterlib/environment.py b/scripts/pylib/twister/twisterlib/environment.py index e0773878ddf8aee..2bebc62bdd277fa 100644 --- a/scripts/pylib/twister/twisterlib/environment.py +++ b/scripts/pylib/twister/twisterlib/environment.py @@ -633,6 +633,12 @@ def add_parse_arguments(parser = None): 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 f5e2cabf74dcb3e..6fc392058b3cf06 100644 --- a/scripts/pylib/twister/twisterlib/runner.py +++ b/scripts/pylib/twister/twisterlib/runner.py @@ -1467,34 +1467,56 @@ def add_tasks_to_queue(self, pipeline, build_only=False, test_only=False, retry_ else: pipeline.put({"op": "cmake", "test": instance}) + @staticmethod + def clear_pipeline(pipeline): + while not pipeline.empty(): + try: + pipeline.get_nowait() + except queue.Empty: + break def pipeline_mgr(self, pipeline, done_queue, lock, results): try: + quit_on_failure = False if sys.platform == 'linux': with self.jobserver.get_job(): while True: try: task = pipeline.get_nowait() except queue.Empty: + if self.env.options.quit_on_failure and quit_on_failure: + return True break else: instance = task['test'] pb = ProjectBuilder(instance, self.env, self.jobserver) pb.duts = self.duts pb.process(pipeline, done_queue, task, lock, results) - + if pb and self.env.options.quit_on_failure and not quit_on_failure: + if pb.instance.status in [TwisterStatus.FAIL, TwisterStatus.ERROR]: + self.clear_pipeline(pipeline) + next_op = 'report' + pb._add_to_pipeline(pipeline, next_op) + quit_on_failure = True return True else: while True: try: task = pipeline.get_nowait() except queue.Empty: + if self.env.options.quit_on_failure and quit_on_failure: + return True break else: instance = task['test'] pb = ProjectBuilder(instance, self.env, self.jobserver) pb.duts = self.duts pb.process(pipeline, done_queue, task, lock, results) + if pb and self.env.options.quit_on_failure and not quit_on_failure: + if pb.instance.status in [TwisterStatus.FAIL, TwisterStatus.ERROR]: + next_op = 'report' + pb._add_to_pipeline(pipeline, next_op) + quit_on_failure = True return True except Exception as e: logger.error(f"General exception: {e}")