From 7842320ab715e63e7069aca1d49f318af8e404ea Mon Sep 17 00:00:00 2001 From: Robert Walton Date: Wed, 7 Jul 2021 17:10:04 +0100 Subject: [PATCH 1/8] CMake: Add option to enable greentea tests Add an option to enable the greentea tests independently from the unit tests. We can't just use the typical BUILD_TESTING option to enable greentea tests. BUILD_TESTING enables unit tests and fetches googletest, which are compiled for the host. Greentea tests are cross compiled and require a toolchain file. For this reason we add a new option just to enable greentea tests, preventing build failures triggered by the unit tests and googletest. --- CMakeLists.txt | 24 ++++++++++++------- connectivity/cellular/CMakeLists.txt | 6 ++++- connectivity/lorawan/CMakeLists.txt | 6 ++++- connectivity/netsocket/CMakeLists.txt | 6 ++++- drivers/CMakeLists.txt | 6 ++++- events/CMakeLists.txt | 9 ++++--- hal/CMakeLists.txt | 6 ++++- platform/CMakeLists.txt | 6 ++++- rtos/CMakeLists.txt | 6 ++++- storage/blockdevice/CMakeLists.txt | 6 ++++- storage/filesystem/CMakeLists.txt | 6 ++++- storage/kvstore/CMakeLists.txt | 6 ++++- .../kvstore/filesystemstore/CMakeLists.txt | 6 ++++- storage/kvstore/tdbstore/CMakeLists.txt | 6 ++++- 14 files changed, 81 insertions(+), 24 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e91ccf6388b..afb153ad4a7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,6 +5,8 @@ cmake_minimum_required(VERSION 3.19.0 FATAL_ERROR) +option(BUILD_GREENTEA_TESTS "Build greentea tests only." OFF) + if(${CMAKE_CROSSCOMPILING}) include(${MBED_CONFIG_PATH}/mbed_config.cmake) include(mbed_set_linker_script) @@ -19,12 +21,14 @@ list(APPEND CMAKE_MODULE_PATH add_subdirectory(extern) -option(BUILD_TESTING "Run unit tests only." OFF) - -if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_TESTING) +if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) include(CTest) - add_definitions(-DUNITTEST) - add_subdirectory(UNITTESTS) + + if((NOT BUILD_GREENTEA_TESTS) AND BUILD_TESTING) + # Building unit tests only. + add_definitions(-DUNITTEST) + add_subdirectory(UNITTESTS) + endif() endif() add_library(mbed-core INTERFACE) @@ -94,10 +98,12 @@ if(${CMAKE_CROSSCOMPILING}) # Add MBED_TEST_MODE for backward compatibility with Greentea tests written for use with Mbed CLI 1 if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_TESTING) - target_compile_definitions(${PROJECT_NAME} - INTERFACE - MBED_TEST_MODE - ) + if(NOT BUILD_GREENTEA_TESTS) + target_compile_definitions(${PROJECT_NAME} + INTERFACE + MBED_TEST_MODE + ) + endif() endif() # We need to generate a "response file" to pass to the C preprocessor when we preprocess the linker diff --git a/connectivity/cellular/CMakeLists.txt b/connectivity/cellular/CMakeLists.txt index d7ce11f90d4..1c87aedf697 100644 --- a/connectivity/cellular/CMakeLists.txt +++ b/connectivity/cellular/CMakeLists.txt @@ -2,7 +2,11 @@ # SPDX-License-Identifier: Apache-2.0 if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_TESTING) - add_subdirectory(tests/UNITTESTS) + if(BUILD_GREENTEA_TESTS) + # add greentea test + else() + add_subdirectory(tests/UNITTESTS) + endif() endif() add_subdirectory(source/framework) diff --git a/connectivity/lorawan/CMakeLists.txt b/connectivity/lorawan/CMakeLists.txt index 941b01e04e5..d30bdacfbce 100644 --- a/connectivity/lorawan/CMakeLists.txt +++ b/connectivity/lorawan/CMakeLists.txt @@ -2,7 +2,11 @@ # SPDX-License-Identifier: Apache-2.0 if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_TESTING) - add_subdirectory(tests/UNITTESTS) + if(BUILD_GREENTEA_TESTS) + # add greentea test + else() + add_subdirectory(tests/UNITTESTS) + endif() endif() add_subdirectory(lorastack) diff --git a/connectivity/netsocket/CMakeLists.txt b/connectivity/netsocket/CMakeLists.txt index 62bea8cc636..9760c60316d 100644 --- a/connectivity/netsocket/CMakeLists.txt +++ b/connectivity/netsocket/CMakeLists.txt @@ -2,7 +2,11 @@ # SPDX-License-Identifier: Apache-2.0 if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_TESTING) - add_subdirectory(tests/UNITTESTS) + if(BUILD_GREENTEA_TESTS) + # add greentea test + else() + add_subdirectory(tests/UNITTESTS) + endif() endif() # TODO CMake: Perhaps move this/these file(s) into connectivity/drivers/cellular diff --git a/drivers/CMakeLists.txt b/drivers/CMakeLists.txt index 9079d3d75ac..ad62808a457 100644 --- a/drivers/CMakeLists.txt +++ b/drivers/CMakeLists.txt @@ -2,7 +2,11 @@ # SPDX-License-Identifier: Apache-2.0 if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_TESTING) - add_subdirectory(tests/UNITTESTS) + if(BUILD_GREENTEA_TESTS) + # add greentea test + else() + add_subdirectory(tests/UNITTESTS) + endif() endif() target_include_directories(mbed-core diff --git a/events/CMakeLists.txt b/events/CMakeLists.txt index da4d6935112..6e7a6c6bda9 100644 --- a/events/CMakeLists.txt +++ b/events/CMakeLists.txt @@ -2,8 +2,12 @@ # SPDX-License-Identifier: Apache-2.0 if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_TESTING) - add_subdirectory(tests/UNITTESTS) -else() + if(BUILD_GREENTEA_TESTS) + # add greentea test + else() + add_subdirectory(tests/UNITTESTS) + endif() +endif() add_library(mbed-events INTERFACE) @@ -28,4 +32,3 @@ target_compile_definitions(mbed-events INTERFACE MBED_CONF_EVENTS_PRESENT=1 ) -endif() diff --git a/hal/CMakeLists.txt b/hal/CMakeLists.txt index 87f88bef6f7..3af169e0f16 100644 --- a/hal/CMakeLists.txt +++ b/hal/CMakeLists.txt @@ -2,7 +2,11 @@ # SPDX-License-Identifier: Apache-2.0 if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_TESTING) - add_subdirectory(tests/UNITTESTS) + if(BUILD_GREENTEA_TESTS) + # add greentea test + else() + add_subdirectory(tests/UNITTESTS) + endif() endif() add_subdirectory(TARGET_FLASH_CMSIS_ALGO EXCLUDE_FROM_ALL) diff --git a/platform/CMakeLists.txt b/platform/CMakeLists.txt index df83719fc69..4be54141b6e 100644 --- a/platform/CMakeLists.txt +++ b/platform/CMakeLists.txt @@ -2,7 +2,11 @@ # SPDX-License-Identifier: Apache-2.0 if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_TESTING) - add_subdirectory(tests/UNITTESTS) + if(BUILD_GREENTEA_TESTS) + # add greentea test + else() + add_subdirectory(tests/UNITTESTS) + endif() endif() # List of all optional platform libraries available. diff --git a/rtos/CMakeLists.txt b/rtos/CMakeLists.txt index ab9d3082ea9..8af23d87054 100644 --- a/rtos/CMakeLists.txt +++ b/rtos/CMakeLists.txt @@ -2,7 +2,11 @@ # SPDX-License-Identifier: Apache-2.0 if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_TESTING) - add_subdirectory(tests/UNITTESTS) + if(BUILD_GREENTEA_TESTS) + # add greentea test + else() + add_subdirectory(tests/UNITTESTS) + endif() endif() target_include_directories(mbed-core diff --git a/storage/blockdevice/CMakeLists.txt b/storage/blockdevice/CMakeLists.txt index 9f847d43604..6b03244aebd 100644 --- a/storage/blockdevice/CMakeLists.txt +++ b/storage/blockdevice/CMakeLists.txt @@ -2,7 +2,11 @@ # SPDX-License-Identifier: Apache-2.0 if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_TESTING) - add_subdirectory(tests/UNITTESTS) + if(BUILD_GREENTEA_TESTS) + # add greentea test + else() + add_subdirectory(tests/UNITTESTS) + endif() endif() if("DATAFLASH" IN_LIST MBED_TARGET_LABELS) diff --git a/storage/filesystem/CMakeLists.txt b/storage/filesystem/CMakeLists.txt index cacd4232086..5d6fca3ec57 100644 --- a/storage/filesystem/CMakeLists.txt +++ b/storage/filesystem/CMakeLists.txt @@ -2,7 +2,11 @@ # SPDX-License-Identifier: Apache-2.0 if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_TESTING) - add_subdirectory(tests/UNITTESTS) + if(BUILD_GREENTEA_TESTS) + # add greentea test + else() + add_subdirectory(tests/UNITTESTS) + endif() endif() add_subdirectory(fat) diff --git a/storage/kvstore/CMakeLists.txt b/storage/kvstore/CMakeLists.txt index 3f9f137edb4..1d0feeef628 100644 --- a/storage/kvstore/CMakeLists.txt +++ b/storage/kvstore/CMakeLists.txt @@ -2,7 +2,11 @@ # SPDX-License-Identifier: Apache-2.0 if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_TESTING) - add_subdirectory(tests/UNITTESTS) + if(BUILD_GREENTEA_TESTS) + # add greentea test + else() + add_subdirectory(tests/UNITTESTS) + endif() endif() add_subdirectory(tdbstore) diff --git a/storage/kvstore/filesystemstore/CMakeLists.txt b/storage/kvstore/filesystemstore/CMakeLists.txt index 7289fe8b8df..49b2d344d7f 100644 --- a/storage/kvstore/filesystemstore/CMakeLists.txt +++ b/storage/kvstore/filesystemstore/CMakeLists.txt @@ -2,7 +2,11 @@ # SPDX-License-Identifier: Apache-2.0 if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_TESTING) - add_subdirectory(tests/UNITTESTS) + if(BUILD_GREENTEA_TESTS) + # add greentea test + else() + add_subdirectory(tests/UNITTESTS) + endif() endif() target_include_directories(mbed-storage-filesystemstore diff --git a/storage/kvstore/tdbstore/CMakeLists.txt b/storage/kvstore/tdbstore/CMakeLists.txt index d4f8d92ed59..82cd283761b 100644 --- a/storage/kvstore/tdbstore/CMakeLists.txt +++ b/storage/kvstore/tdbstore/CMakeLists.txt @@ -2,7 +2,11 @@ # SPDX-License-Identifier: Apache-2.0 if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_TESTING) - add_subdirectory(tests/UNITTESTS) + if(BUILD_GREENTEA_TESTS) + # add greentea test + else() + add_subdirectory(tests/UNITTESTS) + endif() endif() target_include_directories(mbed-storage-tdbstore From 2a12566c704a9e195756e8be4b6930e9014d6b86 Mon Sep 17 00:00:00 2001 From: Robert Walton Date: Wed, 7 Jul 2021 17:17:14 +0100 Subject: [PATCH 2/8] CMake: greentea: Set variables usually defined by external apps We rely on external applications to set MBED_CONFIG_PATH and include app.cmake. Mbed OS can't build for a target without those parameters set. When building greentea tests there is no external application. So, we define the appropriate settings in our root CMakeLists.txt for greentea tests. --- CMakeLists.txt | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index afb153ad4a7..ea364a105f5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,6 +7,15 @@ cmake_minimum_required(VERSION 3.19.0 FATAL_ERROR) option(BUILD_GREENTEA_TESTS "Build greentea tests only." OFF) +if(BUILD_GREENTEA_TESTS) + # Usually we rely on the application to set MBED_CONFIG_PATH and include + # app.cmake. They are both required if we're building an application to run + # on an mbed-target. + set(MBED_CONFIG_PATH ${CMAKE_CURRENT_BINARY_DIR} CACHE STRING "") + # TODO: Remove when https://github.com/ARMmbed/mbed-os/issues/14518 is fixed + include(${CMAKE_CURRENT_LIST_DIR}/tools/cmake/app.cmake) +endif() + if(${CMAKE_CROSSCOMPILING}) include(${MBED_CONFIG_PATH}/mbed_config.cmake) include(mbed_set_linker_script) From 40154ee2b1e256c3e39c92ab950a15a44bb3724d Mon Sep 17 00:00:00 2001 From: Robert Walton Date: Wed, 7 Jul 2021 17:39:36 +0100 Subject: [PATCH 3/8] CMake: greentea: Port mbed-drivers-ticker to CTest Call add_test in mbed_greentea_add_test and specify mbedhtrun as the command to run. An 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. We automate passing some of the htrun arguments in CMake using data provided by mbed_config.cmake or gathered from the CMake environment. The following arguments are passed to htrun from CMake: * -f/--image-path * -e/--enum-host-tests * -m/--micro * -R/--reset-timeout --baud-rate is also passed if the MBED_CONF_PLATFORM_STDIO_BAUD_RATE config parameter is defined. 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. These checks should be removed after we make all greentea tests runnable by CTest. --- drivers/CMakeLists.txt | 2 +- drivers/tests/TESTS/CMakeLists.txt | 4 ++ .../TESTS/mbed_drivers/ticker/CMakeLists.txt | 13 ++--- tools/cmake/mbed_greentea.cmake | 58 ++++++++++++++++--- 4 files changed, 60 insertions(+), 17 deletions(-) create mode 100644 drivers/tests/TESTS/CMakeLists.txt diff --git a/drivers/CMakeLists.txt b/drivers/CMakeLists.txt index ad62808a457..256ff5b5584 100644 --- a/drivers/CMakeLists.txt +++ b/drivers/CMakeLists.txt @@ -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() diff --git a/drivers/tests/TESTS/CMakeLists.txt b/drivers/tests/TESTS/CMakeLists.txt new file mode 100644 index 00000000000..ec9280fee98 --- /dev/null +++ b/drivers/tests/TESTS/CMakeLists.txt @@ -0,0 +1,4 @@ +# Copyright (c) 2021 ARM Limited. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +add_subdirectory(mbed_drivers/ticker) diff --git a/drivers/tests/TESTS/mbed_drivers/ticker/CMakeLists.txt b/drivers/tests/TESTS/mbed_drivers/ticker/CMakeLists.txt index 6aed7b9a70b..cdc28e4ca19 100644 --- a/drivers/tests/TESTS/mbed_drivers/ticker/CMakeLists.txt +++ b/drivers/tests/TESTS/mbed_drivers/ticker/CMakeLists.txt @@ -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" ) diff --git a/tools/cmake/mbed_greentea.cmake b/tools/cmake/mbed_greentea.cmake index ffe73ed0f11..27c27c4c7d3 100644 --- a/tools/cmake/mbed_greentea.cmake +++ b/tools/cmake/mbed_greentea.cmake @@ -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: @@ -14,6 +19,7 @@ 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 +# HOST_TESTS_DIR - Path to the "host_tests" directory # # calling the macro: # mbed_greentea_add_test( @@ -21,6 +27,7 @@ set(MBED_ROOT ${CMAKE_CURRENT_LIST_DIR}/../.. CACHE INTERNAL "") # 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 # ) macro(mbed_greentea_add_test) @@ -30,6 +37,7 @@ macro(mbed_greentea_add_test) TEST_INCLUDE_DIRS TEST_SOURCES TEST_REQUIRED_LIBS + HOST_TESTS_DIR ) cmake_parse_arguments(MBED_GREENTEA "${options}" @@ -37,12 +45,15 @@ macro(mbed_greentea_add_test) "${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 @@ -70,6 +81,39 @@ 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() + + if(NOT "${MBED_GREENTEA_TEST_RESET_TIMEOUT}" STREQUAL "") + list(APPEND MBED_HTRUN_ARGUMENTS "-R;${MBED_GREENTEA_TEST_RESET_TIMEOUT}") + 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) From 00dbf4c71d23e7c861e514a48a7c08f00fbfa34e Mon Sep 17 00:00:00 2001 From: Robert Walton Date: Wed, 7 Jul 2021 17:56:36 +0100 Subject: [PATCH 4/8] CMake: greentea: Use more specific name for baremetal option Make it obvious the option is used for greentea tests. --- tools/cmake/README.md | 2 +- tools/cmake/mbed_greentea.cmake | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/cmake/README.md b/tools/cmake/README.md index 50ef9531d35..7ae8223dc59 100644 --- a/tools/cmake/README.md +++ b/tools/cmake/README.md @@ -97,7 +97,7 @@ Install prerequisites suggested in the previous section and follow the below ste ``` Or build the test binary with the baremetal profile ``` - cd cmake_build//// && cmake ../../../.. -G Ninja -DMBED_TEST_BAREMETAL=ON && cmake --build . + cd cmake_build//// && cmake ../../../.. -G Ninja -DMBED_GREENTEA_TEST_BAREMETAL=ON && cmake --build . ``` Notes: diff --git a/tools/cmake/mbed_greentea.cmake b/tools/cmake/mbed_greentea.cmake index 27c27c4c7d3..1541447db4f 100644 --- a/tools/cmake/mbed_greentea.cmake +++ b/tools/cmake/mbed_greentea.cmake @@ -1,7 +1,7 @@ # Copyright (c) 2020-2021 ARM Limited. All rights reserved. # SPDX-License-Identifier: Apache-2.0 -option(MBED_TEST_BAREMETAL OFF) +option(MBED_GREENTEA_TEST_BAREMETAL "Select baremetal greentea tests" OFF) set(MBED_HTRUN_ARGUMENTS "" CACHE STRING "Argument list to forward to htrun.") @@ -66,7 +66,7 @@ macro(mbed_greentea_add_test) ${MBED_GREENTEA_TEST_SOURCES} ) - if(MBED_TEST_BAREMETAL) + if(MBED_GREENTEA_TEST_BAREMETAL) list(APPEND MBED_GREENTEA_TEST_REQUIRED_LIBS mbed-baremetal) else() list(APPEND MBED_GREENTEA_TEST_REQUIRED_LIBS mbed-os) From 1dda219d3c103bb865579b54a576c6080d7f7fac Mon Sep 17 00:00:00 2001 From: Robert Walton Date: Fri, 30 Jul 2021 11:38:47 +0100 Subject: [PATCH 5/8] ci: Add github action to build greentea tests with cmake Build for two targets, one with baremetal profile and one full profile. --- .github/workflows/greentea_cmake.yml | 30 ++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 .github/workflows/greentea_cmake.yml diff --git a/.github/workflows/greentea_cmake.yml b/.github/workflows/greentea_cmake.yml new file mode 100644 index 00000000000..f98921a196c --- /dev/null +++ b/.github/workflows/greentea_cmake.yml @@ -0,0 +1,30 @@ +name: test building greentea tests with cmake + +on: [pull_request] + +jobs: + build-greentea-cmake: + runs-on: ubuntu-latest + container: ghcr.io/armmbed/mbed-os-env:master-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Install the latest mbed-tools + run: | + pip3 install --upgrade mbed-tools + mbedtools --version + + - name: Build NUCLEO_G031K8 with baremetal profile + run: | + rm -rf __build + mbedtools configure -t GCC_ARM -m NUCLEO_G031K8 --mbed-os-path . --output-dir __build --app-config TESTS/configs/baremetal.json + cmake -S . -B __build -GNinja -DCMAKE_CTEST_ARGUMENTS="--output-on-failure;-V" -DBUILD_GREENTEA_TESTS=ON -DMBED_GREENTEA_TEST_BAREMETAL=ON + cmake --build __build + + - name: Build ARM_MUSCA_S1 with full profile + run: | + rm -rf __build + mbedtools configure -t GCC_ARM -m ARM_MUSCA_S1 --mbed-os-path . --output-dir __build + cmake -S . -B __build -GNinja -DCMAKE_CTEST_ARGUMENTS="--output-on-failure;-V" -DBUILD_GREENTEA_TESTS=ON + cmake --build __build From cfc68a0918e094f246c88aaa0f4a1c9a2c536bce Mon Sep 17 00:00:00 2001 From: Robert Walton Date: Fri, 30 Jul 2021 16:01:22 +0100 Subject: [PATCH 6/8] CMake: Use CMAKE_MODULE_PATH to locate nuvoton post build hook We were previously relying on the global MBED_PATH variable to provide the root for the include path to the post build hooks. We can't guarantee that MBED_PATH will be set by any application building us, so use CMAKE_MODULE_PATH (which we always set) like we do for the other post-build hooks. --- CMakeLists.txt | 2 +- .../TARGET_NU_M2354/COMPONENT_TFM_S_FW/CMakeLists.txt | 2 +- .../TARGET_NUVOTON/scripts/mbed_set_post_build_nuvoton.cmake | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ea364a105f5..18a926ccb57 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,7 +25,7 @@ project(mbed-os) # Add all paths to the list files within Mbed OS list(APPEND CMAKE_MODULE_PATH - "${mbed-os_SOURCE_DIR}/platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_LATEST/scripts;${mbed-os_SOURCE_DIR}/targets/TARGET_Cypress/scripts;${mbed-os_SOURCE_DIR}/targets/TARGET_NXP/scripts" + "${mbed-os_SOURCE_DIR}/platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_LATEST/scripts;${mbed-os_SOURCE_DIR}/targets/TARGET_Cypress/scripts;${mbed-os_SOURCE_DIR}/targets/TARGET_NXP/scripts;${mbed-os_SOURCE_DIR}/targets/TARGET_NUVOTON/scripts/" ) add_subdirectory(extern) diff --git a/targets/TARGET_NUVOTON/TARGET_M2354/TARGET_TFM/TARGET_NU_M2354/COMPONENT_TFM_S_FW/CMakeLists.txt b/targets/TARGET_NUVOTON/TARGET_M2354/TARGET_TFM/TARGET_NU_M2354/COMPONENT_TFM_S_FW/CMakeLists.txt index 03127cc5a5d..01ead3cced7 100644 --- a/targets/TARGET_NUVOTON/TARGET_M2354/TARGET_TFM/TARGET_NU_M2354/COMPONENT_TFM_S_FW/CMakeLists.txt +++ b/targets/TARGET_NUVOTON/TARGET_M2354/TARGET_TFM/TARGET_NU_M2354/COMPONENT_TFM_S_FW/CMakeLists.txt @@ -1,7 +1,7 @@ # Copyright (c) 2020-2021 ARM Limited. All rights reserved. # SPDX-License-Identifier: Apache-2.0 -include(${MBED_PATH}/targets/TARGET_NUVOTON/scripts/mbed_set_post_build_nuvoton.cmake) +include(mbed_set_post_build_nuvoton) target_link_libraries(mbed-m2354-tfm INTERFACE diff --git a/targets/TARGET_NUVOTON/scripts/mbed_set_post_build_nuvoton.cmake b/targets/TARGET_NUVOTON/scripts/mbed_set_post_build_nuvoton.cmake index 9f7a3cb9c9c..d0340a53b03 100644 --- a/targets/TARGET_NUVOTON/scripts/mbed_set_post_build_nuvoton.cmake +++ b/targets/TARGET_NUVOTON/scripts/mbed_set_post_build_nuvoton.cmake @@ -1,7 +1,7 @@ # Copyright (c) 2021 ARM Limited. All rights reserved. # SPDX-License-Identifier: Apache-2.0 -include(${MBED_PATH}/tools/cmake/mbed_set_post_build.cmake) +include(mbed_set_post_build) # # Sign TF-M secure and non-secure images and combine them with the bootloader From a437ed4047afdd427a8c7493ffe14887c0b420cd Mon Sep 17 00:00:00 2001 From: Robert Walton Date: Fri, 30 Jul 2021 16:04:06 +0100 Subject: [PATCH 7/8] targets: Add "bare-metal" to supported_application_profiles We weren't setting the "supported_application_profiles" correctly for some baremetal supported targets. This didn't cause build failures with mbed-cli 1 as it just seems to ignore this config parameter. In our CMake build system we have added a hard dependency on the supported_application_profiles; we fail the build if the profile we're trying to build isn't in the list. --- targets/targets.json | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/targets/targets.json b/targets/targets.json index 55d9c35a592..a54bdc64da0 100644 --- a/targets/targets.json +++ b/targets/targets.json @@ -993,6 +993,10 @@ "GCC_ARM", "IAR" ], + "supported_application_profiles": [ + "full", + "bare-metal" + ], "macros": [ "CPU_MK64FN1M0VMD12", "FSL_RTOS_MBED", @@ -4417,6 +4421,10 @@ "GCC_ARM", "IAR" ], + "supported_application_profiles": [ + "full", + "bare-metal" + ], "extra_labels": [ "NXP", "MCUXpresso_MCUS", From 1a7a89a8ed1798179e9350d867adbeb930041808 Mon Sep 17 00:00:00 2001 From: Robert Walton Date: Wed, 11 Aug 2021 10:13:36 +0100 Subject: [PATCH 8/8] ci: Use new mbed-os-env docker image in "multiple executables" test The github workflow to test building multiple executables was using the soon to be deprecated docker image "mbedos/mbed-os-env:latest". This commit points it at the new docker image on ghcr.io. --- .github/workflows/test_building_multiple_executables.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test_building_multiple_executables.yml b/.github/workflows/test_building_multiple_executables.yml index 7e3f64595d9..09d3a5abd81 100644 --- a/.github/workflows/test_building_multiple_executables.yml +++ b/.github/workflows/test_building_multiple_executables.yml @@ -5,7 +5,7 @@ on: [pull_request] jobs: multiple-executables-example: runs-on: ubuntu-latest - container: mbedos/mbed-os-env:latest + container: ghcr.io/armmbed/mbed-os-env:master-latest steps: - name: Checkout uses: actions/checkout@v2