-
Notifications
You must be signed in to change notification settings - Fork 3k
CMake : Refactor Mbed OS drivers UNITTESTS #14285
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 : Refactor Mbed OS drivers UNITTESTS #14285
Conversation
@rajkan01, thank you for your changes. |
ab9a7df
to
a94191b
Compare
@@ -0,0 +1,22 @@ | |||
# Copyright (c) 2020 ARM Limited. All rights reserved. | |||
# SPDX-License-Identifier: Apache-2.0 | |||
cmake_minimum_required(VERSION 3.0.2) |
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.
shouldn't this be in our main unittests cmake?
I noticed this one is 3.0.2 other is 3.19?
a94191b
to
1d1c02e
Compare
UNITTESTS/fakes/CMakeLists.txt
Outdated
@@ -0,0 +1,11 @@ | |||
# Copyright (c) 2020 ARM Limited. All rights reserved. |
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.
# Copyright (c) 2020 ARM Limited. All rights reserved. | |
# Copyright (c) 2021 ARM Limited. All rights reserved. |
1d1c02e
to
25d199f
Compare
8a2fa37
to
4bced25
Compare
@paul-szczepanek-arm @hugueskamba @0xc0170 I have addressed all the review comments, please re-review |
|
||
target_link_libraries(${TEST_NAME} | ||
PRIVATE | ||
mbed-os-headers |
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 should follow the naming we agreed, mbed
prefix only. Or is this mbed-os
(could be mbed-baremetal
?) ?
- Created a CMake stubs library. - Created CMake fake watchdog and PWM out the library. - Added CMakeLists in Watchdog and PWM unittest to build with the respective watchdog and PWM fake library.
SocketAddress_stub.cpp | ||
aes_stub.c | ||
cipher_stub.c | ||
#AT_CellularContext_stub.cpp |
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 is work in progress as I add connectivity tests
FileHandle_stub.cpp | ||
FlashSimBlockDevice_stub.cpp | ||
HeapBlockDevice_stub.cpp | ||
#MBRBlockDevice_stub.cpp |
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.
appears broken and unused - this needs to be checked if any tests actually use it
I kept stubs headers in a separate dir and as a separate lib as some tests use the stub headers directly |
3339819
to
44be976
Compare
- Remove redundant file
44be976
to
5a27f3b
Compare
- Fix connectivity build issue of miss to link aginst gtest
b985936
to
0a915fa
Compare
CMakeLists.txt
Outdated
@@ -5,6 +5,18 @@ | |||
|
|||
cmake_minimum_required(VERSION 3.19.0 FATAL_ERROR) | |||
|
|||
option(UNITTESTS "Run unit tests only." OFF) | |||
|
|||
if(UNITTESTS) |
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.
Should we be more specific to avoid clashes with a users (if they want to run their unittests only, not ours and they might have the same macro ? https://cliutils.gitlab.io/modern-cmake/chapters/testing.html (using BUILD_TESTING and project name):
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_TESTING)
add_subdirectory(tests)
endif()
BUILD_TESTING
is already provided, shall we use it ? Or rather to use MBED_BUILD_TESTING
to be able to distinguish build testing in Mbed OS only or everywhere (if everywhere, a user would set MBED_BUILD_TESTING and BUILD_TESTING) ? Reading some issues around this (enable_testing is a global thing), I would go with MBED_BUILD_TESTING
.
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.
oh yeah, if there's already an option for that then that'd be perfect
message(WARNING "No test source files found for ${TEST_SUITE_NAME}.\n") | ||
endif(unittest-test-sources) | ||
endforeach(testfile) | ||
macro( mbed_add_all_subdirectories subdirectories_list ) |
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.
Where is this used , I can't find a reference.
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.
it's no longer used since we're not globbing the dirs any more
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.
lets remove 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.
I have used this macro in storage unittest refactoring #14319 as we have more number of subdirectories to add
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.
OK lets look at 14319 once t his get in and we can get back to this macro usability and if it should stay or be removed.
add_subdirectory(drivers/tests/UNITTESTS) | ||
add_subdirectory(connectivity/cellular/tests/UNITTESTS) | ||
|
||
else() |
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.
do we need else
clause here ? A project usually just do if build testing and add tests as we do. What's the reason for else clause?
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.
without it won't it also try to configure and build mbed-os?
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.
yes, they need to be two different projects because we're doing cross compilation.
For our project we had it setup like this to start with and eventually moved to a completely unrelated project. We had to duplicate a few things but in the end it was much easier.
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.
Would it build if you do not link to Mbed Os at all?
For our project we had it setup like this to start with and eventually moved to a completely unrelated project. We had to duplicate a few things but in the end it was much easier.
you also had either tests or the component ? Can you illustrate?
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.
Would it build if you do not link to Mbed Os at all?
Good question, I must do some testing.
The issue we ran into was that you actually need two different compiles for unit testing and hardware and cmake cannot handle this case.
I'll create an example and report here.
e5b5662
to
d7cd47f
Compare
d7cd47f
to
29eed7c
Compare
Summary of changes
Impact of changes
None.
Migration actions required
None.
Documentation
None.
Pull request type
Test results
Reviewers
@0xc0170 @hugueskamba @paul-szczepanek-arm @pan-