diff --git a/.github/workflows/tools-test.yml b/.github/workflows/tools-test.yml index 56fdc079e141..b5dc5a6bd49b 100644 --- a/.github/workflows/tools-test.yml +++ b/.github/workflows/tools-test.yml @@ -24,10 +24,13 @@ jobs: python -m pip install --upgrade pip python -m pip install tox python -m pip install kconfiglib + sudo apt-get install gcc-multilib - name: Test backport_pr run: cd dist/tools/backport_pr && tox - name: Test compile_and_test_for_board run: cd dist/tools/compile_and_test_for_board && tox + - name: Test riotctrl_ctrl + run: cd dist/pythonlibs/riotctrl_ctrl && tox - name: Test riotctrl_shell run: cd dist/pythonlibs/riotctrl_shell && tox - name: Test kconfig script diff --git a/dist/pythonlibs/riotctrl_ctrl/__init__.py b/dist/pythonlibs/riotctrl_ctrl/__init__.py new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/dist/pythonlibs/riotctrl_ctrl/native.py b/dist/pythonlibs/riotctrl_ctrl/native.py new file mode 100644 index 000000000000..bc44140cb3c0 --- /dev/null +++ b/dist/pythonlibs/riotctrl_ctrl/native.py @@ -0,0 +1,30 @@ +# Copyright (C) 2021 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. + +import riotctrl.ctrl + +import psutil + + +class NativeRIOTCtrl(riotctrl.ctrl.RIOTCtrl): + """RIOTCtrl abstraction for a native node + + This works exactly as a normal RIOTCtrl, with the exception that + `DEBUG_ADAPTER_ID` is set in the environment to the PID of the `native` + process, whenever a terminal is started. This allows for `reset()` to also + work for a the `native` instance. + """ + def _set_debug_adapter_id(self, child): + if child.name().endswith('.elf'): + self.env['DEBUG_ADAPTER_ID'] = str(child.pid) + return True + return False + + def start_term(self, *args, **kwargs): + super().start_term(*args, **kwargs) + for child in psutil.Process(pid=self._term_pid()).children(): + if self._set_debug_adapter_id(child): + break diff --git a/dist/pythonlibs/riotctrl_ctrl/requirements.txt b/dist/pythonlibs/riotctrl_ctrl/requirements.txt new file mode 100644 index 000000000000..a2b3329f101c --- /dev/null +++ b/dist/pythonlibs/riotctrl_ctrl/requirements.txt @@ -0,0 +1,2 @@ +psutil +riotctrl diff --git a/dist/pythonlibs/riotctrl_ctrl/tests/test_native.py b/dist/pythonlibs/riotctrl_ctrl/tests/test_native.py new file mode 100644 index 000000000000..190834b67857 --- /dev/null +++ b/dist/pythonlibs/riotctrl_ctrl/tests/test_native.py @@ -0,0 +1,45 @@ +# Copyright (C) 2021 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. + +import os.path + +import riotctrl.ctrl + +import riotctrl_ctrl.native + + +def test_reset(): + env = {'DEBUG_ADAPTER_ID': '', 'BOARD': 'native'} + ctrl = riotctrl_ctrl.native.NativeRIOTCtrl( + application_directory=os.path.normpath(os.path.join( + os.path.abspath(__file__), + '..', '..', '..', '..', '..', + 'examples', 'hello-world' + )), + env=env, + ) + print(ctrl.application_directory) + assert not ctrl.env['DEBUG_ADAPTER_ID'] + ctrl.make_run(['flash']) + with ctrl.run_term(reset=False): + # DEBUG_ADAPTER_ID is now a PID + assert int(ctrl.env['DEBUG_ADAPTER_ID']) + ctrl.term.expect_exact('Hello World!') + ctrl.reset() + ctrl.term.expect_exact('!! REBOOT !!') + ctrl.term.expect_exact('Hello World!') + + +def test_w_factory(): + env = {'BOARD': 'native'} + factory = riotctrl.ctrl.RIOTCtrlBoardFactory( + board_cls={'native': riotctrl_ctrl.native.NativeRIOTCtrl} + ) + assert 'native' in factory.board_cls + ctrl = factory.get_ctrl(env=env) + # pylint: disable=unidiomatic-typecheck + # in this case we want to know the exact type + assert type(ctrl) is riotctrl_ctrl.native.NativeRIOTCtrl diff --git a/dist/pythonlibs/riotctrl_ctrl/tox.ini b/dist/pythonlibs/riotctrl_ctrl/tox.ini new file mode 100644 index 000000000000..1b8ac29b71fb --- /dev/null +++ b/dist/pythonlibs/riotctrl_ctrl/tox.ini @@ -0,0 +1,20 @@ +[tox] +envlist = test,flake8 +skipsdist = True + +[testenv] +commands = + test: {[testenv:test]commands} + flake8: {[testenv:flake8]commands} + +[testenv:test] +deps = + pytest + -rrequirements.txt +commands = + pytest -v --doctest-modules + +[testenv:flake8] +deps = flake8 +commands = + flake8 .