Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dist/pythonlibs/testrunner: reset before term #12862

Merged
merged 2 commits into from
Dec 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Makefile.include
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,12 @@ TESTS ?= $(foreach file,$(wildcard $(APPDIR)/tests/*[^~]),\
# See #11762.
TEST_DEPS += $(TERMDEPS)

# Export TESTRUNNER_RESET_AFTER_TERM only for the test target. This allows for
# it to be accessed through the environment from python test script.
# This is currently needed only by `examples/%/tests` and should be removed in
# the future since `make reset` after `term` is not a valid synch method across
# all platforms.
$(call target-export-variables,test,TESTRUNNER_RESET_AFTER_TERM)
test: $(TEST_DEPS)
$(Q) for t in $(TESTS); do \
$$t || exit 1; \
Expand Down
48 changes: 29 additions & 19 deletions dist/pythonlibs/testrunner/spawn.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,20 @@
TEST_INTERACTIVE_RETRIES = int(os.environ.get('TEST_INTERACTIVE_RETRIES') or 5)
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')


def _reset_board(env):
try:
subprocess.check_output(('make', 'reset'), env=env,
stderr=subprocess.PIPE)
except subprocess.CalledProcessError:
# make reset yields error on some boards even if successful
pass


def list_until(l, cond):
return l[:([i for i, e in enumerate(l) if cond(e)][0])]
Expand All @@ -41,6 +55,10 @@ 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)

child = spawnclass("make cleanterm", env=env, timeout=timeout,
codec_errors='replace', echo=False)

Expand All @@ -49,15 +67,8 @@ def setup_child(timeout=10, spawnclass=pexpect.spawnu, env=None, logfile=None):

child.logfile = logfile

try:
subprocess.check_output(('make', 'reset'), env=env,
stderr=subprocess.PIPE)
except subprocess.CalledProcessError:
# make reset yields error on some boards even if successful
pass

# Handle synchronization if requested by the build system
sync_child(child)
sync_child(child, env)

return child

Expand All @@ -77,16 +88,15 @@ def modules_list():
return modules


def sync_child(child):
def sync_child(child, env):
# Do a child synchronization if used by a module
modules = modules_list()
_test_utils_interactive_sync(child, modules)


def _test_utils_interactive_sync(child, modules):
if 'test_utils_interactive_sync' not in modules:
return

utils.test_utils_interactive_sync(child,
TEST_INTERACTIVE_RETRIES,
TEST_INTERACTIVE_DELAY)
if 'test_utils_interactive_sync' in modules:
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.
elif TESTRUNNER_RESET_AFTER_TERM:
_reset_board(env)
4 changes: 4 additions & 0 deletions examples/micropython/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,8 @@ RIOT_TERMINAL ?= miniterm
FEATURES_OPTIONAL += periph_adc
FEATURES_OPTIONAL += periph_spi

# For now `examples/%/tests" still rely on the test applicaton being reset after
# a terminal is opened to synchronize.
TESTRUNNER_RESET_AFTER_TERM ?= 1

include $(RIOTBASE)/Makefile.include
3 changes: 3 additions & 0 deletions examples/suit_update/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ endif
# don't compile themselves and re-create signed images, thus add the required
# files here so they will be submitted along with the test jobs.
TEST_EXTRA_FILES += $(SLOT_RIOT_ELFS) $(SUIT_SEC) $(SUIT_PUB)
# For now `examples/%/tests" still rely on the test applicaton being reset after
# a terminal is opened to synchronize.
TESTRUNNER_RESET_AFTER_TERM ?= 1

include $(RIOTBASE)/Makefile.include

Expand Down