Skip to content

Conversation

miri64
Copy link
Member

@miri64 miri64 commented Feb 10, 2021

Contribution description

This provides two helper classes for tests with riotctrl:

  1. A NativeRIOTCtrl for native specifically, so the nodes can be resetable with the workflow provided in native: allow for native to be resetable via SIGUSR1 #12517.
  2. A factory class RIOTCtrlFactory that allows for automatic generation of a RIOTCtrl object. In a first step, the NativeRIOTCtrl is selected, when BOARD is set to native in the environment variables (or a provided env dictionary) (migrated to riotctrl)

Testing procedure

Tests are provided and hooked into the test-tools Github Action. For manual testing call

cd dist/pythonlibs/riotctrl_ctrl
tox

Issues/PRs references

None

@miri64 miri64 added Area: tests Area: tests and testing framework Type: new feature The issue requests / The PR implemements a new feature for RIOT Area: tools Area: Supplementary tools CI: skip compile test If set, CI server will run only non-compile jobs, but no compile jobs or their dependent jobs labels Feb 10, 2021
@miri64 miri64 force-pushed the riotctrl_ctrl/enh/native_reset branch from cfaa95c to 84968f4 Compare February 10, 2021 10:24
Copy link
Contributor

@fjmolinas fjmolinas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a question about this approach, specifically on how these board_clsss would evolve.

It seems the issue you fix for native is also an issue we would have for other BOARD, just that we don't have it in the default case on iot-lab, but we would have it in local setups as well if multiple similar BOARDs are connected.

Might it make more sense to change generically start_term with a special case for native. because for all other BOARDs it's going to be the same. Emulation might also inherit the same handling so it might more be a case of "physical" BOARD vs emulated ones. What do you think?

I'm not against the NativeRIOTCtrl, it just seems like a bit of an overkill, and I just worry about how this will grow, having Samr21XproRiotrCtrl, etc.. for +200 BOARDs could end up in a nightmare.

Comment on lines 23 to 30
if child.name().endswith('.elf'):
self.env['DEBUG_ADAPTER_ID'] = str(child.pid)
break
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this elf needed? Won't it always be like that for native?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because we need to find the actual executable of the native instance. Those end in elf. There might be other child processes of the make term or the user might decide to use e.g. pyterm via TCP to control the native instance.

Comment on lines 15 to 23
"""Abstract factory to create different RIOTCtrl types based on
the environment variables.

:param board_cls: A dict that maps a `BOARD` name to a RIOTCtrl class.
"""
DEFAULT_CLS = riotctrl.ctrl.RIOTCtrl
BOARD_CLS = {
'native': NativeRIOTCtrl
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How would this evolve? Are we going to start implementing BOARD_CLS for all BOARD. Here I see the wrapper is only for setting the DEBUG_ADAPTER_ID. Do you foresee other functionalities for the native class?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, because that is mostly how the native board differs from other boards: We don't know the DEBUG_ADAPTER_ID before the instance starts, while for other boards it is an intrinsic property of the physical board.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, because that is mostly how the native board differs from other boards: We don't know the DEBUG_ADAPTER_ID before the instance starts, while for other boards it is an intrinsic property of the physical board.

I like that argument.

@miri64
Copy link
Member Author

miri64 commented Feb 16, 2021

Might it make more sense to change generically start_term with a special case for native. because for all other BOARDs it's going to be the same. Emulation might also inherit the same handling so it might more be a case of "physical" BOARD vs emulated ones. What do you think?

You mean in riotctrl itself? To me the BOARD name native is specific to RIOT, so we would break the agnostic nature of riotctrl. So alone on that, I would prefer keeping something like this in the RIOT repo.

I'm not against the NativeRIOTCtrl, it just seems like a bit of an overkill, and I just worry about how this will grow, having Samr21XproRiotrCtrl, etc.. for +200 BOARDs could end up in a nightmare.

My hope is that this will be more of an exception than the special case. There is nothing special about Samr21Xpro so I don't see why the base class can't be used. Also keep in mind that most special cases, can be summarized under a common roof topic. E.g. for boards were reset is just not possible, something like YepKitRiotCtrl would rather be the way to go, to control a smart USB hub to power-cycle the node.

@fjmolinas
Copy link
Contributor

You mean in riotctrl itself? To me the BOARD name native is specific to RIOT, so we would break the agnostic nature of riotctrl. So alone on that, I would prefer keeping something like this in the RIOT repo.

No not RIOTCtrl itself, do it in RIOT, I guess its the naming pattern BOARD <-> board_clss I'm commenting on mostly.

@fjmolinas
Copy link
Contributor

My hope is that this will be more of an exception than the special case. There is nothing special about Samr21Xpro so I don't see why the base class can't be used. Also keep in mind that most special cases, can be summarized under a common roof topic. E.g. for boards were reset is just not possible, something like YepKitRiotCtrl would rather be the way to go, to control a smart USB hub to power-cycle the node.

So what about changing the mapping to an adapter point of view instead of BOARD? So that the mapping is not BOARD <-> board_clss but BOARD --> adapter class (not suggesting naming). It would make more sense towards how you forsee the evolution. What do you think?

@miri64
Copy link
Member Author

miri64 commented Feb 16, 2021

You mean in riotctrl itself? To me the BOARD name native is specific to RIOT, so we would break the agnostic nature of riotctrl. So alone on that, I would prefer keeping something like this in the RIOT repo.

No not RIOTCtrl itself, do it in RIOT, I guess its the naming pattern BOARD <-> board_clss I'm commenting on mostly.

I don't understand that statement or how you meant your original one then ^^. If we want to change the behavior of start_term we need to do it either in riotctrl.ctrl.RIOTCtrl directly or overload it in an ancestor class (which is what I am doing here).

@miri64
Copy link
Member Author

miri64 commented Feb 16, 2021

So what about changing the mapping to an adapter point of view instead of BOARD? So that the mapping is not BOARD <-> board_clss but BOARD --> adapter class (not suggesting naming). It would make more sense towards how you forsee the evolution. What do you think?

That is how my implementation is meant to be. It's just that the behavior I am adapting here is very intrinsic to native, so I named it NativeRIOTCtrl. We could name it SetDebugAdapterIdOnStartTermRIOTCtrl and it would also be fine with me, but I don't think that name is very catchy.

(+ just to clarify the DEBUG_ADAPTER_ID has nothing to do with the adapter class I am talking about here ;-)).

