diff --git a/Makefile.dep b/Makefile.dep index d31ec529af..5e560da119 100644 --- a/Makefile.dep +++ b/Makefile.dep @@ -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 diff --git a/dist/pythonlibs/testrunner/spawn.py b/dist/pythonlibs/testrunner/spawn.py index 1c2008a173..6061141758 100644 --- a/dist/pythonlibs/testrunner/spawn.py +++ b/dist/pythonlibs/testrunner/spawn.py @@ -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. diff --git a/dist/pythonlibs/testrunner/utils.py b/dist/pythonlibs/testrunner/utils.py index 94a9091aeb..5f39f6b9dc 100644 --- a/dist/pythonlibs/testrunner/utils.py +++ b/dist/pythonlibs/testrunner/utils.py @@ -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', '>') diff --git a/makefiles/pseudomodules.inc.mk b/makefiles/pseudomodules.inc.mk index 917df3c8df..475c22a7eb 100644 --- a/makefiles/pseudomodules.inc.mk +++ b/makefiles/pseudomodules.inc.mk @@ -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 diff --git a/sys/auto_init/auto_init.c b/sys/auto_init/auto_init.c index 315ffac856..406b4255b6 100644 --- a/sys/auto_init/auto_init.c +++ b/sys/auto_init/auto_init.c @@ -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(); } diff --git a/tests/README.md b/tests/README.md index f75b6868f1..f57b7b9eeb 100644 --- a/tests/README.md +++ b/tests/README.md @@ -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 -----------------------