diff --git a/dist/pythonlibs/testrunner/spawn.py b/dist/pythonlibs/testrunner/spawn.py index 60d06187d7..e334a894b3 100644 --- a/dist/pythonlibs/testrunner/spawn.py +++ b/dist/pythonlibs/testrunner/spawn.py @@ -39,7 +39,13 @@ TEST_INTERACTIVE_DELAY = int(os.environ.get('TEST_INTERACTIVE_DELAY') or 1) # By default never reset after the terminal is open unless explicitly requested # through an environment variable. TESTRUNNER_RESET_AFTER_TERM = int(os.environ.get('TESTRUNNER_RESET_AFTER_TERM') - or '0') + or 0) + +# When running e.g. tests/shell_ble we don't want to reset the board, because +# then ble-serial would terminate and the created virtual serial port would get +# lost. By default the board is reset before the test starts. +TESTRUNNER_RESET_BOARD_ON_STARTUP = \ + int(os.environ.get('TESTRUNNER_RESET_BOARD_ON_STARTUP') or 1) MAKE = os.environ.get('MAKE', 'make') @@ -70,7 +76,8 @@ def find_exc_origin(exc_info): def setup_child(timeout=10, spawnclass=pexpect.spawnu, env=None, logfile=None): # Some boards can't be reset after a terminal is open. Therefore reset # before `cleanterm`. - _reset_board(env) + if TESTRUNNER_RESET_BOARD_ON_STARTUP: + _reset_board(env) # on platforms exposing UART over USB, wait a little before connecting to # the serial terminal. This gives time for stdio to be ready. diff --git a/sys/stdio_nimble/README.md b/sys/stdio_nimble/README.md index b9e2ee0559..381b2efa63 100644 --- a/sys/stdio_nimble/README.md +++ b/sys/stdio_nimble/README.md @@ -50,6 +50,8 @@ USEMODULE += nimble_autoadv USEMODULE += stdio_nimble ``` +**NOTE:** You can also have a look at `tests/shell_ble`. + - Flash `$ make -C tests/shell -j clean all flash` diff --git a/tests/shell/tests/01-run.py b/tests/shell/tests/01-run.py index a4b423ad8d..86bf96e43b 100755 --- a/tests/shell/tests/01-run.py +++ b/tests/shell/tests/01-run.py @@ -32,6 +32,8 @@ EXPECTED_PS = ( RIOT_TERMINAL = os.environ.get('RIOT_TERMINAL') CLEANTERMS = {"socat"} +TESTRUNNER_SHELL_SKIP_REBOOT = bool(int(os.environ.get('TESTRUNNER_SHELL_SKIP_REBOOT') or 0)) + # In native we are directly executing the binary (no terminal program). We must # therefore use Ctrl-V (DLE or "data link escape") before Ctrl-C to send a # literal ETX instead of SIGINT. @@ -220,6 +222,10 @@ def testfunc(child): # loop other defined commands and expected output for cmd, expected in CMDS: + + if cmd == "reboot" and TESTRUNNER_SHELL_SKIP_REBOOT: + continue + check_cmd(child, cmd, expected) if RIOT_TERMINAL in CLEANTERMS: diff --git a/tests/shell_ble/Makefile b/tests/shell_ble/Makefile new file mode 100644 index 0000000000..652e0d0e05 --- /dev/null +++ b/tests/shell_ble/Makefile @@ -0,0 +1,42 @@ +DEVELHELP = 0 +BOARD ?= nrf52dk +include ../Makefile.tests_common + +USEMODULE += app_metadata +USEMODULE += shell +USEMODULE += shell_commands +USEMODULE += ps + +USEMODULE += stdio_nimble stdio_nimble_debug +USEMODULE += nimble_autoadv +CFLAGS += -DNIMBLE_AUTOADV_DEVICE_NAME='"tests/shell_ble"' + +TESTRUNNER_SHELL_SKIP_REBOOT = 1 +TESTRUNNER_RESET_BOARD_ON_STARTUP = 0 + +ifneq (,$(filter term,$(MAKECMDGOALS))) + # for z1, socat doesn't work (unknown reason) + ifeq (z1, $(BOARD)) + RIOT_TERMINAL ?= pyterm + endif + + # Use a terminal that does not introduce extra characters into the stream. + RIOT_TERMINAL ?= socat +else ifneq (,$(filter test,$(MAKECMDGOALS))) + # Use the virtual serial port created by ble-serial + RIOT_TERMINAL = picocom +endif + +# The test requires some setup so it cannot currently be run +TEST_ON_CI_BLACKLIST += all + +APP_SHELL_FMT ?= NONE + +include $(RIOTBASE)/Makefile.include + +# the test script skips tests if socat is not used +$(call target-export-variables,$(RIOT_TERMINAL),RIOT_TERMINAL) + +# a reboot or a reset would disconnect the device from bluetooth and break the test +$(call target-export-variables,$(TESTRUNNER_SHELL_SKIP_REBOOT),TESTRUNNER_SHELL_SKIP_REBOOT) +$(call target-export-variables,$(TESTRUNNER_RESET_BOARD_ON_STARTUP),TESTRUNNER_RESET_BOARD_ON_STARTUP) diff --git a/tests/shell_ble/README.md b/tests/shell_ble/README.md new file mode 100644 index 0000000000..b5e694e2bb --- /dev/null +++ b/tests/shell_ble/README.md @@ -0,0 +1,22 @@ +This is basically the same tests as for the normal shell, but here we are +testing via blueooth instead of UART. You have to set up a virtual serial port +manually. + +For instructions on how to open a virtual serial port to your bluetooth device +see `sys/stdio_nimble/README`. + +**Note:** `make term` and `make test-with-config` will open two different types of terminals. +- When calling `make term` then a terminal will communicate with the board +via UART. Due to the nature of `stdio_nimble` the board won't respond to input +coming from here) +- When calling `make test-with-config` then picocom will communicate with the board via the +given virtual serial port + +So a procedure to run this test could be: +0. Make sure that the current test application instance is fresh and no test was +run on it before. Otherwise your test might fail, because the test case +`check_control_d` only works once per run. +1. Execute `make flash term` +2. Open a virtual serial port with `ble-serial` and note the virtual serial port +that was created (search for `Slave created on /tmp/dev_riot_ble -> /dev/pts/25`) +3. Execute `PORT=/dev/pts/25 make test-with-config` diff --git a/tests/shell_ble/main.c b/tests/shell_ble/main.c new file mode 120000 index 0000000000..c541a5892a --- /dev/null +++ b/tests/shell_ble/main.c @@ -0,0 +1 @@ +../shell/main.c \ No newline at end of file diff --git a/tests/shell_ble/tests-with-config/01-run.py b/tests/shell_ble/tests-with-config/01-run.py new file mode 120000 index 0000000000..b3e9bd6b21 --- /dev/null +++ b/tests/shell_ble/tests-with-config/01-run.py @@ -0,0 +1 @@ +../../shell/tests/01-run.py \ No newline at end of file