@fjmolinas
Copy link
Contributor

You mean in riotctrl itself? To me the BOARD name native is specific to RIOT, so we would break the agnostic nature of riotctrl. So alone on that, I would prefer keeping something like this in the RIOT repo.

No not RIOTCtrl itself, do it in RIOT, I guess its the naming pattern BOARD <-> board_clss I'm commenting on mostly.

I don't understand that statement or how you meant your original one then ^^. If we want to change the behavior of start_term we need to do it either in riotctrl.ctrl.RIOTCtrl directly or overload it in an ancestor class (which is what I am doing here).

Sorry, it's just the naming I don't like because it makes me think of BOARD (here native) <-> board_cls(NativeRIOTCtrl) mapping (1 to 1), when if running emulators or other similar through RIOTCtrl you would probably want to do the same kind of handling you are doing for native, capture the PID of the process.

That is how my implementation is meant to be. It's just that the behavior I am adapting here is very intrinsic to native, so I named it NativeRIOTCtrl. We could name it SetDebugAdapterIdOnStartTermRIOTCtrl and it would also be fine with me, but I don't think that name is very catchy.

Ok, let's keep the current name, we can change it later if needed to factor in common handling.

@miri64
Copy link
Member Author

miri64 commented Feb 16, 2021

Sorry, it's just the naming I don't like because it makes me think of BOARD (here native) <-> board_cls(NativeRIOTCtrl) mapping (1 to 1), when if running emulators or other similar through RIOTCtrl you would probably want to do the same kind of handling you are doing for native, capture the PID of the process.

Oh, yeah the reason I named the member board_cls is not because I think every board should have its own board-specific class, or that this factory only should generate board-specific objects, it's because those are supposed to be a mapping of the BOARD environment variable to a class. It is imaginable (e.g. as you proposed - for emulators) that other mappings or combinations of mappings could resolve to a different class in the future (e.g. (self.TERM_TARGETS.contains('emulate'), native) => QemuX86RIOTCtrl).

@miri64
Copy link
Member Author

miri64 commented Feb 16, 2021

We could name it SetDebugAdapterIdOnStartTermRIOTCtrl and it would also be fine with me, but I don't think that name is very catchy.

Ok, let's keep the current name, we can change it later if needed to factor in common handling.

Just gave me the idea to make this actually a proper method within the class, so that it is overrideable in the future :-)

@@ -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
Copy link
Contributor

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).

Copy link
Member Author

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.

from .native import NativeRIOTCtrl


class RIOTCtrlFactory:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to be generic enough to go to riotctrl.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking the same tbh. Also would be useful with RIOT-OS/riotctrl#13 when there is a iotlabcli adaptor for that.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@miri64
Copy link
Member Author

miri64 commented Feb 16, 2021

We could name it SetDebugAdapterIdOnStartTermRIOTCtrl and it would also be fine with me, but I don't think that name is very catchy.

Ok, let's keep the current name, we can change it later if needed to factor in common handling.

Just gave me the idea to make this actually a proper method within the class, so that it is overrideable in the future :-)

Done.

@miri64
Copy link
Member Author

miri64 commented Feb 18, 2021

Adopted for riotctrl v0.4.0.

@miri64 miri64 changed the title riotctrl_ctrl: Helper classes riotctrl_ctrl: A reset helper class for native Feb 18, 2021
@fjmolinas
Copy link
Contributor

If this is still needed please squash @miri64

@miri64 miri64 force-pushed the riotctrl_ctrl/enh/native_reset branch from 2013732 to 9f8b4a1 Compare May 4, 2021 09:47
@miri64
Copy link
Member Author

miri64 commented May 4, 2021

Rebased. (just squashed)

Copy link
Contributor

@fjmolinas fjmolinas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK

@miri64 miri64 added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label May 4, 2021
@miri64 miri64 merged commit c71a52d into RIOT-OS:master May 4, 2021
@miri64 miri64 deleted the riotctrl_ctrl/enh/native_reset branch May 4, 2021 11:48
@MrKevinWeiss MrKevinWeiss added this to the Release 2021.07 milestone Jul 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: tests Area: tests and testing framework Area: tools Area: Supplementary tools CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR CI: skip compile test If set, CI server will run only non-compile jobs, but no compile jobs or their dependent jobs Type: new feature The issue requests / The PR implemements a new feature for RIOT
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants