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

Move mbed-stubs-platform to the platform directory #14773

Merged
merged 6 commits into from
Jul 7, 2021

Conversation

rwalton-arm
Copy link
Contributor

@rwalton-arm rwalton-arm commented Jun 14, 2021

Summary of changes

Fixes #14795

This PR makes the mbed-stubs-platform library more self-contained by
removing the dependencies on the monolithic header libraries we created to
make implementing the stubs easier. We also move the files to the platform
directory so the stubs live with the associated component.

Now the mbed-stubs-platform library should only depend on the headers it
uses. It also now owns and exposes it's own public headers rather than
depending on every available stub header from the mbed-stubs-headers library.

This change makes the flow of dependencies easier to see and allows for a
more modular architecture moving forward.

Impact of changes

Migration actions required

Documentation


Pull request type

[x] Patch update (Bug fix / Target update / Docs update / Test update / Refactor)
[] Feature update (New feature / Functionality change / New API)
[] Major update (Breaking change E.g. Return code change / API behaviour change)

Test results

[] No Tests required for this change (E.g docs only update)
[x] Covered by existing mbed-os tests (Greentea or Unittest)
[] Tests / results supplied as part of this PR

Reviewers


@ciarmcom ciarmcom added the release-type: patch Indentifies a PR as containing just a patch label Jun 14, 2021
@ciarmcom ciarmcom requested a review from a team June 14, 2021 14:00
@ciarmcom
Copy link
Member

@rwalton-arm, thank you for your changes.
@ARMmbed/mbed-os-maintainers please review.


add_library(mbed-stubs-platform)
Copy link
Contributor

Choose a reason for hiding this comment

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

stubs or doubles (the folder is named doubles but we talk or used stubs). Was there a reason to name the folder differently?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought doubles was more "correct" as some of these are stubs, some are a bit more like fakes. I can revert the folder name back to stubs if we think that's better/less confusing.

Copy link
Contributor

Choose a reason for hiding this comment

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

doubles is fine then.

@ciarmcom
Copy link
Member

@rwalton-arm, thank you for your changes.
@ARMmbed/mbed-os-maintainers please review.

@ciarmcom ciarmcom requested a review from a team June 14, 2021 15:30
Copy link
Contributor

@LDong-Arm LDong-Arm left a comment

Choose a reason for hiding this comment

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

To me this looks like a good, minimal-impact approach. The stub headers and sources are unchanged but just moved into the platform directory, with CMake definitions adjusted accordingly and decoupled.

Let's see if others from @ARMmbed/mbed-os-core agree with this approach.

