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

sys/irq: Add C++ wrapper using RAII #17066

Merged
merged 1 commit into from Jan 15, 2023
Merged

Conversation

jenswet
Copy link
Contributor

@jenswet jenswet commented Oct 27, 2021

Contribution description

This adds a C++ wrapper around the irq.h API. The wrapper uses RAII to accomplish a convenient and bug resistent use.

A little background: I'm currently writing my master thesis on using C++ for embedded development, at the working group that @maribu is part of. For that I will try to add better C++ support to several parts of RIOT and then do some benchmarking and metrics to compare it with the C implementation. For example, I also plan to add a wrapper around i2c, a std::cout drop-in replacement and probably some more about networks or threads.

Testing procedure

I've added a unit test to verify that the IRQ wrapper calls the original irq functions as expected. As C++ and wrapper testing isn't done much so far in this project, I've added two additional headers to ease testing:

  1. pkg/fff: Add fake functions framework package #17076 - fake functions framework, already merged
  2. As there is no framework for C++ unit tests yet, I've added something for this too. Unfortunately the existing frameworks like GoogleTest, CppUTest or CppUnit don't easily compile for embedded or are difficult to integrate in to the RIOT build process. That's why I wrote some (simple) helper functions and macros inspired by the above frameworks. That allows to create C++ tests based on a fixture class with set up and tear down methods. It also allows some simple assertions and is easily extendable for other use cases. It wraps some of the fff functionality too.

Both of this is obviously not required for the initial reason of this PR. But I'd like to provide unit tests for the features that I suggest to introduce where possible. So I'd appreciate some feedback on that too. If you'd prefer a PR without or different tests please let me know.

You can run the test irq_cpp locally or on the CI to test the implementation.

Please feel free to give feedback or suggest improvements!

@github-actions github-actions bot added Area: core Area: RIOT kernel. Handle PRs marked with this with care! Area: doc Area: Documentation Area: sys Area: System Area: tests Area: tests and testing framework labels Oct 27, 2021
@benpicco benpicco requested a review from maribu October 27, 2021 18:33
@github-actions github-actions bot added the Area: tools Area: Supplementary tools label Oct 28, 2021
Copy link
Member

@maribu maribu left a comment

Choose a reason for hiding this comment

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

Thanks for your PR, this looks pretty good to me. I added some comments inline.

sys/include/cppunit/fff.h Outdated Show resolved Hide resolved
dist/tools/doccheck/exclude_patterns Outdated Show resolved Hide resolved
core/include/irq.hpp Outdated Show resolved Hide resolved
irq_restore(state);
}

irq_lock(irq_lock const& irq) = delete;
Copy link
Member

Choose a reason for hiding this comment

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

Note to myself: Check if it is possible to get rid of the bogus "keyword 'delete' not followed by a single space" warning of the CI.

sys/include/cppunit/cpp_test.hpp Outdated Show resolved Hide resolved
sys/include/cppunit/cpp_test.hpp Outdated Show resolved Hide resolved
sys/include/cppunit/cpp_test.hpp Outdated Show resolved Hide resolved
sys/include/cppunit/cpp_test.hpp Outdated Show resolved Hide resolved
sys/include/cppunit/cpp_test.hpp Outdated Show resolved Hide resolved
tests/irq_cpp/irq.h Outdated Show resolved Hide resolved
core/include/irq.hpp Outdated Show resolved Hide resolved
@github-actions github-actions bot added Area: Kconfig Area: Kconfig integration Area: pkg Area: External package ports and removed Area: tools Area: Supplementary tools labels Oct 28, 2021
pkg/fff/Kconfig Outdated Show resolved Hide resolved
@aabadie
Copy link
Contributor

aabadie commented Oct 28, 2021

This PR also introduces the fff package. I'd like to also see a test application in C, just for it.

@jenswet
Copy link
Contributor Author

jenswet commented Oct 28, 2021

This PR also introduces the fff package. I'd like to also see a test application in C, just for it.

@aabadie I've added a test fff_test that shows a basic test with an irq mock in C language. Is that enough or would you like to see more?

