Merge branch 'master' into master

pull/14693/head
Yahya Tawil 2021-05-24 20:04:41 +03:00 committed by GitHub
commit ae31d20904
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
478 changed files with 20756 additions and 10887 deletions

2
.gitignore vendored
View File

@ -102,3 +102,5 @@ DELIVERY/
CMakeCache.txt
cmake_install.cmake
CMakeFiles/
cmake_build/
Testing/

View File

@ -39,9 +39,11 @@ addons:
- sourceline: 'deb https://apt.kitware.com/ubuntu/ focal main'
key_url: 'https://apt.kitware.com/keys/kitware-archive-latest.asc'
packages:
- cmake
- ninja-build
- libncursesw5
- cmake
- ninja-build
- gcovr
- libncursesw5
- g++-7
matrix:
include:
@ -321,3 +323,23 @@ matrix:
- mbedtools configure -p ${ROOT} -t ${TOOLCHAIN} -m ${TARGET_NAME} --mbed-os-path .
- cmake -S ${ROOT} -B ${ROOT}/cmake_build/${TARGET_NAME}/${PROFILE}/${TOOLCHAIN}/ -GNinja -DCMAKE_BUILD_TYPE=${PROFILE}
- cmake --build ${ROOT}/cmake_build/${TARGET_NAME}/${PROFILE}/${TOOLCHAIN}/
### Mbed OS unittest ###
- &cmake-build-run-unittest
stage: "CMake"
name: "CMake unittest build"
env: NAME=cmake_unittest
install:
# Hide Travis-preinstalled CMake
# The Travis-preinstalled CMake is unfortunately not installed via apt, so we
# can't replace it with an apt-supplied version very easily. Additionally, we
# can't permit the Travis-preinstalled copy to survive, as the Travis default
# path lists the Travis CMake install location ahead of any place where apt
# would install CMake to. Instead of apt removing or upgrading to a new CMake
# version, we must instead delete the Travis copy of CMake.
- sudo rm -rf /usr/local/cmake*
script:
- echo ctest --build-and-test . build --build-generator Ninja --build-options -DBUILD_TESTING=ON -DCMAKE_BUILD_TYPE=Debug -DCOVERAGE=ON -DCMAKE_CXX_COMPILER=g++-7 -DCMAKE_C_COMPILER=gcc-7 --test-command ctest
- ctest --build-and-test . build --build-generator Ninja --build-options -DBUILD_TESTING=ON -DCMAKE_BUILD_TYPE=Debug -DCOVERAGE=ON -DCMAKE_CXX_COMPILER=g++-7 -DCMAKE_C_COMPILER=gcc-7 --test-command ctest
- gcovr --gcov-executable gcov-7 -r . ./build -s -e ".*\.h" --exclude-directories=$TRAVIS_BUILD_DIR/build/UNITTESTS --exclude-directories=$TRAVIS_BUILD_DIR/build/_deps
- ccache -s

View File

