Skip to content

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

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

Merged
merged 6 commits into from
Jul 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions UNITTESTS/stubs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
add_library(mbed-stubs-headers INTERFACE)
add_library(mbed-headers INTERFACE)
add_library(mbed-headers-base INTERFACE)
add_library(mbed-headers-platform INTERFACE)
add_library(mbed-headers-connectivity INTERFACE)
add_library(mbed-headers-events INTERFACE)

Expand All @@ -19,15 +18,6 @@ target_link_libraries(mbed-headers
mbed-headers-rtos
)

target_include_directories(mbed-headers-platform
INTERFACE
${mbed-os_SOURCE_DIR}/platform/include
${mbed-os_SOURCE_DIR}/platform/include/platform
${mbed-os_SOURCE_DIR}/platform/randlib/include/mbed-client-randlib/
${mbed-os_SOURCE_DIR}/platform/randlib/include/
${mbed-os_SOURCE_DIR}/platform/mbed-trace/include
)

target_include_directories(mbed-headers-base
INTERFACE
${mbed-os_SOURCE_DIR}/UNITTESTS/target_h
Expand Down Expand Up @@ -80,7 +70,6 @@ target_include_directories(mbed-stubs-headers

add_subdirectory(connectivity)
add_subdirectory(events)
add_subdirectory(platform)

add_library(mbed-stubs INTERFACE)
Copy link
Contributor

@LDong-Arm LDong-Arm Jul 5, 2021

Choose a reason for hiding this comment

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

(Referring to the lines below)
Shall we remove mbed-stubs-platform from mbed-stubs, and let tests explicitly link mbed-stubs-platform? Similar to what's been done to the headers - only link what is used.
Once all component stubs have been refactors, it'd be nice to have no global mbed-stubs but only component stubs eventually.

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 recall some build failures when I tried that initially. I think we can only remove this when everything else depending on platform has been refactored. I'll take another look and see how tricky it is to untangle at this stage, now that we've merged some other stubs PRs.

Copy link
Contributor

@LDong-Arm LDong-Arm Jul 5, 2021

Choose a reason for hiding this comment

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

I think if we take it out from mbed-stubs, lots of tests need to have mbed-stubs-platform explicitly added - this would be tedious. I imagine platform is the trickiest given everything depends on it, and it might be true for hal too.
Personally I'm okay with leaving it here for now.


Expand Down
1 change: 1 addition & 0 deletions UNITTESTS/stubs/connectivity/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,6 @@ target_link_libraries(mbed-stubs-connectivity
mbed-headers
mbed-stubs-headers
mbed-stubs-rtos
mbed-stubs-platform
gtest
)
30 changes: 0 additions & 30 deletions UNITTESTS/stubs/platform/CMakeLists.txt

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ target_link_libraries(mbed-stubs-cellular
PRIVATE
mbed-headers-base
mbed-headers-connectivity
mbed-headers-platform
mbed-stubs-platform
mbed-headers-rtos
mbed-headers-drivers
mbed-headers-hal
Expand Down
2 changes: 0 additions & 2 deletions platform/tests/UNITTESTS/ATCmdParser/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ target_sources(${TEST_NAME}

target_link_libraries(${TEST_NAME}
PRIVATE
mbed-headers
mbed-stubs-headers
mbed-stubs-platform
gmock_main
)
Expand Down
1 change: 1 addition & 0 deletions platform/tests/UNITTESTS/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Copyright (c) 2021 ARM Limited. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

add_subdirectory(doubles)
add_subdirectory(ATCmdParser)
add_subdirectory(CircularBuffer)
5 changes: 2 additions & 3 deletions platform/tests/UNITTESTS/CircularBuffer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@ set(TEST_NAME circularbuffer-unittest)
add_executable(${TEST_NAME})

target_sources(${TEST_NAME}
PRIVATE
PRIVATE
test_CircularBuffer.cpp
)

target_link_libraries(${TEST_NAME}
PRIVATE
mbed-headers
mbed-stubs-platform
mbed-stubs-platform
gmock_main
)

Expand Down
38 changes: 38 additions & 0 deletions platform/tests/UNITTESTS/doubles/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Copyright (c) 2021 ARM Limited. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

add_library(mbed-headers-platform INTERFACE)
target_include_directories(mbed-headers-platform
INTERFACE
${mbed-os_SOURCE_DIR}/platform/include
${mbed-os_SOURCE_DIR}/platform/include/platform
${mbed-os_SOURCE_DIR}/platform/randlib/include/mbed-client-randlib/
${mbed-os_SOURCE_DIR}/platform/randlib/include/
${mbed-os_SOURCE_DIR}/platform/mbed-trace/include
)

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.

target_sources(mbed-stubs-platform
PRIVATE
mbed_critical_stub.c
mbed_atomic_stub.c
mbed_error.c
mbed_poll_stub.cpp
mbed_assert_stub.cpp
mbed_wait_api_stub.cpp
mbed_retarget_stub.cpp
FileHandle_stub.cpp
nvic_wrapper_stub.c
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!)

.
)
target_link_libraries(mbed-stubs-platform
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

mbed-headers-base
mbed-headers-hal
mbed-headers-platform
)