@jenswet jenswet requested a review from maribu October 28, 2021 13:53
@aabadie
Copy link
Contributor

aabadie commented Oct 28, 2021

I've added a test fff_test that shows a basic test with an irq mock in C language. Is that enough or would you like to see more?

Thanks! I think the addition of the fff package and the test application could into their own separate PR to simplify the review.

@aabadie
Copy link
Contributor

aabadie commented Oct 28, 2021

Also make sure that you read our CONTRIBUTING guidelines and especially the section about commit conventions and about fixup commits.

@benpicco benpicco modified the milestone: Release 2022.10 Jan 13, 2023
@benpicco
Copy link
Contributor

This needs a squashing, right?

@maribu
Copy link
Member

maribu commented Jan 13, 2023

Yes. I fear that squashing done by anyone else except the author results in the PR being closes (likely a security feature to avoid sneaking in unrelated code while obfuscating the commit history / authorship). At least this was what happened the last two times a maintainer squashed a PR she/he didn't open.

But then again, I could just open a new PR if that happens and keep the correct authorship in the commit meta data.

@benpicco
Copy link
Contributor

it worked for #12353 😇

@jenswet
Copy link
Contributor Author

jenswet commented Jan 13, 2023

Hey guys

I am sorry for the long delay in communication. I was a few months abroad without regular access to my computer. I will make the PR ready for merging asap in the next weeks.

@maribu
Copy link
Member

maribu commented Jan 13, 2023

@jenswet: Thx :) I the squashing (and the disabling of ESP8266) was the only thing missing. Let's see if we can get this in now.

bors merge

@bors
Copy link
Contributor

bors bot commented Jan 13, 2023

🕐 Waiting for PR status (GitHub check) to be set, probably by CI. Bors will automatically try to run when all required PR statuses are set.

@riot-ci
Copy link

riot-ci commented Jan 13, 2023

Murdock results

✔️ PASSED

a9c5987 core/irq: Add C++ wrapper

Success Failures Total Runtime
6779 0 6779 12m:36s

Artifacts

@maribu
Copy link
Member

maribu commented Jan 15, 2023

bors retry

@bors
Copy link
Contributor

bors bot commented Jan 15, 2023

🕐 Waiting for PR status (GitHub check) to be set, probably by CI. Bors will automatically try to run when all required PR statuses are set.

@maribu
Copy link
Member

maribu commented Jan 15, 2023

bors cancel
bors merge

@bors
Copy link
Contributor

bors bot commented Jan 15, 2023

🕐 Waiting for PR status (GitHub check) to be set, probably by CI. Bors will automatically try to run when all required PR statuses are set.

@benpicco benpicco added Area: pkg Area: External package ports and removed Area: pkg Area: External package ports labels Jan 15, 2023
@maribu
Copy link
Member

maribu commented Jan 15, 2023

bors cancel

@maribu
Copy link
Member

maribu commented Jan 15, 2023

bors merge

@maribu
Copy link
Member

maribu commented Jan 15, 2023

bors r+

@maribu
Copy link
Member

maribu commented Jan 15, 2023

bors retry

@maribu
Copy link
Member

maribu commented Jan 15, 2023

bors ping

@bors
Copy link
Contributor

bors bot commented Jan 15, 2023

pong

@bors
Copy link
Contributor

bors bot commented Jan 15, 2023

Already running a review

1 similar comment
@bors
Copy link
Contributor

bors bot commented Jan 15, 2023

Already running a review

@bors
Copy link
Contributor

bors bot commented Jan 15, 2023

Build succeeded:

@bors bors bot merged commit 1b352d6 into RIOT-OS:master Jan 15, 2023
@maribu
Copy link
Member

maribu commented Jan 15, 2023

🎉

@jenswet: Thanks for your patience :) I'm confident that the next PR should get in much quicker :)

@jia200x jia200x added this to the Release 2023.04 milestone Apr 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: pkg Area: External package ports Area: sys Area: System Area: tests Area: tests and testing framework 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.

None yet