diff --git a/Makefile.dep b/Makefile.dep index cb186821dc..0ded69d32c 100644 --- a/Makefile.dep +++ b/Makefile.dep @@ -1078,6 +1078,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/sys/shell/commands/Makefile b/sys/shell/commands/Makefile index 38104f7efc..d279ecb3a4 100644 --- a/sys/shell/commands/Makefile +++ b/sys/shell/commands/Makefile @@ -96,10 +96,6 @@ ifneq (,$(filter nimble_netif,$(USEMODULE))) SRC += sc_nimble_netif.c endif -ifneq (,$(filter test_utils_interactive_sync,$(USEMODULE))) - SRC += sc_interactive_sync.c -endif - ifneq (,$(filter suit_coap,$(USEMODULE))) SRC += sc_suit.c endif diff --git a/sys/shell/commands/sc_interactive_sync.c b/sys/shell/commands/sc_interactive_sync.c deleted file mode 100644 index 31f46200e4..0000000000 --- a/sys/shell/commands/sc_interactive_sync.c +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (C) 2019 Inria - * - * This file is subject to the terms and conditions of the GNU Lesser - * General Public License v2.1. See the file LICENSE in the top level - * directory for more details. - */ - -/** - * @ingroup sys_shell_commands - * @{ - * - * @file - * @brief Shell commands interactive sync util - * - * @author Francisco Molina - * @} - */ - -#include -#include "test_utils/interactive_sync.h" - -#if defined(__AVR__) -#include -/* For small AVR targets the extra strings generated by test interactive - can make the application overflow the .data section (RAM), we use puts_P() - to write those constant string to .txt section (FLASH)*/ -#define PUTS(_s) puts_P(PSTR(_s)) -#else -#define PUTS(_s) puts(_s) -#endif - -int _test_start(int argc, char **argv) -{ - (void) argc; - (void) argv; - PUTS("START"); - - return 0; -} - - -int _test_ready(int argc, char **argv) -{ - (void) argc; - (void) argv; - PUTS("READY"); - return 0; -} diff --git a/sys/shell/commands/shell_commands.c b/sys/shell/commands/shell_commands.c index 87b2483b2d..6655d89bce 100644 --- a/sys/shell/commands/shell_commands.c +++ b/sys/shell/commands/shell_commands.c @@ -159,11 +159,6 @@ extern int _loramac_handler(int argc, char **argv); extern int _nimble_netif_handler(int argc, char **argv); #endif -#ifdef MODULE_TEST_UTILS_INTERACTIVE_SYNC -extern int _test_start(int argc, char **argv); -extern int _test_ready(int argc, char **argv); -#endif - #ifdef MODULE_SUIT_COAP extern int _suit_handler(int argc, char **argv); #endif @@ -275,10 +270,6 @@ const shell_command_t _shell_command_list[] = { #ifdef MODULE_NIMBLE_NETIF { "ble", "Manage BLE connections for NimBLE", _nimble_netif_handler }, #endif -#ifdef MODULE_TEST_UTILS_INTERACTIVE_SYNC - { "r", "Test sync, Ready query", _test_ready }, - { "s", "Test sync, Start test trigger", _test_start }, -#endif #ifdef MODULE_SUIT_COAP { "suit", "Trigger a SUIT firmware update", _suit_handler }, #endif 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 ----------------------- diff --git a/tests/periph_gpio/tests/02-bench.py b/tests/periph_gpio/tests/02-bench.py index ea2d00371a..1932e41021 100755 --- a/tests/periph_gpio/tests/02-bench.py +++ b/tests/periph_gpio/tests/02-bench.py @@ -15,9 +15,6 @@ TIMEOUT = 30 def testfunc(child): - child.expect_exact("GPIO peripheral driver test") - child.expect_exact(">") - for pin in range(0, 8): child.sendline("bench 0 {}".format(pin)) child.expect(r" *nop loop: +(\d+)us --- +(\d+\.\d+)us per call --- +(\d+) calls per sec") diff --git a/tests/periph_wdt/Makefile b/tests/periph_wdt/Makefile index 6471052756..a18b03d01e 100644 --- a/tests/periph_wdt/Makefile +++ b/tests/periph_wdt/Makefile @@ -5,6 +5,5 @@ FEATURES_REQUIRED += periph_wdt USEMODULE += xtimer USEMODULE += shell -USEMODULE += shell_commands include $(RIOTBASE)/Makefile.include diff --git a/tests/ps_schedstatistics/Makefile b/tests/ps_schedstatistics/Makefile index ecf853a64a..071a344950 100644 --- a/tests/ps_schedstatistics/Makefile +++ b/tests/ps_schedstatistics/Makefile @@ -6,4 +6,9 @@ USEMODULE += ps USEMODULE += schedstatistics USEMODULE += printf_float +# For this test we don't want to use the shell version of +# test_utils_interactive_sync, since we want to synchronize before +# the start of the shell +DISABLE_MODULE += test_utils_interactive_sync_shell + include $(RIOTBASE)/Makefile.include diff --git a/tests/struct_tm_utility/Makefile b/tests/struct_tm_utility/Makefile index 3a0b8405c2..adaf43d075 100644 --- a/tests/struct_tm_utility/Makefile +++ b/tests/struct_tm_utility/Makefile @@ -1,7 +1,6 @@ include ../Makefile.tests_common USEMODULE += shell -USEMODULE += shell_commands USEMODULE += timex # The MSP-430 toolchain lacks sscanf: diff --git a/tests/test_tools/Makefile b/tests/test_tools/Makefile index da17abbb2d..b3fece6382 100644 --- a/tests/test_tools/Makefile +++ b/tests/test_tools/Makefile @@ -6,4 +6,8 @@ USEMODULE += shell # Disable shell echo and prompt to not have them in the way for testing CFLAGS += -DSHELL_NO_ECHO=1 -DSHELL_NO_PROMPT=1 +# No need for test_utils_interactive_sync in this test since the test +# synchronizes by itself through `shellping` command. +DISABLE_MODULE += test_utils_interactive_sync + include $(RIOTBASE)/Makefile.include diff --git a/tests/test_tools/tests/01-run.py b/tests/test_tools/tests/01-run.py index ca278074a8..94d057e874 100755 --- a/tests/test_tools/tests/01-run.py +++ b/tests/test_tools/tests/01-run.py @@ -64,8 +64,6 @@ def testfunc(child): * getting some test output without other messages * sending empty lines """ - child.expect_exact("Running 'tests_tools' application") - _wait_shell_ready(child) # Verify there is no local and remote echo as it is disabled