Skip to content

Commit

Permalink
CMake: greentea: Port mbed-drivers-ticker to CTest
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rwalton-arm committed Jul 18, 2021
1 parent bfac0b2 commit 69e3065
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 17 deletions.
2 changes: 1 addition & 1 deletion drivers/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 4 additions & 0 deletions drivers/tests/TESTS/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Copyright (c) 2021 ARM Limited. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

add_subdirectory(mbed_drivers/ticker)
13 changes: 4 additions & 9 deletions drivers/tests/TESTS/mbed_drivers/ticker/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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"
)
52 changes: 45 additions & 7 deletions tools/cmake/mbed_greentea.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -30,19 +35,23 @@ macro(mbed_greentea_add_test)
TEST_INCLUDE_DIRS
TEST_SOURCES
TEST_REQUIRED_LIBS
HOST_TESTS_DIR
)
cmake_parse_arguments(MBED_GREENTEA
"${options}"
"${singleValueArgs}"
"${multipleValueArgs}"
${ARGN}
)
add_subdirectory(${MBED_ROOT} build)

add_executable(${MBED_GREENTEA_TEST_NAME})
# 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()

# Explicitly enable BUILD_TESTING until CTest is added to the Greentea client
set(BUILD_TESTING ON)
add_executable(${MBED_GREENTEA_TEST_NAME})

target_include_directories(${MBED_GREENTEA_TEST_NAME}
PRIVATE
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 69e3065

Please sign in to comment.