-
Notifications
You must be signed in to change notification settings - Fork 102
[#1178] Add loom test setup #1194
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
base: main
Are you sure you want to change the base?
Conversation
|
@mox692 Thanks you for the pull requests and taking care of loom! |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1194 +/- ##
==========================================
+ Coverage 77.39% 78.34% +0.94%
==========================================
Files 397 413 +16
Lines 39532 41033 +1501
Branches 916 1117 +201
==========================================
+ Hits 30596 32147 +1551
+ Misses 8190 8030 -160
- Partials 746 856 +110
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
elfenpiff
left a comment
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 reviewed it and you implemented it exactly how we intended to integrate loom into iceoryx2 - well done, thank you!
Since it is a crucial part in iceoryx2 I ask @elBoberido that he reviews the PR as well and approves it. Then we can merge it.
elBoberido
left a comment
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.
Looks good. Just some questions regarding no_std and documentation. Nothing blocking if no_std is still possible, which I assume.
| #[cfg(all(test, loom))] | ||
| pub fn new() -> Self { | ||
| Self { | ||
| data: UnsafeCell::new(None), | ||
| is_initialized: IoxAtomicBool::new(false), | ||
| is_finalized: IoxAtomicBool::new(false), | ||
| } | ||
| } |
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.
Can we document that loom cannot handle const functions somewhere? I mean in case we introduce a new function and loom breaks. A good option would be to add the error message and the fix to FAQ_ICEORYX_DEVS.md.
|
Thank you for the review!
Yes good catch, I think this PR should probably be modified so that the loom tests are gated behind the std feature. At this moment, loom does not support no_std environment. Would it be acceptable to enable loom support only for the targets that are built with |
@mox692 Yup, makes sense to me :) |
| version = { workspace = true } | ||
|
|
||
| [lints] | ||
| workspace = true |
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.
@elfenpiff Do we want to have these kind of configurations defined at the crate level?
| //! ``` | ||
| use core::{alloc::Layout, cell::UnsafeCell, fmt::Debug, sync::atomic::Ordering}; | ||
| #[cfg(all(test, loom, feature = "std"))] |
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.
If the type is not coming from std, perhaps the std feature gate could be removed. The check for the loom environment would be enough. It's probably functionally the same, but it seems semantically inaccurate.
Does the loom setup work if removing the std feature gate?
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.
Does the loom setup work if removing the std feature gate?
Yes, it should work. Let me update the code so that the std feature gate is applied only to the parts that require std.
|
|
||
| #[cfg(not(all(test, loom, feature = "std")))] | ||
| static LOG_LEVEL: IoxAtomicU8 = IoxAtomicU8::new(DEFAULT_LOG_LEVEL as u8); | ||
| #[cfg(all(test, loom, feature = "std"))] |
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.
In instances like this, the std feature gate makes more sense to me.
| } | ||
| } | ||
|
|
||
| #[cfg(not(all(test, loom, feature = "std")))] |
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.
Curious, why is this removed for the loom build?
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.
This function contains static variable IS_LOCKED, which loom can't emulate. Since this is top level function and not used in the internal code path, I just exclude that function from loom instead of doing this:
pub unsafe fn strerror_r() {
...
#[cfg(all(test, loom, feature = "std"))]
static IS_LOCKED: IoxAtomicBool = IoxAtomicBool::new(false);
#[cfg(not(all(test, loom, feature = "std")))]
static IS_LOCKED: std::sync::LazyLock<IoxAtomicU32> = std::sync::LazyLock::new(|| { unimplemented!("loom does not provide const-initialization for atomic variables.") });
...
}... but this might be confusing, as all other places do this way. I may update this to unify the style.
Notes for Reviewer
This PR adds the setup for loom tests. The actual loom tests will be added in follow-up PRs.
A couple of notes:
cfgflag. I chosecfgbecause I assume we don’t want to introduce a new Cargo feature across several crates just for this purpose. Usingcfgavoids having to touchCargo.tomlin many places.staticvariables that would otherwise cause a runtime error when executed under loom.Pre-Review Checklist for the PR Author
Convert to draft)SPDX-License-Identifier: Apache-2.0 OR MITiox2-123-introduce-posix-ipc-example)[#123] Add posix ipc example)task-list-completed)Checklist for the PR Reviewer
Post-review Checklist for the PR Author
References
Relates to #1178.