Skip to content

Commit 4917e01

Browse files
committed
CMake: tests: Support skipping a test with a reason
Add a new argument `TEST_SKIPPED` to `mbed_greentea_add_test()` to indicate a test is skipped and give a reason (e.g. the Mbed target and/or configuration does not provide what the test requires). The skip reason of a test is printed when running tests with `ctest`, and the test is marked as "Skipped" in the test report.
1 parent 86c00f6 commit 4917e01

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

tools/cmake/mbed_greentea.cmake

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,12 @@ endif()
2020
# TEST_SOURCES - Test suite sources
2121
# TEST_REQUIRED_LIBS - Test suite required libraries
2222
# HOST_TESTS_DIR - Path to the "host_tests" directory
23+
# TEST_SKIPPED - Reason if suite is skipped
2324
#
2425
# calling the macro:
26+
# if(MBED_GREENTEA_TEST_BAREMETAL)
27+
# set(skip_reason "RTOS required")
28+
# endif()
2529
# mbed_greentea_add_test(
2630
# TEST_NAME
2731
# mbed-platform-system-reset
@@ -35,11 +39,16 @@ endif()
3539
# mbed-xyz
3640
# HOST_TESTS_DIR
3741
# ${CMAKE_CURRENT_LIST_DIR}/host_tests
42+
# TEST_SKIPPED
43+
# ${skip_reason}
3844
# )
3945

4046
function(mbed_greentea_add_test)
4147
set(options)
42-
set(singleValueArgs TEST_NAME)
48+
set(singleValueArgs
49+
TEST_NAME
50+
TEST_SKIPPED
51+
)
4352
set(multipleValueArgs
4453
TEST_INCLUDE_DIRS
4554
TEST_SOURCES
@@ -53,6 +62,22 @@ function(mbed_greentea_add_test)
5362
${ARGN}
5463
)
5564

65+
if(NOT "${MBED_GREENTEA_TEST_SKIPPED}" STREQUAL "")
66+
add_test(
67+
NAME
68+
${MBED_GREENTEA_TEST_NAME}
69+
COMMAND
70+
${CMAKE_COMMAND} -E echo
71+
"Skipping ${MBED_GREENTEA_TEST_NAME}:"
72+
"${MBED_GREENTEA_TEST_SKIPPED}"
73+
)
74+
set_tests_properties(${MBED_GREENTEA_TEST_NAME}
75+
PROPERTIES
76+
SKIP_REGULAR_EXPRESSION "."
77+
)
78+
return()
79+
endif()
80+
5681
# TODO: After we convert all greentea tests to use CTest, remove this
5782
# add_subdirectory call. We will attach the tests to the mbed-os project,
5883
# rather than creating a new project for each test that depends on mbed-os.

0 commit comments

Comments
 (0)