Skip to content

Commit d731166

Browse files
committed
CMake: greentea: Port mbed-drivers-ticker to CTest
Call add_test in mbed_greentea_add_test and specify mbedhtrun as the command to run. To allow mbedhtrun to communicate with the DUT, the user is required to pass in -DMBED_TARGET_SERIAL_PORT, -DMBED_TARGET_SERIAL_NUM and -DMBED_TARGET_MOUNT_POINT so mbedhtrun can find the device. Also add an MBED_HTRUN_OPTIONAL_ARGUMENTS variable which takes a semicolon separated list of optional arguments to forward to htrun. When we refine the argument list to htrun, we can make use of this mechanism to provide optional flags and reduce the number of variables the user is forced to define to make the tests run. Temporary checks have been added to mbed_greentea_add_test to keep the old flow working until we port all of the greentea tests to CTest.
1 parent 0c44607 commit d731166

File tree

4 files changed

+55
-18
lines changed

4 files changed

+55
-18
lines changed

drivers/CMakeLists.txt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
# Copyright (c) 2020 ARM Limited. All rights reserved.
22
# SPDX-License-Identifier: Apache-2.0
33

4-
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_TESTING)
5-
add_subdirectory(tests/UNITTESTS)
4+
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
5+
if(BUILD_TESTING)
6+
add_subdirectory(tests/UNITTESTS)
7+
elseif(BUILD_GREENTEA_TESTS)
8+
add_subdirectory(tests/TESTS)
9+
endif()
610
endif()
711

812
target_include_directories(mbed-core

drivers/tests/TESTS/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Copyright (c) 2021 ARM Limited. All rights reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
add_subdirectory(mbed_drivers/ticker)
Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,13 @@
11
# Copyright (c) 2020 ARM Limited. All rights reserved.
22
# SPDX-License-Identifier: Apache-2.0
33

4-
cmake_minimum_required(VERSION 3.19.0 FATAL_ERROR)
5-
6-
set(MBED_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../../../.. CACHE INTERNAL "")
7-
set(TEST_TARGET mbed-drivers-ticker)
8-
9-
include(${MBED_PATH}/tools/cmake/mbed_greentea.cmake)
10-
11-
project(${TEST_TARGET})
4+
include(mbed_greentea)
125

136
mbed_greentea_add_test(
147
TEST_NAME
15-
${TEST_TARGET}
8+
mbed-drivers-ticker
169
TEST_SOURCES
1710
main.cpp
11+
HOST_TESTS_DIR
12+
"${CMAKE_CURRENT_LIST_DIR}/../../host_tests"
1813
)

tools/cmake/mbed_greentea.cmake

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,18 @@
33

44
option(MBED_TEST_BAREMETAL OFF)
55

6-
set(MBED_CONFIG_PATH ${CMAKE_CURRENT_BINARY_DIR} CACHE INTERNAL "")
6+
set(MBED_TARGET_SERIAL_PORT "" CACHE STRING "Serial port of the DUT")
7+
set(MBED_TARGET_SERIAL_NUM "" CACHE STRING "USB Serial number of the DUT")
8+
set(MBED_TARGET_MOUNT_POINT "" CACHE STRING "Mount point for the DUT")
9+
set(MBED_HTRUN_OPTIONAL_ARGUMENTS "" CACHE STRING "Optional argument list to forward to htrun.")
710

8-
include(${CMAKE_CURRENT_LIST_DIR}/app.cmake)
9-
set(MBED_ROOT ${CMAKE_CURRENT_LIST_DIR}/../.. CACHE INTERNAL "")
11+
# TODO: After we convert all greentea tests to use CTest, remove this code. We
12+
# define these parameters in mbed-os/CMakeLists.txt for greentea tests.
13+
if(NOT BUILD_GREENTEA_TESTS)
14+
set(MBED_CONFIG_PATH ${CMAKE_CURRENT_BINARY_DIR} CACHE INTERNAL "")
15+
include(${CMAKE_CURRENT_LIST_DIR}/app.cmake)
16+
set(MBED_ROOT ${CMAKE_CURRENT_LIST_DIR}/../.. CACHE INTERNAL "")
17+
endif()
1018

1119
# CMake Macro for generalizing CMake configuration across the greentea test suite with configurable parameters
1220
# Macro args:
@@ -30,19 +38,23 @@ macro(mbed_greentea_add_test)
3038
TEST_INCLUDE_DIRS
3139
TEST_SOURCES
3240
TEST_REQUIRED_LIBS
41+
HOST_TESTS_DIR
3342
)
3443
cmake_parse_arguments(MBED_GREENTEA
3544
"${options}"
3645
"${singleValueArgs}"
3746
"${multipleValueArgs}"
3847
${ARGN}
3948
)
40-
add_subdirectory(${MBED_ROOT} build)
4149

42-
add_executable(${MBED_GREENTEA_TEST_NAME})
50+
# TODO: After we convert all greentea tests to use CTest, remove this
51+
# add_subdirectory call. We will attach the tests to the mbed-os project,
52+
# rather than creating a new project for each test that depends on mbed-os.
53+
if(NOT BUILD_GREENTEA_TESTS)
54+
add_subdirectory(${MBED_ROOT} build)
55+
endif()
4356

44-
# Explicitly enable BUILD_TESTING until CTest is added to the Greentea client
45-
set(BUILD_TESTING ON)
57+
add_executable(${MBED_GREENTEA_TEST_NAME})
4658

4759
target_include_directories(${MBED_GREENTEA_TEST_NAME}
4860
PRIVATE
@@ -70,6 +82,28 @@ macro(mbed_greentea_add_test)
7082

7183
mbed_set_post_build(${MBED_GREENTEA_TEST_NAME})
7284

85+
if(NOT ${MBED_OUTPUT_EXT} STREQUAL "")
86+
set(MBED_GREENTEA_TEST_IMAGE_NAME "${MBED_GREENTEA_TEST_NAME}.${MBED_OUTPUT_EXT}" CACHE INTERNAL "")
87+
else()
88+
set(MBED_GREENTEA_TEST_IMAGE_NAME "${MBED_GREENTEA_TEST_NAME}.bin" CACHE INTERNAL "")
89+
endif()
90+
91+
if(DEFINED MBED_GREENTEA_HOST_TESTS_DIR)
92+
list(APPEND MBED_HTRUN_OPTIONAL_ARGUMENTS "-e;${MBED_GREENTEA_HOST_TESTS_DIR}")
93+
endif()
94+
95+
add_test(
96+
NAME ${MBED_GREENTEA_TEST_NAME}
97+
COMMAND mbedhtrun
98+
-m ${MBED_TARGET}
99+
-f ${MBED_GREENTEA_TEST_IMAGE_NAME}
100+
-p ${MBED_TARGET_SERIAL_PORT}
101+
-t ${MBED_TARGET_SERIAL_NUM}
102+
-d ${MBED_TARGET_MOUNT_POINT}
103+
${MBED_HTRUN_OPTIONAL_ARGUMENTS}
104+
COMMAND_EXPAND_LISTS
105+
)
106+
73107
option(VERBOSE_BUILD "Have a verbose build process")
74108
if(VERBOSE_BUILD)
75109
set(CMAKE_VERBOSE_MAKEFILE ON)

0 commit comments

Comments
 (0)