From a5ffd7f7a34b673af9bd1d469b7aa8213c27f2ac Mon Sep 17 00:00:00 2001 From: Jordan Yates Date: Sat, 5 Apr 2025 10:20:02 +1000 Subject: [PATCH] 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 --- doc/develop/test/twister.rst | 5 +++++ scripts/pylib/twister/twisterlib/harness.py | 5 +++-- scripts/schemas/twister/testsuite-schema.yaml | 3 +++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/doc/develop/test/twister.rst b/doc/develop/test/twister.rst index 562e671b9e4..948a487439a 100644 --- a/doc/develop/test/twister.rst +++ b/doc/develop/test/twister.rst @@ -734,6 +734,11 @@ required_snippets: - cdc-acm-console - user-snippet-example +expect_reboot: (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 diff --git a/scripts/pylib/twister/twisterlib/harness.py b/scripts/pylib/twister/twisterlib/harness.py index 5a5988220d2..33120ccf7aa 100644 --- a/scripts/pylib/twister/twisterlib/harness.py +++ b/scripts/pylib/twister/twisterlib/harness.py @@ -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 diff --git a/scripts/schemas/twister/testsuite-schema.yaml b/scripts/schemas/twister/testsuite-schema.yaml index 2b1a7265584..796c342faa5 100644 --- a/scripts/schemas/twister/testsuite-schema.yaml +++ b/scripts/schemas/twister/testsuite-schema.yaml @@ -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