@ -5,8 +5,10 @@
cmake_minimum_required(VERSION 3.19.0 FATAL_ERROR)
include(${MBED_CONFIG_PATH}/mbed_config.cmake)
include(mbed_set_linker_script)
if(${CMAKE_CROSSCOMPILING})
include(${MBED_CONFIG_PATH}/mbed_config.cmake)
include(mbed_set_linker_script)
endif()
project(mbed-os)
@ -15,6 +17,13 @@ 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"
)
option(BUILD_TESTING "Run unit tests only." OFF)
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_TESTING)
include(CTest)
add_subdirectory(UNITTESTS)
endif()
add_library(mbed-core INTERFACE)
add_library(mbed-os INTERFACE)
@ -33,88 +42,91 @@ target_link_libraries(mbed-baremetal
)
# Validate selected C library type
# The C library type selected has to match the library that the target can support
if(${MBED_C_LIB} STREQUAL "small")
if(NOT "small" IN_LIST MBED_TARGET_SUPPORTED_C_LIBS)
if("std" IN_LIST MBED_TARGET_SUPPORTED_C_LIBS)
message(WARNING
"We noticed that target.c_lib is set to `${MBED_C_LIB}`."
" As the ${MBED_TARGET} target does not support a small C library for the ${MBED_TOOLCHAIN} toolchain,"
" we are using the standard C library instead."
)
set(MBED_C_LIB "std" CACHE STRING "")
if(${CMAKE_CROSSCOMPILING})
if(${MBED_C_LIB} STREQUAL "small")
if(NOT "small" IN_LIST MBED_TARGET_SUPPORTED_C_LIBS)
if("std" IN_LIST MBED_TARGET_SUPPORTED_C_LIBS)
message(WARNING
"We noticed that target.c_lib is set to `${MBED_C_LIB}`."
" As the ${MBED_TARGET} target does not support a small C library for the ${MBED_TOOLCHAIN} toolchain,"
" we are using the standard C library instead."
)
set(MBED_C_LIB "std" CACHE STRING "")
endif()
endif()
elseif(NOT ${MBED_C_LIB} IN_LIST MBED_TARGET_SUPPORTED_C_LIBS)
message(FATAL_ERROR
"Invalid `target.c_lib` ('${MBED_C_LIB}') for '${MBED_TARGET}' target."
"\nPossible value(s): ${MBED_TARGET_SUPPORTED_C_LIBS}"
)
endif()
elseif(NOT ${MBED_C_LIB} IN_LIST MBED_TARGET_SUPPORTED_C_LIBS)
message(FATAL_ERROR
"Invalid `target.c_lib` ('${MBED_C_LIB}') for '${MBED_TARGET}' target."
"\nPossible value(s): ${MBED_TARGET_SUPPORTED_C_LIBS}"
)
endif()
# Validate selected printf library
set(MBED_PRINTF_LIB_TYPES std minimal-printf)
if(NOT ${MBED_PRINTF_LIB} IN_LIST MBED_PRINTF_LIB_TYPES)
message(FATAL_ERROR
"Invalid printf library type '${MBED_PRINTF_LIB}'. Possible values:\n ${MBED_PRINTF_LIB_TYPES}"
)
endif()
# Validate selected printf library
set(MBED_PRINTF_LIB_TYPES std minimal-printf)
if(NOT ${MBED_PRINTF_LIB} IN_LIST MBED_PRINTF_LIB_TYPES)
message(FATAL_ERROR
"Invalid printf library type '${MBED_PRINTF_LIB}'. Possible values:\n ${MBED_PRINTF_LIB_TYPES}"
)
endif()
mbed_set_cpu_core_definitions(mbed-core)
if(${MBED_TOOLCHAIN_FILE_USED})
message(STATUS ${MBED_TOOLCHAIN})
mbed_set_profile_options(mbed-core ${MBED_TOOLCHAIN})
mbed_set_c_lib(mbed-core ${MBED_C_LIB})
mbed_set_printf_lib(mbed-core ${MBED_PRINTF_LIB})
target_compile_features(mbed-core
INTERFACE
c_std_11
cxx_std_14
)
endif()
mbed_set_cpu_core_definitions(mbed-core)
if(${MBED_TOOLCHAIN_FILE_USED})
mbed_set_profile_options(mbed-core ${MBED_TOOLCHAIN})
mbed_set_c_lib(mbed-core ${MBED_C_LIB})
mbed_set_printf_lib(mbed-core ${MBED_PRINTF_LIB})
target_compile_features(mbed-core
INTERFACE
c_std_11
cxx_std_14
)
endif()
target_compile_definitions(mbed-core
INTERFACE
${MBED_TARGET_DEFINITIONS}
${MBED_CONFIG_DEFINITIONS}
)
# 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}
PUBLIC
MBED_TEST_MODE
)
endif()
# We need to generate a "response file" to pass to the C preprocessor when we preprocess the linker
# script, because of path length limitations on Windows. We set the response file and bind the path
# to a global property here. The MBED_TARGET being built queries this global property when it sets
# the linker script.
#
# We must set this global property before the targets subdirectory is added to the project. This is
# required because the MBED_TARGET depends on the response file. If the path to the response file
# is not defined when the target requests it the config definitions will not be passed to CPP.
#
# TODO: Remove this and find a more idiomatic way of passing compile definitions to CPP without
# using response files or global properties.
mbed_generate_options_for_linker(mbed-core RESPONSE_FILE_PATH)
set_property(GLOBAL PROPERTY COMPILE_DEFS_RESPONSE_FILE ${RESPONSE_FILE_PATH})
# Add compile definitions for backward compatibility with the toolchain
# supported. New source files should instead check for __GNUC__ and __clang__
# for the GCC_ARM and ARM toolchains respectively.
if(${MBED_TOOLCHAIN} STREQUAL "GCC_ARM")
target_compile_definitions(mbed-core
INTERFACE
TOOLCHAIN_GCC_ARM
TOOLCHAIN_GCC
)
elseif(${MBED_TOOLCHAIN} STREQUAL "ARM")
target_compile_definitions(mbed-core
INTERFACE
TOOLCHAIN_ARM
${MBED_TARGET_DEFINITIONS}
${MBED_CONFIG_DEFINITIONS}
)
# 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}
PUBLIC
MBED_TEST_MODE
)
endif()
# We need to generate a "response file" to pass to the C preprocessor when we preprocess the linker
# script, because of path le ngth limitations on Windows. We set the response file and bind the path
# to a global property here. The MBED_TARGET being built queries this global property when it sets
# the linker script.
#
# We must set this global property before the targets subdirectory is added to the project. This is
# required because the MBED_TARGET depends on the response file. If the path to the response file
# is not defined when the target requests it the config definitions will not be passed to CPP.
#
# TODO: Remove this and find a more idiomatic way of passing compile definitions to CPP without
# using response files or global properties.
mbed_generate_options_for_linker(mbed-core RESPONSE_FILE_PATH)
set_property(GLOBAL PROPERTY COMPILE_DEFS_RESPONSE_FILE ${RESPONSE_FILE_PATH})
# Add compile definitions for backward compatibility with the toolchain
# supported. New source files should instead check for __GNUC__ and __clang__
# for the GCC_ARM and ARM toolchains respectively.
if(${MBED_TOOLCHAIN} STREQUAL "GCC_ARM")
target_compile_definitions(mbed-core
INTERFACE
TOOLCHAIN_GCC_ARM
TOOLCHAIN_GCC
)
elseif(${MBED_TOOLCHAIN} STREQUAL "ARM")
target_compile_definitions(mbed-core
INTERFACE
TOOLCHAIN_ARM
)
endif()
endif()
# Include mbed.h and config from generate folder
@ -136,23 +148,26 @@ add_subdirectory(hal)
add_subdirectory(platform)
add_subdirectory(rtos)
add_subdirectory(targets)
add_subdirectory(storage)
add_subdirectory(events)
add_subdirectory(connectivity)
# The directories below contain optional target libraries
add_subdirectory(events EXCLUDE_FROM_ALL)
add_subdirectory(connectivity EXCLUDE_FROM_ALL)
add_subdirectory(storage EXCLUDE_FROM_ALL)
add_subdirectory(drivers/device_key EXCLUDE_FROM_ALL)
add_subdirectory(drivers/usb EXCLUDE_FROM_ALL)
add_subdirectory(features EXCLUDE_FROM_ALL)
add_subdirectory(cmsis/CMSIS_5/CMSIS/RTOS2 EXCLUDE_FROM_ALL)
add_subdirectory(cmsis/device/rtos EXCLUDE_FROM_ALL)
# Ensure the words that make up the Mbed target name are separated with a hyphen, lowercase, and with the `mbed-` prefix.
string(TOLOWER ${MBED_TARGET} MBED_TARGET_CONVERTED)
string(REPLACE "_" "-" MBED_TARGET_CONVERTED ${MBED_TARGET_CONVERTED})
string(PREPEND MBED_TARGET_CONVERTED "mbed-")
target_link_libraries(mbed-core INTERFACE ${MBED_TARGET_CONVERTED})
if(${CMAKE_CROSSCOMPILING})
# Ensure the words that make up the Mbed target name are separated with a hyphen, lowercase, and with the `mbed-` prefix.
string(TOLOWER ${MBED_TARGET} MBED_TARGET_CONVERTED)
string(REPLACE "_" "-" MBED_TARGET_CONVERTED ${MBED_TARGET_CONVERTED})
string(PREPEND MBED_TARGET_CONVERTED "mbed-")
target_link_libraries(mbed-core INTERFACE ${MBED_TARGET_CONVERTED})
endif()
#
# Converts output file of `target` to binary file and to Intel HEX file.

View File

@ -18,6 +18,7 @@
"storage_filesystem",
"storage_tdb_external",
"fat_chan",
"cordio-stm32wb",
"lora",
"sx1276-lora-driver",
"stm32wl-lora-driver",

View File

