Skip to content

Commit 40154ee

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. An MBED_HTRUN_ARGUMENTS variable has been added, which is a semicolon separated list of arguments to forward to htrun. The user is required to pass in any arguments mbedhtrun needs to communicate with the device under test at CMake configuration time. We automate passing some of the htrun arguments in CMake using data provided by mbed_config.cmake or gathered from the CMake environment. The following arguments are passed to htrun from CMake: * -f/--image-path * -e/--enum-host-tests * -m/--micro * -R/--reset-timeout --baud-rate is also passed if the MBED_CONF_PLATFORM_STDIO_BAUD_RATE config parameter is defined. 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. These checks should be removed after we make all greentea tests runnable by CTest.
1 parent 2a12566 commit 40154ee

File tree

4 files changed

+60
-17
lines changed

4 files changed

+60
-17
lines changed

drivers/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_TESTING)
55
if(BUILD_GREENTEA_TESTS)
6-
# add greentea test
6+
add_subdirectory(tests/TESTS)
77
else()
88
add_subdirectory(tests/UNITTESTS)
99
endif()

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: 51 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,31 @@
33

44
option(MBED_TEST_BAREMETAL OFF)
55

6-
set(MBED_CONFIG_PATH ${CMAKE_CURRENT_BINARY_DIR} CACHE INTERNAL "")
6+
set(MBED_HTRUN_ARGUMENTS "" CACHE STRING "Argument list to forward to htrun.")
77

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

1116
# CMake Macro for generalizing CMake configuration across the greentea test suite with configurable parameters
1217
# Macro args:
1318
# TEST_NAME - Test suite name
1419
# TEST_INCLUDE_DIRS - Test suite include directories for the test
1520
# TEST_SOURCES - Test suite sources
1621
# TEST_REQUIRED_LIBS - Test suite required libraries
22+
# HOST_TESTS_DIR - Path to the "host_tests" directory
1723
#
1824
# calling the macro:
1925
# mbed_greentea_add_test(
2026
# TEST_NAME mbed-platform-system-reset
2127
# TEST_INCLUDE_DIRS mbed_store
2228
# TEST_SOURCES foo.cpp bar.cpp
2329
# TEST_REQUIRED_LIBS mbed-kvstore mbed-xyz
30+
# HOST_TESTS_DIR ${CMAKE_CURRENT_LIST_DIR}/host_tests
2431
# )
2532

2633
macro(mbed_greentea_add_test)
@@ -30,19 +37,23 @@ macro(mbed_greentea_add_test)
3037
TEST_INCLUDE_DIRS
3138
TEST_SOURCES
3239
TEST_REQUIRED_LIBS
40+
HOST_TESTS_DIR
3341
)
3442
cmake_parse_arguments(MBED_GREENTEA
3543
"${options}"
3644
"${singleValueArgs}"
3745
"${multipleValueArgs}"
3846
${ARGN}
3947
)
40-
add_subdirectory(${MBED_ROOT} build)
4148

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

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

4758
target_include_directories(${MBED_GREENTEA_TEST_NAME}
4859
PRIVATE
@@ -70,6 +81,39 @@ macro(mbed_greentea_add_test)
7081

7182
mbed_set_post_build(${MBED_GREENTEA_TEST_NAME})
7283

84+
if(NOT ${MBED_OUTPUT_EXT} STREQUAL "")
85+
set(MBED_GREENTEA_TEST_IMAGE_NAME "${MBED_GREENTEA_TEST_NAME}.${MBED_OUTPUT_EXT}")
86+
else()
87+
set(MBED_GREENTEA_TEST_IMAGE_NAME "${MBED_GREENTEA_TEST_NAME}.bin")
88+
endif()
89+
90+
if(DEFINED MBED_GREENTEA_HOST_TESTS_DIR)
91+
list(APPEND MBED_HTRUN_ARGUMENTS "-e;${MBED_GREENTEA_HOST_TESTS_DIR}")
92+
endif()
93+
94+
if(DEFINED MBED_TARGET)
95+
list(APPEND MBED_HTRUN_ARGUMENTS "-m;${MBED_TARGET}")
96+
endif()
97+
98+
if(NOT "${MBED_GREENTEA_TEST_RESET_TIMEOUT}" STREQUAL "")
99+
list(APPEND MBED_HTRUN_ARGUMENTS "-R;${MBED_GREENTEA_TEST_RESET_TIMEOUT}")
100+
endif()
101+
102+
list(APPEND CONFIG_DEFS_COPY ${MBED_CONFIG_DEFINITIONS})
103+
list(FILTER CONFIG_DEFS_COPY INCLUDE REGEX "MBED_CONF_PLATFORM_STDIO_BAUD_RATE")
104+
if(NOT ${CONFIG_DEFS_COPY} STREQUAL "")
105+
string(REGEX MATCH "[0-9]*$" BAUD_RATE ${CONFIG_DEFS_COPY})
106+
list(APPEND MBED_HTRUN_ARGUMENTS "--baud-rate=${BAUD_RATE}")
107+
endif()
108+
109+
add_test(
110+
NAME ${MBED_GREENTEA_TEST_NAME}
111+
COMMAND mbedhtrun
112+
-f ${MBED_GREENTEA_TEST_IMAGE_NAME}
113+
${MBED_HTRUN_ARGUMENTS}
114+
COMMAND_EXPAND_LISTS
115+
)
116+
73117
option(VERBOSE_BUILD "Have a verbose build process")
74118
if(VERBOSE_BUILD)
75119
set(CMAKE_VERBOSE_MAKEFILE ON)

0 commit comments

Comments
 (0)