Skip to content

Commit

Permalink
Merge pull request #14892 from rwalton-arm/greentea_ctest
Browse files Browse the repository at this point in the history
Add CTest support for `mbed-drivers-ticker` greentea test
  • Loading branch information
Patater authored Aug 11, 2021
2 parents d4b1534 + 1a7a89a commit 159f832
Show file tree
Hide file tree
Showing 23 changed files with 194 additions and 47 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/greentea_cmake.yml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion .github/workflows/test_building_multiple_executables.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
35 changes: 25 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,17 @@

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)
Expand All @@ -14,17 +25,19 @@ 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)

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)
Expand Down Expand Up @@ -94,10 +107,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
Expand Down
6 changes: 5 additions & 1 deletion connectivity/cellular/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 5 additions & 1 deletion connectivity/lorawan/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 5 additions & 1 deletion connectivity/netsocket/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion drivers/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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_subdirectory(tests/TESTS)
else()
add_subdirectory(tests/UNITTESTS)
endif()
endif()

target_include_directories(mbed-core
Expand Down
4 changes: 4 additions & 0 deletions drivers/tests/TESTS/CMakeLists.txt
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(mbed_drivers/ticker)
13 changes: 4 additions & 9 deletions drivers/tests/TESTS/mbed_drivers/ticker/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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"
)
9 changes: 6 additions & 3 deletions events/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -28,4 +32,3 @@ target_compile_definitions(mbed-events
INTERFACE
MBED_CONF_EVENTS_PRESENT=1
)
endif()
6 changes: 5 additions & 1 deletion hal/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 5 additions & 1 deletion platform/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 5 additions & 1 deletion rtos/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion storage/blockdevice/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 5 additions & 1 deletion storage/filesystem/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 5 additions & 1 deletion storage/kvstore/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 5 additions & 1 deletion storage/kvstore/filesystemstore/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion storage/kvstore/tdbstore/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
8 changes: 8 additions & 0 deletions targets/targets.json
Original file line number Diff line number Diff line change
Expand Up @@ -993,6 +993,10 @@
"GCC_ARM",
"IAR"
],
"supported_application_profiles": [
"full",
"bare-metal"
],
"macros": [
"CPU_MK64FN1M0VMD12",
"FSL_RTOS_MBED",
Expand Down Expand Up @@ -4417,6 +4421,10 @@
"GCC_ARM",
"IAR"
],
"supported_application_profiles": [
"full",
"bare-metal"
],
"extra_labels": [
"NXP",
"MCUXpresso_MCUS",
Expand Down
2 changes: 1 addition & 1 deletion tools/cmake/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/<MBED_TARGET>/<PROFILE>/<TOOLCHAIN>/ && cmake ../../../.. -G Ninja -DMBED_TEST_BAREMETAL=ON && cmake --build .
cd cmake_build/<MBED_TARGET>/<PROFILE>/<TOOLCHAIN>/ && cmake ../../../.. -G Ninja -DMBED_GREENTEA_TEST_BAREMETAL=ON && cmake --build .
```

Notes:
Expand Down
Loading

0 comments on commit 159f832

Please sign in to comment.