scripts: twisterlib: extend testcase schema for reboots

Extend the testcase schema to provide a way to communicate that a given
test is expected to reboot during execution. The generic harness takes
that information and suppresses `already STARTED` warnings if the
restart is expected.

Signed-off-by: Jordan Yates <jordan@embeint.com>
This commit is contained in:
Jordan Yates 2025-04-05 10:20:02 +10:00 committed by Benjamin Cabé
commit a5ffd7f7a3
3 changed files with 11 additions and 2 deletions

View file

@ -734,6 +734,11 @@ required_snippets: <list of needed snippets>
- cdc-acm-console
- user-snippet-example
expect_reboot: <True|False> (default False)
Notify twister that the test scenario is expected to reboot while executing.
When enabled, twister will suppress warnings about unexpected multiple runs
of a testsuite or testcase.
The set of test scenarios that actually run depends on directives in the test scenario
filed and options passed in on the command line. If there is any confusion,
running with ``-v`` or examining the discard report

View file

@ -91,6 +91,7 @@ class Harness:
config = instance.testsuite.harness_config
self.id = instance.testsuite.id
self.run_id = instance.run_id
self.expect_reboot = getattr(instance.testsuite, 'expect_reboot', False)
if instance.testsuite.ignore_faults:
self.fail_on_fault = False
@ -848,7 +849,7 @@ class Test(Harness):
logger.debug(f"{phase}: unexpected Ztest suite '{suite_name}' is "
f"not present among: {self.instance.testsuite.ztest_suite_names}")
if suite_name in self.started_suites:
if self.started_suites[suite_name]['count'] > 0:
if self.started_suites[suite_name]['count'] > 0 and not self.expect_reboot:
# Either the suite restarts itself or unexpected state transition.
logger.warning(f"{phase}: already STARTED '{suite_name}':"
f"{self.started_suites[suite_name]}")
@ -878,7 +879,7 @@ class Test(Harness):
def start_case(self, tc_name, phase='TC_START'):
if tc_name in self.started_cases:
if self.started_cases[tc_name]['count'] > 0:
if self.started_cases[tc_name]['count'] > 0 and not self.expect_reboot:
logger.warning(f"{phase}: already STARTED case "
f"'{tc_name}':{self.started_cases[tc_name]}")
self.started_cases[tc_name]['count'] += 1

View file

@ -70,6 +70,9 @@ schema;scenario-schema:
"extra_sections":
type: any
required: false
"expect_reboot":
type: bool
required: false
"required_snippets":
type: seq
required: false