Skip to content
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

examples/leds_shell: use periph_gpio_mock on native #20796

Merged

Conversation

krzysztof-cabaj
Copy link
Contributor

Contribution description

In current version of the leds_shell when user uses gpio set or gpio clear command in the native program ends with segmentation fault error. This PR solves this problem by adding periph_gpio_mock module. Now, when user in native uses these commands program works without crach - of course as this is mockup - nothing really happens. I tested this PR in few real boards and everything works fine.

Testing procedure

Output from examples/leds_shell for native without this PR:

main(): This is RIOT! (Version: 2021.07-devel-10924-g4612c)
This board has 2 LEDs
> gpio set 0 0
gpio set 0 0
Set HIGH to PORT 0, PIN 0
Segmentation fault

and with this PR:

main(): This is RIOT! (Version: 2021.07-devel-10924-g4612c-examples-leds_shell-fix-segfault)
This board has 2 LEDs
> gpio set 0 0
gpio set 0 0
Set HIGH to PORT 0, PIN 0
> 

Issues/PRs references

See also #20431

@github-actions github-actions bot added the Area: examples Area: Example Applications label Jul 24, 2024
@@ -19,4 +19,9 @@ QUIET ?= 1
USEMODULE += shell
USEMODULE += periph_gpio

# Prevents native program from segfault when gpio set/clear are used
ifeq (native, $(BOARD))
Copy link
Contributor

Choose a reason for hiding this comment

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

You also want to check for native64

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Till today, I never use native64- but it behave like native and crash without gpio_periph_mock.

Im not an exepert in Makfile but after reading few pages about or adding logical OR to ifeq (for example) i decided leave this "nasty" copy-paste code.

@krzysztof-cabaj krzysztof-cabaj force-pushed the examples-leds_shell-fix-segfault branch from b2fcc52 to 29c63f6 Compare July 26, 2024 15:31
Copy link
Contributor

@benpicco benpicco left a comment

Choose a reason for hiding this comment

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

Please squash

@krzysztof-cabaj krzysztof-cabaj force-pushed the examples-leds_shell-fix-segfault branch from 29c63f6 to f7473f2 Compare July 26, 2024 15:33
@krzysztof-cabaj
Copy link
Contributor Author

Squashed!

Thanks for support!

@benpicco benpicco added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Jul 26, 2024
@benpicco benpicco changed the title examples/leds_shell: fix segfault examples/leds_shell: use periph_gpio_mock on native Jul 26, 2024
@riot-ci
Copy link

riot-ci commented Jul 26, 2024

Murdock results

✔️ PASSED

ca9835f examples/leds_shell: fix segfault

Success Failures Total Runtime
19 0 19 01m:18s

Artifacts

@krzysztof-cabaj krzysztof-cabaj force-pushed the examples-leds_shell-fix-segfault branch from f7473f2 to ca9835f Compare July 26, 2024 15:40
@benpicco benpicco added this pull request to the merge queue Jul 26, 2024
Merged via the queue into RIOT-OS:master with commit d2fa0c6 Jul 26, 2024
25 checks passed
@mguetschow
Copy link
Contributor

Sorry to chime in late, but shouldn't the module periph_gpio depend on the feature with the same name, which shouldn't be present on native or native64 if not mocked?

@benpicco
Copy link
Contributor

native has support for GPIOs, you can specify --gpio /dev/gpiochip0 to export GPIO port to RIOT, see #12451

@mguetschow
Copy link
Contributor

Oh nice, didn't know about that! If that is the default, there is probably no way around manually specifying periph_gpio_mock in that example.

Still, I'm wondering if missing that module in a certain application on native could trigger an (run-time) error message instead of a segfault?

@benpicco benpicco added this to the Release 2024.10 milestone Nov 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: examples Area: Example Applications CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants