From 7842320ab715e63e7069aca1d49f318af8e404ea Mon Sep 17 00:00:00 2001 From: Robert Walton Date: Wed, 7 Jul 2021 17:10:04 +0100 Subject: [PATCH] CMake: Add option to enable greentea tests Add an option to enable the greentea tests independently from the unit tests. We can't just use the typical BUILD_TESTING option to enable greentea tests. BUILD_TESTING enables unit tests and fetches googletest, which are compiled for the host. Greentea tests are cross compiled and require a toolchain file. For this reason we add a new option just to enable greentea tests, preventing build failures triggered by the unit tests and googletest. --- CMakeLists.txt | 24 ++++++++++++------- connectivity/cellular/CMakeLists.txt | 6 ++++- connectivity/lorawan/CMakeLists.txt | 6 ++++- connectivity/netsocket/CMakeLists.txt | 6 ++++- drivers/CMakeLists.txt | 6 ++++- events/CMakeLists.txt | 9 ++++--- hal/CMakeLists.txt | 6 ++++- platform/CMakeLists.txt | 6 ++++- rtos/CMakeLists.txt | 6 ++++- storage/blockdevice/CMakeLists.txt | 6 ++++- storage/filesystem/CMakeLists.txt | 6 ++++- storage/kvstore/CMakeLists.txt | 6 ++++- .../kvstore/filesystemstore/CMakeLists.txt | 6 ++++- storage/kvstore/tdbstore/CMakeLists.txt | 6 ++++- 14 files changed, 81 insertions(+), 24 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e91ccf6388..afb153ad4a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,6 +5,8 @@ cmake_minimum_required(VERSION 3.19.0 FATAL_ERROR) +option(BUILD_GREENTEA_TESTS "Build greentea tests only." OFF) + if(${CMAKE_CROSSCOMPILING}) include(${MBED_CONFIG_PATH}/mbed_config.cmake) include(mbed_set_linker_script) @@ -19,12 +21,14 @@ list(APPEND CMAKE_MODULE_PATH add_subdirectory(extern) -option(BUILD_TESTING "Run unit tests only." OFF) - -if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_TESTING) +if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) include(CTest) - add_definitions(-DUNITTEST) - add_subdirectory(UNITTESTS) + + if((NOT BUILD_GREENTEA_TESTS) AND BUILD_TESTING) + # Building unit tests only. + add_definitions(-DUNITTEST) + add_subdirectory(UNITTESTS) + endif() endif() add_library(mbed-core INTERFACE) @@ -94,10 +98,12 @@ if(${CMAKE_CROSSCOMPILING}) # Add MBED_TEST_MODE for backward compatibility with Greentea tests written for use with Mbed CLI 1 if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_TESTING) - target_compile_definitions(${PROJECT_NAME} - INTERFACE - MBED_TEST_MODE - ) + if(NOT BUILD_GREENTEA_TESTS) + target_compile_definitions(${PROJECT_NAME} + INTERFACE + MBED_TEST_MODE + ) + endif() endif() # We need to generate a "response file" to pass to the C preprocessor when we preprocess the linker diff --git a/connectivity/cellular/CMakeLists.txt b/connectivity/cellular/CMakeLists.txt index d7ce11f90d..1c87aedf69 100644 --- a/connectivity/cellular/CMakeLists.txt +++ b/connectivity/cellular/CMakeLists.txt @@ -2,7 +2,11 @@ # SPDX-License-Identifier: Apache-2.0 if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_TESTING) - add_subdirectory(tests/UNITTESTS) + if(BUILD_GREENTEA_TESTS) + # add greentea test + else() + add_subdirectory(tests/UNITTESTS) + endif() endif() add_subdirectory(source/framework) diff --git a/connectivity/lorawan/CMakeLists.txt b/connectivity/lorawan/CMakeLists.txt index 941b01e04e..d30bdacfbc 100644 --- a/connectivity/lorawan/CMakeLists.txt +++ b/connectivity/lorawan/CMakeLists.txt @@ -2,7 +2,11 @@ # SPDX-License-Identifier: Apache-2.0 if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_TESTING) - add_subdirectory(tests/UNITTESTS) + if(BUILD_GREENTEA_TESTS) + # add greentea test + else() + add_subdirectory(tests/UNITTESTS) + endif() endif() add_subdirectory(lorastack) diff --git a/connectivity/netsocket/CMakeLists.txt b/connectivity/netsocket/CMakeLists.txt index 62bea8cc63..9760c60316 100644 --- a/connectivity/netsocket/CMakeLists.txt +++ b/connectivity/netsocket/CMakeLists.txt @@ -2,7 +2,11 @@ # SPDX-License-Identifier: Apache-2.0 if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_TESTING) - add_subdirectory(tests/UNITTESTS) + if(BUILD_GREENTEA_TESTS) + # add greentea test + else() + add_subdirectory(tests/UNITTESTS) + endif() endif() # TODO CMake: Perhaps move this/these file(s) into connectivity/drivers/cellular diff --git a/drivers/CMakeLists.txt b/drivers/CMakeLists.txt index 9079d3d75a..ad62808a45 100644 --- a/drivers/CMakeLists.txt +++ b/drivers/CMakeLists.txt @@ -2,7 +2,11 @@ # SPDX-License-Identifier: Apache-2.0 if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_TESTING) - add_subdirectory(tests/UNITTESTS) + if(BUILD_GREENTEA_TESTS) + # add greentea test + else() + add_subdirectory(tests/UNITTESTS) + endif() endif() target_include_directories(mbed-core diff --git a/events/CMakeLists.txt b/events/CMakeLists.txt index da4d693511..6e7a6c6bda 100644 --- a/events/CMakeLists.txt +++ b/events/CMakeLists.txt @@ -2,8 +2,12 @@ # SPDX-License-Identifier: Apache-2.0 if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_TESTING) - add_subdirectory(tests/UNITTESTS) -else() + if(BUILD_GREENTEA_TESTS) + # add greentea test + else() + add_subdirectory(tests/UNITTESTS) + endif() +endif() add_library(mbed-events INTERFACE) @@ -28,4 +32,3 @@ target_compile_definitions(mbed-events INTERFACE MBED_CONF_EVENTS_PRESENT=1 ) -endif() diff --git a/hal/CMakeLists.txt b/hal/CMakeLists.txt index 87f88bef6f..3af169e0f1 100644 --- a/hal/CMakeLists.txt +++ b/hal/CMakeLists.txt @@ -2,7 +2,11 @@ # SPDX-License-Identifier: Apache-2.0 if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_TESTING) - add_subdirectory(tests/UNITTESTS) + if(BUILD_GREENTEA_TESTS) + # add greentea test + else() + add_subdirectory(tests/UNITTESTS) + endif() endif() add_subdirectory(TARGET_FLASH_CMSIS_ALGO EXCLUDE_FROM_ALL) diff --git a/platform/CMakeLists.txt b/platform/CMakeLists.txt index df83719fc6..4be54141b6 100644 --- a/platform/CMakeLists.txt +++ b/platform/CMakeLists.txt @@ -2,7 +2,11 @@ # SPDX-License-Identifier: Apache-2.0 if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_TESTING) - add_subdirectory(tests/UNITTESTS) + if(BUILD_GREENTEA_TESTS) + # add greentea test + else() + add_subdirectory(tests/UNITTESTS) + endif() endif() # List of all optional platform libraries available. diff --git a/rtos/CMakeLists.txt b/rtos/CMakeLists.txt index ab9d3082ea..8af23d8705 100644 --- a/rtos/CMakeLists.txt +++ b/rtos/CMakeLists.txt @@ -2,7 +2,11 @@ # SPDX-License-Identifier: Apache-2.0 if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_TESTING) - add_subdirectory(tests/UNITTESTS) + if(BUILD_GREENTEA_TESTS) + # add greentea test + else() + add_subdirectory(tests/UNITTESTS) + endif() endif() target_include_directories(mbed-core diff --git a/storage/blockdevice/CMakeLists.txt b/storage/blockdevice/CMakeLists.txt index 9f847d4360..6b03244aeb 100644 --- a/storage/blockdevice/CMakeLists.txt +++ b/storage/blockdevice/CMakeLists.txt @@ -2,7 +2,11 @@ # SPDX-License-Identifier: Apache-2.0 if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_TESTING) - add_subdirectory(tests/UNITTESTS) + if(BUILD_GREENTEA_TESTS) + # add greentea test + else() + add_subdirectory(tests/UNITTESTS) + endif() endif() if("DATAFLASH" IN_LIST MBED_TARGET_LABELS) diff --git a/storage/filesystem/CMakeLists.txt b/storage/filesystem/CMakeLists.txt index cacd423208..5d6fca3ec5 100644 --- a/storage/filesystem/CMakeLists.txt +++ b/storage/filesystem/CMakeLists.txt @@ -2,7 +2,11 @@ # SPDX-License-Identifier: Apache-2.0 if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_TESTING) - add_subdirectory(tests/UNITTESTS) + if(BUILD_GREENTEA_TESTS) + # add greentea test + else() + add_subdirectory(tests/UNITTESTS) + endif() endif() add_subdirectory(fat) diff --git a/storage/kvstore/CMakeLists.txt b/storage/kvstore/CMakeLists.txt index 3f9f137edb..1d0feeef62 100644 --- a/storage/kvstore/CMakeLists.txt +++ b/storage/kvstore/CMakeLists.txt @@ -2,7 +2,11 @@ # SPDX-License-Identifier: Apache-2.0 if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_TESTING) - add_subdirectory(tests/UNITTESTS) + if(BUILD_GREENTEA_TESTS) + # add greentea test + else() + add_subdirectory(tests/UNITTESTS) + endif() endif() add_subdirectory(tdbstore) diff --git a/storage/kvstore/filesystemstore/CMakeLists.txt b/storage/kvstore/filesystemstore/CMakeLists.txt index 7289fe8b8d..49b2d344d7 100644 --- a/storage/kvstore/filesystemstore/CMakeLists.txt +++ b/storage/kvstore/filesystemstore/CMakeLists.txt @@ -2,7 +2,11 @@ # SPDX-License-Identifier: Apache-2.0 if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_TESTING) - add_subdirectory(tests/UNITTESTS) + if(BUILD_GREENTEA_TESTS) + # add greentea test + else() + add_subdirectory(tests/UNITTESTS) + endif() endif() target_include_directories(mbed-storage-filesystemstore diff --git a/storage/kvstore/tdbstore/CMakeLists.txt b/storage/kvstore/tdbstore/CMakeLists.txt index d4f8d92ed5..82cd283761 100644 --- a/storage/kvstore/tdbstore/CMakeLists.txt +++ b/storage/kvstore/tdbstore/CMakeLists.txt @@ -2,7 +2,11 @@ # SPDX-License-Identifier: Apache-2.0 if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_TESTING) - add_subdirectory(tests/UNITTESTS) + if(BUILD_GREENTEA_TESTS) + # add greentea test + else() + add_subdirectory(tests/UNITTESTS) + endif() endif() target_include_directories(mbed-storage-tdbstore