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.
Due to multi-process running, some process will still
processed.

Signed-off-by: Hake Huang <[email protected]>
  • Loading branch information
hakehuang committed Oct 25, 2024
1 parent 7128e33 commit 765941e
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
1 change: 0 additions & 1 deletion samples/hello_world/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,5 @@
int main(void)
{
printf("Hello World! %s\n", CONFIG_BOARD_TARGET);

return 0;
}
6 changes: 6 additions & 0 deletions scripts/pylib/twister/twisterlib/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
24 changes: 23 additions & 1 deletion scripts/pylib/twister/twisterlib/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand Down

0 comments on commit 765941e

Please sign in to comment.