Skip to content

Commit

Permalink
Merge pull request #14902 from LDong-Arm/greentea_skip
Browse files Browse the repository at this point in the history
CMake: tests: Support skipping unsupported test with reason
  • Loading branch information
Patater authored Aug 11, 2021
2 parents 4125fd0 + 6776069 commit e588f80
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 16 deletions.
6 changes: 6 additions & 0 deletions drivers/tests/TESTS/mbed_drivers/ticker/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,17 @@

include(mbed_greentea)

if(NOT "DEVICE_USTICKER=1" IN_LIST MBED_TARGET_DEFINITIONS)
set(TEST_SKIPPED "Microsecond ticker required")
endif()

mbed_greentea_add_test(
TEST_NAME
mbed-drivers-ticker
TEST_SOURCES
main.cpp
HOST_TESTS_DIR
"${CMAKE_CURRENT_LIST_DIR}/../../host_tests"
TEST_SKIPPED
${TEST_SKIPPED}
)
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,8 @@ target_link_libraries(mbed-psa

add_subdirectory(test_abstraction_layers)

if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_TESTING)
if(BUILD_GREENTEA_TESTS)
add_subdirectory(TESTS)
endif()
endif()
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(attestation/test)
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
# Copyright (c) 2021 ARM Limited. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

cmake_minimum_required(VERSION 3.19.0 FATAL_ERROR)
include(mbed_greentea)

set(MBED_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../../ CACHE INTERNAL "")
set(TEST_TARGET mbed-platform-psa-attestation)

include(${MBED_PATH}/tools/cmake/mbed_greentea.cmake)

project(${TEST_TARGET})
if(MBED_GREENTEA_TEST_BAREMETAL)
set(TEST_SKIPPED "RTOS required")
endif()

mbed_greentea_add_test(
TEST_NAME
${TEST_TARGET}
mbed-platform-psa-attestation
TEST_SOURCES
main.cpp
TEST_SKIPPED
${TEST_SKIPPED}
)
48 changes: 40 additions & 8 deletions tools/cmake/mbed_greentea.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,35 @@ endif()
# TEST_SOURCES - Test suite sources
# TEST_REQUIRED_LIBS - Test suite required libraries
# HOST_TESTS_DIR - Path to the "host_tests" directory
# TEST_SKIPPED - Reason if suite is skipped
#
# calling the macro:
# if(MBED_GREENTEA_TEST_BAREMETAL)
# set(skip_reason "RTOS required")
# endif()
# mbed_greentea_add_test(
# TEST_NAME mbed-platform-system-reset
# TEST_INCLUDE_DIRS mbed_store
# TEST_SOURCES foo.cpp bar.cpp
# TEST_REQUIRED_LIBS mbed-kvstore mbed-xyz
# HOST_TESTS_DIR ${CMAKE_CURRENT_LIST_DIR}/host_tests
# TEST_NAME
# mbed-platform-system-reset
# TEST_INCLUDE_DIRS
# mbed_store
# TEST_SOURCES
# foo.cpp
# bar.cpp
# TEST_REQUIRED_LIBS
# mbed-kvstore
# mbed-xyz
# HOST_TESTS_DIR
# ${CMAKE_CURRENT_LIST_DIR}/host_tests
# TEST_SKIPPED
# ${skip_reason}
# )

macro(mbed_greentea_add_test)
function(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 @@ -46,6 +62,22 @@ macro(mbed_greentea_add_test)
${ARGN}
)

if(NOT "${MBED_GREENTEA_TEST_SKIPPED}" STREQUAL "")
add_test(
NAME
${MBED_GREENTEA_TEST_NAME}
COMMAND
${CMAKE_COMMAND} -E echo
"Skipping ${MBED_GREENTEA_TEST_NAME}:"
"${MBED_GREENTEA_TEST_SKIPPED}"
)
set_tests_properties(${MBED_GREENTEA_TEST_NAME}
PROPERTIES
SKIP_REGULAR_EXPRESSION "."
)
return()
endif()

# 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.
Expand Down Expand Up @@ -119,4 +151,4 @@ macro(mbed_greentea_add_test)
set(CMAKE_VERBOSE_MAKEFILE ON)
endif()

endmacro()
endfunction()

0 comments on commit e588f80

Please sign in to comment.