Skip to content

Commit 49ea453

Browse files
committed
riotctrl_ctrl: provide helper class for native reset
1 parent 609c9ad commit 49ea453

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

dist/pythonlibs/riotctrl_ctrl/__init__.py

Whitespace-only changes.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Copyright (C) 2021 Freie Universität Berlin
2+
#
3+
# This file is subject to the terms and conditions of the GNU Lesser
4+
# General Public License v2.1. See the file LICENSE in the top level
5+
# directory for more details.
6+
7+
import riotctrl.ctrl
8+
9+
import psutil
10+
11+
12+
class NativeRIOTCtrl(riotctrl.ctrl.RIOTCtrl):
13+
"""RIOTCtrl abstraction for a native node
14+
15+
This works exactly as a normal RIOTCtrl, with the exception that
16+
`DEBUG_ADAPTER_ID` is set in the environment to the PID of the `native`
17+
process, whenever a terminal is started. This allows for `reset()` to also
18+
work for a the `native` instance.
19+
"""
20+
def _set_debug_adapter_id(self, child):
21+
if child.name().endswith('.elf'):
22+
self.env['DEBUG_ADAPTER_ID'] = str(child.pid)
23+
return True
24+
return False
25+
26+
def start_term(self, *args, **kwargs):
27+
super().start_term(*args, **kwargs)
28+
for child in psutil.Process(pid=self._term_pid()).children():
29+
if self._set_debug_adapter_id(child):
30+
break
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
psutil
2+
riotctrl

0 commit comments

Comments
 (0)