Skip to content

Commit

Permalink
trunner: add reboot property in yaml
Browse files Browse the repository at this point in the history
JIRA CI-303
  • Loading branch information
mateusz-bloch committed Jul 28, 2023
1 parent 972e3c9 commit 01fdcf3
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 29 deletions.
9 changes: 9 additions & 0 deletions trunner/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)
Expand Down
49 changes: 21 additions & 28 deletions trunner/test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -180,42 +198,17 @@ 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

if not result.is_skip():
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:
Expand Down
2 changes: 1 addition & 1 deletion trunner/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 01fdcf3

Please sign in to comment.