Skip to content

Commit 7842320

Browse files
committed
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.
1 parent d4b1534 commit 7842320

File tree

14 files changed

+81
-24
lines changed

14 files changed

+81
-24
lines changed

CMakeLists.txt

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
cmake_minimum_required(VERSION 3.19.0 FATAL_ERROR)
77

8+
option(BUILD_GREENTEA_TESTS "Build greentea tests only." OFF)
9+
810
if(${CMAKE_CROSSCOMPILING})
911
include(${MBED_CONFIG_PATH}/mbed_config.cmake)
1012
include(mbed_set_linker_script)
@@ -19,12 +21,14 @@ list(APPEND CMAKE_MODULE_PATH
1921

2022
add_subdirectory(extern)
2123

22-
option(BUILD_TESTING "Run unit tests only." OFF)
23-
24-
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_TESTING)
24+
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
2525
include(CTest)
26-
add_definitions(-DUNITTEST)
27-
add_subdirectory(UNITTESTS)
26+
27+
if((NOT BUILD_GREENTEA_TESTS) AND BUILD_TESTING)
28+
# Building unit tests only.
29+
add_definitions(-DUNITTEST)
30+
add_subdirectory(UNITTESTS)
31+
endif()
2832
endif()
2933

3034
add_library(mbed-core INTERFACE)
@@ -94,10 +98,12 @@ if(${CMAKE_CROSSCOMPILING})
9498

9599
# Add MBED_TEST_MODE for backward compatibility with Greentea tests written for use with Mbed CLI 1
96100
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_TESTING)
97-
target_compile_definitions(${PROJECT_NAME}
98-
INTERFACE
99-
MBED_TEST_MODE
100-
)
101+
if(NOT BUILD_GREENTEA_TESTS)
102+
target_compile_definitions(${PROJECT_NAME}
103+
INTERFACE
104+
MBED_TEST_MODE
105+
)
106+
endif()
101107
endif()
102108

103109
# We need to generate a "response file" to pass to the C preprocessor when we preprocess the linker

connectivity/cellular/CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22
# SPDX-License-Identifier: Apache-2.0
33

44
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_TESTING)
5-
add_subdirectory(tests/UNITTESTS)
5+
if(BUILD_GREENTEA_TESTS)
6+
# add greentea test
7+
else()
8+
add_subdirectory(tests/UNITTESTS)
9+
endif()
610
endif()
711

812
add_subdirectory(source/framework)

connectivity/lorawan/CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22
# SPDX-License-Identifier: Apache-2.0
33

44
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_TESTING)
5-
add_subdirectory(tests/UNITTESTS)
5+
if(BUILD_GREENTEA_TESTS)
6+
# add greentea test
7+
else()
8+
add_subdirectory(tests/UNITTESTS)
9+
endif()
610
endif()
711

812
add_subdirectory(lorastack)

connectivity/netsocket/CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22
# SPDX-License-Identifier: Apache-2.0
33

44
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_TESTING)
5-
add_subdirectory(tests/UNITTESTS)
5+
if(BUILD_GREENTEA_TESTS)
6+
# add greentea test
7+
else()
8+
add_subdirectory(tests/UNITTESTS)
9+
endif()
610
endif()
711

812
# TODO CMake: Perhaps move this/these file(s) into connectivity/drivers/cellular

drivers/CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22
# SPDX-License-Identifier: Apache-2.0
33

44
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_TESTING)
5-
add_subdirectory(tests/UNITTESTS)
5+
if(BUILD_GREENTEA_TESTS)
6+
# add greentea test
7+
else()
8+
add_subdirectory(tests/UNITTESTS)
9+
endif()
610
endif()
711

812
target_include_directories(mbed-core

events/CMakeLists.txt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@
22
# SPDX-License-Identifier: Apache-2.0
33

44
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_TESTING)
5-
add_subdirectory(tests/UNITTESTS)
6-
else()
5+
if(BUILD_GREENTEA_TESTS)
6+
# add greentea test
7+
else()
8+
add_subdirectory(tests/UNITTESTS)
9+
endif()
10+
endif()
711

812
add_library(mbed-events INTERFACE)
913

@@ -28,4 +32,3 @@ target_compile_definitions(mbed-events
2832
INTERFACE
2933
MBED_CONF_EVENTS_PRESENT=1
3034
)
31-
endif()

hal/CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22
# SPDX-License-Identifier: Apache-2.0
33

44
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_TESTING)
5-
add_subdirectory(tests/UNITTESTS)
5+
if(BUILD_GREENTEA_TESTS)
6+
# add greentea test
7+
else()
8+
add_subdirectory(tests/UNITTESTS)
9+
endif()
610
endif()
711

812
add_subdirectory(TARGET_FLASH_CMSIS_ALGO EXCLUDE_FROM_ALL)

platform/CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22
# SPDX-License-Identifier: Apache-2.0
33

44
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_TESTING)
5-
add_subdirectory(tests/UNITTESTS)
5+
if(BUILD_GREENTEA_TESTS)
6+
# add greentea test
7+
else()
8+
add_subdirectory(tests/UNITTESTS)
9+
endif()
610
endif()
711

812
# List of all optional platform libraries available.

rtos/CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22
# SPDX-License-Identifier: Apache-2.0
33

44
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_TESTING)
5-
add_subdirectory(tests/UNITTESTS)
5+
if(BUILD_GREENTEA_TESTS)
6+
# add greentea test
7+
else()
8+
add_subdirectory(tests/UNITTESTS)
9+
endif()
610
endif()
711

812
target_include_directories(mbed-core

storage/blockdevice/CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22
# SPDX-License-Identifier: Apache-2.0
33

44
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_TESTING)
5-
add_subdirectory(tests/UNITTESTS)
5+
if(BUILD_GREENTEA_TESTS)
6+
# add greentea test
7+
else()
8+
add_subdirectory(tests/UNITTESTS)
9+
endif()
610
endif()
711

812
if("DATAFLASH" IN_LIST MBED_TARGET_LABELS)

0 commit comments

Comments
 (0)