tests: add interactive_sync adapted to shell

This commit is contained in:
Francisco Molina 2020-03-11 09:59:22 +01:00
parent d57c39f09f
commit a31003a23c
No known key found for this signature in database
GPG Key ID: 3E94EAC3DBDEEDA8
6 changed files with 55 additions and 14 deletions

View File

@ -1083,6 +1083,12 @@ ifneq (,$(filter ecc_%,$(USEMODULE)))
USEMODULE += ecc
endif
ifneq (,$(filter test_utils_interactive_sync,$(USEMODULE)))
ifneq (,$(filter shell,$(USEMODULE)))
DEFAULT_MODULE += test_utils_interactive_sync_shell
endif
endif
# recursively catch transitive dependencies
USEMODULE := $(sort $(USEMODULE))
USEPKG := $(sort $(USEPKG))
@ -1102,5 +1108,11 @@ else
USEMODULE += $(filter periph_init_%,$(filter-out $(DISABLE_MODULE),$(DEFAULT_MODULE)))
endif
# Add test_utils_interactive_sync_shell
ifneq (,$(filter test_utils_interactive_sync,$(USEMODULE)))
USEMODULE += $(filter test_utils_interactive_sync_%, \
$(filter-out $(DISABLE_MODULE),$(DEFAULT_MODULE)))
endif
USEMODULE := $(sort $(USEMODULE))
endif

View File

@ -99,9 +99,14 @@ def sync_child(child, env):
# Do a child synchronization if used by a module
modules = modules_list()
if 'test_utils_interactive_sync' in modules:
utils.test_utils_interactive_sync(child,
TEST_INTERACTIVE_RETRIES,
TEST_INTERACTIVE_DELAY)
if 'test_utils_interactive_sync_shell' in modules:
utils.test_utils_interactive_sync_shell(child,
TEST_INTERACTIVE_RETRIES,
TEST_INTERACTIVE_DELAY)
else:
utils.test_utils_interactive_sync(child,
TEST_INTERACTIVE_RETRIES,
TEST_INTERACTIVE_DELAY)
# If requested also reset after opening the terminal, this should not be used
# by any application since it breaks the tests for boards that do not support
# this feature.

View File

@ -9,19 +9,33 @@
import pexpect
def test_utils_interactive_sync(child, retries, delay):
"""Synchronisation for 'test_utils_interactive_sync' function.
def _test_utils_interactive_sync(child, retries, delay, ready_cmd='r',
ready_exp='READY'):
Interacts through input to wait for node being ready.
"""
for _ in range(0, retries):
child.sendline('r')
ret = child.expect_exact(['READY', pexpect.TIMEOUT], timeout=delay)
for _ in range(retries):
child.sendline(ready_cmd)
ret = child.expect_exact([ready_exp, pexpect.TIMEOUT], timeout=delay)
if ret == 0:
break
else:
# Last call to make it fail her,
child.expect_exact('READY', timeout=0)
# Last call to make it fail here,
child.expect_exact(ready_exp, timeout=0)
def test_utils_interactive_sync(child, retries, delay):
"""Synchronization for 'test_utils_interactive_sync' function
Interacts through input to wait for node being ready.
"""
_test_utils_interactive_sync(child, retries, delay)
child.sendline('s')
child.expect_exact('START')
def test_utils_interactive_sync_shell(child, retries, delay):
"""Synchronization `shell` and `test_utils_interactive_sync` modules are
used ('test_utils_interactive_sync' function is not)
Interacts through input to wait for node being ready.
"""
_test_utils_interactive_sync(child, retries, delay, '\n', '>')

View File

@ -227,6 +227,9 @@ PSEUDOMODULES += crypto_aes_precalculated
# This pseudomodule causes a loop in AES to be unrolled (more flash, less CPU)
PSEUDOMODULES += crypto_aes_unroll
# declare shell version of test_utils_interactive_sync
PSEUDOMODULES += test_utils_interactive_sync_shell
# All auto_init modules are pseudomodules
PSEUDOMODULES += auto_init_%
NO_PSEUDOMODULES += auto_init_can

View File

@ -238,8 +238,7 @@ void auto_init(void)
}
}
if (IS_USED(MODULE_TEST_UTILS_INTERACTIVE_SYNC) &&
(!IS_USED(MODULE_SHELL_COMMANDS) || !IS_USED(MODULE_SHELL))) {
if (IS_USED(MODULE_TEST_UTILS_INTERACTIVE_SYNC) && !IS_USED(MODULE_SHELL)) {
extern void test_utils_interactive_sync(void);
test_utils_interactive_sync();
}

View File

@ -26,6 +26,14 @@ default module in `Makefile.tests_common`. It can be disabled by setting in the
application makefile `DISABLE_MODULE += test_utils_interactive_sync`. The python
test script will adapt to it automatically.
When using the `shell` module, `test_utils_interactive_sync` will use the shell
itself to synchronize, and will not use `test_utils_interactive_sync();` function
to synchronize. Some times you will want to synchronize before the start of the
script and use `test_utils_interactive_sync();` function (e.g.:
[tests/ps_schedstatistics](tests/ps_schedstatistics/main.c)). For these cases
you can disable `test_utils_interactive_sync_shell` module in the application
`Makefile`: `DISABLE_MODULE += test_utils_interactive_sync_shell`.
Running automated tests
-----------------------