diff --git a/dist/pythonlibs/testrunner/__init__.py b/dist/pythonlibs/testrunner/__init__.py index 3a372e5136..31fa260eb4 100755 --- a/dist/pythonlibs/testrunner/__init__.py +++ b/dist/pythonlibs/testrunner/__init__.py @@ -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 diff --git a/dist/pythonlibs/testrunner/utils.py b/dist/pythonlibs/testrunner/utils.py new file mode 100644 index 0000000000..faee374235 --- /dev/null +++ b/dist/pythonlibs/testrunner/utils.py @@ -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')