CMake: greentea: Port mbed-drivers-ticker to CTest

Call add_test in mbed_greentea_add_test and specify mbedhtrun as the
command to run. A 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.

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.
pull/14949/head
Robert Walton 2021-07-07 17:39:36 +01:00
parent bfac0b2d02
commit 69e306561d
4 changed files with 54 additions and 17 deletions

View File

@ -3,7 +3,7 @@
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_TESTING)
if(BUILD_GREENTEA_TESTS)
# add greentea test
add_subdirectory(tests/TESTS)
else()
add_subdirectory(tests/UNITTESTS)
endif()

View File

@ -0,0 +1,4 @@
# Copyright (c) 2021 ARM Limited. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
add_subdirectory(mbed_drivers/ticker)

View File

@ -1,18 +1,13 @@
# Copyright (c) 2020 ARM Limited. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
cmake_minimum_required(VERSION 3.19.0 FATAL_ERROR)
set(MBED_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../../../.. CACHE INTERNAL "")
set(TEST_TARGET mbed-drivers-ticker)
include(${MBED_PATH}/tools/cmake/mbed_greentea.cmake)
project(${TEST_TARGET})
include(mbed_greentea)
mbed_greentea_add_test(
TEST_NAME
${TEST_TARGET}
mbed-drivers-ticker
TEST_SOURCES
main.cpp
HOST_TESTS_DIR
"${CMAKE_CURRENT_LIST_DIR}/../../host_tests"
)

View File

@ -3,10 +3,15 @@
option(MBED_TEST_BAREMETAL OFF)
set(MBED_CONFIG_PATH ${CMAKE_CURRENT_BINARY_DIR} CACHE INTERNAL "")
set(MBED_HTRUN_ARGUMENTS "" CACHE STRING "Argument list to forward to htrun.")
include(${CMAKE_CURRENT_LIST_DIR}/app.cmake)
set(MBED_ROOT ${CMAKE_CURRENT_LIST_DIR}/../.. CACHE INTERNAL "")
# TODO: After we convert all greentea tests to use CTest, remove this code. We
# define these parameters in mbed-os/CMakeLists.txt for greentea tests.
if(NOT BUILD_GREENTEA_TESTS)
set(MBED_CONFIG_PATH ${CMAKE_CURRENT_BINARY_DIR} CACHE INTERNAL "")
include(${CMAKE_CURRENT_LIST_DIR}/app.cmake)
set(MBED_ROOT ${CMAKE_CURRENT_LIST_DIR}/../.. CACHE INTERNAL "")
endif()
# CMake Macro for generalizing CMake configuration across the greentea test suite with configurable parameters
# Macro args:
@ -30,6 +35,7 @@ macro(mbed_greentea_add_test)
TEST_INCLUDE_DIRS
TEST_SOURCES
TEST_REQUIRED_LIBS
HOST_TESTS_DIR
)
cmake_parse_arguments(MBED_GREENTEA
"${options}"
@ -37,13 +43,16 @@ macro(mbed_greentea_add_test)
"${multipleValueArgs}"
${ARGN}
)
add_subdirectory(${MBED_ROOT} build)
# TODO: After we convert all greentea tests to use CTest, remove this
# add_subdirectory call. We will attach the tests to the mbed-os project,
# rather than creating a new project for each test that depends on mbed-os.
if(NOT BUILD_GREENTEA_TESTS)
add_subdirectory(${MBED_ROOT} build)
endif()
add_executable(${MBED_GREENTEA_TEST_NAME})
# Explicitly enable BUILD_TESTING until CTest is added to the Greentea client
set(BUILD_TESTING ON)
target_include_directories(${MBED_GREENTEA_TEST_NAME}
PRIVATE
.
@ -70,6 +79,35 @@ macro(mbed_greentea_add_test)
mbed_set_post_build(${MBED_GREENTEA_TEST_NAME})
if(NOT ${MBED_OUTPUT_EXT} STREQUAL "")
set(MBED_GREENTEA_TEST_IMAGE_NAME "${MBED_GREENTEA_TEST_NAME}.${MBED_OUTPUT_EXT}")
else()
set(MBED_GREENTEA_TEST_IMAGE_NAME "${MBED_GREENTEA_TEST_NAME}.bin")
endif()
if(DEFINED MBED_GREENTEA_HOST_TESTS_DIR)
list(APPEND MBED_HTRUN_ARGUMENTS "-e;${MBED_GREENTEA_HOST_TESTS_DIR}")
endif()
if(DEFINED MBED_TARGET)
list(APPEND MBED_HTRUN_ARGUMENTS "-m;${MBED_TARGET}")
endif()
list(APPEND CONFIG_DEFS_COPY ${MBED_CONFIG_DEFINITIONS})
list(FILTER CONFIG_DEFS_COPY INCLUDE REGEX "MBED_CONF_PLATFORM_STDIO_BAUD_RATE")
if(NOT ${CONFIG_DEFS_COPY} STREQUAL "")
string(REGEX MATCH "[0-9]*$" BAUD_RATE ${CONFIG_DEFS_COPY})
list(APPEND MBED_HTRUN_ARGUMENTS "--baud-rate=${BAUD_RATE}")
endif()
add_test(
NAME ${MBED_GREENTEA_TEST_NAME}
COMMAND mbedhtrun
-f ${MBED_GREENTEA_TEST_IMAGE_NAME}
${MBED_HTRUN_ARGUMENTS}
COMMAND_EXPAND_LISTS
)
option(VERBOSE_BUILD "Have a verbose build process")
if(VERBOSE_BUILD)
set(CMAKE_VERBOSE_MAKEFILE ON)