Skip to content

Commit

Permalink
fix(unity): make single board test procedure more robust
Browse files Browse the repository at this point in the history
  • Loading branch information
hfudev committed Dec 22, 2023
1 parent 873aae1 commit f8b6d21
Showing 1 changed file with 24 additions and 12 deletions.
36 changes: 24 additions & 12 deletions pytest-embedded-idf/pytest_embedded_idf/unity_tester.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ def __init__(self, *args, **kwargs):

super().__init__(*args, **kwargs)

self._ignore_first_ready_pattern = False

def confirm_write(
self,
write_str: t.Any,
Expand Down Expand Up @@ -219,16 +221,28 @@ def _parse_unity_menu_from_str(s: str) -> t.List[UnittestMenuCase]:

return test_menu

def _hard_reset(self) -> None:
if self._hard_reset_func:
try:
self._hard_reset_func()
except NotImplementedError:
# since menu printed but been expected (buffer has gone)... ignore the first ready pattern
self.confirm_write('\n', expect_pattern=READY_PATTERN_LIST)
self._ignore_first_ready_pattern = True
pass

def _get_ready(self, timeout: float = 30) -> None:
if self._ignore_first_ready_pattern:
self._ignore_first_ready_pattern = False
else:
self.expect_exact(READY_PATTERN_LIST, timeout=timeout)

@property
def test_menu(self) -> t.List[UnittestMenuCase]:
if self._test_menu is None:
self._test_menu = self._parse_test_menu()
logging.debug('Successfully parsed unity test menu')
if self._hard_reset_func:
try:
self._hard_reset_func()
except NotImplementedError:
self.write('\n') # print the menu
self._hard_reset()

return self._test_menu

Expand All @@ -254,11 +268,8 @@ def wrapper(self, *args, **kwargs):
try:
# do it here since the first hard reset before test case shouldn't be counted in duration time
if 'reset' in kwargs:
if kwargs.get('reset') and self._hard_reset_func:
try:
self._hard_reset_func()
except NotImplementedError:
self.write('\n') # print the menu
if kwargs.get('reset'):
self._hard_reset()

_start_at = time.perf_counter()
func(self, *args, **kwargs)
Expand Down Expand Up @@ -345,7 +356,7 @@ def _run_normal_case(
logging.warning('case %s is not a normal case', case.name)
return

self.expect_exact(READY_PATTERN_LIST, timeout=timeout)
self._get_ready(timeout)
self.confirm_write(case.index, expect_str=f'Running {case.name}...')

@_record_single_unity_test_case
Expand Down Expand Up @@ -378,10 +389,11 @@ def _run_multi_stage_case(
if _timeout < 0: # pexpect process would expect 30s if < 0
_timeout = 0

self.expect_exact(READY_PATTERN_LIST, timeout=_timeout)
self._get_ready(timeout)
self.confirm_write(case.index, expect_str=f'Running {case.name}...')

# here we can't use confirm_write because the sub cases won't print anything
time.sleep(1)
self.write(str(sub_case['index']))

_timestamp = time.perf_counter()
Expand Down

0 comments on commit f8b6d21

Please sign in to comment.