Skip to content

Commit af311b7

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 -DSERIAL_PORT, -DSERIAL_NUM and -DMOUNT_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 d2fc596 commit af311b7

File tree

4 files changed

+38
-18
lines changed

4 files changed

+38
-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: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,15 @@
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+
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:
@@ -30,19 +35,20 @@ macro(mbed_greentea_add_test)
3035
TEST_INCLUDE_DIRS
3136
TEST_SOURCES
3237
TEST_REQUIRED_LIBS
38+
HOST_TESTS_DIR
3339
)
3440
cmake_parse_arguments(MBED_GREENTEA
3541
"${options}"
3642
"${singleValueArgs}"
3743
"${multipleValueArgs}"
3844
${ARGN}
3945
)
40-
add_subdirectory(${MBED_ROOT} build)
4146

42-
add_executable(${MBED_GREENTEA_TEST_NAME})
47+
if(NOT BUILD_GREENTEA_TESTS)
48+
add_subdirectory(${MBED_ROOT} build)
49+
endif()
4350

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

4753
target_include_directories(${MBED_GREENTEA_TEST_NAME}
4854
PRIVATE
@@ -70,6 +76,17 @@ macro(mbed_greentea_add_test)
7076

7177
mbed_set_post_build(${MBED_GREENTEA_TEST_NAME})
7278

79+
add_test(
80+
NAME ${MBED_GREENTEA_TEST_NAME}
81+
COMMAND mbedhtrun
82+
-m ${MBED_TARGET}
83+
-f ${CMAKE_CURRENT_BINARY_DIR}/${MBED_GREENTEA_TEST_NAME}.bin
84+
-p ${MBED_TARGET_SERIAL_PORT}
85+
-t ${MBED_TARGET_SERIAL_NUM}
86+
-d ${MBED_TARGET_MOUNT_POINT}
87+
-e ${MBED_GREENTEA_HOST_TESTS_DIR}
88+
)
89+
7390
option(VERBOSE_BUILD "Have a verbose build process")
7491
if(VERBOSE_BUILD)
7592
set(CMAKE_VERBOSE_MAKEFILE ON)

0 commit comments

Comments
 (0)