Rename inconsistently named testing-related variables. Also fix STM32CUBE not working from application code.

pull/15339/head
Jamie Smith 2022-06-12 22:45:18 -07:00 committed by Jay Sridharan
parent ae64b05c15
commit 69c1d4a55a
29 changed files with 75 additions and 76 deletions

View File

@ -229,6 +229,6 @@ jobs:
name: cmake unittest
run: |
set -x
ctest --build-and-test . build --build-generator Ninja --build-options -DBUILD_TESTING=ON -DCMAKE_BUILD_TYPE=Debug -DCOVERAGE=ON --test-command ctest
ctest --build-and-test . build --build-generator Ninja --build-options -DMBED_ENABLE_TESTING=ON -DCMAKE_BUILD_TYPE=Debug -DCOVERAGE=ON --test-command ctest
gcovr --gcov-executable gcov -r . ./build -s -e ".*\.h" --exclude-directories=${GITHUB_WORKSPACE}/build/UNITTESTS --exclude-directories=${GITHUB_WORKSPACE}/build/_deps
ccache -s

View File

@ -19,12 +19,12 @@ jobs:
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 -S . -B __build -GNinja -DCMAKE_CTEST_ARGUMENTS="--output-on-failure;-V" -DMBED_BUILD_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 -S . -B __build -GNinja -DCMAKE_CTEST_ARGUMENTS="--output-on-failure;-V" -DMBED_BUILD_GREENTEA_TESTS=ON
cmake --build __build

View File

@ -15,6 +15,6 @@ jobs:
- name: Compile and test for host
run: |
mkdir __build && cd __build
cmake .. -GNinja -DBUILD_GREENTEA_TESTS=FALSE -DBUILD_TESTING=TRUE
cmake .. -GNinja -DMBED_BUILD_GREENTEA_TESTS=FALSE -DMBED_ENABLE_TESTING=TRUE
ninja
ctest . --output-on-failure

View File

@ -20,7 +20,7 @@ extraction:
- cmake --version
configure:
command:
- cmake -S . -B __build -GNinja -DBUILD_TESTING=ON -DCOVERAGE=OFF -DCMAKE_BUILD_TYPE=Debug
- cmake -S . -B __build -GNinja -DMBED_ENABLE_TESTING=ON -DCOVERAGE=OFF -DCMAKE_BUILD_TYPE=Debug
index:
build_command:
- cmake --build __build

View File

