-
Notifications
You must be signed in to change notification settings - Fork 3k
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
CMake: Remove mbed-stubs-rtos-headers library #14870
Conversation
@rajkan01, thank you for your changes. |
connectivity/cellular/tests/UNITTESTS/framework/AT/at_cellularcontext/CMakeLists.txt
Outdated
Show resolved
Hide resolved
|
||
add_definitions(-DUNITTEST) |
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.
add_definitions(-DUNITTEST) |
This is already defined in UNITTESTS/CMakeLists.txt. The removal of this can be a separate commit.
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.
Thanks for your review comment. This add_definition is required, and we can remove the one in "UNITTEST/CMakeLists.txt" as add_definitions (definition of UNITTEST macro ) visible in the current directory CMake and below add_subdirectories from there and don't have the option to expose to parent scope to visible across CMake
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.
We may want to create a "unit-tests" INTERFACE target in UNITTEST/CMakeLists.txt, and link to it in each test executable, instead of using the directory scoped add_definitions
to set this macro. Or maybe we can just bodge it into CMAKE_C_FLAGS
and CMAKE_CXX_FLAGS
globally, like we do with the coverage compile options?
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.
Or maybe we can just bodge it into
CMAKE_C_FLAGS
andCMAKE_CXX_FLAGS
globally, like we do with the coverage compile options?
This sounds like the easiest approach.
A more fundamental question is, a few libraries check UNITTEST
:
$ grep -rn '\bUNITTEST\b'
drivers/include/drivers/MbedCRC.h:32:#ifdef UNITTEST
UNITTESTS/target_h/platform/mbed_assert.h:44:#ifndef UNITTEST
storage/kvstore/tdbstore/tests/UNITTESTS/TDBStore/CMakeLists.txt:10: UNITTEST
storage/kvstore/filesystemstore/tests/UNITTESTS/FileSystemStore/CMakeLists.txt:10: UNITTEST
rtos/include/rtos/internal/mbed_rtos_storage.h:20:#if MBED_CONF_RTOS_PRESENT || defined(UNITTEST)
rtos/include/rtos/internal/mbed_rtos1_types.h:20:#if MBED_CONF_RTOS_PRESENT || defined(UNITTEST)
rtos/include/rtos/Thread.h:36:#if MBED_CONF_RTOS_PRESENT || defined(DOXYGEN_ONLY) || defined(UNITTEST)
rtos/include/rtos/mbed_rtos_types.h:20:#if MBED_CONF_RTOS_PRESENT || defined(DOXYGEN_ONLY) || defined(UNITTEST)
but is this actually ideal? I thought libraries shouldn't need to specially handle tests. Instead, fakes/mocks/stubs/... should wrap tested modules while maintaining normal-use interfaces?
Anyway this is just out of curiosity, not the scope of this PR.
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.
Not ideal at all IMO. Adding test specific logic to your production/library code is the wrong approach. Ideally we'd remove the need for those checks altogether.
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.
There's one simple way to get rid of -DUNITTEST
, at least from rtos which this PR is for. Notice the snippet in my previous comment - MBED_CONF_RTOS_PRESENT
and defined(UNITTEST)
are connected by ||
. So what about defining MBED_CONF_RTOS_PRESENT=1
directly?
It's enough to remove add_definitions(-DUNITTEST)
and add
target_compile_definitions(mbed-stubs-rtos
PRIVATE
MBED_CONF_RTOS_PRESENT=1
)
here, and also add MBED_CONF_RTOS_PRESENT=1
to
mbed-os/connectivity/cellular/tests/UNITTESTS/framework/device/athandler/CMakeLists.txt
Lines 8 to 16 in 8d3fc33
target_compile_definitions(${TEST_NAME} | |
PRIVATE | |
MBED_CONF_CELLULAR_DEBUG_AT=true | |
OS_STACK_SIZE=2048 | |
DEVICE_SERIAL=1 | |
DEVICE_INTERRUPTIN=1 | |
MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE=115200 | |
MBED_CONF_CELLULAR_AT_HANDLER_BUFFER_SIZE=32 | |
) |
because
ATHandler.cpp
specifically checks this macro.
Then we can safely remove all defined(UNITTEST)
checks from rtos/
.
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.
Seems like we should review all of these and fix them in another PR. It would be good to keep this PR scoped to removal of the stub-headers library.
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.
There are not many of files to fix and the fix is simple as shown above, we can raise another PR to fix all of them in one go. I already made locally changes when experimenting a bit for my previous comment, so I can do it.
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.
We may want to create a "unit-tests" INTERFACE target in UNITTEST/CMakeLists.txt, and link to it in each test executable, instead of using the directory scoped
add_definitions
to set this macro. Or maybe we can just bodge it intoCMAKE_C_FLAGS
andCMAKE_CXX_FLAGS
globally, like we do with the coverage compile options?
I just moved the add_defenition into Mbed OS root Cmake under testing check as we may end up removing mbed-os/UNITTEST CMake after we migrated all stubs to their respective component and append -DUNITTEST into CMAKE_C_FLAGS and CMAKE_CXX_FLAGS will not work as it accepts -Dmacro=value when set() calls
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.
Either is fine for this PR. I've created an issue #14883 to fully remove the UNITTEST
macro.
9d41b9b
to
d2a7ab9
Compare
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.
LGTM
d2a7ab9
to
d9fcff7
Compare
@0xc0170 Could you review and start the CI for this PR |
CI started |
This PR cannot be merged due to conflicts. Please rebase to resolve them. |
Jenkins CI Test : ✔️ SUCCESSBuild Number: 1 | 🔒 Jenkins CI Job | 🌐 Logs & ArtifactsCLICK for Detailed Summary
|
d9fcff7
to
3fc6c4d
Compare
- Previous changes moved all rtos stubs headers into mbed-stubs-rtos-headers lib, but the decision to keep all stubs headers under the respective component stubs library so moved all stubs rtos headers under mbed-stubs-rtos and updated it depend component CMake - Remove unnecessary add_definition call for UNITTEST as any of the stubs library added from UNITTEST/CMakeLists.txt is not required this macro
3fc6c4d
to
bb3cd37
Compare
@0xc0170 I have re-based this PR, Could you restart the CI |
CI restarted |
Jenkins CI Test : ✔️ SUCCESSBuild Number: 2 | 🔒 Jenkins CI Job | 🌐 Logs & ArtifactsCLICK for Detailed Summary
|
I'll merge this. It was approved prior the conflict. |
Summary of changes
Previous changes moved all rtos stubs headers into mbed-stubs-rtos-headers lib, but the decision to keep all stubs headers under the respective component stubs library so moved all stubs rtos headers under mbed-stubs-rtos and updated it depend component CMake
Impact of changes
None.
Migration actions required
None.
Documentation
None.
Pull request type
Test results
Reviewers