-
Notifications
You must be signed in to change notification settings - Fork 2.1k
riotctrl_ctrl: A reset helper class for native
#15978
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
psutil | ||
riotctrl |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 . |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't seem to be needed for testing the new classes (pure Python).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test is compiling
examples/hello-world
to test if the feature really work. Sure I can mock that up, but that can get stale quickly and wouldn't test if everything is working right.