From e60ffed6f45cc36ac1fa783d96f53f8268f9d6cc Mon Sep 17 00:00:00 2001 From: Lingkai Dong Date: Fri, 23 Jul 2021 13:27:27 +0100 Subject: [PATCH 1/5] CMake: turn mbed_greentea_add_test() into a function Unlike a macro, a function is more self-contained and can return early if necessary. --- tools/cmake/mbed_greentea.cmake | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/cmake/mbed_greentea.cmake b/tools/cmake/mbed_greentea.cmake index 1541447db4f..5f236d494f5 100644 --- a/tools/cmake/mbed_greentea.cmake +++ b/tools/cmake/mbed_greentea.cmake @@ -30,7 +30,7 @@ endif() # HOST_TESTS_DIR ${CMAKE_CURRENT_LIST_DIR}/host_tests # ) -macro(mbed_greentea_add_test) +function(mbed_greentea_add_test) set(options) set(singleValueArgs TEST_NAME) set(multipleValueArgs @@ -119,4 +119,4 @@ macro(mbed_greentea_add_test) set(CMAKE_VERBOSE_MAKEFILE ON) endif() -endmacro() +endfunction() From 86c00f6b4b46cb751ea802e447514053307f8f02 Mon Sep 17 00:00:00 2001 From: Lingkai Dong Date: Thu, 8 Jul 2021 15:28:08 +0100 Subject: [PATCH 2/5] cmake: Improve indentation of mbed_greentea_add_test doc --- tools/cmake/mbed_greentea.cmake | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/tools/cmake/mbed_greentea.cmake b/tools/cmake/mbed_greentea.cmake index 5f236d494f5..e3fbd123158 100644 --- a/tools/cmake/mbed_greentea.cmake +++ b/tools/cmake/mbed_greentea.cmake @@ -23,11 +23,18 @@ endif() # # calling the macro: # 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 # ) function(mbed_greentea_add_test) From 4917e0154ca37b7e47cc2372fc2f98aec5570b6b Mon Sep 17 00:00:00 2001 From: Lingkai Dong Date: Fri, 9 Jul 2021 12:03:04 +0100 Subject: [PATCH 3/5] 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. --- tools/cmake/mbed_greentea.cmake | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/tools/cmake/mbed_greentea.cmake b/tools/cmake/mbed_greentea.cmake index e3fbd123158..1c4df556938 100644 --- a/tools/cmake/mbed_greentea.cmake +++ b/tools/cmake/mbed_greentea.cmake @@ -20,8 +20,12 @@ 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 @@ -35,11 +39,16 @@ endif() # mbed-xyz # HOST_TESTS_DIR # ${CMAKE_CURRENT_LIST_DIR}/host_tests +# TEST_SKIPPED +# ${skip_reason} # ) function(mbed_greentea_add_test) set(options) - set(singleValueArgs TEST_NAME) + set(singleValueArgs + TEST_NAME + TEST_SKIPPED + ) set(multipleValueArgs TEST_INCLUDE_DIRS TEST_SOURCES @@ -53,6 +62,22 @@ function(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. From d7ef8f857f9f187241f026ce27b834cfd6adc25e Mon Sep 17 00:00:00 2001 From: Lingkai Dong Date: Fri, 23 Jul 2021 14:13:22 +0100 Subject: [PATCH 4/5] CMake: greentea: Add skip reason to ticker test --- drivers/tests/TESTS/mbed_drivers/ticker/CMakeLists.txt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/tests/TESTS/mbed_drivers/ticker/CMakeLists.txt b/drivers/tests/TESTS/mbed_drivers/ticker/CMakeLists.txt index cdc28e4ca19..baf39bc0e58 100644 --- a/drivers/tests/TESTS/mbed_drivers/ticker/CMakeLists.txt +++ b/drivers/tests/TESTS/mbed_drivers/ticker/CMakeLists.txt @@ -3,6 +3,10 @@ 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 @@ -10,4 +14,6 @@ mbed_greentea_add_test( main.cpp HOST_TESTS_DIR "${CMAKE_CURRENT_LIST_DIR}/../../host_tests" + TEST_SKIPPED + ${TEST_SKIPPED} ) From 6776069a1852a50516eee5db157a8b3e158ba18f Mon Sep 17 00:00:00 2001 From: Lingkai Dong Date: Fri, 9 Jul 2021 11:05:51 +0100 Subject: [PATCH 5/5] CMake: greentea: Port PSA Attestation test to CTest The PSA Attestation test suite requires full RTOS. There is no need to explicitly check PSA support, because when we build all greentea tests from the top of Mbed OS, PSA tests only get included if PSA is enabled. --- .../TARGET_MBED_PSA_SRV/CMakeLists.txt | 5 +++++ .../TARGET_MBED_PSA_SRV/TESTS/CMakeLists.txt | 4 ++++ .../TESTS/attestation/test/CMakeLists.txt | 15 +++++++-------- 3 files changed, 16 insertions(+), 8 deletions(-) create mode 100644 platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_MBED_PSA_SRV/TESTS/CMakeLists.txt diff --git a/platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_MBED_PSA_SRV/CMakeLists.txt b/platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_MBED_PSA_SRV/CMakeLists.txt index 7ece49f3734..ab076952547 100644 --- a/platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_MBED_PSA_SRV/CMakeLists.txt +++ b/platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_MBED_PSA_SRV/CMakeLists.txt @@ -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() diff --git a/platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_MBED_PSA_SRV/TESTS/CMakeLists.txt b/platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_MBED_PSA_SRV/TESTS/CMakeLists.txt new file mode 100644 index 00000000000..ae5d6b9f82f --- /dev/null +++ b/platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_MBED_PSA_SRV/TESTS/CMakeLists.txt @@ -0,0 +1,4 @@ +# Copyright (c) 2021 Arm Limited. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +add_subdirectory(attestation/test) diff --git a/platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_MBED_PSA_SRV/TESTS/attestation/test/CMakeLists.txt b/platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_MBED_PSA_SRV/TESTS/attestation/test/CMakeLists.txt index 5d82e086c87..6c3c9487b21 100644 --- a/platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_MBED_PSA_SRV/TESTS/attestation/test/CMakeLists.txt +++ b/platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_MBED_PSA_SRV/TESTS/attestation/test/CMakeLists.txt @@ -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} )