Skip to content

Commit c96b9f1

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. 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 be88cb4 commit c96b9f1

File tree

4 files changed

+43
-18
lines changed

4 files changed

+43
-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: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,17 @@
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")
79

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

1118
# CMake Macro for generalizing CMake configuration across the greentea test suite with configurable parameters
1219
# Macro args:
@@ -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,17 @@ macro(mbed_greentea_add_test)
7081

7182
mbed_set_post_build(${MBED_GREENTEA_TEST_NAME})
7283

84+
add_test(
85+
NAME ${MBED_GREENTEA_TEST_NAME}
86+
COMMAND mbedhtrun
87+
-m ${MBED_TARGET}
88+
-f ${CMAKE_CURRENT_BINARY_DIR}/${MBED_GREENTEA_TEST_NAME}.bin
89+
-p ${MBED_TARGET_SERIAL_PORT}
90+
-t ${MBED_TARGET_SERIAL_NUM}
91+
-d ${MBED_TARGET_MOUNT_POINT}
92+
-e ${MBED_GREENTEA_HOST_TESTS_DIR}
93+
)
94+
7395
option(VERBOSE_BUILD "Have a verbose build process")
7496
if(VERBOSE_BUILD)
7597
set(CMAKE_VERBOSE_MAKEFILE ON)

0 commit comments

Comments
 (0)