Skip to content

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

Merged
merged 13 commits into from
Feb 23, 2021

Conversation

rajkan01
Copy link
Contributor

Summary of changes

  • 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.

Impact of changes

None.

Migration actions required

None.

Documentation

None.


Pull request type

[] Patch update (Bug fix / Target update / Docs update / Test update / Refactor)
[x] 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

@0xc0170 @hugueskamba @paul-szczepanek-arm @pan-


@rajkan01 rajkan01 changed the title CMake : Refactor Mbed OS UNITTESTS CMake : Refactor Mbed OS drivers UNITTESTS Feb 15, 2021
@ciarmcom
Copy link
Member

@rajkan01, thank you for your changes.
@0xc0170 @pan- @hugueskamba @paul-szczepanek-arm @ARMmbed/mbed-os-maintainers please review.

@rajkan01 rajkan01 force-pushed the unittest_refactor branch 2 times, most recently from ab9a7df to a94191b Compare February 15, 2021 13:22
@@ -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)
Copy link
Contributor

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?

@@ -0,0 +1,11 @@
# Copyright (c) 2020 ARM Limited. All rights reserved.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
# Copyright (c) 2020 ARM Limited. All rights reserved.
# Copyright (c) 2021 ARM Limited. All rights reserved.

@rajkan01 rajkan01 force-pushed the unittest_refactor branch 3 times, most recently from 8a2fa37 to 4bced25 Compare February 16, 2021 17:09
@rajkan01
Copy link
Contributor Author

@paul-szczepanek-arm @hugueskamba @0xc0170 I have addressed all the review comments, please re-review


target_link_libraries(${TEST_NAME}
PRIVATE
mbed-os-headers
Copy link
Contributor

@0xc0170 0xc0170 Feb 17, 2021

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

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

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

@paul-szczepanek-arm
Copy link
Member

I kept stubs headers in a separate dir and as a separate lib as some tests use the stub headers directly

- Remove redundant file
- Fix connectivity build issue of miss to link aginst gtest
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)
Copy link
Contributor

@0xc0170 0xc0170 Feb 22, 2021

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.

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 )
Copy link
Contributor

@0xc0170 0xc0170 Feb 22, 2021

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.

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

Copy link
Contributor

Choose a reason for hiding this comment

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

lets remove it

Copy link
Contributor Author

@rajkan01 rajkan01 Feb 22, 2021

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

Copy link
Contributor

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()
Copy link
Contributor

@0xc0170 0xc0170 Feb 22, 2021

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?

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?

Copy link
Contributor

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.

Copy link
Contributor

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?

Copy link
Contributor

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.

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.

7 participants