@ -1,75 +1,39 @@
cmake_minimum_required(VERSION 3.0.2)
set(PROJECT_NAME unittests)
set(LIB_NAME MbedOS)
project(${PROJECT_NAME})
# Copyright (c) 2021 ARM Limited. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
# Setup c++ standard
macro(use_cxx14)
if (CMAKE_VERSION VERSION_LESS 3.1)
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++14")
endif()
else()
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
endif()
endmacro()
use_cxx14()
set(CMAKE_CXX_STANDARD 14 CACHE STRING "")
set(CMAKE_CXX_STANDARD_REQUIRED ON CACHE BOOL "")
add_definitions(-DUNITTEST)
if (MINGW)
# enable PRIx formatting globally
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D__STDC_FORMAT_MACROS")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D__STDC_FORMAT_MACROS")
# enable PRIx formatting globally
add_definitions(-D__STDC_FORMAT_MACROS)
endif (MINGW)
####################
# GTEST
####################
# Download and unpack googletest at configure time
configure_file(googletest-CMakeLists.txt.in googletest-download/CMakeLists.txt)
execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .
RESULT_VARIABLE result
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/googletest-download)
if (result)
message(FATAL_ERROR "CMake failed for google test: ${result}")
endif()
execute_process(COMMAND ${CMAKE_COMMAND} --build .
RESULT_VARIABLE result
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/googletest-download)
if (result)
message(FATAL_ERROR "Build failed for google test: ${result}")
endif()
include(FetchContent)
# Download and unpack googletest
FetchContent_Declare(googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG release-1.10.0
)
FetchContent_MakeAvailable(googletest)
# Prevent overriding the parent project's compiler/linker
# settings on Windows
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
# Add googletest directly to our build. This defines
# the gtest and gtest_main targets.
add_subdirectory(${CMAKE_BINARY_DIR}/googletest-src
${CMAKE_BINARY_DIR}/googletest-build
EXCLUDE_FROM_ALL)
# The gtest/gtest_main/gmock/gmock_main targets carry header search path
# dependencies automatically when using CMake 2.8.11 or
# later.
target_include_directories(gmock_main SYSTEM BEFORE INTERFACE
"$<BUILD_INTERFACE:${gtest_SOURCE_DIR}/include>"
"$<BUILD_INTERFACE:${gmock_SOURCE_DIR}/include>")
####################
# TESTING
####################
include(CTest)
set_property(DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES
"${CMAKE_BINARY_DIR}/Testing"
"${CMAKE_BINARY_DIR}/Testing"
)
####################
@ -78,163 +42,19 @@ set_property(DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES
if (COVERAGE)
if (NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
message(WARNING "Non-debug build may result misleading code coverage results.")
endif()
if (NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
message(WARNING "Non-debug build may result misleading code coverage results.")
endif()
# Append coverage compiler flags
set(COVERAGE_COMPILER_FLAGS "-g -O0 --coverage")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${COVERAGE_COMPILER_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COVERAGE_COMPILER_FLAGS}")
# Append coverage compiler flags
set(COVERAGE_COMPILER_FLAGS "-g -O0 --coverage")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${COVERAGE_COMPILER_FLAGS}" CACHE STRING "" FORCE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COVERAGE_COMPILER_FLAGS}" CACHE STRING "" FORCE)
endif(COVERAGE)
if (VALGRIND)
find_program(MEMORYCHECK_COMMAND valgrind)
find_program(MEMORYCHECK_COMMAND valgrind)
endif(VALGRIND)
####################
# UNIT TESTS
####################
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DUNITTEST")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUNITTEST")
# Set include dirs.
set(unittest-includes-base
"${PROJECT_SOURCE_DIR}/target_h"
"${PROJECT_SOURCE_DIR}/../events/tests/UNITTESTS/target_h"
"${PROJECT_SOURCE_DIR}/../events/tests/UNITTESTS/target_h/equeue"
"${PROJECT_SOURCE_DIR}/target_h/platform"
"${PROJECT_SOURCE_DIR}/target_h/platform/cxxsupport"
"${PROJECT_SOURCE_DIR}/target_h/drivers"
"${PROJECT_SOURCE_DIR}/target_h/rtos/include"
"${PROJECT_SOURCE_DIR}/stubs"
"${PROJECT_SOURCE_DIR}/.."
"${PROJECT_SOURCE_DIR}/../features"
"${PROJECT_SOURCE_DIR}/../platform/include"
"${PROJECT_SOURCE_DIR}/../platform/include/platform"
"${PROJECT_SOURCE_DIR}/../platform/mbed-trace/include"
"${PROJECT_SOURCE_DIR}/../storage/filesystem/littlefs/include"
"${PROJECT_SOURCE_DIR}/../storage/filesystem/fat/include"
"${PROJECT_SOURCE_DIR}/../storage/blockdevice/include"
"${PROJECT_SOURCE_DIR}/../storage/filesystem/include"
"${PROJECT_SOURCE_DIR}/../storage/kvstore/include"
"${PROJECT_SOURCE_DIR}/../storage/kvstore/kv_config"
"${PROJECT_SOURCE_DIR}/../storage/kvstore/kv_config/include"
"${PROJECT_SOURCE_DIR}/../storage/kvstore/tdbstore/include"
"${PROJECT_SOURCE_DIR}/../storage/kvstore/filesystemstore/include"
"${PROJECT_SOURCE_DIR}/../storage/kvstore/kvstore_global_api/include"
"${PROJECT_SOURCE_DIR}/../drivers"
"${PROJECT_SOURCE_DIR}/../drivers/include"
"${PROJECT_SOURCE_DIR}/../drivers/include/drivers"
"${PROJECT_SOURCE_DIR}/../drivers/include/drivers/internal"
"${PROJECT_SOURCE_DIR}/../hal"
"${PROJECT_SOURCE_DIR}/../hal/include"
"${PROJECT_SOURCE_DIR}/../events/include"
"${PROJECT_SOURCE_DIR}/../events/include/events/internal"
"${PROJECT_SOURCE_DIR}/../events/source"
"${PROJECT_SOURCE_DIR}/../rtos/include"
"${PROJECT_SOURCE_DIR}/../features/frameworks"
"${PROJECT_SOURCE_DIR}/../connectivity/libraries/nanostack-libservice"
"${PROJECT_SOURCE_DIR}/../connectivity/libraries/nanostack-libservice/mbed-client-libservice"
"${PROJECT_SOURCE_DIR}/../connectivity/netsocket/include"
"${PROJECT_SOURCE_DIR}/../features/filesystem/fat"
"${PROJECT_SOURCE_DIR}/../features/filesystem/fat/ChaN"
"${PROJECT_SOURCE_DIR}/../features/filesystem/bd"
"${PROJECT_SOURCE_DIR}/../features/filesystem/"
"${PROJECT_SOURCE_DIR}/../features/filesystem/littlefs"
"${PROJECT_SOURCE_DIR}/../features/filesystem/littlefs/littlefs"
"${PROJECT_SOURCE_DIR}/../connectivity/cellular/include/cellular/framework/API"
"${PROJECT_SOURCE_DIR}/../connectivity/cellular/include/cellular/framework/AT"
"${PROJECT_SOURCE_DIR}/../connectivity/cellular/include/cellular/framework/device"
"${PROJECT_SOURCE_DIR}/../connectivity/cellular/include/cellular/framework"
"${PROJECT_SOURCE_DIR}/../connectivity/cellular/include/cellular/framework/common"
"${PROJECT_SOURCE_DIR}/../connectivity"
"${PROJECT_SOURCE_DIR}/../connectivity/lorawan/include/lorawan"
"${PROJECT_SOURCE_DIR}/../connectivity/lorawan/lorastack"
"${PROJECT_SOURCE_DIR}/../connectivity/lorawan/lorastack/mac"
"${PROJECT_SOURCE_DIR}/../connectivity/lorawan/lorastack/phy"
"${PROJECT_SOURCE_DIR}/../connectivity/lorawan"
"${PROJECT_SOURCE_DIR}/../connectivity/mbedtls"
"${PROJECT_SOURCE_DIR}/../connectivity/mbedtls/include"
)
# Create a list for test suites.
set(TEST_SUITES)
# Get all matched tests.
file(GLOB_RECURSE unittest-file-list
"../unittest.cmake" # matches any ../**/unittest.cmake
)
if ("${unittest-file-list}" STREQUAL "")
message(FATAL_ERROR "No tests found. Exiting...")
endif()
# Create unit test targets
foreach(testfile ${unittest-file-list})
####################
# DEFINE TARGETS
####################
# Init file lists.
set(unittest-includes ${unittest-includes-base})
set(unittest-sources)
set(unittest-test-sources)
set(unittest-test-flags)
# Get source files
include("${testfile}")
get_filename_component(TEST_SUITE_DIR ${testfile} DIRECTORY)
file(RELATIVE_PATH
TEST_SUITE_NAME # output
"${PROJECT_SOURCE_DIR}/.." # root
${TEST_SUITE_DIR} #abs dirpath
)
string(REGEX REPLACE "/|\\\\" "-" TEST_SUITE_NAME ${TEST_SUITE_NAME})
set(TEST_SUITES ${TEST_SUITES} ${TEST_SUITE_NAME})
set(LIBS_TO_BE_LINKED gmock_main)
# Build directories list
set(BUILD_DIRECTORIES)
if (unittest-sources)
# Create the testable static library.
add_library("${TEST_SUITE_NAME}.${LIB_NAME}" STATIC ${unittest-sources})
target_include_directories("${TEST_SUITE_NAME}.${LIB_NAME}" PRIVATE
${unittest-includes})
target_compile_options("${TEST_SUITE_NAME}.${LIB_NAME}" PRIVATE
${unittest-test-flags})
set(LIBS_TO_BE_LINKED ${LIBS_TO_BE_LINKED} "${TEST_SUITE_NAME}.${LIB_NAME}")
# Append lib build directory to list
list(APPEND BUILD_DIRECTORIES "./CMakeFiles/${TEST_SUITE_NAME}.${LIB_NAME}.dir")
endif(unittest-sources)
if (unittest-test-sources)
# Create the executable.
add_executable(${TEST_SUITE_NAME} ${unittest-test-sources})
target_include_directories(${TEST_SUITE_NAME} PRIVATE
${unittest-includes})
target_compile_options(${TEST_SUITE_NAME} PRIVATE
${unittest-test-flags})
# Link the executable with the libraries.
target_link_libraries(${TEST_SUITE_NAME} ${LIBS_TO_BE_LINKED})
add_test(NAME "${TEST_SUITE_NAME}" COMMAND ${TEST_SUITE_NAME})
# Append test build directory to list
list(APPEND BUILD_DIRECTORIES "./CMakeFiles/${TEST_SUITE_NAME}.dir")
else()
message(WARNING "No test source files found for ${TEST_SUITE_NAME}.\n")
endif(unittest-test-sources)
endforeach(testfile)
add_subdirectory(stubs)

View File

@ -1,306 +0,0 @@
## Unit testing
This document describes how to write and use unit tests for Arm Mbed OS.
### Introduction
Unit tests test code in small sections on a host machine. Unlike other testing tools, unit testing doesn't require embedded hardware or need to build a full operating system. Because of this, unit testing can result in faster tests than other tools. Unit testing happens in a build environment where you test each C or C++ class or module in isolation. Build test suites into separate test binaries and stub all access outside to remove dependencies on any specific embedded hardware or software combination. This allows you to complete tests using native compilers on the build machine.
### Prerequisites
Please install the following dependencies to use Mbed OS unit testing:
* GNU toolchains.
* GCC 6 or later. We recommend you use MinGW-W64 on Windows, but any Windows port of the above GCC versions works. Default compilers can be used on Mac OS instead of GCC to shorten build times, but code coverage results can differ.
* CMake 3.0 or newer.
* Python 2.7.x, 3.5 or newer.
* Pip 10.0 or newer.
* Gcovr 4.1 or newer.
* Arm Mbed CLI 1.8.0 or newer.
Detailed instructions for supported operating systems are below.
#### Installing dependencies on Debian or Ubuntu
In a terminal window:
1. `sudo apt-get -y install build-essential cmake`
1. Install Python and Pip with:
```
sudo apt-get -y install python python-setuptools
sudo easy_install pip
```
1. Install Gcovr and [Mbed CLI](https://os.mbed.com/docs/mbed-os/latest/tools/developing-mbed-cli.html) with `pip install "gcovr>=4.1" mbed-cli`.
#### Installing dependencies on macOS
In a terminal window:
1. Install [Homebrew](https://brew.sh/).
1. Install Xcode Command Line Tools with `xcode-select --install`.
1. Install CMake with: `brew install cmake`.
1. Install Python and Pip:
```
brew install python
sudo easy_install pip
```
1. Install Gcovr and [Mbed CLI](https://os.mbed.com/docs/mbed-os/latest/tools/developing-mbed-cli.html) with `pip install "gcovr>=4.1" mbed-cli`.
1. (Optional) Install GCC with `brew install gcc`.
#### Installing dependencies on Windows
In a terminal window:
1. Download and install MinGW-W64 from [SourceForge](https://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win64/Personal%20Builds/mingw-builds/).
1. Download CMake binaries from https://cmake.org/download/, and run the installer.
1. Download Python 2.7 or Python 3 from https://www.python.org/getit/, and run the installer.
1. Add MinGW, CMake and Python into system PATH.
1. Install Gcovr and [Mbed CLI](https://os.mbed.com/docs/mbed-os/latest/tools/developing-mbed-cli.html) with `pip install "gcovr>=4.1" mbed-cli`.
### Test code structure
Find unit tests in the Mbed OS repository under the `UNITTESTS` folder. We recommend unit test files use an identical directory path as the file under test. This makes it easier to find unit tests for a particular class or a module. For example, if the file you're testing is `some/example/path/ClassName.cpp`, then all the test files are in the `UNITTESTS/some/example/path/ClassName` directory. Each test suite needs to have its own `unittest.cmake` file for test configuration.
All the class stubs should be located in the `UNITTESTS/stubs` directory. A single stub class can be used by multiple test suites and should follow the naming convention `ClassName_stub.cpp` for the source file, and `ClassName_stub.h` for the header file. Use the actual header files for the unit tests, and don't stub headers if possible. The stubbed headers reside in the `UNITTESTS/target_h` directory.
#### Test discovery
Registering unit tests to run happens automatically, and the test runner handles registration. However, test files do not automatically build. Build unit tests with a separate system that searches for unit tests under the `UNITTESTS` directory.
For the build system to find and build any test suite automatically, include a unit test configuration file named `unittest.cmake` for each unit test suite. This configuration file lists all the source files required for the test build.
#### Test names
The build system automatically generates names of test suites. The name is constructed by taking a relative file path from the UNITTESTS directory to the test directory and replacing path separators with dashes. For example, the test suite name for `some/example/path/ClassName.cpp` is `some-example-path-ClassName`. Suite names are used when deciding which test suites to run.
### Unit testing with Mbed CLI
Mbed CLI supports unit tests through the `mbed test --unittests` command. For information on using Mbed CLI, please see the [CLI documentation](https://os.mbed.com/docs/mbed-os/latest/tools/developing-mbed-cli.html).
### Writing unit tests
A unit tests suite consists of one or more test cases. The test cases should cover all the functions in a class under test. All the external dependencies are stubbed including the other classes in the same module. Avoid stubbing header files. Finally, analyze code coverage to ensure all code is tested, and no dead code is found.
Unit tests are written using [Google Test v1.10.0](https://github.com/google/googletest/releases/tag/release-1.10.0).
Please see the [documentation for Google Test](https://github.com/google/googletest/blob/master/googletest/docs/primer.md) to learn how to write unit tests using its framework. See the [documentation for Google Mock](https://github.com/google/googletest/blob/master/googlemock/docs/Documentation.md) if you want to write and use C++ mock classes instead of stubs.
#### Test suite configuration
Create two files in the test directory for each test suite:
* Unit test source file (`test_ClassName.cpp`).
* Unit test configuration file (`unittest.cmake`).
List all the required files for the build in the `unittest.cmake` file with paths relative to the `UNITTESTS` folder. Use the following variables to list the source files and include paths:
* **unittest-includes**: List of header include paths. You can use this to extend or overwrite default paths listed in `UNITTESTS/CMakeLists.txt`.
* **unittest-sources**: List of files under test.
* **unittest-test-sources**: List of test sources and stubs.
You can also set custom compiler flags and other configurations supported by CMake in `unittest.cmake`.
#### Example
With the following steps, you can write a simple unit test. This example creates dummy classes to be tested, creates and configures unit tests for a class and stubs all external dependencies.
1. Create the following dummy classes in `mbed-os/example`:
**MyClass.h**
```
#ifndef MYCLASS_H_
#define MYCLASS_H_
namespace example {
class MyClass {
public:
int myFunction();
};
}
#endif
```
**MyClass.cpp**
```
#include "MyClass.h"
#include "OtherClass.h"
namespace example {
int MyClass::myFunction() {
OtherClass o = OtherClass();
return o.otherFunction();
}
}
```
**OtherClass.h**
```
#ifndef OTHERCLASS_H_
#define OTHERCLASS_H_
namespace example {
class OtherClass {
public:
int otherFunction();
};
}
#endif
```
**OtherClass.cpp**
```
#include "OtherClass.h"
namespace example {
int OtherClass::otherFunction() {
return 1;
}
}
```
1. Create a directory for MyClass unit tests in `UNITTESTS/example/MyClass`.
1. Create a configuration file and a source file for MyClass unit tests in `UNITTESTS/example/MyClass`:
**unittest.cmake**
```
# Add here additional test specific include paths
set(unittest-includes ${unittest-includes}
../example
)
# Add here classes under test
set(unittest-sources
../example/MyClass.cpp
)
# Add here test classes and stubs
set(unittest-test-sources
example/MyClass/test_MyClass.cpp
stubs/OtherClass_stub.cpp
)
```
**test_MyClass.cpp**
```
#include "gtest/gtest.h"
#include "example/MyClass.h"
class TestMyClass : public testing::Test {
protected:
example::MyClass *obj;
virtual void SetUp()
{
obj = new example::MyClass();
}
virtual void TearDown()
{
delete obj;
}
};
TEST_F(TestMyClass, constructor)
{
EXPECT_TRUE(obj);
}
TEST_F(TestMyClass, myfunction)
{
EXPECT_EQ(obj->myFunction(), 0);
}
```
1. Stub all external dependencies. Create the following stub in `UNITTESTS/stubs`:
**OtherClass_stub.cpp**
```
#include "example/OtherClass.h"
namespace example {
int OtherClass::otherFunction() {
return 0;
}
}
```
This example does not use any Mbed OS code, but if your unit tests do, then remember to update header stubs in `UNITTESTS/target_h` and source stubs in `UNITTESTS/stubs` with any missing type or function declarations.
### Building and running unit tests
Use Mbed CLI to build and run unit tests. For advanced use, you can run CMake and a Make program directly.
#### Build tests directly with CMake
1. Create a build directory `mkdir UNITTESTS/build`.
1. Move to the build directory `cd UNITTESTS/build`.
1. Run CMake using a relative path to `UNITTESTS` folder as the argument. So from `UNITTESTS/build` use `cmake ..`:
* Add `-g [generator]` if generating other than Unix Makefiles such in case of MinGW use `-g "MinGW Makefiles"`.
* Add `-DCMAKE_MAKE_PROGRAM=<value>`, `-DCMAKE_CXX_COMPILER=<value>` and `-DCMAKE_C_COMPILER=<value>` to use a specific Make program and compilers.
* Add `-DCMAKE_BUILD_TYPE=Debug` for a debug build.
* Add `-DCOVERAGE=True` to add coverage compiler flags.
* Add `-Dgtest_disable_pthreads=ON` to run in a single thread.
* See the [CMake manual](https://cmake.org/cmake/help/v3.0/manual/cmake.1.html) for more information.
1. Run a Make program to build tests.
#### Run tests directly with CTest
Run a test binary in the build directory to run a unit test suite. To run multiple test suites at once, use the CTest test runner. Run CTest with `ctest`. Add `-v` to get results for each test case. See the [CTest manual](https://cmake.org/cmake/help/v3.0/manual/ctest.1.html) for more information.
#### Run tests with GUI test runner
1. Install `gtest-runner` according to the [documentation](https://github.com/nholthaus/gtest-runner).
1. Run `gtest-runner`.
1. Add test executables into the list and run.
### Debugging
1. Use Mbed CLI to build a debug build. For advanced use, run CMake directly with `-DCMAKE_BUILD_TYPE=Debug`, and then run a Make program.
1. Run GDB with a test executable as an argument to debug unit tests.
1. Run tests with Valgrind to analyze the test memory profile.
### Get code coverage
Use Mbed CLI to generate code coverage reports. For advanced use, follow these steps:
1. Run CMake with both `-DCMAKE_BUILD_TYPE=Debug` and `-DCOVERAGE=True`.
1. Run a Make program to build the tests.
1. Run the tests.
1. Run Gcovr or any other code coverage tool directly in the build directory.
### Troubleshooting
**Problem:** Generic problems with CMake or with the build process.
* **Solution**: Delete the build directory. Make sure that CMake, g++, GCC and a Make program can be found in the path and are correct versions.
**Problem:** (Windows) Virus protection identifies files generated by CMake as malicious and quarantines the files.
* **Solution**: Restore false-positive files from the quarantine.
**Problem:** (Windows) Git with shell installation adds sh.exe to the path and then CMake throws an error: sh.exe was found in your PATH. For MinGW make to work correctly, sh.exe must NOT be in your path.
* **Solution**: Remove sh.exe from the system path.
**Problem:** (Mac OS) CMake compiler check fails on Mac OS Mojave when using GCC-8.
* **Solution**: Make sure gnm (binutils) is not installed. Uninstall binutils with `brew uninstall binutils`.

View File

@ -1,7 +1,7 @@
#!/usr/bin/env python
"""
Copyright (c) 2018, Arm Limited
Copyright (c) 2018-2021, Arm Limited
SPDX-License-Identifier: Apache-2.0
Licensed under the Apache License, Version 2.0 (the "License");
@ -71,9 +71,8 @@ def _mbed_unittest_test(options, cwd, pwd):
clean=options.clean)
if options.compile_only:
# Create makefiles
src_path = os.path.relpath(pwd, options.build)
tool.create_makefiles(path_to_src=src_path,
# Create makefiles
tool.create_makefiles(path_to_src=cwd,
generator=options.cmake_generator,
coverage_output_type=options.coverage,
debug=options.debug_build,

View File

@ -0,0 +1,149 @@
# Copyright (c) 2021 ARM Limited. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
add_library(mbed-stubs-headers INTERFACE)
add_library(mbed-headers INTERFACE)
add_library(mbed-headers-base INTERFACE)
add_library(mbed-headers-platform INTERFACE)
add_library(mbed-headers-connectivity INTERFACE)
add_library(mbed-headers-storage INTERFACE)
add_library(mbed-headers-drivers INTERFACE)
add_library(mbed-headers-hal INTERFACE)
add_library(mbed-headers-events INTERFACE)
add_library(mbed-headers-rtos INTERFACE)
target_link_libraries(mbed-headers
INTERFACE
mbed-headers-base
mbed-headers-platform
mbed-headers-connectivity
mbed-headers-storage
mbed-headers-drivers
mbed-headers-hal
mbed-headers-events
mbed-headers-rtos
)
target_include_directories(mbed-headers-platform
INTERFACE
${mbed-os_SOURCE_DIR}/platform/include
${mbed-os_SOURCE_DIR}/platform/include/platform
${mbed-os_SOURCE_DIR}/platform/randlib/include/mbed-client-randlib/
${mbed-os_SOURCE_DIR}/platform/randlib/include/
${mbed-os_SOURCE_DIR}/platform/mbed-trace/include
)
target_include_directories(mbed-headers-base
INTERFACE
${mbed-os_SOURCE_DIR}/UNITTESTS/target_h
${mbed-os_SOURCE_DIR}/UNITTESTS/target_h/platform
${mbed-os_SOURCE_DIR}/UNITTESTS/target_h/platform/cxxsupport
${mbed-os_SOURCE_DIR}/UNITTESTS/target_h/drivers
${mbed-os_SOURCE_DIR}/UNITTESTS/target_h/rtos/include
${mbed-os_SOURCE_DIR}/UNITTESTS/target_h/rtos
${mbed-os_SOURCE_DIR}/UNITTESTS/target_h/sys
)
target_include_directories(mbed-headers-storage
INTERFACE
${mbed-os_SOURCE_DIR}/storage/filesystem/fat/include
${mbed-os_SOURCE_DIR}/storage/filesystem/fat/ChaN
${mbed-os_SOURCE_DIR}/storage/filesystem/littlefs
${mbed-os_SOURCE_DIR}/storage/filesystem/littlefs/include
${mbed-os_SOURCE_DIR}/storage/filesystem/littlefsv2/littlefs
${mbed-os_SOURCE_DIR}/storage/filesystem/littlefsv2/littlefs/bd
${mbed-os_SOURCE_DIR}/storage/filesystem/littlefs/littlefs
${mbed-os_SOURCE_DIR}/storage/blockdevice/include
${mbed-os_SOURCE_DIR}/storage/filesystem/include
${mbed-os_SOURCE_DIR}/storage/kvstore/include
${mbed-os_SOURCE_DIR}/storage/kvstore/kv_config
${mbed-os_SOURCE_DIR}/storage/kvstore/kv_config/include
${mbed-os_SOURCE_DIR}/storage/kvstore/tdbstore/include
${mbed-os_SOURCE_DIR}/storage/kvstore/filesystemstore/include
${mbed-os_SOURCE_DIR}/storage/kvstore/kvstore_global_api/include
${mbed-os_SOURCE_DIR}/storage/blockdevice/include/blockdevice
)
target_include_directories(mbed-headers-connectivity
INTERFACE
${mbed-os_SOURCE_DIR}/connectivity/libraries/nanostack-libservice
${mbed-os_SOURCE_DIR}/connectivity/libraries/nanostack-libservice/mbed-client-libservice
${mbed-os_SOURCE_DIR}/connectivity/netsocket/include
${mbed-os_SOURCE_DIR}/connectivity/cellular/include/cellular/framework/API
${mbed-os_SOURCE_DIR}/connectivity/cellular/include/cellular/framework/AT
${mbed-os_SOURCE_DIR}/connectivity/cellular/include/cellular/framework/device
${mbed-os_SOURCE_DIR}/connectivity/cellular/include/cellular/framework
${mbed-os_SOURCE_DIR}/connectivity/cellular/include/cellular/framework/common
${mbed-os_SOURCE_DIR}/connectivity
${mbed-os_SOURCE_DIR}/connectivity/lorawan/include/lorawan
${mbed-os_SOURCE_DIR}/connectivity/lorawan/lorastack
${mbed-os_SOURCE_DIR}/connectivity/lorawan/lorastack/mac
${mbed-os_SOURCE_DIR}/connectivity/lorawan/lorastack/phy
${mbed-os_SOURCE_DIR}/connectivity/lorawan
${mbed-os_SOURCE_DIR}/connectivity/lorawan/system
${mbed-os_SOURCE_DIR}/connectivity/mbedtls
${mbed-os_SOURCE_DIR}/connectivity/mbedtls/include
${mbed-os_SOURCE_DIR}/connectivity/FEATURE_BLE/include
${mbed-os_SOURCE_DIR}/connectivity/FEATURE_BLE/include/ble
)
target_include_directories(mbed-headers-drivers
INTERFACE
${mbed-os_SOURCE_DIR}/drivers
${mbed-os_SOURCE_DIR}/drivers/include
${mbed-os_SOURCE_DIR}/drivers/include/drivers
)
target_include_directories(mbed-headers-events
INTERFACE
${mbed-os_SOURCE_DIR}/events/tests/UNITTESTS/target_h
${mbed-os_SOURCE_DIR}/events/tests/UNITTESTS/target_h/equeue
${mbed-os_SOURCE_DIR}/events/include
${mbed-os_SOURCE_DIR}/events/include/events
${mbed-os_SOURCE_DIR}/events/include/events/internal
)
target_include_directories(mbed-headers-hal
INTERFACE
${mbed-os_SOURCE_DIR}/hal
${mbed-os_SOURCE_DIR}/hal/include
)
target_include_directories(mbed-headers-rtos
INTERFACE
${mbed-os_SOURCE_DIR}/rtos/include
${mbed-os_SOURCE_DIR}/rtos/include/rtos
)
target_include_directories(mbed-headers
INTERFACE
${mbed-os_SOURCE_DIR}/features
${mbed-os_SOURCE_DIR}/features/frameworks
)
target_include_directories(mbed-stubs-headers
INTERFACE
.
${mbed-os_SOURCE_DIR}/connectivity/nanostack/coap-service/test/coap-service/unittest/stub
)
add_subdirectory(connectivity)
add_subdirectory(drivers)
add_subdirectory(events)
add_subdirectory(hal)
add_subdirectory(platform)
add_subdirectory(rtos)
add_subdirectory(storage)
add_library(mbed-stubs INTERFACE)
target_link_libraries(mbed-stubs
INTERFACE
mbed-stubs-connectivity
mbed-stubs-drivers
mbed-stubs-events
mbed-stubs-hal
mbed-stubs-platform
mbed-stubs-rtos
mbed-stubs-storage
)

View File

@ -0,0 +1,63 @@
# Copyright (c) 2021 ARM Limited. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
add_library(mbed-stubs-connectivity)
target_compile_definitions(mbed-stubs-connectivity
PRIVATE
DEVICE_SERIAL=1
DEVICE_INTERRUPTIN=1
MBED_CONF_CELLULAR_USE_SMS=1
MBED_CONF_NSAPI_DEFAULT_CELLULAR_APN=NULL
MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE=115200
MBED_CONF_LORA_OVER_THE_AIR_ACTIVATION=true
MBED_CONF_LORA_AUTOMATIC_UPLINK_MESSAGE=true
MBED_CONF_LORA_TX_MAX_SIZE=255
MDMTXD=NC
MDMRXD=NC
)
target_sources(mbed-stubs-connectivity
PRIVATE
aes_stub.c
AT_CellularContext_stub.cpp
AT_CellularDevice_stub.cpp
AT_CellularInformation_stub.cpp
AT_CellularNetwork_stub.cpp
AT_CellularSMS_stub.cpp
AT_CellularStack_stub.cpp
AT_ControlPlane_netif_stub.cpp
ATHandler_stub.cpp
CellularContext_stub.cpp
CellularDevice_stub.cpp
CellularInterface_stub.cpp
CellularStateMachine_stub.cpp
CellularUtil_stub.cpp
cipher_stub.c
cmac_stub.c
ip4tos_stub.c
LoRaMacChannelPlan_stub.cpp
LoRaMacCommand_stub.cpp
LoRaMacCrypto_stub.cpp
LoRaMac_stub.cpp
LoRaPHYEU868_stub.cpp
LoRaPHY_stub.cpp
LoRaWANStack_stub.cpp
LoRaWANTimer_stub.cpp
MeshInterface_stub.cpp
NetworkInterfaceDefaults_stub.cpp
NetworkInterface_stub.cpp
NetworkStack_stub.cpp
nsapi_dns_stub.cpp
SocketAddress_stub.cpp
SocketStats_Stub.cpp
stoip4_stub.c
${mbed-os_SOURCE_DIR}/connectivity/nanostack/coap-service/test/coap-service/unittest/stub/mbedtls_stub.c
)
target_link_libraries(mbed-stubs-connectivity
PRIVATE
mbed-headers
mbed-stubs-headers
gtest
)

View File

@ -0,0 +1,23 @@
# Copyright (c) 2021 ARM Limited. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
add_library(mbed-stubs-drivers)
target_sources(mbed-stubs-drivers
PRIVATE
BufferedSerial_stub.cpp
SerialBase_stub.cpp
)
target_compile_definitions(mbed-stubs-drivers
PRIVATE
DEVICE_SERIAL=1
DEVICE_INTERRUPTIN=1
MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE=115200
)
target_link_libraries(mbed-stubs-drivers
PRIVATE
mbed-headers
mbed-stubs-headers
)

View File

@ -0,0 +1,19 @@
# Copyright (c) 2021 ARM Limited. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
add_library(mbed-stubs-events)
target_sources(mbed-stubs-events
PRIVATE
equeue_stub.c
${mbed-os_SOURCE_DIR}/events/tests/UNITTESTS/stubs/EqueuePosix_stub.c
EventFlags_stub.cpp
EventQueue_stub.cpp
mbed_shared_queues_stub.cpp
)
target_link_libraries(mbed-stubs-events
PRIVATE
mbed-headers
mbed-stubs-headers
)

View File

@ -0,0 +1,29 @@
# Copyright (c) 2021 ARM Limited. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
add_library(mbed-stubs-hal)
target_compile_definitions(mbed-stubs-hal
PRIVATE
DEVICE_PWMOUT
DEVICE_WATCHDOG
MBED_WDOG_ASSERT=1
)
target_sources(mbed-stubs-hal
PRIVATE
pwmout_api_stub.c
us_ticker_stub.cpp
watchdog_api_stub.c
)
target_link_options(mbed-stubs-hal
PRIVATE
--coverage
)
target_link_libraries(mbed-stubs-hal
PRIVATE
mbed-headers
mbed-stubs-headers
)

View File

@ -0,0 +1,30 @@
# Copyright (c) 2021 ARM Limited. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
add_library(mbed-stubs-platform)
target_sources(mbed-stubs-platform
PRIVATE
mbed_critical_stub.c
mbed_atomic_stub.c
mbed_error.c
mbed_poll_stub.cpp
mbed_assert_stub.cpp
mbed_wait_api_stub.cpp
mbed_retarget_stub.cpp
FileHandle_stub.cpp
nvic_wrapper_stub.c
randLIB_stub.c
randLIB_stub.cpp
)
target_link_options(mbed-stubs-platform
PRIVATE
--coverage
)
target_link_libraries(mbed-stubs-platform
PRIVATE
mbed-headers
mbed-stubs-headers
)

View File

@ -0,0 +1,22 @@
# Copyright (c) 2021 ARM Limited. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
add_library(mbed-stubs-rtos)
target_sources(mbed-stubs-rtos
PRIVATE
ConditionVariable_stub.cpp
Kernel_stub.cpp
mbed_rtos_rtx_stub.c
Mutex_stub.cpp
rtx_mutex_stub.c
Semaphore_stub.cpp
ThisThread_stub.cpp
Thread_stub.cpp
)
target_link_libraries(mbed-stubs-rtos
PRIVATE
mbed-headers
mbed-stubs-headers
)

View File

@ -15,6 +15,6 @@
* limitations under the License.
*/
#include "cmsis_os2.h"
#include "mbed_rtos_types.h"
osMutexId_t singleton_mutex_id;

View File

@ -15,7 +15,7 @@
* limitations under the License.
*/
#include "cmsis_os2.h"
#include "mbed_rtos_types.h"
osStatus_t osMutexAcquire(osMutexId_t mutex_id, uint32_t timeout)
{

View File

@ -0,0 +1,26 @@
# Copyright (c) 2021 ARM Limited. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
add_library(mbed-stubs-storage)
target_sources(mbed-stubs-storage
PRIVATE
BufferedBlockDevice_stub.cpp
ChainingBlockDevice_stub.cpp
EmulatedSD.cpp
ExhaustibleBlockDevice_stub.cpp
FlashSimBlockDevice_stub.cpp
HeapBlockDevice_stub.cpp
MBRBlockDevice_stub.cpp
ObservingBlockDevice_stub.cpp
ProfilingBlockDevice_stub.cpp
ReadOnlyBlockDevice_stub.cpp
SlicingBlockDevice_stub.cpp
kv_config_stub.cpp
)
target_link_libraries(mbed-stubs-storage
PRIVATE
mbed-headers
mbed-stubs-headers
)

View File

@ -18,6 +18,7 @@
#include "MBRBlockDevice.h"
#include "mbed_critical.h"
#include <algorithm>
#include "mbed_toolchain.h"
// On disk structures, all entries are little endian

View File

@ -18,7 +18,7 @@
#ifndef CMSIS_OS_H_
#define CMSIS_OS_H_
#include "cmsis_os2.h"
#include "mbed_rtos_types.h"
#define osPriority osPriority_t
@ -27,4 +27,5 @@
typedef struct {
} osEvent;
typedef int32_t osStatus;
#endif

View File

@ -18,7 +18,7 @@
#define SEMAPHORE_H
#include <stdint.h>
#include "cmsis_os2.h"
#include "internal/mbed_rtos1_types.h"
#include "rtos/Kernel.h"
namespace rtos {

View File

@ -22,7 +22,7 @@
extern "C" {
#endif
#include "cmsis_os2.h"
#include "mbed_rtos_types.h"
#include "rtx_os.h"
#include "rtx_lib.h"
#include "mbed_rtx_conf.h"

View File

@ -86,6 +86,7 @@ class UnitTestTool(object):
args = [cmake,
"-G",
generator,
"-DBUILD_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

@ -1,47 +1,49 @@
# Copyright (c) 2020-2021 ARM Limited. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
function(_mbed_get_cortex_m_exception_handlers toolchain_dir)
foreach(key ${MBED_TARGET_LABELS})
if(${key} STREQUAL CORTEX_A)
set(STARTUP_RTX_FILE TARGET_CORTEX_A/irq_ca.S)
elseif(${key} STREQUAL M0)
set(STARTUP_RTX_FILE TARGET_M0/irq_cm0.S)
elseif(${key} STREQUAL M0P)
set(STARTUP_RTX_FILE TARGET_M0P/irq_cm0.S)
elseif(${key} STREQUAL M23)
set(STARTUP_RTX_FILE TARGET_M23/irq_armv8mbl.S)
elseif(${key} STREQUAL M3)
set(STARTUP_RTX_FILE TARGET_M3/irq_cm3.S)
elseif(${key} STREQUAL M33)
set(STARTUP_RTX_FILE TARGET_M33/irq_armv8mml.S)
elseif(${key} STREQUAL M55)
set(STARTUP_RTX_FILE TARGET_M33/irq_armv8mml.S)
elseif(${key} STREQUAL RTOS_M4_M7)
set(STARTUP_RTX_FILE TARGET_RTOS_M4_M7/irq_cm4f.S)
endif()
if(${CMAKE_CROSSCOMPILING})
function(_mbed_get_cortex_m_exception_handlers toolchain_dir)
foreach(key ${MBED_TARGET_LABELS})
if(${key} STREQUAL CORTEX_A)
set(STARTUP_RTX_FILE TARGET_CORTEX_A/irq_ca.S)
elseif(${key} STREQUAL M0)
set(STARTUP_RTX_FILE TARGET_M0/irq_cm0.S)
elseif(${key} STREQUAL M0P)
set(STARTUP_RTX_FILE TARGET_M0P/irq_cm0.S)
elseif(${key} STREQUAL M23)
set(STARTUP_RTX_FILE TARGET_M23/irq_armv8mbl.S)
elseif(${key} STREQUAL M3)
set(STARTUP_RTX_FILE TARGET_M3/irq_cm3.S)
elseif(${key} STREQUAL M33)
set(STARTUP_RTX_FILE TARGET_M33/irq_armv8mml.S)
elseif(${key} STREQUAL M55)
set(STARTUP_RTX_FILE TARGET_M33/irq_armv8mml.S)
elseif(${key} STREQUAL RTOS_M4_M7)
set(STARTUP_RTX_FILE TARGET_RTOS_M4_M7/irq_cm4f.S)
endif()
target_sources(mbed-rtos
INTERFACE
Source/${toolchain_dir}/${STARTUP_RTX_FILE}
)
endforeach()
endfunction()
function(_mbed_get_cortex_a_exception_handlers)
foreach(key ${MBED_TARGET_LABELS})
if(${key} STREQUAL CORTEX_A)
target_sources(mbed-rtos INTERFACE Config/TARGET_CORTEX_A/handlers.c)
endif()
endforeach()
endfunction()
_mbed_get_cortex_a_exception_handlers()
if(${MBED_TOOLCHAIN} STREQUAL "GCC_ARM")
_mbed_get_cortex_m_exception_handlers(TOOLCHAIN_GCC)
elseif(${MBED_TOOLCHAIN} STREQUAL "ARM")
_mbed_get_cortex_m_exception_handlers(TOOLCHAIN_ARM)
target_sources(mbed-rtos
INTERFACE
Source/${toolchain_dir}/${STARTUP_RTX_FILE}
)
endforeach()
endfunction()
function(_mbed_get_cortex_a_exception_handlers)
foreach(key ${MBED_TARGET_LABELS})
if(${key} STREQUAL CORTEX_A)
target_sources(mbed-rtos INTERFACE Config/TARGET_CORTEX_A/handlers.c)
endif()
endforeach()
endfunction()
_mbed_get_cortex_a_exception_handlers()
if(${MBED_TOOLCHAIN} STREQUAL "GCC_ARM")
_mbed_get_cortex_m_exception_handlers(TOOLCHAIN_GCC)
elseif(${MBED_TOOLCHAIN} STREQUAL "ARM")
_mbed_get_cortex_m_exception_handlers(TOOLCHAIN_ARM)
endif()
endif()
target_include_directories(mbed-rtos

View File

@ -1,16 +1,18 @@
# Copyright (c) 2020-2021 ARM Limited. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
if(${MBED_TOOLCHAIN} STREQUAL "GCC_ARM")
target_sources(mbed-rtos
INTERFACE
TOOLCHAIN_GCC_ARM/mbed_boot_gcc_arm.c
)
elseif(${MBED_TOOLCHAIN} STREQUAL "ARM")
target_sources(mbed-rtos
INTERFACE
TOOLCHAIN_ARM_STD/mbed_boot_arm_std.c
)
if(${CMAKE_CROSSCOMPILING})
if(${MBED_TOOLCHAIN} STREQUAL "GCC_ARM")
target_sources(mbed-rtos
INTERFACE
TOOLCHAIN_GCC_ARM/mbed_boot_gcc_arm.c
)
elseif(${MBED_TOOLCHAIN} STREQUAL "ARM")
target_sources(mbed-rtos
INTERFACE
TOOLCHAIN_ARM_STD/mbed_boot_arm_std.c
)
endif()
endif()
target_include_directories(mbed-rtos

View File

@ -24,14 +24,21 @@ add_library(mbed-nfc INTERFACE)
add_library(mbed-ppp INTERFACE)
add_library(mbed-wifi INTERFACE)
add_subdirectory(FEATURE_BLE)
add_subdirectory(cellular)
add_subdirectory(drivers)
add_subdirectory(libraries)
add_subdirectory(lorawan)
add_subdirectory(lwipstack)
add_subdirectory(mbedtls)
add_subdirectory(nanostack)
add_subdirectory(netsocket)
add_subdirectory(nfc)
if(${CMAKE_CROSSCOMPILING})
# The directories below contain optional target libraries
add_subdirectory(FEATURE_BLE EXCLUDE_FROM_ALL)
add_subdirectory(cellular EXCLUDE_FROM_ALL)
add_subdirectory(drivers EXCLUDE_FROM_ALL)
add_subdirectory(libraries EXCLUDE_FROM_ALL)
add_subdirectory(lorawan EXCLUDE_FROM_ALL)
add_subdirectory(lwipstack EXCLUDE_FROM_ALL)
add_subdirectory(mbedtls EXCLUDE_FROM_ALL)
add_subdirectory(nanostack EXCLUDE_FROM_ALL)
add_subdirectory(netsocket EXCLUDE_FROM_ALL)
add_subdirectory(nfc EXCLUDE_FROM_ALL)
else()
# Add these subdirectories for the Unit test
add_subdirectory(cellular)
add_subdirectory(lorawan)
add_subdirectory(netsocket)
endif()

View File

@ -41,7 +41,7 @@ private:
};
static entry_t *as_entry(entry_handle_t db_handle);
static constexpr uint8_t KVSTORESECURITYDB_VERSION = 1;
static constexpr size_t DB_PREFIX_SIZE = 7 + sizeof (STR(MBED_CONF_STORAGE_DEFAULT_KV)) - 1;

View File

@ -1,6 +1,10 @@
# Copyright (c) 2020 ARM Limited. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
if(NOT ${CMAKE_CROSSCOMPILING})
add_subdirectory(tests/UNITTESTS)
endif()
add_subdirectory(source/framework)
target_include_directories(mbed-cellular

View File

@ -0,0 +1,4 @@
# Copyright (c) 2021 ARM Limited. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
add_subdirectory(framework)

View File

@ -0,0 +1,9 @@
# Copyright (c) 2021 ARM Limited. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
add_subdirectory(at_cellularcontext)
add_subdirectory(at_cellulardevice)
add_subdirectory(at_cellularinformation)
add_subdirectory(at_cellularnetwork)
add_subdirectory(at_cellularsms)
add_subdirectory(at_cellularstack)

View File

@ -0,0 +1,33 @@
# Copyright (c) 2021 ARM Limited. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
set(TEST_NAME at_cellularcontext-unittest)
add_executable(${TEST_NAME})
target_compile_definitions(${TEST_NAME}
PRIVATE
DEVICE_SERIAL=1
DEVICE_INTERRUPTIN=1
MBED_CONF_CELLULAR_USE_SMS=1
MBED_CONF_NSAPI_DEFAULT_CELLULAR_APN=NULL
MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE=115200
)
target_sources(${TEST_NAME}
PRIVATE
${mbed-os_SOURCE_DIR}/connectivity/cellular/source/framework/AT/AT_CellularContext.cpp
at_cellularcontexttest.cpp
)
target_link_libraries(${TEST_NAME}
PRIVATE
mbed-headers
mbed-stubs
mbed-stubs-headers
gmock_main
)
add_test(NAME "${TEST_NAME}" COMMAND ${TEST_NAME})
set_tests_properties(${TEST_NAME} PROPERTIES LABELS "cellular")

Some files were not shown because too many files have changed in this diff Show More