mirror of https://github.com/ARMmbed/mbed-os.git
Merge branch 'ARMmbed:master' into adcBank
commit
72138269d3
|
@ -102,3 +102,5 @@ DELIVERY/
|
|||
CMakeCache.txt
|
||||
cmake_install.cmake
|
||||
CMakeFiles/
|
||||
cmake_build/
|
||||
Testing/
|
||||
|
|
142
.travis.yml
142
.travis.yml
|
@ -16,7 +16,7 @@
|
|||
|
||||
language: sh
|
||||
os: linux
|
||||
dist: xenial
|
||||
dist: focal
|
||||
|
||||
|
||||
env:
|
||||
|
@ -35,8 +35,15 @@ before_install:
|
|||
|
||||
addons:
|
||||
apt:
|
||||
sources:
|
||||
- sourceline: 'deb https://apt.kitware.com/ubuntu/ focal main'
|
||||
key_url: 'https://apt.kitware.com/keys/kitware-archive-latest.asc'
|
||||
packages:
|
||||
- ninja-build
|
||||
- cmake
|
||||
- ninja-build
|
||||
- gcovr
|
||||
- libncursesw5
|
||||
- g++-7
|
||||
|
||||
matrix:
|
||||
include:
|
||||
|
@ -216,10 +223,10 @@ matrix:
|
|||
### Python Tests ###
|
||||
- &pytools-vm
|
||||
stage: "Pytest"
|
||||
name: "tools-py27"
|
||||
env: NAME=tools-py2.7
|
||||
name: "tools-py35"
|
||||
env: NAME=tools-py3.5
|
||||
language: python
|
||||
python: 2.7
|
||||
python: 3.5
|
||||
install:
|
||||
# Install gcc
|
||||
- source_pkg gcc
|
||||
|
@ -246,11 +253,6 @@ matrix:
|
|||
- coverage run -a tools/project.py -S | sed -n '/^Total/p'
|
||||
- coverage html
|
||||
|
||||
- <<: *pytools-vm
|
||||
name: "tools-py35"
|
||||
env: NAME=tools-py3.5
|
||||
python: 3.5
|
||||
|
||||
- <<: *pytools-vm
|
||||
name: "tools-py36"
|
||||
env: NAME=tools-py3.6
|
||||
|
@ -261,68 +263,8 @@ matrix:
|
|||
env: NAME=tools-py3.7
|
||||
python: 3.7
|
||||
|
||||
|
||||
### Extended Tests ###
|
||||
- &extended-vm
|
||||
stage: "Extended"
|
||||
name: "littlefs"
|
||||
env: NAME=littlefs LITTLEFS=storage/filesystem/littlefs
|
||||
language: python
|
||||
python: 3.7
|
||||
install:
|
||||
# Install gcc
|
||||
- source_pkg gcc
|
||||
- arm-none-eabi-gcc --version
|
||||
# Install python modules
|
||||
- python -m pip install --upgrade pip==18.1
|
||||
- python -m pip install --upgrade setuptools==40.4.3
|
||||
- pip install -r requirements.txt
|
||||
- pip list --verbose
|
||||
# Install test-specific packages
|
||||
- source_pkg fuse
|
||||
- source_pkg libfuse-dev
|
||||
- fusermount --version
|
||||
before_script:
|
||||
# Setup and patch littlefs-fuse
|
||||
- git clone https://github.com/armmbed/littlefs-fuse littlefs_fuse
|
||||
- git -C littlefs_fuse checkout 3f1ed6e37799e49e3710830dc6abb926d5503cf2
|
||||
- echo '*' > littlefs_fuse/.mbedignore
|
||||
- rm -rf littlefs_fuse/littlefs/*
|
||||
- cp -r $(git ls-tree --name-only HEAD ${LITTLEFS}/littlefs/) littlefs_fuse/littlefs
|
||||
# Create file-backed disk
|
||||
- mkdir MOUNT
|
||||
- sudo chmod a+rw /dev/loop0
|
||||
- dd if=/dev/zero bs=512 count=2048 of=DISK
|
||||
- losetup /dev/loop0 DISK
|
||||
- CFLAGS="-Werror -Wno-format"
|
||||
script:
|
||||
# Run local littlefs tests
|
||||
- make -C${LITTLEFS}/littlefs test QUIET=1
|
||||
# Run local littlefs tests with set of variations
|
||||
- make -C${LITTLEFS}/littlefs test QUIET=1 CFLAGS+="-DLFS_READ_SIZE=64 -DLFS_PROG_SIZE=64"
|
||||
- make -C${LITTLEFS}/littlefs test QUIET=1 CFLAGS+="-DLFS_READ_SIZE=1 -DLFS_PROG_SIZE=1"
|
||||
- make -C${LITTLEFS}/littlefs test QUIET=1 CFLAGS+="-DLFS_READ_SIZE=512 -DLFS_PROG_SIZE=512"
|
||||
- make -C${LITTLEFS}/littlefs test QUIET=1 CFLAGS+="-DLFS_BLOCK_COUNT=1023 -DLFS_LOOKAHEAD=2048"
|
||||
- make -C${LITTLEFS}/littlefs clean test QUIET=1 CFLAGS+="-DLFS_NO_INTRINSICS"
|
||||
# Self-hosting littlefs fuzz test with littlefs-fuse
|
||||
- make -Clittlefs_fuse
|
||||
- littlefs_fuse/lfs --format /dev/loop0
|
||||
- littlefs_fuse/lfs /dev/loop0 MOUNT
|
||||
- ls MOUNT
|
||||
- mkdir MOUNT/littlefs
|
||||
- cp -r $(git ls-tree --name-only HEAD ${LITTLEFS}/littlefs/) MOUNT/littlefs
|
||||
- ls MOUNT/littlefs
|
||||
- CFLAGS="-Wno-format" make -CMOUNT/littlefs -B test_dirs test_files QUIET=1
|
||||
# Compile and find the code size with smallest configuration
|
||||
- cd ${TRAVIS_BUILD_DIR}/${LITTLEFS}/littlefs
|
||||
- make clean size
|
||||
CC='arm-none-eabi-gcc -mthumb'
|
||||
OBJ="$(ls lfs*.o | tr '\n' ' ')"
|
||||
CFLAGS+="-DLFS_NO_ASSERT -DLFS_NO_DEBUG -DLFS_NO_WARN -DLFS_NO_ERROR"
|
||||
| tee sizes
|
||||
- ccache -s
|
||||
- <<: extended-pinvalidate
|
||||
stage: "Extended"
|
||||
stage: "Pin validation"
|
||||
name: "pinvalidate"
|
||||
env: NAME=pinvalidate
|
||||
language: python
|
||||
|
@ -343,3 +285,61 @@ matrix:
|
|||
| while read file; do python ./hal/tests/pinvalidate/pinvalidate.py -vfp "${file}"; done
|
||||
- git diff --exit-code --diff-filter=d --color
|
||||
|
||||
### CMake Check ###
|
||||
- &cmake-vm
|
||||
stage: "CMake Check"
|
||||
name: "Backward compatiblity check - MBED_TEST_MODE"
|
||||
env: NAME=mbed-test-mode-check ROOT=tools/cmake/tests/mbed_test_mode/ TOOLCHAIN=GCC_ARM TARGET_NAME=K64F PROFILE=develop
|
||||
language: python
|
||||
python: 3.8
|
||||
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*
|
||||
# Setup ccache
|
||||
- ccache -o compiler_check=content
|
||||
- ccache -M 1G
|
||||
- pushd /usr/lib/ccache
|
||||
- sudo ln -s ../../bin/ccache arm-none-eabi-gcc
|
||||
- sudo ln -s ../../bin/ccache arm-none-eabi-g++
|
||||
- export PATH="/usr/lib/ccache:$PATH"
|
||||
- popd
|
||||
# Install arm-none-eabi-gcc
|
||||
- pushd /home/travis/build && mkdir arm-gcc && cd arm-gcc
|
||||
- curl -L0 "https://developer.arm.com/-/media/Files/downloads/gnu-rm/9-2020q2/gcc-arm-none-eabi-9-2020-q2-update-x86_64-linux.tar.bz2?revision=05382cca-1721-44e1-ae19-1e7c3dc96118&la=en&hash=D7C9D18FCA2DD9F894FD9F3C3DC9228498FA281A" --output gcc-arm-none-eabi-9-2020-q2-update.tar.bz2
|
||||
- tar xf gcc-arm-none-eabi-9-2020-q2-update.tar.bz2
|
||||
- export PATH="$PATH:${PWD}/gcc-arm-none-eabi-9-2020-q2-update/bin"
|
||||
- popd
|
||||
- arm-none-eabi-gcc --version
|
||||
# Install python modules
|
||||
- pip install --upgrade mbed-tools
|
||||
- pip install -r tools/cmake/requirements.txt
|
||||
script:
|
||||
- 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
|
188
CMakeLists.txt
188
CMakeLists.txt
|
@ -5,8 +5,24 @@
|
|||
|
||||
cmake_minimum_required(VERSION 3.19.0 FATAL_ERROR)
|
||||
|
||||
include(${MBED_CONFIG_PATH}/mbed_config.cmake)
|
||||
include(tools/cmake/set_linker_script.cmake)
|
||||
if(${CMAKE_CROSSCOMPILING})
|
||||
include(${MBED_CONFIG_PATH}/mbed_config.cmake)
|
||||
include(mbed_set_linker_script)
|
||||
endif()
|
||||
|
||||
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"
|
||||
)
|
||||
|
||||
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)
|
||||
|
||||
|
@ -26,80 +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}
|
||||
)
|
||||
|
||||
# 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
|
||||
|
@ -121,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.
|
||||
|
@ -214,7 +244,7 @@ function(mbed_generate_map_file target)
|
|||
TARGET
|
||||
${target}
|
||||
POST_BUILD
|
||||
COMMAND ${Python3_EXECUTABLE} ${MBED_PATH}/tools/memap.py -t ${MBED_TOOLCHAIN} ${CMAKE_CURRENT_BINARY_DIR}/${target}${CMAKE_EXECUTABLE_SUFFIX}.map
|
||||
COMMAND ${Python3_EXECUTABLE} ${mbed-os_SOURCE_DIR}/tools/memap.py -t ${MBED_TOOLCHAIN} ${CMAKE_CURRENT_BINARY_DIR}/${target}${CMAKE_EXECUTABLE_SUFFIX}.map
|
||||
WORKING_DIRECTORY
|
||||
${CMAKE_CURRENT_BINARY_DIR}
|
||||
COMMENT
|
||||
|
@ -259,7 +289,7 @@ endfunction()
|
|||
if ("${CMAKE_GENERATOR}" MATCHES "Ninja")
|
||||
# known issue ARMClang and Ninja with response files for windows
|
||||
# https://gitlab.kitware.com/cmake/cmake/-/issues/21093
|
||||
if(NOT (CMAKE_HOST_SYSTEM_NAME MATCHES "Windows" AND CMAKE_CXX_COMPILER_ID MATCHES "ARMClang"))
|
||||
if((CMAKE_HOST_SYSTEM_NAME MATCHES "Windows" AND NOT CMAKE_CXX_COMPILER_ID MATCHES "ARMClang"))
|
||||
set(CMAKE_NINJA_FORCE_RESPONSE_FILE 1 CACHE INTERNAL "")
|
||||
endif()
|
||||
endif()
|
||||
|
|
|
@ -18,8 +18,10 @@
|
|||
"storage_filesystem",
|
||||
"storage_tdb_external",
|
||||
"fat_chan",
|
||||
"cordio-stm32wb",
|
||||
"lora",
|
||||
"sx1276-lora-driver",
|
||||
"stm32wl-lora-driver",
|
||||
"nfc",
|
||||
"network-emac",
|
||||
"flashiap-block-device",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# NFC tests.
|
||||
|
||||
A CI test suite for NFC component. These tests validate card mbed emulation cases. The key use case is an NFC smart poster supporting comissioning workflow.
|
||||
A CI test suite for NFC component. These tests validate card mbed emulation cases. The key use case is an NFC smart poster supporting commissioning workflow.
|
||||
The SUT (system under test) is the NFC target. Tests exercise the framework and NDEF transactions when a NFC controller driver is used, or when the stack is configured for an NFC EEPROM chip in the system integration.
|
||||
|
||||
This project is called CreamScone, which is an ice tea framework based cli-driven python test.
|
||||
|
@ -42,7 +42,7 @@ Not in scope. Test procedures using a mobile phone app for Android and for IOS w
|
|||
|
||||

|
||||
|
||||
Because the comissioning workflow application quality is the end goal, the NFC suite includes learnings to design the CI setup needed for future system testing that bring a mobile phone into the test-rig. The use of a mobile and bluetooth pairing as well as the continous integration system is not included.
|
||||
Because the commissioning workflow application quality is the end goal, the NFC suite includes learnings to design the CI setup needed for future system testing that bring a mobile phone into the test-rig. The use of a mobile and bluetooth pairing as well as the continuous integration system is not included.
|
||||
|
||||
|
||||
|
||||
|
@ -288,7 +288,7 @@ NFCProcessController::NFCProcessController(events::EventQueue &queue) :
|
|||
}
|
||||
```
|
||||
1. You will want to replace this and reference the desired controller driver. Likewise, this code is where pinout changes have to be made if using the supplied Controller driver.
|
||||
2. Search for occurences of guard macros `#ifdef TARGET_PN512` , and `#endif`. Add a new guard macro and code for your specific controller driver at the same point.
|
||||
2. Search for occurrences of guard macros `#ifdef TARGET_PN512` , and `#endif`. Add a new guard macro and code for your specific controller driver at the same point.
|
||||
|
||||
|
||||
Note: If the target uses an EEPROM, it need not be powered/running, to be read, mbedOS is not running at that point.
|
||||
|
@ -333,4 +333,4 @@ You can issue the command "getlastnfcerror help" to see a list of error codes th
|
|||
|
||||
1. Test test_nfce2e_discovery_loop fails on NFC controller. The NFC controller driver discovery loop cannot be stopped manually. No major functionality is lost, it only prevents a complete disable of NFC at runtime. A bug ticket #IOTPAN-313 was logged to fix the stop function. The Controller still restarts discovery loop normally under app control after a peer disconnects.
|
||||
|
||||
1. The smartposter NDEF record wrapper class `smartposter.h` is also provided as part of the NFC examples. The examples are not needed to compile the test app, but this example class may be usefull to customers. This file may thus move into the NFC component in future.
|
||||
1. The smartposter NDEF record wrapper class `smartposter.h` is also provided as part of the NFC examples. The examples are not needed to compile the test app, but this example class may be useful to customers. This file may thus move into the NFC component in future.
|
||||
|
|
|
@ -15,7 +15,7 @@ A comparison of the SDKs exposed to manage NFC tags on Android IOs and Python mo
|
|||
<!-- /TOC -->
|
||||
|
||||
# Overview
|
||||
A comparison which analyses NFC use cases on mobile, as background to the test case design/implementation in the comissioning workflow :NFC-Bluetooth-pairing application.
|
||||
A comparison which analyses NFC use cases on mobile, as background to the test case design/implementation in the commissioning workflow :NFC-Bluetooth-pairing application.
|
||||
- Analyse the [Apple API](https://developer.apple.com/documentation/corenfc)
|
||||
- Analyse the [Android API](https://developer.android.com/guide/topics/connectivity/nfc/advanced-nfc#java)
|
||||
- Python test [pynfc modules](https://nfcpy.readthedocs.io/en/latest/modules/index.html)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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`.
|
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
)
|
|
@ -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
|
||||
)
|
|
@ -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
|
||||
)
|
|
@ -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
|
||||
)
|
|
@ -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
|
||||
)
|
|
@ -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
|
||||
)
|
|
@ -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
|
||||
)
|
|
@ -15,6 +15,6 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "cmsis_os2.h"
|
||||
#include "mbed_rtos_types.h"
|
||||
|
||||
osMutexId_t singleton_mutex_id;
|
|
@ -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)
|
||||
{
|
|
@ -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
|
||||
)
|
|
@ -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
|
|
@ -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
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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()]
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -122,8 +122,9 @@ public:
|
|||
}
|
||||
|
||||
/**
|
||||
* Function invoked when the server has sent data to a client as
|
||||
* part of a notification/indication.
|
||||
* Function invoked when the server has sent data to a client. For
|
||||
* notifications this is triggered when data is sent, for indications
|
||||
* it's only triggered when the confirmation has been received.
|
||||
*
|
||||
* @note params has a temporary scope and should be copied by the
|
||||
* application if needed later
|
||||
|
@ -188,12 +189,13 @@ public:
|
|||
}
|
||||
|
||||
/**
|
||||
* Function invoked when an ACK has been received for an
|
||||
* indication sent to the client.
|
||||
* Event not used.
|
||||
*
|
||||
* @note params has a temporary scope and should be copied by the
|
||||
* application if needed later
|
||||
*/
|
||||
MBED_DEPRECATED_SINCE("mbed-os-6.11.0", "This event is never triggered. Indication triggers onDataSent"
|
||||
"when confirmation is received.")
|
||||
virtual void onConfirmationReceived(const GattConfirmationReceivedCallbackParams ¶ms) {
|
||||
(void)params;
|
||||
}
|
||||
|
@ -274,7 +276,7 @@ public:
|
|||
* Event handler that handles subscription to characteristic updates,
|
||||
* unsubscription from characteristic updates and notification confirmation.
|
||||
*
|
||||
* @see onUpdatesEnabled() onUpdateDisabled() onConfirmationReceived()
|
||||
* @see onUpdatesEnabled() onUpdateDisabled()
|
||||
*/
|
||||
typedef FunctionPointerWithContext<GattAttribute::Handle_t> EventCallback_t;
|
||||
|
||||
|
@ -705,7 +707,8 @@ public:
|
|||
* @param[in] callback Event handler being registered.
|
||||
*/
|
||||
MBED_DEPRECATED_SINCE("mbed-os-6.3.0", "Individual callback-registering functions have"
|
||||
"been replaced by GattServer::setEventHandler. Use that function instead.")
|
||||
"been replaced by an event handler. Indication confirmation triggers"
|
||||
"GattServer::onDataSent event instead.")
|
||||
void onConfirmationReceived(EventCallback_t callback);
|
||||
|
||||
#if !defined(DOXYGEN_ONLY)
|
||||
|
|
|
@ -1672,19 +1672,30 @@ public:
|
|||
*
|
||||
* @attention This function is not meant to be called by user code.
|
||||
*
|
||||
* @param[in] params Context of the read-auth request; it contains an
|
||||
* @param[in,out] params Context of the read-auth request; it contains an
|
||||
* out-parameter used as a reply and the handler can fill it with outgoing
|
||||
* data.
|
||||
* data. The params->data provides a pointer to the data and params->len
|
||||
* provides the length of this data. params->len is also used to pass the
|
||||
* maximum size of data that the params->data can contain. If you set the
|
||||
* params->len to a value larger than the passed in value the read operation
|
||||
* will fail.
|
||||
*
|
||||
* @return A GattAuthCallbackReply_t value indicating whether authorization
|
||||
* is granted.
|
||||
*
|
||||
* @note If the read is approved, the event handler can specify an outgoing
|
||||
* value directly with the help of the fields params->data and params->len.
|
||||
*
|
||||
* @note If the read request is approved and params->data remains nullptr, then
|
||||
* the current characteristic value is used in the read response payload.
|
||||
*
|
||||
* @note If the read is approved, the event handler can specify an outgoing
|
||||
* value directly with the help of the fields
|
||||
* GattReadAuthCallbackParams::data and GattReadAuthCallbackParams::len.
|
||||
* @note The params->len parameter initially contains the maximum length of
|
||||
* data that can be returned. Set it to the length of your data but it must
|
||||
* not be larger than the original value.
|
||||
*
|
||||
* @note You must also take into account the offset provided in params->offset.
|
||||
* The params->len you provide must be larger then the offset as the read operation
|
||||
* will attempt to read at that offset.
|
||||
*/
|
||||
GattAuthCallbackReply_t authorizeRead(GattReadAuthCallbackParams *params)
|
||||
{
|
||||
|
|
|
@ -160,7 +160,7 @@ ble_error_t Gap::startPeriodicAdvertising(advertising_handle_t handle)
|
|||
|
||||
ble_error_t Gap::stopPeriodicAdvertising(advertising_handle_t handle)
|
||||
{
|
||||
return impl->stopAdvertising(handle);
|
||||
return impl->stopPeriodicAdvertising(handle);
|
||||
}
|
||||
|
||||
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue