Skip to content

Commit

Permalink
CMake: tests: Support skipping unsupported test with reason
Browse files Browse the repository at this point in the history
Add a new argument `TEST_SKIPPED` to `mbed_greentea_add_test()` to
indicate a test is skip and give a reason (e.g. the test does not
support the target and/or configuration used).

This is achieved with a custom target in place of an executable
while keeping the same target name. The skipping message is printed
at both configuration and build stages.
  • Loading branch information
LDong-Arm committed Jul 14, 2021
1 parent fb77a38 commit 9228210
Showing 1 changed file with 49 additions and 29 deletions.
78 changes: 49 additions & 29 deletions tools/cmake/mbed_greentea.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,12 @@ set(MBED_ROOT ${CMAKE_CURRENT_LIST_DIR}/../.. CACHE INTERNAL "")
# TEST_INCLUDE_DIRS - Test suite include directories for the test
# TEST_SOURCES - Test suite sources
# TEST_REQUIRED_LIBS - Test suite required libraries
# TEST_SKIPPED - Reason if suite is skipped
#
# calling the macro:
# if(MBED_TEST_BAREMETAL)
# set(skip_reason "RTOS required")
# endif()
# mbed_greentea_add_test(
# TEST_NAME
# mbed-platform-system-reset
Expand All @@ -27,11 +31,16 @@ set(MBED_ROOT ${CMAKE_CURRENT_LIST_DIR}/../.. CACHE INTERNAL "")
# TEST_REQUIRED_LIBS
# mbed-kvstore
# mbed-xyz
# TEST_SKIPPED
# ${skip_reason}
# )

macro(mbed_greentea_add_test)
set(options)
set(singleValueArgs TEST_NAME)
set(singleValueArgs
TEST_NAME
TEST_SKIPPED
)
set(multipleValueArgs
TEST_INCLUDE_DIRS
TEST_SOURCES
Expand All @@ -43,42 +52,53 @@ macro(mbed_greentea_add_test)
"${multipleValueArgs}"
${ARGN}
)
add_subdirectory(${MBED_ROOT} build)
if(NOT "${MBED_GREENTEA_TEST_SKIPPED}" STREQUAL "")
set(msg "Skipping ${MBED_GREENTEA_TEST_NAME}: ${MBED_GREENTEA_TEST_SKIPPED}")
message(DEBUG "${msg}")
add_custom_target(${MBED_GREENTEA_TEST_NAME}
ALL
COMMAND ${CMAKE_COMMAND} -E echo ${msg}
)
else()

add_executable(${MBED_GREENTEA_TEST_NAME})
add_subdirectory(${MBED_ROOT} build)

# 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
.
${MBED_GREENTEA_TEST_INCLUDE_DIRS}
)
# Explicitly enable BUILD_TESTING until CTest is added to the Greentea client
set(BUILD_TESTING ON)

target_sources(${MBED_GREENTEA_TEST_NAME}
PRIVATE
${MBED_GREENTEA_TEST_SOURCES}
)
target_include_directories(${MBED_GREENTEA_TEST_NAME}
PRIVATE
.
${MBED_GREENTEA_TEST_INCLUDE_DIRS}
)

if(MBED_TEST_BAREMETAL)
list(APPEND MBED_GREENTEA_TEST_REQUIRED_LIBS mbed-baremetal)
else()
list(APPEND MBED_GREENTEA_TEST_REQUIRED_LIBS mbed-os)
endif()
target_sources(${MBED_GREENTEA_TEST_NAME}
PRIVATE
${MBED_GREENTEA_TEST_SOURCES}
)

list(APPEND MBED_GREENTEA_TEST_REQUIRED_LIBS greentea::client_userio mbed-greentea-io mbed-unity mbed-utest)
if(MBED_TEST_BAREMETAL)
list(APPEND MBED_GREENTEA_TEST_REQUIRED_LIBS mbed-baremetal)
else()
list(APPEND MBED_GREENTEA_TEST_REQUIRED_LIBS mbed-os)
endif()

target_link_libraries(${MBED_GREENTEA_TEST_NAME}
PRIVATE
${MBED_GREENTEA_TEST_REQUIRED_LIBS}
)
list(APPEND MBED_GREENTEA_TEST_REQUIRED_LIBS greentea::client_userio mbed-greentea-io mbed-unity mbed-utest)

target_link_libraries(${MBED_GREENTEA_TEST_NAME}
PRIVATE
${MBED_GREENTEA_TEST_REQUIRED_LIBS}
)

mbed_set_post_build(${MBED_GREENTEA_TEST_NAME})

mbed_set_post_build(${MBED_GREENTEA_TEST_NAME})
option(VERBOSE_BUILD "Have a verbose build process")
if(VERBOSE_BUILD)
set(CMAKE_VERBOSE_MAKEFILE ON)
endif()

option(VERBOSE_BUILD "Have a verbose build process")
if(VERBOSE_BUILD)
set(CMAKE_VERBOSE_MAKEFILE ON)
endif()
endif() # NOT MBED_GREENTEA_TEST_SKIPPED

endmacro()

0 comments on commit 9228210

Please sign in to comment.