From 01fdcf3e44d744f38c98e67d0be0f91395ba367b Mon Sep 17 00:00:00 2001 From: Mateusz Bloch Date: Mon, 24 Jul 2023 10:59:07 +0200 Subject: [PATCH] trunner: add reboot property in yaml JIRA CI-303 --- trunner/config.py | 9 ++++++++ trunner/test_runner.py | 49 ++++++++++++++++++------------------------ trunner/types.py | 2 +- 3 files changed, 31 insertions(+), 29 deletions(-) diff --git a/trunner/config.py b/trunner/config.py index ae2ca46e1..f60e8e2e0 100644 --- a/trunner/config.py +++ b/trunner/config.py @@ -169,6 +169,14 @@ def _parse_shell_command(self, config: dict): cmd=parsed_cmd, ) + def _parse_reboot(self, config: dict) -> None: + reboot = config.get("reboot", self.test.should_reboot) + + if not isinstance(reboot, bool): + raise ParserError(f"reboot must be a boolean value (true/false) not {reboot}") + + self.test.should_reboot = reboot + def _parse_ignore(self, config: dict) -> None: ignore = config.get("ignore", self.main.ignore) @@ -248,6 +256,7 @@ def _parse_config(self, config: dict): if self.test.ignore: return + self._parse_reboot(config) self._parse_shell_command(config) self._parse_load(config) self._parse_kwargs(config) diff --git a/trunner/test_runner.py b/trunner/test_runner.py index b69a08a83..362f764f8 100644 --- a/trunner/test_runner.py +++ b/trunner/test_runner.py @@ -156,8 +156,26 @@ def run_tests(self, tests: Sequence[TestOptions]): """ fail, skip = 0, 0 + # Reboot is required for the initial test. + tests[0].should_reboot = True + last_test_failed = False for idx, test in enumerate(tests): + # Reboot is required under these circumstances: + #1. The previous test has failed. + #2. Runner runs in the "nightly" mode + #3. We have to enter the bootloader in order to load applications. + if ( + last_test_failed + or self.ctx.nightly + or ( + not self.ctx.target.rootfs + and tests[idx].bootloader is not None + and tests[idx].bootloader.apps + ) + ): + tests[idx].should_reboot = True + result = TestResult(test.name) print(f"{result.get_name()}: ", end="", flush=True) @@ -180,7 +198,10 @@ def run_tests(self, tests: Sequence[TestOptions]): print(result, end="", flush=True) if result.is_fail(): + last_test_failed = True fail += 1 + elif result.is_ok(): + last_test_failed = False elif result.is_skip(): skip += 1 @@ -188,34 +209,6 @@ def run_tests(self, tests: Sequence[TestOptions]): testname_stripped = test.name.replace("phoenix-rtos-tests/", "").replace("/", ".") dump_logfiles(self.target.dut, testname_stripped, self.ctx.logdir) - def set_reboot_flag(tests, idx, result): - # If the test is successful and the next test doesn't require loading via - # the plo we don't want to reboot the entire device (to speed up the test execution). - # There are three exceptions to this rule: - # 1. Runner runs in the "nightly" mode when we are not concerned about slow execution. - # 2. The test has failed. - # 3. We have to enter the bootloader in order to load applications. - if idx == len(tests) - 1: - return - - tests[idx + 1].should_reboot = False - - if result.is_skip(): - tests[idx + 1].should_reboot = tests[idx].should_reboot - - if ( - result.is_fail() - or self.ctx.nightly - or ( - not self.ctx.target.rootfs - and tests[idx + 1].bootloader is not None - and tests[idx + 1].bootloader.apps - ) - ): - tests[idx + 1].should_reboot = True - - set_reboot_flag(tests, idx, result) - return fail, skip def run(self) -> bool: diff --git a/trunner/types.py b/trunner/types.py index 09a127ce5..c66ea317e 100644 --- a/trunner/types.py +++ b/trunner/types.py @@ -208,7 +208,7 @@ class TestOptions: target: Optional[str] = None bootloader: Optional[BootloaderOptions] = None shell: Optional[ShellOptions] = None - should_reboot: bool = True + should_reboot: bool = False ignore: bool = False nightly: bool = False kwargs: Dict = field(default_factory=dict)