-
-
Notifications
You must be signed in to change notification settings - Fork 270
Add input path for sysfs GPIOs #1935
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
Open
ozan956
wants to merge
4
commits into
labgrid-project:master
Choose a base branch
from
ozan956:add-gpio-input-support
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 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
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
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
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
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,10 @@ | ||
| import abc | ||
|
|
||
|
|
||
| class DigitalInputProtocol(abc.ABC): | ||
| """Abstract class providing the DigitalInputProtocol interface""" | ||
|
|
||
| @abc.abstractmethod | ||
| def get(self): | ||
| """Implementations should return the status of the digital input.""" | ||
| raise NotImplementedError |
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
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
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
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,92 @@ | ||
| import types | ||
|
|
||
| import labgrid.driver.gpiodriver as gpiodriver | ||
| from labgrid.driver.gpiodriver import GpioDigitalInputDriver, GpioDigitalOutputDriver | ||
| from labgrid.remote.client import ClientSession | ||
| from labgrid.resource.common import ResourceManager | ||
| from labgrid.resource.remote import NetworkSysfsGPIO | ||
| from labgrid.resource import SysfsGPIO | ||
|
|
||
|
|
||
| class FakeWrapper: | ||
| def __init__(self, host, proxy): | ||
| self.host = host | ||
| self.proxy = proxy | ||
|
|
||
| def load(self, name): | ||
| assert name == 'sysfsgpio' | ||
| return self.proxy | ||
|
|
||
| def close(self): | ||
| pass | ||
|
|
||
|
|
||
| def test_gpio_input_driver_get(target, monkeypatch): | ||
| proxy = types.SimpleNamespace(calls=[]) | ||
|
|
||
| def proxy_get(index, invert, direction): | ||
| proxy.calls.append((index, invert, direction)) | ||
| return True | ||
|
|
||
| proxy.get = proxy_get | ||
|
|
||
| monkeypatch.setattr(gpiodriver, "AgentWrapper", lambda host: FakeWrapper(host, proxy)) | ||
|
|
||
| SysfsGPIO(target, name=None, index=13, invert=True) | ||
| driver = GpioDigitalInputDriver(target, name=None) | ||
|
|
||
| target.activate(driver) | ||
|
|
||
| assert driver.get() is True | ||
| assert proxy.calls == [(13, True, 'in')] | ||
|
|
||
| target.deactivate(driver) | ||
|
|
||
|
|
||
| def test_gpio_output_driver_implements_digital_input_protocol(target): | ||
| SysfsGPIO(target, name=None, index=13, invert=False) | ||
| driver = GpioDigitalOutputDriver(target, name=None) | ||
|
|
||
| assert target.get_driver("DigitalInputProtocol", activate=False) is driver | ||
|
|
||
|
|
||
| def test_client_io_get_uses_configured_gpio_input_driver(target, monkeypatch, capsys): | ||
| proxy = types.SimpleNamespace(calls=[]) | ||
|
|
||
| def proxy_get(index, invert, direction): | ||
| proxy.calls.append((index, invert, direction)) | ||
| return True | ||
|
|
||
| proxy.get = proxy_get | ||
|
|
||
| monkeypatch.setattr(gpiodriver, "AgentWrapper", lambda host: FakeWrapper(host, proxy)) | ||
|
|
||
| SysfsGPIO(target, name="gpio_in", index=13, invert=False) | ||
| GpioDigitalInputDriver(target, name="gpio_in") | ||
|
|
||
| session = object.__new__(ClientSession) | ||
| session.args = types.SimpleNamespace(action="get", name="gpio_in") | ||
| session.get_acquired_place = lambda: types.SimpleNamespace(name="test") | ||
| session._get_target = lambda place: target | ||
|
|
||
| session.digital_io() | ||
|
|
||
| assert "digital IO gpio_in for place test is high" in capsys.readouterr().out | ||
| assert proxy.calls == [(13, False, 'in')] | ||
|
|
||
|
|
||
| def test_client_io_get_keeps_network_sysfs_output_fallback(target, monkeypatch, mocker): | ||
| monkeypatch.setattr(NetworkSysfsGPIO, "manager_cls", ResourceManager) | ||
| driver = types.SimpleNamespace(get=mocker.MagicMock(return_value=False)) | ||
| session = object.__new__(ClientSession) | ||
| session.args = types.SimpleNamespace(action="get", name="gpio") | ||
| session.get_acquired_place = lambda: types.SimpleNamespace(name="test") | ||
| session._get_target = lambda place: target | ||
| session._get_driver_or_new = mocker.MagicMock(return_value=driver) | ||
|
|
||
| NetworkSysfsGPIO(target, name="gpio", host="exporter", index=13, invert=False) | ||
|
|
||
| session.digital_io() | ||
|
|
||
| session._get_driver_or_new.assert_called_once_with(target, "GpioDigitalOutputDriver", name="gpio") | ||
| driver.get.assert_called_once_with() |
Oops, something went wrong.
Oops, something went wrong.
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.
I believe this implementation in the client has the same issue as I had when I attempted to implement this.
Have you checked whether #1458 (comment) also happens for you?
Uh oh!
There was an error while loading. Please reload this page.
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.
Yes, tested on a Raspberry Pi 2 Model B running Raspbian with kernel
6.12.47+rpt-rpi-v7.I tested whether
labgrid-client io getchanges the sysfs direction fromouttoinafter setting the line high:So I could not reproduce the behavior from the linked comment with this branch. After io get, the line remains configured as out and the value remains high.
This should be because the resource-only NetworkSysfsGPIO fallback still uses GpioDigitalOutputDriver for labgrid-client io get. The new DigitalInputProtocol path is only used when an input driver is explicitly configured.