@ -8,32 +8,32 @@ cmake_policy(VERSION 3.16...3.22)
# Setup build type (target type, tests/unit tests/real build) ----------------------------------------------------------------------------------
# This block sets up the following variables for all subdirs to use:
# - MBED_OS_IS_STANDALONE: True if Mbed OS is the top-level project. False if Mbed is being built as part of an application.
# - MBED_IS_STANDALONE: True if Mbed OS is the top-level project. False if Mbed is being built as part of an application.
# - MBED_IS_NATIVE_BUILD: True if we are building for the host machine. False if we are building for a microcontroller
# - MBED_OS_ENABLE_TESTS: True if we are building *any* internal Mbed OS tests at all. Enabled by -DBUILD_TESTING=TRUE (which is enabled by default when standalone).
# - BUILD_GREENTEA_TESTS: True to build greentea on-target tests. False to build host UNITTESTS. Defaults to false when standalone.
# - MBED_ENABLE_OS_INTERNAL_TESTS: True if we are building *any* internal Mbed OS tests at all. Enabled by -DMBED_ENABLE_TESTING=TRUE (which is enabled by default when standalone).
# - MBED_BUILD_GREENTEA_TESTS: True to build greentea on-target tests. False to build host UNITTESTS. Defaults to false when standalone.
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
# We are the top level project, so tests or unittests are being built.
set(MBED_OS_IS_STANDALONE TRUE)
set(MBED_IS_STANDALONE TRUE)
else()
# Not the top level project
set(MBED_OS_IS_STANDALONE FALSE)
set(MBED_IS_STANDALONE FALSE)
endif()
# Set up options for testing
option(BUILD_TESTING "Whether to enable CTest tests in this project" ${MBED_OS_IS_STANDALONE}) # This option is also created by include(CTest) but we need it here earlier on.
if(MBED_OS_IS_STANDALONE AND BUILD_TESTING)
set(MBED_OS_ENABLE_TESTS TRUE)
option(BUILD_GREENTEA_TESTS "Build greentea tests instead of unit tests" FALSE)
option(MBED_ENABLE_TESTING "Whether to enable CTest tests in this project" ${MBED_IS_STANDALONE}) # This option is also created by include(CTest) but we need it here earlier on.
if(MBED_IS_STANDALONE AND MBED_ENABLE_TESTING)
set(MBED_ENABLE_OS_INTERNAL_TESTS TRUE)
option(MBED_BUILD_GREENTEA_TESTS "Build greentea tests instead of unit tests" FALSE)
endif()
# Figure out if this is a native build
if(MBED_OS_IS_STANDALONE)
if(MBED_IS_STANDALONE)
# Standalone build, use BUILD_GREENTEA_TESTS to determine if we are building for native or not (user can select)
if(BUILD_GREENTEA_TESTS)
# Standalone build, use MBED_BUILD_GREENTEA_TESTS to determine if we are building for native or not (user can select)
if(MBED_BUILD_GREENTEA_TESTS)
set(MBED_IS_NATIVE_BUILD FALSE)
else()
set(MBED_IS_NATIVE_BUILD TRUE)
@ -51,7 +51,7 @@ else()
endif()
if(MBED_OS_IS_STANDALONE AND NOT MBED_IS_NATIVE_BUILD)
if(MBED_IS_STANDALONE AND NOT MBED_IS_NATIVE_BUILD)
# For standalone builds, default to looking for mbed-config.cmake in the binary dir
set(MBED_CONFIG_PATH ${CMAKE_CURRENT_BINARY_DIR} CACHE STRING "")
@ -70,8 +70,8 @@ else()
endif()
# Print build type
if(MBED_OS_ENABLE_TESTS)
if(BUILD_GREENTEA_TESTS)
if(MBED_ENABLE_OS_INTERNAL_TESTS)
if(MBED_BUILD_GREENTEA_TESTS)
message(STATUS "Mbed: Compiling Greentea on-target tests for ${MBED_TARGET}")
else()
message(STATUS "Mbed: Compiling host UNITTESTS for native execution")
@ -101,17 +101,17 @@ list(APPEND CMAKE_MODULE_PATH
add_subdirectory(extern)
if(MBED_OS_IS_STANDALONE)
include(CTest)
if((NOT BUILD_GREENTEA_TESTS) AND BUILD_TESTING)
if(MBED_IS_STANDALONE)
if((NOT MBED_BUILD_GREENTEA_TESTS) AND MBED_ENABLE_TESTING)
# Building unit tests only.
add_definitions(-DUNITTEST)
add_subdirectory(UNITTESTS)
endif()
endif()
if(BUILD_GREENTEA_TESTS)
if(MBED_ENABLE_TESTING)
include(CTest)
include(mbed_greentea)
endif()
@ -172,8 +172,8 @@ if(NOT MBED_IS_NATIVE_BUILD)
)
# Add MBED_TEST_MODE for backward compatibility with Greentea tests written for use with Mbed CLI 1
if(MBED_OS_ENABLE_TESTS)
if(NOT BUILD_GREENTEA_TESTS)
if(MBED_ENABLE_OS_INTERNAL_TESTS)
if(NOT MBED_BUILD_GREENTEA_TESTS)
target_compile_definitions(${PROJECT_NAME}
INTERFACE
MBED_TEST_MODE

View File

@ -86,7 +86,7 @@ class UnitTestTool(object):
args = [cmake,
"-G",
generator,
"-DBUILD_TESTING=ON"
"-DMBED_ENABLE_TESTING=ON"
"-DCMAKE_MAKE_PROGRAM=%s" % self.make_program,
"-DCMAKE_CXX_COMPILER=%s" % get_cxx_tool(),
"-DCMAKE_C_COMPILER=%s" % get_c_tool()]

View File

@ -4,6 +4,6 @@
add_subdirectory(CMSIS_5)
add_subdirectory(device)
if(MBED_OS_ENABLE_TESTS)
if(MBED_ENABLE_OS_INTERNAL_TESTS)
add_subdirectory(tests/UNITTESTS/doubles)
endif()

View File

@ -1,8 +1,8 @@
# Copyright (c) 2020 ARM Limited. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
if(MBED_OS_ENABLE_TESTS)
if(NOT BUILD_GREENTEA_TESTS)
if(MBED_ENABLE_OS_INTERNAL_TESTS)
if(NOT MBED_BUILD_GREENTEA_TESTS)
add_subdirectory(tests/UNITTESTS)
endif()
endif()

View File

@ -1,8 +1,8 @@
# Copyright (c) 2020 ARM Limited. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
if(MBED_OS_ENABLE_TESTS)
if(BUILD_GREENTEA_TESTS)
if(MBED_ENABLE_OS_INTERNAL_TESTS)
if(MBED_BUILD_GREENTEA_TESTS)
add_subdirectory(TESTS)
endif()
endif()

View File

@ -1,8 +1,8 @@
# Copyright (c) 2020 ARM Limited. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
if(MBED_OS_ENABLE_TESTS)
if(BUILD_GREENTEA_TESTS)
if(MBED_ENABLE_OS_INTERNAL_TESTS)
if(MBED_BUILD_GREENTEA_TESTS)
# add greentea test
else()
add_subdirectory(tests/UNITTESTS)

View File

@ -1,8 +1,8 @@
# Copyright (c) 2020 ARM Limited. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
if(MBED_OS_ENABLE_TESTS)
if(NOT BUILD_GREENTEA_TESTS)
if(MBED_ENABLE_OS_INTERNAL_TESTS)
if(NOT MBED_BUILD_GREENTEA_TESTS)
add_subdirectory(tests/UNITTESTS)
endif()
endif()

View File

@ -1,8 +1,8 @@
# Copyright (c) 2020 ARM Limited. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
if(MBED_OS_ENABLE_TESTS)
if(BUILD_GREENTEA_TESTS)
if(MBED_ENABLE_OS_INTERNAL_TESTS)
if(MBED_BUILD_GREENTEA_TESTS)
# add greentea test
else()
add_subdirectory(tests/UNITTESTS)

View File

@ -1,8 +1,8 @@
# Copyright (c) 2020 ARM Limited. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
if(MBED_OS_ENABLE_TESTS)
if(NOT BUILD_GREENTEA_TESTS)
if(MBED_ENABLE_OS_INTERNAL_TESTS)
if(NOT MBED_BUILD_GREENTEA_TESTS)
add_subdirectory(tests/UNITTESTS)
endif()
endif()

View File

@ -1,8 +1,8 @@
# Copyright (c) 2020 ARM Limited. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
if(MBED_OS_ENABLE_TESTS)
if(BUILD_GREENTEA_TESTS)
if(MBED_ENABLE_OS_INTERNAL_TESTS)
if(MBED_BUILD_GREENTEA_TESTS)
add_subdirectory(tests/TESTS)
else()
add_subdirectory(tests/UNITTESTS)

View File

@ -5,8 +5,8 @@ add_library(mbed-nfc STATIC EXCLUDE_FROM_ALL)
add_subdirectory(libraries)
if(MBED_OS_ENABLE_TESTS)
if(BUILD_GREENTEA_TESTS)
if(MBED_ENABLE_OS_INTERNAL_TESTS)
if(MBED_BUILD_GREENTEA_TESTS)
add_subdirectory(tests/TESTS)
endif()
endif()

View File

@ -1,8 +1,8 @@
# Copyright (c) 2020 ARM Limited. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
if(MBED_OS_ENABLE_TESTS)
if(BUILD_GREENTEA_TESTS)
if(MBED_ENABLE_OS_INTERNAL_TESTS)
if(MBED_BUILD_GREENTEA_TESTS)
add_subdirectory(tests/TESTS)
else()
add_subdirectory(tests/UNITTESTS)

View File

@ -1,8 +1,8 @@
# Copyright (c) 2020 ARM Limited. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
if(MBED_OS_ENABLE_TESTS)
if(BUILD_GREENTEA_TESTS)
if(MBED_ENABLE_OS_INTERNAL_TESTS)
if(MBED_BUILD_GREENTEA_TESTS)
# add greentea test
else()
add_subdirectory(tests/UNITTESTS)

View File

@ -1,8 +1,8 @@
# Copyright (c) 2020-2021 ARM Limited. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
if(MBED_OS_ENABLE_TESTS)
if(BUILD_GREENTEA_TESTS)
if(MBED_ENABLE_OS_INTERNAL_TESTS)
if(MBED_BUILD_GREENTEA_TESTS)
add_subdirectory(tests/TESTS)
else()
add_subdirectory(tests/UNITTESTS)

View File

@ -1,8 +1,8 @@
# Copyright (c) 2020 ARM Limited. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
if(MBED_OS_ENABLE_TESTS)
if(BUILD_GREENTEA_TESTS)
if(MBED_ENABLE_OS_INTERNAL_TESTS)
if(MBED_BUILD_GREENTEA_TESTS)
add_subdirectory(tests/TESTS)
else()
add_subdirectory(tests/UNITTESTS)

View File

@ -73,8 +73,8 @@ target_link_libraries(mbed-psa
add_subdirectory(test_abstraction_layers)
if(MBED_OS_ENABLE_TESTS)
if(BUILD_GREENTEA_TESTS)
if(MBED_ENABLE_OS_INTERNAL_TESTS)
if(MBED_BUILD_GREENTEA_TESTS)
add_subdirectory(TESTS)
endif()
endif()

View File

@ -1,8 +1,8 @@
# Copyright (c) 2020 ARM Limited. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
if(MBED_OS_ENABLE_TESTS)
if(BUILD_GREENTEA_TESTS)
if(MBED_ENABLE_OS_INTERNAL_TESTS)
if(MBED_BUILD_GREENTEA_TESTS)
add_subdirectory(tests/TESTS)
else()
add_subdirectory(tests/UNITTESTS)

View File

@ -1,8 +1,8 @@
# Copyright (c) 2020 ARM Limited. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
if(MBED_OS_ENABLE_TESTS)
if(BUILD_GREENTEA_TESTS)
if(MBED_ENABLE_OS_INTERNAL_TESTS)
if(MBED_BUILD_GREENTEA_TESTS)
# add greentea test
else()
add_subdirectory(COMPONENT_QSPIF)

View File

@ -16,8 +16,8 @@ target_sources(mbed-storage-qspif
target_link_libraries(mbed-storage-qspif PUBLIC mbed-storage-blockdevice)
if(MBED_OS_ENABLE_TESTS)
if (NOT BUILD_GREENTEA_TESTS)
if(MBED_ENABLE_OS_INTERNAL_TESTS)
if (NOT MBED_BUILD_GREENTEA_TESTS)
add_subdirectory(UNITTESTS)
endif()
endif()

View File

@ -1,8 +1,8 @@
# Copyright (c) 2020 ARM Limited. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
if(MBED_OS_ENABLE_TESTS)
if(BUILD_GREENTEA_TESTS)
if(MBED_ENABLE_OS_INTERNAL_TESTS)
if(MBED_BUILD_GREENTEA_TESTS)
# add greentea test
else()
add_subdirectory(tests/UNITTESTS)

View File

@ -1,8 +1,8 @@
# Copyright (c) 2020 ARM Limited. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
if(MBED_OS_ENABLE_TESTS)
if(BUILD_GREENTEA_TESTS)
if(MBED_ENABLE_OS_INTERNAL_TESTS)
if(MBED_BUILD_GREENTEA_TESTS)
# add greentea test
else()
add_subdirectory(tests/UNITTESTS)

View File

@ -1,8 +1,8 @@
# Copyright (c) 2020 ARM Limited. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
if(MBED_OS_ENABLE_TESTS)
if(BUILD_GREENTEA_TESTS)
if(MBED_ENABLE_OS_INTERNAL_TESTS)
if(MBED_BUILD_GREENTEA_TESTS)
# add greentea test
else()
add_subdirectory(tests/UNITTESTS)

View File

@ -1,8 +1,8 @@
# Copyright (c) 2020 ARM Limited. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
if(MBED_OS_ENABLE_TESTS)
if(BUILD_GREENTEA_TESTS)
if(MBED_ENABLE_OS_INTERNAL_TESTS)
if(MBED_BUILD_GREENTEA_TESTS)
# add greentea test
else()
add_subdirectory(tests/UNITTESTS)

View File

@ -4,8 +4,8 @@
* SPDX-License-Identifier: Apache-2.0
*/
#if BUILD_TESTING && !defined(MBED_TEST_MODE)
#error "MBED_TEST_MODE not defined with BUILD_TESTING on"
#if MBED_ENABLE_TESTING && !defined(MBED_TEST_MODE)
#error "MBED_TEST_MODE not defined with MBED_ENABLE_TESTING on"
#else
int main(){
return 0;

View File

@ -84,10 +84,9 @@ endif()
# Create COMMAND variables
if(EXISTS "${STM32CubeProg_PATH}")
set(STM32CubeProg_COMMAND ${STM32CubeProg_PATH})
set(STM32CubeProg_COMMAND ${STM32CubeProg_PATH} CACHE INTERNAL "" FORCE)
endif()
# on Linux and Mac the GDB server needs help to find libSTLinkUSBDriver dll which is in a subfolder
if(EXISTS "${STLINK_gdbserver_PATH}")
@ -97,13 +96,13 @@ if(EXISTS "${STLINK_gdbserver_PATH}")
if("${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "Linux")
# Linux: set LD_LIBRARY_PATH
set(STLINK_gdbserver_COMMAND ${CMAKE_COMMAND} -E env "LD_LIBRARY_PATH=${STLINK_NATIVE_DIR}" ${STLINK_gdbserver_PATH})
set(STLINK_gdbserver_COMMAND ${CMAKE_COMMAND} -E env "LD_LIBRARY_PATH=${STLINK_NATIVE_DIR}" ${STLINK_gdbserver_PATH} CACHE INTERNAL "" FORCE)
elseif("${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "Darwin")
# OS X: set DYLD_FALLBACK_LIBRARY_PATH
set(STLINK_gdbserver_COMMAND ${CMAKE_COMMAND} -E env "DYLD_FALLBACK_LIBRARY_PATH=${STLINK_NATIVE_DIR}" ${STLINK_gdbserver_PATH})
set(STLINK_gdbserver_COMMAND ${CMAKE_COMMAND} -E env "DYLD_FALLBACK_LIBRARY_PATH=${STLINK_NATIVE_DIR}" ${STLINK_gdbserver_PATH} CACHE INTERNAL "" FORCE)
else()
# Windows -- doesn't need help
set(STLINK_gdbserver_COMMAND ${STLINK_gdbserver_PATH})
set(STLINK_gdbserver_COMMAND ${STLINK_gdbserver_PATH} CACHE INTERNAL "" FORCE)
endif()
endif()