testrunner/utils: add helper for test_utils_interactive_sync

Add helper to do the synchronisation.
This commit is contained in:
Gaëtan Harter 2019-03-23 14:46:37 +01:00
parent 027426793c
commit e5e9d81cce
No known key found for this signature in database
GPG Key ID: 76DF6BCF1B1F883B
2 changed files with 28 additions and 0 deletions

View File

@ -14,6 +14,7 @@ import pexpect
from .spawn import find_exc_origin, setup_child, teardown_child
from .unittest import PexpectTestCase # noqa, F401 expose to users
from .utils import test_utils_interactive_sync # noqa, F401 expose to users
# Timeout for tests can be changed by setting RIOT_TEST_TIMEOUT to the desired
# value in the environment variables

27
dist/pythonlibs/testrunner/utils.py vendored Normal file
View File

@ -0,0 +1,27 @@
# Copyright (C) 2019 Freie Universität Berlin
#
# 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.
"""Utility functions for writing tests."""
import pexpect
def test_utils_interactive_sync(child, retries=5, delay=1):
"""Synchronisation for 'test_utils_interactive_sync' function.
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)
if ret == 0:
break
else:
# Last call to make it fail her,
child.expect_exact('READY', timeout=0)
child.sendline('s')
child.expect_exact('START')