0xc0170
0xc0170 previously approved these changes Jun 16, 2021
@mergify mergify bot added needs: CI and removed needs: review labels Jun 16, 2021
@@ -31,7 +31,9 @@ target_link_options(mbed-stubs-platform
--coverage
)
target_link_libraries(mbed-stubs-platform
PRIVATE
mbed-headers
PUBLIC
Copy link
Contributor

@rajkan01 rajkan01 Jun 16, 2021

Choose a reason for hiding this comment

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

This PR approach is good and minimal-impact but Initially, we have a discussion to use PRIVATE instead of stubs libraries target link libraries with PUBLIC refer #14285 (comment) & #14285 (comment), please share your thoughts

@ciarmcom
Copy link
Member

This pull request has automatically been marked as stale because it has had no recent activity. @ARMmbed/mbed-os-maintainers, please start CI to get the PR merged.

@ciarmcom ciarmcom added stale Stale Pull Request and removed stale Stale Pull Request labels Jun 18, 2021
@@ -17,14 +26,17 @@ target_sources(mbed-stubs-platform
randLIB_stub.c
randLIB_stub.cpp
)

target_include_directories(mbed-stubs-platform
PUBLIC
Copy link
Contributor

@rajkan01 rajkan01 Jun 23, 2021

Choose a reason for hiding this comment

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

Adding all the platform stub headers into mbed-stubs-platform with PUBLIC again, this will be a problem if library unittest (example ATCmdParser unittest) don't want to include stub platform headers but target link aginst mbed-stubs-platform brought those the platform stub headers. Initially, that was one of the reasons we added a mbed-stubs-headers library, it is better to add a new library mbed-stubs-platform-headers INTERFACE library with all platform stub headers refer our discussion #14285 (comment)

Copy link
Contributor Author

@rwalton-arm rwalton-arm Jun 30, 2021

Choose a reason for hiding this comment

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

I'm not sure I'm seeing the issue with the example use case you've given. Why wouldn't you want the headers to be available if you specifically linked to the stub library? I could see the inverse of this being a potential problem: you want the "stub header" but want to provide another implementation yourself. However, if a stub has some "public headers" (every header in this mbed-stubs-headers lib is "public") it seems better to expose them as part of the stub library they belong to. Pulling all the headers out into a monolithic header-only library that requires non-obvious dependencies before you can use it seems like an anti-pattern. Also creating a separate "stub header" library for each stub seems unnecessary to me, unless there's a real issue we're solving by adding the extra library.

Maybe I'm missing something, so if you could show me an example of where this is actually an issue it would help me understand why we need to do this. It doesn't seem to cause a problem with the ATCmdParser test you mentioned.

Copy link
Contributor

@LDong-Arm LDong-Arm Jun 30, 2021

Choose a reason for hiding this comment

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

In the original discussion @rajkan01 linked, @paul-szczepanek-arm said

If they are PUBLIC then if you depend on this library you also depend on the libraries it depends on.

This is like a header relying on another header to include something rather than including it itself. I think it's better if things are self contained and just exposing thing they are meant to expose and not what they are using themselves.

My interpretation of the concern is, if stub libraries A and B both have PUBLIC headers, and B depends on A, and a test T directly depends on B, then A will be "inadvertently" be exposed to T, is this the concern? But in order for compilation to succeed (because of how preprocessors work), this exposure is necessary IMO - otherwise how can T #include something from B which then #include something from A? Both A and B need to be in the include path.

Another thing is, the stub headers are for unit tests only which work within mbed-os, not intended for general use by other repositories, so flexibility isn't a concern and we should prioritise simplicity in my opinion. We are not messing with any "actual" Mbed OS libraries.

(Sorry if I completely misunderstood the original concern!)

@0xc0170
Copy link
Contributor

0xc0170 commented Jun 24, 2021

Based on the review comment above, set to as needs: work. Rob is away this week so will get back to this one the next week.

LDong-Arm
LDong-Arm previously approved these changes Jul 5, 2021
@LDong-Arm
Copy link
Contributor

Hopefully this can get in after a rebase, as it's our initial PR to figure out how to refactor stubs of one module.

@mergify mergify bot dismissed stale reviews from LDong-Arm and paul-szczepanek-arm July 5, 2021 15:36

Pull request has been modified.

@mergify
Copy link

mergify bot commented Jul 6, 2021

This PR cannot be merged due to conflicts. Please rebase to resolve them.

Move the platform stub library into the platform component directory.
This change is so we can avoid duplicating the mbed-os source tree in a
central UNITTESTS folder.
Move the header-only mbed-headers-platform library the unit test stubs
depend on into the platform component directory. This makes the platform
stubs more self contained and improves composition of the library.
Previously the platform stub library depended on `mbed-headers`, which
is a collection of all available headers in mbed-os. To make it easier
to separate the library, only depend on the headers we're actually using.
We have a central collection of "stub headers", which makes reasoning
about dependencies rather difficult, as it forces every stub library to
depend on all available stub headers. The standard approach would be for
each stub library to expose its public headers, and its dependents to
explicitly specify a dependency on the stub library containing the
headers it needs. This is a more modular design than creating a
header-only monolith library. Move the platform stub headers from this
central library into the mbed-stubs-platform library to increase
modularity.

mbed-stubs-connectivity now depends on the mbed-stubs-platform because
it requires some headers which were moved to mbed-stubs-platform.
We set the --coverage flag globally in UNITTESTS/CMakeLists.txt. We
shouldn't need to also set it on mbed-stubs-platform, so remove it.
@rwalton-arm
Copy link
Contributor Author

Rebased.

@mergify mergify bot added needs: CI and removed needs: work labels Jul 6, 2021
@rwalton-arm
Copy link
Contributor Author

@0xc0170 Can we get this in today?

@LDong-Arm
Copy link
Contributor

@ARMmbed/mbed-os-maintainers
This is our first PR to move unit test stubs, and even some later PRs that follow the same ideas are merged already. Also, "platform" stubs are used by all unit tests. So we'd better prioritise getting this in.

@Patater
Copy link
Contributor

Patater commented Jul 7, 2021

CI started

@mbed-ci
Copy link

mbed-ci commented Jul 7, 2021

Jenkins CI Test : ✔️ SUCCESS

Build Number: 1 | 🔒 Jenkins CI Job | 🌐 Logs & Artifacts

CLICK for Detailed Summary

jobs Status
jenkins-ci/mbed-os-ci_unittests ✔️

@Patater Patater merged commit 8287c52 into ARMmbed:master Jul 7, 2021
@mergify mergify bot removed the ready for merge label Jul 7, 2021
@mbedmain mbedmain added release-version: 6.13.0 Release-pending and removed release-type: patch Indentifies a PR as containing just a patch Release-pending labels Jul 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Move platfrom stubs to platform/tests/UNITTESTS
9 participants