-
Notifications
You must be signed in to change notification settings - Fork 3k
Allow unit tests to be compiled with -fno-exception #15214
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
Allow unit tests to be compiled with -fno-exception #15214
Conversation
@ladislas, thank you for your changes. |
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.
Just styling, preprocessor macros should start at the beginning
#ifdef
code....
#else
code...
#endif
b987236
to
568ffbf
Compare
done ✅ |
@ladislas, thank you for your changes. |
CI started |
Jenkins CI Test : ✔️ SUCCESSBuild Number: 1 | 🔒 Jenkins CI Job | 🌐 Logs & ArtifactsCLICK for Detailed Summary
|
This PR does not contain release version label after merging. |
Fixed |
This PR makes it possible to compile unit tests using the
-fno-exception
flag.For some reason, using mbed_assert in unit tests would throw an exception. This is strange as when using mbed on real hardware, exceptions are disabled, thus it's not clear how and why unit test code would use exceptions.
The
FAIL()
mechanism provided by Google Tests should be sufficient.But in order to not break user code relying on mbed_assert throwing an exception, we check if exceptions are enabled or not.
The main advantage of running unit tests with
-fno-exception
is for branch coverage.With exceptions enabled:
With
-fno-exception
:One concrete example is this: we have a
PwmOut
wrapper calledCorePWM
. It's simple enough that branch coverage should 100%, but it's not as gcovr tells us that there is a branch on the PwmOut constructor, because it callsinit()
which in turn will at some point call MBED_ASSERT. This creates a lot of noise for the developers writing unit tests because we don't know if the branch can be controlled or not.With exceptions enabled:
With
-fno-exception
:Another possibility to simplify is to not use throw at all and just rely on the FAIL() in the if/else. I can update the PR if needed.
Good resources on the topic: