diff --git a/.gitignore b/.gitignore index deb1de7433..3e907cf52c 100644 --- a/.gitignore +++ b/.gitignore @@ -102,3 +102,5 @@ DELIVERY/ CMakeCache.txt cmake_install.cmake CMakeFiles/ +cmake_build/ +Testing/ diff --git a/.travis.yml b/.travis.yml index 5b325995d5..64dfc55c49 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 68c48add1c..10d4389f46 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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. diff --git a/UNITTESTS/CMakeLists.txt b/UNITTESTS/CMakeLists.txt index 6aba4ba07f..bb00da96e3 100644 --- a/UNITTESTS/CMakeLists.txt +++ b/UNITTESTS/CMakeLists.txt @@ -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 - "$" - "$") #################### # 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) diff --git a/UNITTESTS/README.md b/UNITTESTS/README.md deleted file mode 100644 index 5dd3f04511..0000000000 --- a/UNITTESTS/README.md +++ /dev/null @@ -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=`, `-DCMAKE_CXX_COMPILER=` and `-DCMAKE_C_COMPILER=` 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`. diff --git a/UNITTESTS/mbed_unittest.py b/UNITTESTS/mbed_unittest.py index 41039b0354..9312c38bfe 100755 --- a/UNITTESTS/mbed_unittest.py +++ b/UNITTESTS/mbed_unittest.py @@ -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, diff --git a/UNITTESTS/stubs/CMakeLists.txt b/UNITTESTS/stubs/CMakeLists.txt new file mode 100644 index 0000000000..942adbcbf8 --- /dev/null +++ b/UNITTESTS/stubs/CMakeLists.txt @@ -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 +) diff --git a/UNITTESTS/stubs/ATHandler_stub.cpp b/UNITTESTS/stubs/connectivity/ATHandler_stub.cpp similarity index 100% rename from UNITTESTS/stubs/ATHandler_stub.cpp rename to UNITTESTS/stubs/connectivity/ATHandler_stub.cpp diff --git a/UNITTESTS/stubs/AT_CellularContext_stub.cpp b/UNITTESTS/stubs/connectivity/AT_CellularContext_stub.cpp similarity index 100% rename from UNITTESTS/stubs/AT_CellularContext_stub.cpp rename to UNITTESTS/stubs/connectivity/AT_CellularContext_stub.cpp diff --git a/UNITTESTS/stubs/AT_CellularDevice_stub.cpp b/UNITTESTS/stubs/connectivity/AT_CellularDevice_stub.cpp similarity index 100% rename from UNITTESTS/stubs/AT_CellularDevice_stub.cpp rename to UNITTESTS/stubs/connectivity/AT_CellularDevice_stub.cpp diff --git a/UNITTESTS/stubs/AT_CellularInformation_stub.cpp b/UNITTESTS/stubs/connectivity/AT_CellularInformation_stub.cpp similarity index 100% rename from UNITTESTS/stubs/AT_CellularInformation_stub.cpp rename to UNITTESTS/stubs/connectivity/AT_CellularInformation_stub.cpp diff --git a/UNITTESTS/stubs/AT_CellularNetwork_stub.cpp b/UNITTESTS/stubs/connectivity/AT_CellularNetwork_stub.cpp similarity index 100% rename from UNITTESTS/stubs/AT_CellularNetwork_stub.cpp rename to UNITTESTS/stubs/connectivity/AT_CellularNetwork_stub.cpp diff --git a/UNITTESTS/stubs/AT_CellularSMS_stub.cpp b/UNITTESTS/stubs/connectivity/AT_CellularSMS_stub.cpp similarity index 100% rename from UNITTESTS/stubs/AT_CellularSMS_stub.cpp rename to UNITTESTS/stubs/connectivity/AT_CellularSMS_stub.cpp diff --git a/UNITTESTS/stubs/AT_CellularStack_stub.cpp b/UNITTESTS/stubs/connectivity/AT_CellularStack_stub.cpp similarity index 100% rename from UNITTESTS/stubs/AT_CellularStack_stub.cpp rename to UNITTESTS/stubs/connectivity/AT_CellularStack_stub.cpp diff --git a/UNITTESTS/stubs/AT_ControlPlane_netif_stub.cpp b/UNITTESTS/stubs/connectivity/AT_ControlPlane_netif_stub.cpp similarity index 100% rename from UNITTESTS/stubs/AT_ControlPlane_netif_stub.cpp rename to UNITTESTS/stubs/connectivity/AT_ControlPlane_netif_stub.cpp diff --git a/UNITTESTS/stubs/connectivity/CMakeLists.txt b/UNITTESTS/stubs/connectivity/CMakeLists.txt new file mode 100644 index 0000000000..faba2e38e2 --- /dev/null +++ b/UNITTESTS/stubs/connectivity/CMakeLists.txt @@ -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 +) diff --git a/UNITTESTS/stubs/CellularContext_stub.cpp b/UNITTESTS/stubs/connectivity/CellularContext_stub.cpp similarity index 100% rename from UNITTESTS/stubs/CellularContext_stub.cpp rename to UNITTESTS/stubs/connectivity/CellularContext_stub.cpp diff --git a/UNITTESTS/stubs/CellularDevice_stub.cpp b/UNITTESTS/stubs/connectivity/CellularDevice_stub.cpp similarity index 100% rename from UNITTESTS/stubs/CellularDevice_stub.cpp rename to UNITTESTS/stubs/connectivity/CellularDevice_stub.cpp diff --git a/UNITTESTS/stubs/CellularInterface_stub.cpp b/UNITTESTS/stubs/connectivity/CellularInterface_stub.cpp similarity index 100% rename from UNITTESTS/stubs/CellularInterface_stub.cpp rename to UNITTESTS/stubs/connectivity/CellularInterface_stub.cpp diff --git a/UNITTESTS/stubs/CellularStateMachine_stub.cpp b/UNITTESTS/stubs/connectivity/CellularStateMachine_stub.cpp similarity index 100% rename from UNITTESTS/stubs/CellularStateMachine_stub.cpp rename to UNITTESTS/stubs/connectivity/CellularStateMachine_stub.cpp diff --git a/UNITTESTS/stubs/CellularUtil_stub.cpp b/UNITTESTS/stubs/connectivity/CellularUtil_stub.cpp similarity index 100% rename from UNITTESTS/stubs/CellularUtil_stub.cpp rename to UNITTESTS/stubs/connectivity/CellularUtil_stub.cpp diff --git a/UNITTESTS/stubs/LoRaMacChannelPlan_stub.cpp b/UNITTESTS/stubs/connectivity/LoRaMacChannelPlan_stub.cpp similarity index 100% rename from UNITTESTS/stubs/LoRaMacChannelPlan_stub.cpp rename to UNITTESTS/stubs/connectivity/LoRaMacChannelPlan_stub.cpp diff --git a/UNITTESTS/stubs/LoRaMacCommand_stub.cpp b/UNITTESTS/stubs/connectivity/LoRaMacCommand_stub.cpp similarity index 100% rename from UNITTESTS/stubs/LoRaMacCommand_stub.cpp rename to UNITTESTS/stubs/connectivity/LoRaMacCommand_stub.cpp diff --git a/UNITTESTS/stubs/LoRaMacCrypto_stub.cpp b/UNITTESTS/stubs/connectivity/LoRaMacCrypto_stub.cpp similarity index 100% rename from UNITTESTS/stubs/LoRaMacCrypto_stub.cpp rename to UNITTESTS/stubs/connectivity/LoRaMacCrypto_stub.cpp diff --git a/UNITTESTS/stubs/LoRaMac_stub.cpp b/UNITTESTS/stubs/connectivity/LoRaMac_stub.cpp similarity index 100% rename from UNITTESTS/stubs/LoRaMac_stub.cpp rename to UNITTESTS/stubs/connectivity/LoRaMac_stub.cpp diff --git a/UNITTESTS/stubs/LoRaPHYEU868_stub.cpp b/UNITTESTS/stubs/connectivity/LoRaPHYEU868_stub.cpp similarity index 100% rename from UNITTESTS/stubs/LoRaPHYEU868_stub.cpp rename to UNITTESTS/stubs/connectivity/LoRaPHYEU868_stub.cpp diff --git a/UNITTESTS/stubs/LoRaPHY_stub.cpp b/UNITTESTS/stubs/connectivity/LoRaPHY_stub.cpp similarity index 100% rename from UNITTESTS/stubs/LoRaPHY_stub.cpp rename to UNITTESTS/stubs/connectivity/LoRaPHY_stub.cpp diff --git a/UNITTESTS/stubs/LoRaWANStack_stub.cpp b/UNITTESTS/stubs/connectivity/LoRaWANStack_stub.cpp similarity index 100% rename from UNITTESTS/stubs/LoRaWANStack_stub.cpp rename to UNITTESTS/stubs/connectivity/LoRaWANStack_stub.cpp diff --git a/UNITTESTS/stubs/LoRaWANTimer_stub.cpp b/UNITTESTS/stubs/connectivity/LoRaWANTimer_stub.cpp similarity index 100% rename from UNITTESTS/stubs/LoRaWANTimer_stub.cpp rename to UNITTESTS/stubs/connectivity/LoRaWANTimer_stub.cpp diff --git a/UNITTESTS/stubs/MeshInterface_stub.cpp b/UNITTESTS/stubs/connectivity/MeshInterface_stub.cpp similarity index 100% rename from UNITTESTS/stubs/MeshInterface_stub.cpp rename to UNITTESTS/stubs/connectivity/MeshInterface_stub.cpp diff --git a/UNITTESTS/stubs/NetworkInterfaceDefaults_stub.cpp b/UNITTESTS/stubs/connectivity/NetworkInterfaceDefaults_stub.cpp similarity index 100% rename from UNITTESTS/stubs/NetworkInterfaceDefaults_stub.cpp rename to UNITTESTS/stubs/connectivity/NetworkInterfaceDefaults_stub.cpp diff --git a/UNITTESTS/stubs/NetworkInterface_stub.cpp b/UNITTESTS/stubs/connectivity/NetworkInterface_stub.cpp similarity index 100% rename from UNITTESTS/stubs/NetworkInterface_stub.cpp rename to UNITTESTS/stubs/connectivity/NetworkInterface_stub.cpp diff --git a/UNITTESTS/stubs/NetworkStack_stub.cpp b/UNITTESTS/stubs/connectivity/NetworkStack_stub.cpp similarity index 100% rename from UNITTESTS/stubs/NetworkStack_stub.cpp rename to UNITTESTS/stubs/connectivity/NetworkStack_stub.cpp diff --git a/UNITTESTS/stubs/SocketAddress_stub.cpp b/UNITTESTS/stubs/connectivity/SocketAddress_stub.cpp similarity index 100% rename from UNITTESTS/stubs/SocketAddress_stub.cpp rename to UNITTESTS/stubs/connectivity/SocketAddress_stub.cpp diff --git a/UNITTESTS/stubs/SocketStats_Stub.cpp b/UNITTESTS/stubs/connectivity/SocketStats_Stub.cpp similarity index 100% rename from UNITTESTS/stubs/SocketStats_Stub.cpp rename to UNITTESTS/stubs/connectivity/SocketStats_Stub.cpp diff --git a/UNITTESTS/stubs/aes_stub.c b/UNITTESTS/stubs/connectivity/aes_stub.c similarity index 100% rename from UNITTESTS/stubs/aes_stub.c rename to UNITTESTS/stubs/connectivity/aes_stub.c diff --git a/UNITTESTS/stubs/cipher_stub.c b/UNITTESTS/stubs/connectivity/cipher_stub.c similarity index 100% rename from UNITTESTS/stubs/cipher_stub.c rename to UNITTESTS/stubs/connectivity/cipher_stub.c diff --git a/UNITTESTS/stubs/cmac_stub.c b/UNITTESTS/stubs/connectivity/cmac_stub.c similarity index 100% rename from UNITTESTS/stubs/cmac_stub.c rename to UNITTESTS/stubs/connectivity/cmac_stub.c diff --git a/UNITTESTS/stubs/ip4tos_stub.c b/UNITTESTS/stubs/connectivity/ip4tos_stub.c similarity index 100% rename from UNITTESTS/stubs/ip4tos_stub.c rename to UNITTESTS/stubs/connectivity/ip4tos_stub.c diff --git a/UNITTESTS/stubs/nsapi_dns_stub.cpp b/UNITTESTS/stubs/connectivity/nsapi_dns_stub.cpp similarity index 100% rename from UNITTESTS/stubs/nsapi_dns_stub.cpp rename to UNITTESTS/stubs/connectivity/nsapi_dns_stub.cpp diff --git a/UNITTESTS/stubs/stoip4_stub.c b/UNITTESTS/stubs/connectivity/stoip4_stub.c similarity index 100% rename from UNITTESTS/stubs/stoip4_stub.c rename to UNITTESTS/stubs/connectivity/stoip4_stub.c diff --git a/UNITTESTS/stubs/BufferedSerial_stub.cpp b/UNITTESTS/stubs/drivers/BufferedSerial_stub.cpp similarity index 100% rename from UNITTESTS/stubs/BufferedSerial_stub.cpp rename to UNITTESTS/stubs/drivers/BufferedSerial_stub.cpp diff --git a/UNITTESTS/stubs/drivers/CMakeLists.txt b/UNITTESTS/stubs/drivers/CMakeLists.txt new file mode 100644 index 0000000000..139fa28451 --- /dev/null +++ b/UNITTESTS/stubs/drivers/CMakeLists.txt @@ -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 +) diff --git a/UNITTESTS/stubs/SerialBase_stub.cpp b/UNITTESTS/stubs/drivers/SerialBase_stub.cpp similarity index 100% rename from UNITTESTS/stubs/SerialBase_stub.cpp rename to UNITTESTS/stubs/drivers/SerialBase_stub.cpp diff --git a/UNITTESTS/stubs/events/CMakeLists.txt b/UNITTESTS/stubs/events/CMakeLists.txt new file mode 100644 index 0000000000..c0127aab56 --- /dev/null +++ b/UNITTESTS/stubs/events/CMakeLists.txt @@ -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 +) diff --git a/UNITTESTS/stubs/EventFlags_stub.cpp b/UNITTESTS/stubs/events/EventFlags_stub.cpp similarity index 100% rename from UNITTESTS/stubs/EventFlags_stub.cpp rename to UNITTESTS/stubs/events/EventFlags_stub.cpp diff --git a/UNITTESTS/stubs/EventQueue_stub.cpp b/UNITTESTS/stubs/events/EventQueue_stub.cpp similarity index 100% rename from UNITTESTS/stubs/EventQueue_stub.cpp rename to UNITTESTS/stubs/events/EventQueue_stub.cpp diff --git a/UNITTESTS/stubs/equeue_stub.c b/UNITTESTS/stubs/events/equeue_stub.c similarity index 100% rename from UNITTESTS/stubs/equeue_stub.c rename to UNITTESTS/stubs/events/equeue_stub.c diff --git a/UNITTESTS/stubs/mbed_shared_queues_stub.cpp b/UNITTESTS/stubs/events/mbed_shared_queues_stub.cpp similarity index 100% rename from UNITTESTS/stubs/mbed_shared_queues_stub.cpp rename to UNITTESTS/stubs/events/mbed_shared_queues_stub.cpp diff --git a/UNITTESTS/stubs/hal/CMakeLists.txt b/UNITTESTS/stubs/hal/CMakeLists.txt new file mode 100644 index 0000000000..a327d31efc --- /dev/null +++ b/UNITTESTS/stubs/hal/CMakeLists.txt @@ -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 +) diff --git a/UNITTESTS/stubs/pwmout_api_stub.c b/UNITTESTS/stubs/hal/pwmout_api_stub.c similarity index 100% rename from UNITTESTS/stubs/pwmout_api_stub.c rename to UNITTESTS/stubs/hal/pwmout_api_stub.c diff --git a/UNITTESTS/stubs/us_ticker_stub.cpp b/UNITTESTS/stubs/hal/us_ticker_stub.cpp similarity index 100% rename from UNITTESTS/stubs/us_ticker_stub.cpp rename to UNITTESTS/stubs/hal/us_ticker_stub.cpp diff --git a/UNITTESTS/stubs/watchdog_api_stub.c b/UNITTESTS/stubs/hal/watchdog_api_stub.c similarity index 100% rename from UNITTESTS/stubs/watchdog_api_stub.c rename to UNITTESTS/stubs/hal/watchdog_api_stub.c diff --git a/UNITTESTS/stubs/platform/CMakeLists.txt b/UNITTESTS/stubs/platform/CMakeLists.txt new file mode 100644 index 0000000000..051bc67877 --- /dev/null +++ b/UNITTESTS/stubs/platform/CMakeLists.txt @@ -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 +) diff --git a/UNITTESTS/stubs/FileHandle_stub.cpp b/UNITTESTS/stubs/platform/FileHandle_stub.cpp similarity index 100% rename from UNITTESTS/stubs/FileHandle_stub.cpp rename to UNITTESTS/stubs/platform/FileHandle_stub.cpp diff --git a/UNITTESTS/stubs/mbed_assert_stub.cpp b/UNITTESTS/stubs/platform/mbed_assert_stub.cpp similarity index 100% rename from UNITTESTS/stubs/mbed_assert_stub.cpp rename to UNITTESTS/stubs/platform/mbed_assert_stub.cpp diff --git a/UNITTESTS/stubs/mbed_atomic_stub.c b/UNITTESTS/stubs/platform/mbed_atomic_stub.c similarity index 100% rename from UNITTESTS/stubs/mbed_atomic_stub.c rename to UNITTESTS/stubs/platform/mbed_atomic_stub.c diff --git a/UNITTESTS/stubs/mbed_critical_stub.c b/UNITTESTS/stubs/platform/mbed_critical_stub.c similarity index 100% rename from UNITTESTS/stubs/mbed_critical_stub.c rename to UNITTESTS/stubs/platform/mbed_critical_stub.c diff --git a/UNITTESTS/stubs/mbed_error.c b/UNITTESTS/stubs/platform/mbed_error.c similarity index 100% rename from UNITTESTS/stubs/mbed_error.c rename to UNITTESTS/stubs/platform/mbed_error.c diff --git a/UNITTESTS/stubs/mbed_poll_stub.cpp b/UNITTESTS/stubs/platform/mbed_poll_stub.cpp similarity index 100% rename from UNITTESTS/stubs/mbed_poll_stub.cpp rename to UNITTESTS/stubs/platform/mbed_poll_stub.cpp diff --git a/UNITTESTS/stubs/mbed_retarget_stub.cpp b/UNITTESTS/stubs/platform/mbed_retarget_stub.cpp similarity index 100% rename from UNITTESTS/stubs/mbed_retarget_stub.cpp rename to UNITTESTS/stubs/platform/mbed_retarget_stub.cpp diff --git a/UNITTESTS/stubs/mbed_wait_api_stub.cpp b/UNITTESTS/stubs/platform/mbed_wait_api_stub.cpp similarity index 100% rename from UNITTESTS/stubs/mbed_wait_api_stub.cpp rename to UNITTESTS/stubs/platform/mbed_wait_api_stub.cpp diff --git a/UNITTESTS/stubs/nvic_wrapper_stub.c b/UNITTESTS/stubs/platform/nvic_wrapper_stub.c similarity index 100% rename from UNITTESTS/stubs/nvic_wrapper_stub.c rename to UNITTESTS/stubs/platform/nvic_wrapper_stub.c diff --git a/UNITTESTS/stubs/randLIB_stub.c b/UNITTESTS/stubs/platform/randLIB_stub.c similarity index 100% rename from UNITTESTS/stubs/randLIB_stub.c rename to UNITTESTS/stubs/platform/randLIB_stub.c diff --git a/UNITTESTS/stubs/randLIB_stub.cpp b/UNITTESTS/stubs/platform/randLIB_stub.cpp similarity index 100% rename from UNITTESTS/stubs/randLIB_stub.cpp rename to UNITTESTS/stubs/platform/randLIB_stub.cpp diff --git a/UNITTESTS/stubs/rtos/CMakeLists.txt b/UNITTESTS/stubs/rtos/CMakeLists.txt new file mode 100644 index 0000000000..fc9a759b8d --- /dev/null +++ b/UNITTESTS/stubs/rtos/CMakeLists.txt @@ -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 +) diff --git a/UNITTESTS/stubs/ConditionVariable_stub.cpp b/UNITTESTS/stubs/rtos/ConditionVariable_stub.cpp similarity index 100% rename from UNITTESTS/stubs/ConditionVariable_stub.cpp rename to UNITTESTS/stubs/rtos/ConditionVariable_stub.cpp diff --git a/UNITTESTS/stubs/Kernel_stub.cpp b/UNITTESTS/stubs/rtos/Kernel_stub.cpp similarity index 100% rename from UNITTESTS/stubs/Kernel_stub.cpp rename to UNITTESTS/stubs/rtos/Kernel_stub.cpp diff --git a/UNITTESTS/stubs/Mutex_stub.cpp b/UNITTESTS/stubs/rtos/Mutex_stub.cpp similarity index 100% rename from UNITTESTS/stubs/Mutex_stub.cpp rename to UNITTESTS/stubs/rtos/Mutex_stub.cpp diff --git a/UNITTESTS/stubs/Semaphore_stub.cpp b/UNITTESTS/stubs/rtos/Semaphore_stub.cpp similarity index 100% rename from UNITTESTS/stubs/Semaphore_stub.cpp rename to UNITTESTS/stubs/rtos/Semaphore_stub.cpp diff --git a/UNITTESTS/stubs/ThisThread_stub.cpp b/UNITTESTS/stubs/rtos/ThisThread_stub.cpp similarity index 100% rename from UNITTESTS/stubs/ThisThread_stub.cpp rename to UNITTESTS/stubs/rtos/ThisThread_stub.cpp diff --git a/UNITTESTS/stubs/Thread_stub.cpp b/UNITTESTS/stubs/rtos/Thread_stub.cpp similarity index 100% rename from UNITTESTS/stubs/Thread_stub.cpp rename to UNITTESTS/stubs/rtos/Thread_stub.cpp diff --git a/UNITTESTS/stubs/mbed_rtos_rtx_stub.c b/UNITTESTS/stubs/rtos/mbed_rtos_rtx_stub.c similarity index 96% rename from UNITTESTS/stubs/mbed_rtos_rtx_stub.c rename to UNITTESTS/stubs/rtos/mbed_rtos_rtx_stub.c index aa45009fa5..889065cbcb 100644 --- a/UNITTESTS/stubs/mbed_rtos_rtx_stub.c +++ b/UNITTESTS/stubs/rtos/mbed_rtos_rtx_stub.c @@ -15,6 +15,6 @@ * limitations under the License. */ -#include "cmsis_os2.h" +#include "mbed_rtos_types.h" osMutexId_t singleton_mutex_id; diff --git a/UNITTESTS/stubs/rtx_mutex_stub.c b/UNITTESTS/stubs/rtos/rtx_mutex_stub.c similarity index 96% rename from UNITTESTS/stubs/rtx_mutex_stub.c rename to UNITTESTS/stubs/rtos/rtx_mutex_stub.c index de5aed92bd..916be3ee95 100644 --- a/UNITTESTS/stubs/rtx_mutex_stub.c +++ b/UNITTESTS/stubs/rtos/rtx_mutex_stub.c @@ -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) { diff --git a/UNITTESTS/stubs/BufferedBlockDevice_stub.cpp b/UNITTESTS/stubs/storage/BufferedBlockDevice_stub.cpp similarity index 100% rename from UNITTESTS/stubs/BufferedBlockDevice_stub.cpp rename to UNITTESTS/stubs/storage/BufferedBlockDevice_stub.cpp diff --git a/UNITTESTS/stubs/storage/CMakeLists.txt b/UNITTESTS/stubs/storage/CMakeLists.txt new file mode 100644 index 0000000000..721f0f1d92 --- /dev/null +++ b/UNITTESTS/stubs/storage/CMakeLists.txt @@ -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 +) diff --git a/UNITTESTS/stubs/ChainingBlockDevice_stub.cpp b/UNITTESTS/stubs/storage/ChainingBlockDevice_stub.cpp similarity index 100% rename from UNITTESTS/stubs/ChainingBlockDevice_stub.cpp rename to UNITTESTS/stubs/storage/ChainingBlockDevice_stub.cpp diff --git a/UNITTESTS/stubs/EmulatedSD.cpp b/UNITTESTS/stubs/storage/EmulatedSD.cpp similarity index 100% rename from UNITTESTS/stubs/EmulatedSD.cpp rename to UNITTESTS/stubs/storage/EmulatedSD.cpp diff --git a/UNITTESTS/stubs/ExhaustibleBlockDevice_stub.cpp b/UNITTESTS/stubs/storage/ExhaustibleBlockDevice_stub.cpp similarity index 100% rename from UNITTESTS/stubs/ExhaustibleBlockDevice_stub.cpp rename to UNITTESTS/stubs/storage/ExhaustibleBlockDevice_stub.cpp diff --git a/UNITTESTS/stubs/FlashSimBlockDevice_stub.cpp b/UNITTESTS/stubs/storage/FlashSimBlockDevice_stub.cpp similarity index 100% rename from UNITTESTS/stubs/FlashSimBlockDevice_stub.cpp rename to UNITTESTS/stubs/storage/FlashSimBlockDevice_stub.cpp diff --git a/UNITTESTS/stubs/HeapBlockDevice_stub.cpp b/UNITTESTS/stubs/storage/HeapBlockDevice_stub.cpp similarity index 100% rename from UNITTESTS/stubs/HeapBlockDevice_stub.cpp rename to UNITTESTS/stubs/storage/HeapBlockDevice_stub.cpp diff --git a/UNITTESTS/stubs/MBRBlockDevice_stub.cpp b/UNITTESTS/stubs/storage/MBRBlockDevice_stub.cpp similarity index 99% rename from UNITTESTS/stubs/MBRBlockDevice_stub.cpp rename to UNITTESTS/stubs/storage/MBRBlockDevice_stub.cpp index 449236be6e..64fe7d181b 100644 --- a/UNITTESTS/stubs/MBRBlockDevice_stub.cpp +++ b/UNITTESTS/stubs/storage/MBRBlockDevice_stub.cpp @@ -18,6 +18,7 @@ #include "MBRBlockDevice.h" #include "mbed_critical.h" #include +#include "mbed_toolchain.h" // On disk structures, all entries are little endian diff --git a/UNITTESTS/stubs/ObservingBlockDevice_stub.cpp b/UNITTESTS/stubs/storage/ObservingBlockDevice_stub.cpp similarity index 100% rename from UNITTESTS/stubs/ObservingBlockDevice_stub.cpp rename to UNITTESTS/stubs/storage/ObservingBlockDevice_stub.cpp diff --git a/UNITTESTS/stubs/ProfilingBlockDevice_stub.cpp b/UNITTESTS/stubs/storage/ProfilingBlockDevice_stub.cpp similarity index 100% rename from UNITTESTS/stubs/ProfilingBlockDevice_stub.cpp rename to UNITTESTS/stubs/storage/ProfilingBlockDevice_stub.cpp diff --git a/UNITTESTS/stubs/ReadOnlyBlockDevice_stub.cpp b/UNITTESTS/stubs/storage/ReadOnlyBlockDevice_stub.cpp similarity index 100% rename from UNITTESTS/stubs/ReadOnlyBlockDevice_stub.cpp rename to UNITTESTS/stubs/storage/ReadOnlyBlockDevice_stub.cpp diff --git a/UNITTESTS/stubs/SlicingBlockDevice_stub.cpp b/UNITTESTS/stubs/storage/SlicingBlockDevice_stub.cpp similarity index 100% rename from UNITTESTS/stubs/SlicingBlockDevice_stub.cpp rename to UNITTESTS/stubs/storage/SlicingBlockDevice_stub.cpp diff --git a/UNITTESTS/stubs/kv_config_stub.cpp b/UNITTESTS/stubs/storage/kv_config_stub.cpp similarity index 100% rename from UNITTESTS/stubs/kv_config_stub.cpp rename to UNITTESTS/stubs/storage/kv_config_stub.cpp diff --git a/UNITTESTS/target_h/cmsis_os.h b/UNITTESTS/target_h/cmsis_os.h index a40ab9e73b..4e8b5570aa 100644 --- a/UNITTESTS/target_h/cmsis_os.h +++ b/UNITTESTS/target_h/cmsis_os.h @@ -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 diff --git a/UNITTESTS/target_h/rtos/Semaphore.h b/UNITTESTS/target_h/rtos/Semaphore.h index ecbdee511d..aecea8f6a3 100644 --- a/UNITTESTS/target_h/rtos/Semaphore.h +++ b/UNITTESTS/target_h/rtos/Semaphore.h @@ -18,7 +18,7 @@ #define SEMAPHORE_H #include -#include "cmsis_os2.h" +#include "internal/mbed_rtos1_types.h" #include "rtos/Kernel.h" namespace rtos { diff --git a/UNITTESTS/target_h/rtos/include/rtos/internal/mbed_rtos_storage.h b/UNITTESTS/target_h/rtos/include/rtos/internal/mbed_rtos_storage.h index e1b1276138..c160374e65 100644 --- a/UNITTESTS/target_h/rtos/include/rtos/internal/mbed_rtos_storage.h +++ b/UNITTESTS/target_h/rtos/include/rtos/internal/mbed_rtos_storage.h @@ -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" diff --git a/UNITTESTS/unit_test/test.py b/UNITTESTS/unit_test/test.py index a2f8b89480..dd0a71642e 100644 --- a/UNITTESTS/unit_test/test.py +++ b/UNITTESTS/unit_test/test.py @@ -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()] diff --git a/cmsis/CMSIS_5/CMSIS/RTOS2/RTX/CMakeLists.txt b/cmsis/CMSIS_5/CMSIS/RTOS2/RTX/CMakeLists.txt index e742f1483d..3695d5bd1e 100644 --- a/cmsis/CMSIS_5/CMSIS/RTOS2/RTX/CMakeLists.txt +++ b/cmsis/CMSIS_5/CMSIS/RTOS2/RTX/CMakeLists.txt @@ -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 diff --git a/cmsis/device/rtos/CMakeLists.txt b/cmsis/device/rtos/CMakeLists.txt index 024cf56218..34cd1623e4 100644 --- a/cmsis/device/rtos/CMakeLists.txt +++ b/cmsis/device/rtos/CMakeLists.txt @@ -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 diff --git a/connectivity/CMakeLists.txt b/connectivity/CMakeLists.txt index 985cdb8c40..e011ad27dd 100644 --- a/connectivity/CMakeLists.txt +++ b/connectivity/CMakeLists.txt @@ -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() diff --git a/connectivity/cellular/CMakeLists.txt b/connectivity/cellular/CMakeLists.txt index 00b5d7a84a..8455c59b4c 100644 --- a/connectivity/cellular/CMakeLists.txt +++ b/connectivity/cellular/CMakeLists.txt @@ -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 diff --git a/connectivity/cellular/tests/UNITTESTS/CMakeLists.txt b/connectivity/cellular/tests/UNITTESTS/CMakeLists.txt new file mode 100644 index 0000000000..7fa72fe29e --- /dev/null +++ b/connectivity/cellular/tests/UNITTESTS/CMakeLists.txt @@ -0,0 +1,4 @@ +# Copyright (c) 2021 ARM Limited. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +add_subdirectory(framework) diff --git a/connectivity/cellular/tests/UNITTESTS/framework/AT/CMakeLists.txt b/connectivity/cellular/tests/UNITTESTS/framework/AT/CMakeLists.txt new file mode 100644 index 0000000000..fcc649fa52 --- /dev/null +++ b/connectivity/cellular/tests/UNITTESTS/framework/AT/CMakeLists.txt @@ -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) diff --git a/connectivity/cellular/tests/UNITTESTS/framework/AT/at_cellularcontext/CMakeLists.txt b/connectivity/cellular/tests/UNITTESTS/framework/AT/at_cellularcontext/CMakeLists.txt new file mode 100644 index 0000000000..5772d7cf45 --- /dev/null +++ b/connectivity/cellular/tests/UNITTESTS/framework/AT/at_cellularcontext/CMakeLists.txt @@ -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") diff --git a/connectivity/cellular/tests/UNITTESTS/framework/AT/at_cellulardevice/CMakeLists.txt b/connectivity/cellular/tests/UNITTESTS/framework/AT/at_cellulardevice/CMakeLists.txt new file mode 100644 index 0000000000..bdf0e68414 --- /dev/null +++ b/connectivity/cellular/tests/UNITTESTS/framework/AT/at_cellulardevice/CMakeLists.txt @@ -0,0 +1,39 @@ +# Copyright (c) 2021 ARM Limited. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +set(TEST_NAME at_cellulardevice-unittest) + +add_executable(${TEST_NAME}) + +target_compile_definitions(${TEST_NAME} + PRIVATE + DEVICE_SERIAL=1 + DEVICE_INTERRUPTIN=1 + MBED_CONF_NSAPI_DEFAULT_CELLULAR_APN=NULL + MBED_CONF_NSAPI_DEFAULT_CELLULAR_USERNAME=NULL + MBED_CONF_NSAPI_DEFAULT_CELLULAR_PASSWORD=NULL + MBED_CONF_NSAPI_DEFAULT_CELLULAR_PLMN=NULL + MBED_CONF_NSAPI_DEFAULT_CELLULAR_SIM_PIN=NULL + MDMTXD=NC + MDMRXD=NC + MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE=115200 + MBED_CONF_CELLULAR_USE_SMS=1 +) + +target_sources(${TEST_NAME} + PRIVATE + ${mbed-os_SOURCE_DIR}/connectivity/cellular/source/framework/AT/AT_CellularDevice.cpp + at_cellulardevicetest.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") diff --git a/connectivity/cellular/tests/UNITTESTS/framework/AT/at_cellularinformation/CMakeLists.txt b/connectivity/cellular/tests/UNITTESTS/framework/AT/at_cellularinformation/CMakeLists.txt new file mode 100644 index 0000000000..6a28c2556d --- /dev/null +++ b/connectivity/cellular/tests/UNITTESTS/framework/AT/at_cellularinformation/CMakeLists.txt @@ -0,0 +1,31 @@ +# Copyright (c) 2021 ARM Limited. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +set(TEST_NAME at_cellularinformation-unittest) + +add_executable(${TEST_NAME}) + +target_compile_definitions(${TEST_NAME} + PRIVATE + DEVICE_SERIAL=1 + DEVICE_INTERRUPTIN=1 + MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE=115200 +) + +target_sources(${TEST_NAME} + PRIVATE + ${mbed-os_SOURCE_DIR}/connectivity/cellular/source/framework/AT/AT_CellularInformation.cpp + at_cellularinformationtest.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") diff --git a/connectivity/cellular/tests/UNITTESTS/framework/AT/at_cellularnetwork/CMakeLists.txt b/connectivity/cellular/tests/UNITTESTS/framework/AT/at_cellularnetwork/CMakeLists.txt new file mode 100644 index 0000000000..459172dc62 --- /dev/null +++ b/connectivity/cellular/tests/UNITTESTS/framework/AT/at_cellularnetwork/CMakeLists.txt @@ -0,0 +1,32 @@ +# Copyright (c) 2021 ARM Limited. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +set(TEST_NAME at_cellularnetwork-unittest) + +add_executable(${TEST_NAME}) + +target_compile_definitions(${TEST_NAME} + PRIVATE + DEVICE_SERIAL=1 + DEVICE_INTERRUPTIN=1 + MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE=115200 +) + +target_sources(${TEST_NAME} + PRIVATE + ${mbed-os_SOURCE_DIR}/connectivity/cellular/source/framework/AT/AT_CellularNetwork.cpp + ${mbed-os_SOURCE_DIR}/connectivity/cellular/source/framework/common/CellularUtil.cpp + at_cellularnetworktest.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") diff --git a/connectivity/cellular/tests/UNITTESTS/framework/AT/at_cellularsms/CMakeLists.txt b/connectivity/cellular/tests/UNITTESTS/framework/AT/at_cellularsms/CMakeLists.txt new file mode 100644 index 0000000000..3278e53bd1 --- /dev/null +++ b/connectivity/cellular/tests/UNITTESTS/framework/AT/at_cellularsms/CMakeLists.txt @@ -0,0 +1,32 @@ +# Copyright (c) 2021 ARM Limited. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +set(TEST_NAME at_cellularsms-unittest) + +add_executable(${TEST_NAME}) + +target_compile_definitions(${TEST_NAME} + PRIVATE + DEVICE_SERIAL=1 + DEVICE_INTERRUPTIN=1 + MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE=115200 + MBED_CONF_CELLULAR_USE_SMS=1 +) + +target_sources(${TEST_NAME} + PRIVATE + ${mbed-os_SOURCE_DIR}/connectivity/cellular/source/framework/AT/AT_CellularSMS.cpp + at_cellularsmstest.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") diff --git a/connectivity/cellular/tests/UNITTESTS/framework/AT/at_cellularstack/CMakeLists.txt b/connectivity/cellular/tests/UNITTESTS/framework/AT/at_cellularstack/CMakeLists.txt new file mode 100644 index 0000000000..ca26a782c4 --- /dev/null +++ b/connectivity/cellular/tests/UNITTESTS/framework/AT/at_cellularstack/CMakeLists.txt @@ -0,0 +1,37 @@ +# Copyright (c) 2021 ARM Limited. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +set(TEST_NAME at_cellularstack-unittest) + +add_executable(${TEST_NAME}) + +target_compile_definitions(${TEST_NAME} + PRIVATE + DEVICE_SERIAL=1 + DEVICE_INTERRUPTIN=1 + MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE=115200 +) + +target_sources(${TEST_NAME} + PRIVATE + ${mbed-os_SOURCE_DIR}/connectivity/cellular/source/framework/AT/AT_CellularStack.cpp + ${mbed-os_SOURCE_DIR}/connectivity/libraries/nanostack-libservice/source/libip4string/ip4tos.c + ${mbed-os_SOURCE_DIR}/connectivity/libraries/nanostack-libservice/source/libip6string/ip6tos.c + ${mbed-os_SOURCE_DIR}/connectivity/libraries/nanostack-libservice/source/libip4string/stoip4.c + ${mbed-os_SOURCE_DIR}/connectivity/libraries/nanostack-libservice/source/libip6string/stoip6.c + ${mbed-os_SOURCE_DIR}/connectivity/libraries/nanostack-libservice/source/libBits/common_functions.c + ${mbed-os_SOURCE_DIR}/connectivity/netsocket/source/SocketAddress.cpp + at_cellularstacktest.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") diff --git a/connectivity/cellular/tests/UNITTESTS/framework/CMakeLists.txt b/connectivity/cellular/tests/UNITTESTS/framework/CMakeLists.txt new file mode 100644 index 0000000000..e9e308a23a --- /dev/null +++ b/connectivity/cellular/tests/UNITTESTS/framework/CMakeLists.txt @@ -0,0 +1,6 @@ +# Copyright (c) 2021 ARM Limited. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +add_subdirectory(AT) +add_subdirectory(common) +add_subdirectory(device) diff --git a/connectivity/cellular/tests/UNITTESTS/framework/common/CMakeLists.txt b/connectivity/cellular/tests/UNITTESTS/framework/common/CMakeLists.txt new file mode 100644 index 0000000000..f61ce37797 --- /dev/null +++ b/connectivity/cellular/tests/UNITTESTS/framework/common/CMakeLists.txt @@ -0,0 +1,5 @@ +# Copyright (c) 2021 ARM Limited. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +add_subdirectory(list) +add_subdirectory(util) diff --git a/connectivity/cellular/tests/UNITTESTS/framework/common/list/CMakeLists.txt b/connectivity/cellular/tests/UNITTESTS/framework/common/list/CMakeLists.txt new file mode 100644 index 0000000000..fea658b740 --- /dev/null +++ b/connectivity/cellular/tests/UNITTESTS/framework/common/list/CMakeLists.txt @@ -0,0 +1,21 @@ +# Copyright (c) 2021 ARM Limited. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +set(TEST_NAME cellular-framework-common-list-unittest) + +add_executable(${TEST_NAME}) + +target_sources(${TEST_NAME} + PRIVATE + listtest.cpp +) + +target_link_libraries(${TEST_NAME} + PRIVATE + mbed-headers + gmock_main +) + +add_test(NAME "${TEST_NAME}" COMMAND ${TEST_NAME}) + +set_tests_properties(${TEST_NAME} PROPERTIES LABELS "cellular") diff --git a/connectivity/cellular/tests/UNITTESTS/framework/common/util/CMakeLists.txt b/connectivity/cellular/tests/UNITTESTS/framework/common/util/CMakeLists.txt new file mode 100644 index 0000000000..5731fb5aff --- /dev/null +++ b/connectivity/cellular/tests/UNITTESTS/framework/common/util/CMakeLists.txt @@ -0,0 +1,23 @@ +# Copyright (c) 2021 ARM Limited. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +set(TEST_NAME cellular-framework-common-util-unittest) + +add_executable(${TEST_NAME}) + +target_sources(${TEST_NAME} + PRIVATE + ${mbed-os_SOURCE_DIR}/connectivity/cellular/source/framework/common/CellularUtil.cpp + utiltest.cpp +) + +target_link_libraries(${TEST_NAME} + PRIVATE + mbed-headers + mbed-stubs-platform + gmock_main +) + +add_test(NAME "${TEST_NAME}" COMMAND ${TEST_NAME}) + +set_tests_properties(${TEST_NAME} PROPERTIES LABELS "cellular") diff --git a/connectivity/cellular/tests/UNITTESTS/framework/device/CMakeLists.txt b/connectivity/cellular/tests/UNITTESTS/framework/device/CMakeLists.txt new file mode 100644 index 0000000000..50b30e3767 --- /dev/null +++ b/connectivity/cellular/tests/UNITTESTS/framework/device/CMakeLists.txt @@ -0,0 +1,7 @@ +# Copyright (c) 2021 ARM Limited. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +add_subdirectory(athandler) +add_subdirectory(cellularcontext) +add_subdirectory(cellulardevice) +add_subdirectory(cellularstatemachine) diff --git a/connectivity/cellular/tests/UNITTESTS/framework/device/athandler/CMakeLists.txt b/connectivity/cellular/tests/UNITTESTS/framework/device/athandler/CMakeLists.txt new file mode 100644 index 0000000000..3b0e7e6ba3 --- /dev/null +++ b/connectivity/cellular/tests/UNITTESTS/framework/device/athandler/CMakeLists.txt @@ -0,0 +1,33 @@ +# Copyright (c) 2021 ARM Limited. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +set(TEST_NAME cellular-framework-device-athandler-unittest) + +add_executable(${TEST_NAME}) + +target_compile_definitions(${TEST_NAME} + PRIVATE + MBED_CONF_CELLULAR_DEBUG_AT=true + OS_STACK_SIZE=2048 + DEVICE_SERIAL=1 + DEVICE_INTERRUPTIN=1 + MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE=115200 +) + +target_sources(${TEST_NAME} + PRIVATE + ${mbed-os_SOURCE_DIR}/connectivity/cellular/source/framework/device/ATHandler.cpp + athandlertest.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") diff --git a/connectivity/cellular/tests/UNITTESTS/framework/device/cellularcontext/CMakeLists.txt b/connectivity/cellular/tests/UNITTESTS/framework/device/cellularcontext/CMakeLists.txt new file mode 100644 index 0000000000..b02db309e4 --- /dev/null +++ b/connectivity/cellular/tests/UNITTESTS/framework/device/cellularcontext/CMakeLists.txt @@ -0,0 +1,45 @@ +# Copyright (c) 2021 ARM Limited. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +set(TEST_NAME cellular-framework-device-cellular-context-unittest) + +add_executable(${TEST_NAME}) + +target_compile_definitions(${TEST_NAME} + PRIVATE + MDMRTS=PTC0 + MDMCTS=PTC1 + MDMTXD=NC + MDMRXD=NC + CELLULAR_DEVICE=myCellularDevice + DEVICE_SERIAL_FC=1 + MBED_CONF_CELLULAR_CONTROL_PLANE_OPT=0 + MBED_CONF_CELLULAR_USE_SMS=1 + DEVICE_SERIAL=1 + DEVICE_INTERRUPTIN=1 + MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE=115200 +) + +target_sources(${TEST_NAME} + PRIVATE + ${mbed-os_SOURCE_DIR}/connectivity/cellular/source/framework/device/CellularContext.cpp + ${mbed-os_SOURCE_DIR}/connectivity/libraries/nanostack-libservice/source/libip4string/ip4tos.c + ${mbed-os_SOURCE_DIR}/connectivity/libraries/nanostack-libservice/source/libip6string/ip6tos.c + ${mbed-os_SOURCE_DIR}/connectivity/libraries/nanostack-libservice/source/libip4string/stoip4.c + ${mbed-os_SOURCE_DIR}/connectivity/libraries/nanostack-libservice/source/libip6string/stoip6.c + ${mbed-os_SOURCE_DIR}/connectivity/libraries/nanostack-libservice/source/libBits/common_functions.c + ${mbed-os_SOURCE_DIR}/connectivity/netsocket/source/SocketAddress.cpp + 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") diff --git a/connectivity/cellular/tests/UNITTESTS/framework/device/cellulardevice/CMakeLists.txt b/connectivity/cellular/tests/UNITTESTS/framework/device/cellulardevice/CMakeLists.txt new file mode 100644 index 0000000000..609015a25e --- /dev/null +++ b/connectivity/cellular/tests/UNITTESTS/framework/device/cellulardevice/CMakeLists.txt @@ -0,0 +1,37 @@ +# Copyright (c) 2021 ARM Limited. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +set(TEST_NAME cellular-framework-device-cellular-device-unittest) + +add_executable(${TEST_NAME}) + +target_compile_definitions(${TEST_NAME} + PRIVATE + MDMRTS=PTC0 + MDMCTS=PTC1 + MDMTXD=NC + MDMRXD=NC + CELLULAR_DEVICE=myCellularDevice + DEVICE_SERIAL_FC=1 + DEVICE_SERIAL=1 + DEVICE_INTERRUPTIN=1 + MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE=115200 +) + +target_sources(${TEST_NAME} + PRIVATE + ${mbed-os_SOURCE_DIR}/connectivity/cellular/source/framework/device/CellularDevice.cpp + cellulardevicetest.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") diff --git a/connectivity/cellular/tests/UNITTESTS/framework/device/cellularstatemachine/CMakeLists.txt b/connectivity/cellular/tests/UNITTESTS/framework/device/cellularstatemachine/CMakeLists.txt new file mode 100644 index 0000000000..2195378184 --- /dev/null +++ b/connectivity/cellular/tests/UNITTESTS/framework/device/cellularstatemachine/CMakeLists.txt @@ -0,0 +1,38 @@ +# Copyright (c) 2021 ARM Limited. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +set(TEST_NAME cellular-framework-device-cellular-state-machine-unittest) + +add_executable(${TEST_NAME}) + +target_compile_definitions(${TEST_NAME} + PRIVATE + MDMRTS=PTC0 + MDMCTS=PTC1 + MDMTXD=NC + MDMRXD=NC + CELLULAR_DEVICE=myCellularDevice + DEVICE_SERIAL_FC=1 + MBED_CONF_RTOS_PRESENT=1 + DEVICE_SERIAL=1 + DEVICE_INTERRUPTIN=1 + MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE=115200 +) + +target_sources(${TEST_NAME} + PRIVATE + ${mbed-os_SOURCE_DIR}/connectivity/cellular/source/framework/device/CellularStateMachine.cpp + cellularstatemachinetest.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") diff --git a/connectivity/cellular/tests/UNITTESTS/framework/device/cellularstatemachine/cellularstatemachinetest.cpp b/connectivity/cellular/tests/UNITTESTS/framework/device/cellularstatemachine/cellularstatemachinetest.cpp index 8f4ad47e62..96c9b89d0c 100644 --- a/connectivity/cellular/tests/UNITTESTS/framework/device/cellularstatemachine/cellularstatemachinetest.cpp +++ b/connectivity/cellular/tests/UNITTESTS/framework/device/cellularstatemachine/cellularstatemachinetest.cpp @@ -23,7 +23,7 @@ #include "AT_CellularNetwork_stub.h" #include "myCellularDevice.h" #include "Thread_stub.h" -#include "cmsis_os2.h" +#include "mbed_rtos_types.h" #include "equeue_stub.h" using namespace mbed; diff --git a/connectivity/drivers/wifi/TARGET_WICED/CMakeLists.txt b/connectivity/drivers/wifi/TARGET_WICED/CMakeLists.txt index c6f83e6b9c..8bcf3677e3 100644 --- a/connectivity/drivers/wifi/TARGET_WICED/CMakeLists.txt +++ b/connectivity/drivers/wifi/TARGET_WICED/CMakeLists.txt @@ -3,13 +3,15 @@ add_library(mbed-wiced INTERFACE) -if(${MBED_TOOLCHAIN} STREQUAL "ARM") - set(LIB_WICED_DRIVERS TOOLCHAIN_ARMC6/TARGET_WIO_EMW3166/libwiced_drivers.ar) -elseif(${MBED_TOOLCHAIN} STREQUAL "GCC_ARM") - set(LIB_WICED_DRIVERS TOOLCHAIN_GCC_ARM/TARGET_WIO_EMW3166/libwiced_drivers.a) -endif() +if(${CMAKE_CROSSCOMPILING}) + if(${MBED_TOOLCHAIN} STREQUAL "ARM") + set(LIB_WICED_DRIVERS TOOLCHAIN_ARMC6/TARGET_WIO_EMW3166/libwiced_drivers.ar) + elseif(${MBED_TOOLCHAIN} STREQUAL "GCC_ARM") + set(LIB_WICED_DRIVERS TOOLCHAIN_GCC_ARM/TARGET_WIO_EMW3166/libwiced_drivers.a) + endif() target_link_libraries(mbed-wiced INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/${LIB_WICED_DRIVERS}) +endif() target_include_directories(mbed-wiced INTERFACE diff --git a/connectivity/lorawan/CMakeLists.txt b/connectivity/lorawan/CMakeLists.txt index 743a0ff9ae..552a72a6fe 100644 --- a/connectivity/lorawan/CMakeLists.txt +++ b/connectivity/lorawan/CMakeLists.txt @@ -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(lorastack) add_subdirectory(system) diff --git a/connectivity/lorawan/tests/UNITTESTS/CMakeLists.txt b/connectivity/lorawan/tests/UNITTESTS/CMakeLists.txt new file mode 100644 index 0000000000..9efa3167f2 --- /dev/null +++ b/connectivity/lorawan/tests/UNITTESTS/CMakeLists.txt @@ -0,0 +1,4 @@ +# Copyright (c) 2021 ARM Limited. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +add_subdirectory(features) diff --git a/connectivity/lorawan/tests/UNITTESTS/features/CMakeLists.txt b/connectivity/lorawan/tests/UNITTESTS/features/CMakeLists.txt new file mode 100644 index 0000000000..11270973b3 --- /dev/null +++ b/connectivity/lorawan/tests/UNITTESTS/features/CMakeLists.txt @@ -0,0 +1,4 @@ +# Copyright (c) 2021 ARM Limited. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +add_subdirectory(lorawan) diff --git a/connectivity/lorawan/tests/UNITTESTS/features/lorawan/CMakeLists.txt b/connectivity/lorawan/tests/UNITTESTS/features/lorawan/CMakeLists.txt new file mode 100644 index 0000000000..68ab2ebc2b --- /dev/null +++ b/connectivity/lorawan/tests/UNITTESTS/features/lorawan/CMakeLists.txt @@ -0,0 +1,20 @@ +# Copyright (c) 2021 ARM Limited. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +add_subdirectory(lorawaninterface) +add_subdirectory(loraphyus915) +add_subdirectory(loraphykr920) +add_subdirectory(loraphyin865) +add_subdirectory(loraphyeu868) +add_subdirectory(loraphyeu433) +add_subdirectory(loraphycn779) +add_subdirectory(loraphycn470) +add_subdirectory(loraphyau915) +add_subdirectory(loraphyas923) +add_subdirectory(loraphy) +add_subdirectory(loramaccrypto) +add_subdirectory(loramaccommand) +add_subdirectory(loramacchannelplan) +add_subdirectory(loramac) +add_subdirectory(lorawantimer) +add_subdirectory(lorawanstack) diff --git a/connectivity/lorawan/tests/UNITTESTS/features/lorawan/loramac/CMakeLists.txt b/connectivity/lorawan/tests/UNITTESTS/features/lorawan/loramac/CMakeLists.txt new file mode 100644 index 0000000000..471c436070 --- /dev/null +++ b/connectivity/lorawan/tests/UNITTESTS/features/lorawan/loramac/CMakeLists.txt @@ -0,0 +1,44 @@ +# Copyright (c) 2021 ARM Limited. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +set(TEST_NAME lorawan-loramac-unittest) + +add_executable(${TEST_NAME}) + +target_compile_definitions(${TEST_NAME} + PRIVATE + MBED_CONF_LORA_ADR_ON=true + MBED_CONF_LORA_PUBLIC_NETWORK=true + MBED_CONF_LORA_NB_TRIALS=2 + MBED_CONF_LORA_DOWNLINK_PREAMBLE_LENGTH=5 + MBED_CONF_LORA_DUTY_CYCLE_ON=true + MBED_CONF_LORA_MAX_SYS_RX_ERROR=10 + MBED_CONF_LORA_TX_MAX_SIZE=255 + MBED_CONF_LORA_DEVICE_ADDRESS=0x00000000 +) + +target_compile_options(${TEST_NAME} + PRIVATE + "-DMBED_CONF_LORA_NWKSKEY={0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}" + "-DMBED_CONF_LORA_NWKSKEY={0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}" + "-DMBED_CONF_LORA_APPSKEY={0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}" + "-DMBED_CONF_LORA_APPSKEY={0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}" +) + +target_sources(${TEST_NAME} + PRIVATE + ${mbed-os_SOURCE_DIR}/connectivity/lorawan/lorastack/mac/LoRaMac.cpp + Test_LoRaMac.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 "lorawan") diff --git a/connectivity/lorawan/tests/UNITTESTS/features/lorawan/loramacchannelplan/CMakeLists.txt b/connectivity/lorawan/tests/UNITTESTS/features/lorawan/loramacchannelplan/CMakeLists.txt new file mode 100644 index 0000000000..63928bfae7 --- /dev/null +++ b/connectivity/lorawan/tests/UNITTESTS/features/lorawan/loramacchannelplan/CMakeLists.txt @@ -0,0 +1,29 @@ +# Copyright (c) 2021 ARM Limited. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +set(TEST_NAME lorawan-loramac-channel-plan-unittest) + +add_executable(${TEST_NAME}) + +target_compile_definitions(${TEST_NAME} + PRIVATE + MBED_CONF_LORA_TX_MAX_SIZE=255 +) + +target_sources(${TEST_NAME} + PRIVATE + ${mbed-os_SOURCE_DIR}/connectivity/lorawan/lorastack/mac/LoRaMacChannelPlan.cpp + Test_LoRaMacChannelPlan.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 "lorawan") diff --git a/connectivity/lorawan/tests/UNITTESTS/features/lorawan/loramaccommand/CMakeLists.txt b/connectivity/lorawan/tests/UNITTESTS/features/lorawan/loramaccommand/CMakeLists.txt new file mode 100644 index 0000000000..9a93feba3e --- /dev/null +++ b/connectivity/lorawan/tests/UNITTESTS/features/lorawan/loramaccommand/CMakeLists.txt @@ -0,0 +1,29 @@ +# Copyright (c) 2021 ARM Limited. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +set(TEST_NAME lorawan-loramac-command-unittest) + +add_executable(${TEST_NAME}) + +target_compile_definitions(${TEST_NAME} + PRIVATE + MBED_CONF_LORA_TX_MAX_SIZE=255 +) + +target_sources(${TEST_NAME} + PRIVATE + ${mbed-os_SOURCE_DIR}/connectivity/lorawan/lorastack/mac/LoRaMacCommand.cpp + Test_LoRaMacCommand.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 "lorawan") diff --git a/connectivity/lorawan/tests/UNITTESTS/features/lorawan/loramaccrypto/CMakeLists.txt b/connectivity/lorawan/tests/UNITTESTS/features/lorawan/loramaccrypto/CMakeLists.txt new file mode 100644 index 0000000000..4ab65c6569 --- /dev/null +++ b/connectivity/lorawan/tests/UNITTESTS/features/lorawan/loramaccrypto/CMakeLists.txt @@ -0,0 +1,29 @@ +# Copyright (c) 2021 ARM Limited. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +set(TEST_NAME lorawan-loramac-crypto-unittest) + +add_executable(${TEST_NAME}) + +target_compile_definitions(${TEST_NAME} + PRIVATE + MBED_CONF_LORA_TX_MAX_SIZE=255 +) + +target_sources(${TEST_NAME} + PRIVATE + ${mbed-os_SOURCE_DIR}/connectivity/lorawan/lorastack/mac/LoRaMacCrypto.cpp + Test_LoRaMacCrypto.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 "lorawan") diff --git a/connectivity/lorawan/tests/UNITTESTS/features/lorawan/loraphy/CMakeLists.txt b/connectivity/lorawan/tests/UNITTESTS/features/lorawan/loraphy/CMakeLists.txt new file mode 100644 index 0000000000..f4dae3d71e --- /dev/null +++ b/connectivity/lorawan/tests/UNITTESTS/features/lorawan/loraphy/CMakeLists.txt @@ -0,0 +1,33 @@ +# Copyright (c) 2021 ARM Limited. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +set(TEST_NAME lorawan-loraphy-unittest) + +add_executable(${TEST_NAME}) + +target_compile_definitions(${TEST_NAME} + PRIVATE + MBED_CONF_LORA_WAKEUP_TIME=5 + MBED_CONF_LORA_DUTY_CYCLE_ON_JOIN=true + MBED_CONF_LORA_UPLINK_PREAMBLE_LENGTH=8 + MBED_CONF_LORA_TX_MAX_SIZE=255 + MBED_CONF_LORA_NB_TRIALS=2 +) + +target_sources(${TEST_NAME} + PRIVATE + ${mbed-os_SOURCE_DIR}/connectivity/lorawan/lorastack/phy/LoRaPHY.cpp + Test_LoRaPHY.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 "lorawan") diff --git a/connectivity/lorawan/tests/UNITTESTS/features/lorawan/loraphyas923/CMakeLists.txt b/connectivity/lorawan/tests/UNITTESTS/features/lorawan/loraphyas923/CMakeLists.txt new file mode 100644 index 0000000000..aeff45c056 --- /dev/null +++ b/connectivity/lorawan/tests/UNITTESTS/features/lorawan/loraphyas923/CMakeLists.txt @@ -0,0 +1,31 @@ +# Copyright (c) 2021 ARM Limited. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +set(TEST_NAME lorawan-loraphy-as923-unittest) + +add_executable(${TEST_NAME}) + +target_compile_definitions(${TEST_NAME} + PRIVATE + MBED_CONF_LORA_DOWNLINK_PREAMBLE_LENGTH=5 + MBED_CONF_LORA_TX_MAX_SIZE=255 + MBED_CONF_LORA_UPLINK_PREAMBLE_LENGTH=8 +) + +target_sources(${TEST_NAME} + PRIVATE + ${mbed-os_SOURCE_DIR}/connectivity/lorawan/lorastack/phy/LoRaPHYAS923.cpp + Test_LoRaPHYAS923.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 "lorawan") diff --git a/connectivity/lorawan/tests/UNITTESTS/features/lorawan/loraphyau915/CMakeLists.txt b/connectivity/lorawan/tests/UNITTESTS/features/lorawan/loraphyau915/CMakeLists.txt new file mode 100644 index 0000000000..479491adb6 --- /dev/null +++ b/connectivity/lorawan/tests/UNITTESTS/features/lorawan/loraphyau915/CMakeLists.txt @@ -0,0 +1,37 @@ +# Copyright (c) 2021 ARM Limited. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +set(TEST_NAME lorawan-loraphy-au915-unittest) + +add_executable(${TEST_NAME}) + +target_compile_definitions(${TEST_NAME} + PRIVATE + MBED_CONF_LORA_DOWNLINK_PREAMBLE_LENGTH=5 + MBED_CONF_LORA_TX_MAX_SIZE=255 + MBED_CONF_LORA_UPLINK_PREAMBLE_LENGTH=8 +) + +target_compile_options(${TEST_NAME} + PRIVATE + "-DMBED_CONF_LORA_FSB_MASK={0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0x00FF}" + "-DMBED_CONF_LORA_FSB_MASK={0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0x00FF}" +) + +target_sources(${TEST_NAME} + PRIVATE + ${mbed-os_SOURCE_DIR}/connectivity/lorawan/lorastack/phy/LoRaPHYAU915.cpp + Test_LoRaPHYAU915.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 "lorawan") diff --git a/connectivity/lorawan/tests/UNITTESTS/features/lorawan/loraphycn470/CMakeLists.txt b/connectivity/lorawan/tests/UNITTESTS/features/lorawan/loraphycn470/CMakeLists.txt new file mode 100644 index 0000000000..e67ef1c9ad --- /dev/null +++ b/connectivity/lorawan/tests/UNITTESTS/features/lorawan/loraphycn470/CMakeLists.txt @@ -0,0 +1,37 @@ +# Copyright (c) 2021 ARM Limited. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +set(TEST_NAME lorawan-loraphy-cn470-unittest) + +add_executable(${TEST_NAME}) + +target_compile_definitions(${TEST_NAME} + PRIVATE + MBED_CONF_LORA_DOWNLINK_PREAMBLE_LENGTH=5 + MBED_CONF_LORA_TX_MAX_SIZE=255 + MBED_CONF_LORA_UPLINK_PREAMBLE_LENGTH=8 +) + +target_compile_options(${TEST_NAME} + PRIVATE + "-DMBED_CONF_LORA_FSB_MASK_CHINA={0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0x00FF}" + "-DMBED_CONF_LORA_FSB_MASK_CHINA={0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0x00FF}" +) + +target_sources(${TEST_NAME} + PRIVATE + ${mbed-os_SOURCE_DIR}/connectivity/lorawan/lorastack/phy/LoRaPHYCN470.cpp + Test_LoRaPHYCN470.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 "lorawan") diff --git a/connectivity/lorawan/tests/UNITTESTS/features/lorawan/loraphycn779/CMakeLists.txt b/connectivity/lorawan/tests/UNITTESTS/features/lorawan/loraphycn779/CMakeLists.txt new file mode 100644 index 0000000000..7a59436f5c --- /dev/null +++ b/connectivity/lorawan/tests/UNITTESTS/features/lorawan/loraphycn779/CMakeLists.txt @@ -0,0 +1,31 @@ +# Copyright (c) 2021 ARM Limited. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +set(TEST_NAME lorawan-loraphy-cn779-unittest) + +add_executable(${TEST_NAME}) + +target_compile_definitions(${TEST_NAME} + PRIVATE + MBED_CONF_LORA_DOWNLINK_PREAMBLE_LENGTH=5 + MBED_CONF_LORA_TX_MAX_SIZE=255 + MBED_CONF_LORA_UPLINK_PREAMBLE_LENGTH=8 +) + +target_sources(${TEST_NAME} + PRIVATE + ${mbed-os_SOURCE_DIR}/connectivity/lorawan/lorastack/phy/LoRaPHYCN779.cpp + Test_LoRaPHYCN779.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 "lorawan") diff --git a/connectivity/lorawan/tests/UNITTESTS/features/lorawan/loraphyeu433/CMakeLists.txt b/connectivity/lorawan/tests/UNITTESTS/features/lorawan/loraphyeu433/CMakeLists.txt new file mode 100644 index 0000000000..913dae3979 --- /dev/null +++ b/connectivity/lorawan/tests/UNITTESTS/features/lorawan/loraphyeu433/CMakeLists.txt @@ -0,0 +1,31 @@ +# Copyright (c) 2021 ARM Limited. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +set(TEST_NAME lorawan-loraphy-eu433-unittest) + +add_executable(${TEST_NAME}) + +target_compile_definitions(${TEST_NAME} + PRIVATE + MBED_CONF_LORA_DOWNLINK_PREAMBLE_LENGTH=5 + MBED_CONF_LORA_TX_MAX_SIZE=255 + MBED_CONF_LORA_UPLINK_PREAMBLE_LENGTH=8 +) + +target_sources(${TEST_NAME} + PRIVATE + ${mbed-os_SOURCE_DIR}/connectivity/lorawan/lorastack/phy/LoRaPHYEU433.cpp + Test_LoRaPHYEU433.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 "lorawan") diff --git a/connectivity/lorawan/tests/UNITTESTS/features/lorawan/loraphyeu868/CMakeLists.txt b/connectivity/lorawan/tests/UNITTESTS/features/lorawan/loraphyeu868/CMakeLists.txt new file mode 100644 index 0000000000..febdec3391 --- /dev/null +++ b/connectivity/lorawan/tests/UNITTESTS/features/lorawan/loraphyeu868/CMakeLists.txt @@ -0,0 +1,31 @@ +# Copyright (c) 2021 ARM Limited. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +set(TEST_NAME lorawan-loraphy-eu868-unittest) + +add_executable(${TEST_NAME}) + +target_compile_definitions(${TEST_NAME} + PRIVATE + MBED_CONF_LORA_DOWNLINK_PREAMBLE_LENGTH=5 + MBED_CONF_LORA_TX_MAX_SIZE=255 + MBED_CONF_LORA_UPLINK_PREAMBLE_LENGTH=8 +) + +target_sources(${TEST_NAME} + PRIVATE + ${mbed-os_SOURCE_DIR}/connectivity/lorawan/lorastack/phy/LoRaPHYEU868.cpp + Test_LoRaPHYEU868.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 "lorawan") diff --git a/connectivity/lorawan/tests/UNITTESTS/features/lorawan/loraphyin865/CMakeLists.txt b/connectivity/lorawan/tests/UNITTESTS/features/lorawan/loraphyin865/CMakeLists.txt new file mode 100644 index 0000000000..8fb2940e36 --- /dev/null +++ b/connectivity/lorawan/tests/UNITTESTS/features/lorawan/loraphyin865/CMakeLists.txt @@ -0,0 +1,31 @@ +# Copyright (c) 2021 ARM Limited. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +set(TEST_NAME lorawan-loraphy-in865-unittest) + +add_executable(${TEST_NAME}) + +target_compile_definitions(${TEST_NAME} + PRIVATE + MBED_CONF_LORA_DOWNLINK_PREAMBLE_LENGTH=5 + MBED_CONF_LORA_TX_MAX_SIZE=255 + MBED_CONF_LORA_UPLINK_PREAMBLE_LENGTH=8 +) + +target_sources(${TEST_NAME} + PRIVATE + ${mbed-os_SOURCE_DIR}/connectivity/lorawan/lorastack/phy/LoRaPHYIN865.cpp + Test_LoRaPHYIN865.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 "lorawan") diff --git a/connectivity/lorawan/tests/UNITTESTS/features/lorawan/loraphykr920/CMakeLists.txt b/connectivity/lorawan/tests/UNITTESTS/features/lorawan/loraphykr920/CMakeLists.txt new file mode 100644 index 0000000000..be56ff856f --- /dev/null +++ b/connectivity/lorawan/tests/UNITTESTS/features/lorawan/loraphykr920/CMakeLists.txt @@ -0,0 +1,31 @@ +# Copyright (c) 2021 ARM Limited. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +set(TEST_NAME lorawan-loraphy-kr920-unittest) + +add_executable(${TEST_NAME}) + +target_compile_definitions(${TEST_NAME} + PRIVATE + MBED_CONF_LORA_DOWNLINK_PREAMBLE_LENGTH=5 + MBED_CONF_LORA_TX_MAX_SIZE=255 + MBED_CONF_LORA_UPLINK_PREAMBLE_LENGTH=8 +) + +target_sources(${TEST_NAME} + PRIVATE + ${mbed-os_SOURCE_DIR}/connectivity/lorawan/lorastack/phy/LoRaPHYKR920.cpp + Test_LoRaPHYKR920.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 "lorawan") diff --git a/connectivity/lorawan/tests/UNITTESTS/features/lorawan/loraphyus915/CMakeLists.txt b/connectivity/lorawan/tests/UNITTESTS/features/lorawan/loraphyus915/CMakeLists.txt new file mode 100644 index 0000000000..3e94d6ee1b --- /dev/null +++ b/connectivity/lorawan/tests/UNITTESTS/features/lorawan/loraphyus915/CMakeLists.txt @@ -0,0 +1,37 @@ +# Copyright (c) 2021 ARM Limited. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +set(TEST_NAME lorawan-loraphy-us915-unittest) + +add_executable(${TEST_NAME}) + +target_compile_definitions(${TEST_NAME} + PRIVATE + MBED_CONF_LORA_DOWNLINK_PREAMBLE_LENGTH=5 + MBED_CONF_LORA_TX_MAX_SIZE=255 + MBED_CONF_LORA_UPLINK_PREAMBLE_LENGTH=8 +) + +target_compile_options(${TEST_NAME} + PRIVATE + "-DMBED_CONF_LORA_FSB_MASK={0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0x00FF}" + "-DMBED_CONF_LORA_FSB_MASK={0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0x00FF}" +) + +target_sources(${TEST_NAME} + PRIVATE + ${mbed-os_SOURCE_DIR}/connectivity/lorawan/lorastack/phy/LoRaPHYUS915.cpp + Test_LoRaPHYUS915.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 "lorawan") diff --git a/connectivity/lorawan/tests/UNITTESTS/features/lorawan/lorawaninterface/CMakeLists.txt b/connectivity/lorawan/tests/UNITTESTS/features/lorawan/lorawaninterface/CMakeLists.txt new file mode 100644 index 0000000000..489cece0c1 --- /dev/null +++ b/connectivity/lorawan/tests/UNITTESTS/features/lorawan/lorawaninterface/CMakeLists.txt @@ -0,0 +1,30 @@ +# Copyright (c) 2021 ARM Limited. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +set(TEST_NAME lorawan-lorawan-interface-unittest) + +add_executable(${TEST_NAME}) + +target_compile_definitions(${TEST_NAME} + PRIVATE + MBED_CONF_LORA_PHY=EU868 + MBED_CONF_LORA_TX_MAX_SIZE=255 +) + +target_sources(${TEST_NAME} + PRIVATE + ${mbed-os_SOURCE_DIR}/connectivity/lorawan/source/LoRaWANInterface.cpp + Test_LoRaWANInterface.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 "lorawan") diff --git a/connectivity/lorawan/tests/UNITTESTS/features/lorawan/lorawanstack/CMakeLists.txt b/connectivity/lorawan/tests/UNITTESTS/features/lorawan/lorawanstack/CMakeLists.txt new file mode 100644 index 0000000000..3f678713c5 --- /dev/null +++ b/connectivity/lorawan/tests/UNITTESTS/features/lorawan/lorawanstack/CMakeLists.txt @@ -0,0 +1,31 @@ +# Copyright (c) 2021 ARM Limited. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +set(TEST_NAME lorawan-lorawan-stack-unittest) + +add_executable(${TEST_NAME}) + +target_compile_definitions(${TEST_NAME} + PRIVATE + MBED_CONF_LORA_OVER_THE_AIR_ACTIVATION=true + MBED_CONF_LORA_AUTOMATIC_UPLINK_MESSAGE=true + MBED_CONF_LORA_TX_MAX_SIZE=255 +) + +target_sources(${TEST_NAME} + PRIVATE + ${mbed-os_SOURCE_DIR}/connectivity/lorawan/source/LoRaWANStack.cpp + Test_LoRaWANStack.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 "lorawan") diff --git a/connectivity/lorawan/tests/UNITTESTS/features/lorawan/lorawantimer/CMakeLists.txt b/connectivity/lorawan/tests/UNITTESTS/features/lorawan/lorawantimer/CMakeLists.txt new file mode 100644 index 0000000000..9efdd076cf --- /dev/null +++ b/connectivity/lorawan/tests/UNITTESTS/features/lorawan/lorawantimer/CMakeLists.txt @@ -0,0 +1,30 @@ +# Copyright (c) 2021 ARM Limited. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +set(TEST_NAME lorawan-lorawan-timer-unittest) + +add_executable(${TEST_NAME}) + +target_compile_definitions(${TEST_NAME} + PRIVATE + NDEBUG=1 + MBED_CONF_LORA_TX_MAX_SIZE=255 +) + +target_sources(${TEST_NAME} + PRIVATE + ${mbed-os_SOURCE_DIR}/connectivity/lorawan/system/LoRaWANTimer.cpp + Test_LoRaWANTimer.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 "lorawan") diff --git a/connectivity/netsocket/CMakeLists.txt b/connectivity/netsocket/CMakeLists.txt index f99ae1dbaa..0ce8a2f466 100644 --- a/connectivity/netsocket/CMakeLists.txt +++ b/connectivity/netsocket/CMakeLists.txt @@ -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() + # TODO CMake: Perhaps move this/these file(s) into connectivity/drivers/cellular target_sources(mbed-cellular INTERFACE diff --git a/connectivity/netsocket/tests/UNITTESTS/CMakeLists.txt b/connectivity/netsocket/tests/UNITTESTS/CMakeLists.txt new file mode 100644 index 0000000000..e23c5d4290 --- /dev/null +++ b/connectivity/netsocket/tests/UNITTESTS/CMakeLists.txt @@ -0,0 +1,4 @@ +# Copyright (c) 2021 ARM Limited. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +add_subdirectory(netsocket) diff --git a/connectivity/netsocket/tests/UNITTESTS/netsocket/CMakeLists.txt b/connectivity/netsocket/tests/UNITTESTS/netsocket/CMakeLists.txt new file mode 100644 index 0000000000..fa4624a27b --- /dev/null +++ b/connectivity/netsocket/tests/UNITTESTS/netsocket/CMakeLists.txt @@ -0,0 +1,18 @@ +# Copyright (c) 2021 ARM Limited. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +add_subdirectory(CellularNonIPSocket) +add_subdirectory(DTLSSocket) +add_subdirectory(DTLSSocketWrapper) +add_subdirectory(EthernetInterface) +add_subdirectory(IfaceDnsSocket) +add_subdirectory(InternetSocket) +add_subdirectory(NetworkInterface) +add_subdirectory(NetworkStack) +add_subdirectory(PPPInterface) +add_subdirectory(SocketAddress) +add_subdirectory(TCPSocket) +add_subdirectory(TLSSocket) +add_subdirectory(TLSSocketWrapper) +add_subdirectory(UDPSocket) +add_subdirectory(WiFiAccessPoint) diff --git a/connectivity/netsocket/tests/UNITTESTS/netsocket/CellularNonIPSocket/CMakeLists.txt b/connectivity/netsocket/tests/UNITTESTS/netsocket/CellularNonIPSocket/CMakeLists.txt new file mode 100644 index 0000000000..214d1abf44 --- /dev/null +++ b/connectivity/netsocket/tests/UNITTESTS/netsocket/CellularNonIPSocket/CMakeLists.txt @@ -0,0 +1,33 @@ +# Copyright (c) 2021 ARM Limited. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +set(TEST_NAME netsocket-cellular-nonip-socket-unittest) + +add_executable(${TEST_NAME}) + +target_compile_definitions(${TEST_NAME} + PRIVATE + MBED_CONF_CELLULAR_PRESENT=1 + DEVICE_SERIAL=1 + DEVICE_INTERRUPTIN=1 + MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE=115200 + +) + +target_sources(${TEST_NAME} + PRIVATE + ${mbed-os_SOURCE_DIR}/connectivity/netsocket/source/CellularNonIPSocket.cpp + test_CellularNonIPSocket.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 "netsocket") diff --git a/connectivity/netsocket/tests/UNITTESTS/netsocket/DTLSSocket/CMakeLists.txt b/connectivity/netsocket/tests/UNITTESTS/netsocket/DTLSSocket/CMakeLists.txt new file mode 100644 index 0000000000..9f241884a2 --- /dev/null +++ b/connectivity/netsocket/tests/UNITTESTS/netsocket/DTLSSocket/CMakeLists.txt @@ -0,0 +1,47 @@ +# Copyright (c) 2021 ARM Limited. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +set(TEST_NAME netsocket-dtls-socket-unittest) + +add_executable(${TEST_NAME}) + +target_compile_definitions(${TEST_NAME} + PRIVATE + MBED_CONF_NSAPI_DNS_ADDRESSES_LIMIT=10 +) + +target_sources(${TEST_NAME} + PRIVATE + ${mbed-os_SOURCE_DIR}/connectivity/netsocket/source/SocketAddress.cpp + ${mbed-os_SOURCE_DIR}/connectivity/netsocket/source/NetworkStack.cpp + ${mbed-os_SOURCE_DIR}/connectivity/netsocket/source/InternetSocket.cpp + ${mbed-os_SOURCE_DIR}/connectivity/netsocket/source/InternetDatagramSocket.cpp + ${mbed-os_SOURCE_DIR}/connectivity/netsocket/source/UDPSocket.cpp + ${mbed-os_SOURCE_DIR}/connectivity/netsocket/source/DTLSSocket.cpp + ${mbed-os_SOURCE_DIR}/connectivity/netsocket/source/DTLSSocketWrapper.cpp + ${mbed-os_SOURCE_DIR}/connectivity/netsocket/source/TLSSocketWrapper.cpp + ${mbed-os_SOURCE_DIR}/connectivity/libraries/nanostack-libservice/source/libip4string/ip4tos.c + ${mbed-os_SOURCE_DIR}/connectivity/libraries/nanostack-libservice/source/libip6string/ip6tos.c + ${mbed-os_SOURCE_DIR}/connectivity/libraries/nanostack-libservice/source/libip4string/stoip4.c + ${mbed-os_SOURCE_DIR}/connectivity/libraries/nanostack-libservice/source/libip6string/stoip6.c + ${mbed-os_SOURCE_DIR}/connectivity/libraries/nanostack-libservice/source/libBits/common_functions.c + test_DTLSSocket.cpp +) + +target_link_libraries(${TEST_NAME} + PRIVATE + mbed-headers + mbed-stubs + mbed-stubs-headers + gmock_main +) + +set(MBEDTLS_USER_CONFIG_FILE_PATH "\"${mbed-os_SOURCE_DIR}/connectivity/netsocket/tests/UNITTESTS/netsocket/DTLSSocket/dtls_test_config.h\"") +set_source_files_properties(${mbed-os_SOURCE_DIR}/connectivity/netsocket/tests/UNITTESTS/netsocket/DTLSSocket/test_DTLSSocket.cpp PROPERTIES COMPILE_DEFINITIONS MBEDTLS_USER_CONFIG_FILE=${MBEDTLS_USER_CONFIG_FILE_PATH}) +set_source_files_properties(${mbed-os_SOURCE_DIR}/connectivity/netsocket/source/DTLSSocket.cpp PROPERTIES COMPILE_DEFINITIONS MBEDTLS_USER_CONFIG_FILE=${MBEDTLS_USER_CONFIG_FILE_PATH}) +set_source_files_properties(${mbed-os_SOURCE_DIR}/connectivity/netsocket/source/DTLSSocketWrapper.cpp PROPERTIES COMPILE_DEFINITIONS MBEDTLS_USER_CONFIG_FILE=${MBEDTLS_USER_CONFIG_FILE_PATH}) +set_source_files_properties(${mbed-os_SOURCE_DIR}/connectivity/netsocket/source/TLSSocketWrapper.cpp PROPERTIES COMPILE_DEFINITIONS MBEDTLS_USER_CONFIG_FILE=${MBEDTLS_USER_CONFIG_FILE_PATH}) + +add_test(NAME "${TEST_NAME}" COMMAND ${TEST_NAME}) + +set_tests_properties(${TEST_NAME} PROPERTIES LABELS "netsocket") diff --git a/connectivity/netsocket/tests/UNITTESTS/netsocket/DTLSSocket/test_DTLSSocket.cpp b/connectivity/netsocket/tests/UNITTESTS/netsocket/DTLSSocket/test_DTLSSocket.cpp index 681366fe4d..854ec2c2b0 100644 --- a/connectivity/netsocket/tests/UNITTESTS/netsocket/DTLSSocket/test_DTLSSocket.cpp +++ b/connectivity/netsocket/tests/UNITTESTS/netsocket/DTLSSocket/test_DTLSSocket.cpp @@ -62,5 +62,6 @@ TEST_F(TestDTLSSocket, connect) stack.return_value = NSAPI_ERROR_OK; SocketAddress a("127.0.0.1", 1024); + stack.return_socketAddress = a; EXPECT_EQ(socket->connect(a), NSAPI_ERROR_OK); } diff --git a/connectivity/netsocket/tests/UNITTESTS/netsocket/DTLSSocketWrapper/CMakeLists.txt b/connectivity/netsocket/tests/UNITTESTS/netsocket/DTLSSocketWrapper/CMakeLists.txt new file mode 100644 index 0000000000..20a0e4cfc3 --- /dev/null +++ b/connectivity/netsocket/tests/UNITTESTS/netsocket/DTLSSocketWrapper/CMakeLists.txt @@ -0,0 +1,46 @@ +# Copyright (c) 2021 ARM Limited. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +set(TEST_NAME netsocket-dtls-socket-wrapper-unittest) + +add_executable(${TEST_NAME}) + +target_compile_definitions(${TEST_NAME} + PRIVATE + MBED_CONF_NSAPI_DNS_ADDRESSES_LIMIT=10 +) + +target_sources(${TEST_NAME} + PRIVATE + ${mbed-os_SOURCE_DIR}/connectivity/netsocket/source/SocketAddress.cpp + ${mbed-os_SOURCE_DIR}/connectivity/netsocket/source/NetworkStack.cpp + ${mbed-os_SOURCE_DIR}/connectivity/netsocket/source/InternetSocket.cpp + ${mbed-os_SOURCE_DIR}/connectivity/netsocket/source/InternetDatagramSocket.cpp + ${mbed-os_SOURCE_DIR}/connectivity/netsocket/source/UDPSocket.cpp + ${mbed-os_SOURCE_DIR}/connectivity/netsocket/source/DTLSSocketWrapper.cpp + ${mbed-os_SOURCE_DIR}/connectivity/netsocket/source/TLSSocketWrapper.cpp + ${mbed-os_SOURCE_DIR}/connectivity/libraries/nanostack-libservice/source/libip4string/ip4tos.c + ${mbed-os_SOURCE_DIR}/connectivity/libraries/nanostack-libservice/source/libip6string/ip6tos.c + ${mbed-os_SOURCE_DIR}/connectivity/libraries/nanostack-libservice/source/libip4string/stoip4.c + ${mbed-os_SOURCE_DIR}/connectivity/libraries/nanostack-libservice/source/libip6string/stoip6.c + ${mbed-os_SOURCE_DIR}/connectivity/libraries/nanostack-libservice/source/libBits/common_functions.c + test_DTLSSocketWrapper.cpp +) + +target_link_libraries(${TEST_NAME} + PRIVATE + mbed-headers + mbed-stubs + mbed-stubs-headers + gmock_main +) + + +set(MBEDTLS_USER_CONFIG_FILE_PATH "\"${mbed-os_SOURCE_DIR}/connectivity/netsocket/tests/UNITTESTS/netsocket/DTLSSocketWrapper/dtls_test_config.h\"") +set_source_files_properties(${mbed-os_SOURCE_DIR}/connectivity/netsocket/tests/UNITTESTS/netsocket/DTLSSocketWrapper/test_DTLSSocketWrapper.cpp PROPERTIES COMPILE_DEFINITIONS MBEDTLS_USER_CONFIG_FILE=${MBEDTLS_USER_CONFIG_FILE_PATH}) +set_source_files_properties(${mbed-os_SOURCE_DIR}/connectivity/netsocket/source/DTLSSocketWrapper.cpp PROPERTIES COMPILE_DEFINITIONS MBEDTLS_USER_CONFIG_FILE=${MBEDTLS_USER_CONFIG_FILE_PATH}) +set_source_files_properties(${mbed-os_SOURCE_DIR}/connectivity/netsocket/source/TLSSocketWrapper.cpp PROPERTIES COMPILE_DEFINITIONS MBEDTLS_USER_CONFIG_FILE=${MBEDTLS_USER_CONFIG_FILE_PATH}) + +add_test(NAME "${TEST_NAME}" COMMAND ${TEST_NAME}) + +set_tests_properties(${TEST_NAME} PROPERTIES LABELS "netsocket") diff --git a/connectivity/netsocket/tests/UNITTESTS/netsocket/DTLSSocketWrapper/test_DTLSSocketWrapper.cpp b/connectivity/netsocket/tests/UNITTESTS/netsocket/DTLSSocketWrapper/test_DTLSSocketWrapper.cpp index fcc72c64f9..d3e09383f3 100644 --- a/connectivity/netsocket/tests/UNITTESTS/netsocket/DTLSSocketWrapper/test_DTLSSocketWrapper.cpp +++ b/connectivity/netsocket/tests/UNITTESTS/netsocket/DTLSSocketWrapper/test_DTLSSocketWrapper.cpp @@ -19,7 +19,7 @@ #include "netsocket/UDPSocket.h" #include "netsocket/DTLSSocketWrapper.h" #include "NetworkStack_stub.h" -#include "connectivity/nanostack/coap-service/test/coap-service/unittest/stub/mbedtls_stub.h" +#include "mbedtls_stub.h" #include //memset #include "mbed_error.h" diff --git a/connectivity/netsocket/tests/UNITTESTS/netsocket/EthernetInterface/CMakeLists.txt b/connectivity/netsocket/tests/UNITTESTS/netsocket/EthernetInterface/CMakeLists.txt new file mode 100644 index 0000000000..2081cf2e94 --- /dev/null +++ b/connectivity/netsocket/tests/UNITTESTS/netsocket/EthernetInterface/CMakeLists.txt @@ -0,0 +1,39 @@ +# Copyright (c) 2021 ARM Limited. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +set(TEST_NAME netsocket-ethernet-interface-unittest) + +add_executable(${TEST_NAME}) + +target_compile_definitions(${TEST_NAME} + PRIVATE + MBED_CONF_NSAPI_DNS_ADDRESSES_LIMIT=10 +) + +target_sources(${TEST_NAME} + PRIVATE + ${mbed-os_SOURCE_DIR}/connectivity/netsocket/source/SocketAddress.cpp + ${mbed-os_SOURCE_DIR}/connectivity/netsocket/source/EthernetInterface.cpp + ${mbed-os_SOURCE_DIR}/connectivity/netsocket/source/EMACInterface.cpp + ${mbed-os_SOURCE_DIR}/connectivity/netsocket/source/NetworkInterface.cpp + ${mbed-os_SOURCE_DIR}/connectivity/netsocket/source/NetworkStack.cpp + ${mbed-os_SOURCE_DIR}/connectivity/libraries/nanostack-libservice/source/libip4string/ip4tos.c + ${mbed-os_SOURCE_DIR}/connectivity/libraries/nanostack-libservice/source/libip6string/ip6tos.c + ${mbed-os_SOURCE_DIR}/connectivity/libraries/nanostack-libservice/source/libip4string/stoip4.c + ${mbed-os_SOURCE_DIR}/connectivity/libraries/nanostack-libservice/source/libip6string/stoip6.c + ${mbed-os_SOURCE_DIR}/connectivity/libraries/nanostack-libservice/source/libBits/common_functions.c + ${mbed-os_SOURCE_DIR}/connectivity/libraries/nanostack-libservice/source/libList/ns_list.c + test_EthernetInterface.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 "netsocket") diff --git a/connectivity/netsocket/tests/UNITTESTS/netsocket/IfaceDnsSocket/CMakeLists.txt b/connectivity/netsocket/tests/UNITTESTS/netsocket/IfaceDnsSocket/CMakeLists.txt new file mode 100644 index 0000000000..68ee8fb941 --- /dev/null +++ b/connectivity/netsocket/tests/UNITTESTS/netsocket/IfaceDnsSocket/CMakeLists.txt @@ -0,0 +1,53 @@ +# Copyright (c) 2021 ARM Limited. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +set(TEST_NAME netsocket-iface-dns-socket-unittest) + +add_executable(${TEST_NAME}) + +target_compile_definitions(${TEST_NAME} + PRIVATE + MBED_CONF_NSAPI_DNS_ADDRESSES_LIMIT=10 + DEVICE_EMAC + MBED_CONF_TARGET_NETWORK_DEFAULT_INTERFACE_TYPE=ETHERNET + MBED_CONF_NSAPI_DNS_RESPONSE_WAIT_TIME=10000 + MBED_CONF_NSAPI_DNS_RETRIES=1 + MBED_CONF_NSAPI_DNS_TOTAL_ATTEMPTS=10 + MBED_CONF_NSAPI_DNS_CACHE_SIZE=5 +) + +target_sources(${TEST_NAME} + PRIVATE + ${mbed-os_SOURCE_DIR}/connectivity/netsocket/source/SocketAddress.cpp + ${mbed-os_SOURCE_DIR}/connectivity/netsocket/source/NetworkInterface.cpp + ${mbed-os_SOURCE_DIR}/connectivity/netsocket/source/NetworkInterfaceDefaults.cpp + ${mbed-os_SOURCE_DIR}/connectivity/netsocket/source/NetworkStack.cpp #nsapi_create_stack + ${mbed-os_SOURCE_DIR}/connectivity/netsocket/source/InternetSocket.cpp + ${mbed-os_SOURCE_DIR}/connectivity/netsocket/source/TCPSocket.cpp + ${mbed-os_SOURCE_DIR}/connectivity/netsocket/source/InternetDatagramSocket.cpp + ${mbed-os_SOURCE_DIR}/connectivity/netsocket/source/UDPSocket.cpp + ${mbed-os_SOURCE_DIR}/connectivity/netsocket/source/SocketStats.cpp + ${mbed-os_SOURCE_DIR}/connectivity/netsocket/source/EthernetInterface.cpp + ${mbed-os_SOURCE_DIR}/connectivity/netsocket/source/EMACInterface.cpp + ${mbed-os_SOURCE_DIR}/connectivity/netsocket/source/nsapi_dns.cpp + ${mbed-os_SOURCE_DIR}/connectivity/libraries/nanostack-libservice/source/libip4string/ip4tos.c + ${mbed-os_SOURCE_DIR}/connectivity/libraries/nanostack-libservice/source/libip6string/ip6tos.c + ${mbed-os_SOURCE_DIR}/connectivity/libraries/nanostack-libservice/source/libip4string/stoip4.c + ${mbed-os_SOURCE_DIR}/connectivity/libraries/nanostack-libservice/source/libip6string/stoip6.c + ${mbed-os_SOURCE_DIR}/connectivity/libraries/nanostack-libservice/source/libBits/common_functions.c + ${mbed-os_SOURCE_DIR}/connectivity/libraries/nanostack-libservice/source/libBits/common_functions.c + ${mbed-os_SOURCE_DIR}/connectivity/libraries/nanostack-libservice/source/libList/ns_list.c + moduletest.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 "netsocket") diff --git a/connectivity/netsocket/tests/UNITTESTS/netsocket/InternetSocket/CMakeLists.txt b/connectivity/netsocket/tests/UNITTESTS/netsocket/InternetSocket/CMakeLists.txt new file mode 100644 index 0000000000..981790d6ea --- /dev/null +++ b/connectivity/netsocket/tests/UNITTESTS/netsocket/InternetSocket/CMakeLists.txt @@ -0,0 +1,36 @@ +# Copyright (c) 2021 ARM Limited. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +set(TEST_NAME netsocket-internet-socket-unittest) + +add_executable(${TEST_NAME}) + +target_compile_definitions(${TEST_NAME} + PRIVATE + MBED_CONF_NSAPI_DNS_ADDRESSES_LIMIT=10 +) + +target_sources(${TEST_NAME} + PRIVATE + ${mbed-os_SOURCE_DIR}/connectivity/netsocket/source/SocketAddress.cpp + ${mbed-os_SOURCE_DIR}/connectivity/netsocket/source/NetworkStack.cpp + ${mbed-os_SOURCE_DIR}/connectivity/netsocket/source/InternetSocket.cpp + ${mbed-os_SOURCE_DIR}/connectivity/libraries/nanostack-libservice/source/libip4string/ip4tos.c + ${mbed-os_SOURCE_DIR}/connectivity/libraries/nanostack-libservice/source/libip6string/ip6tos.c + ${mbed-os_SOURCE_DIR}/connectivity/libraries/nanostack-libservice/source/libip4string/stoip4.c + ${mbed-os_SOURCE_DIR}/connectivity/libraries/nanostack-libservice/source/libip6string/stoip6.c + ${mbed-os_SOURCE_DIR}/connectivity/libraries/nanostack-libservice/source/libBits/common_functions.c + test_InternetSocket.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 "netsocket") diff --git a/connectivity/netsocket/tests/UNITTESTS/netsocket/NetworkInterface/CMakeLists.txt b/connectivity/netsocket/tests/UNITTESTS/netsocket/NetworkInterface/CMakeLists.txt new file mode 100644 index 0000000000..f92e9ed7fe --- /dev/null +++ b/connectivity/netsocket/tests/UNITTESTS/netsocket/NetworkInterface/CMakeLists.txt @@ -0,0 +1,39 @@ +# Copyright (c) 2021 ARM Limited. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +set(TEST_NAME netsocket-network-interface-unittest) + +add_executable(${TEST_NAME}) + +target_compile_definitions(${TEST_NAME} + PRIVATE + MBED_CONF_PLATFORM_CALLBACK_COMPARABLE + MBED_CONF_NSAPI_DNS_ADDRESSES_LIMIT=10 + +) + +target_sources(${TEST_NAME} + PRIVATE + ${mbed-os_SOURCE_DIR}/connectivity/netsocket/source/SocketAddress.cpp + ${mbed-os_SOURCE_DIR}/connectivity/netsocket/source/NetworkStack.cpp + ${mbed-os_SOURCE_DIR}/connectivity/netsocket/source/NetworkInterface.cpp + ${mbed-os_SOURCE_DIR}/connectivity/libraries/nanostack-libservice/source/libip4string/ip4tos.c + ${mbed-os_SOURCE_DIR}/connectivity/libraries/nanostack-libservice/source/libip6string/ip6tos.c + ${mbed-os_SOURCE_DIR}/connectivity/libraries/nanostack-libservice/source/libip4string/stoip4.c + ${mbed-os_SOURCE_DIR}/connectivity/libraries/nanostack-libservice/source/libip6string/stoip6.c + ${mbed-os_SOURCE_DIR}/connectivity/libraries/nanostack-libservice/source/libBits/common_functions.c + ${mbed-os_SOURCE_DIR}/connectivity/libraries/nanostack-libservice/source/libList/ns_list.c + test_NetworkInterface.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 "netsocket") diff --git a/connectivity/netsocket/tests/UNITTESTS/netsocket/NetworkStack/CMakeLists.txt b/connectivity/netsocket/tests/UNITTESTS/netsocket/NetworkStack/CMakeLists.txt new file mode 100644 index 0000000000..f320819f41 --- /dev/null +++ b/connectivity/netsocket/tests/UNITTESTS/netsocket/NetworkStack/CMakeLists.txt @@ -0,0 +1,35 @@ +# Copyright (c) 2021 ARM Limited. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +set(TEST_NAME netsocket-network-stack-unittest) + +add_executable(${TEST_NAME}) + +target_compile_definitions(${TEST_NAME} + PRIVATE + MBED_CONF_NSAPI_DNS_ADDRESSES_LIMIT=10 +) + +target_sources(${TEST_NAME} + PRIVATE + ${mbed-os_SOURCE_DIR}/connectivity/netsocket/source/SocketAddress.cpp + ${mbed-os_SOURCE_DIR}/connectivity/netsocket/source/NetworkStack.cpp + ${mbed-os_SOURCE_DIR}/connectivity/libraries/nanostack-libservice/source/libip4string/ip4tos.c + ${mbed-os_SOURCE_DIR}/connectivity/libraries/nanostack-libservice/source/libip6string/ip6tos.c + ${mbed-os_SOURCE_DIR}/connectivity/libraries/nanostack-libservice/source/libip4string/stoip4.c + ${mbed-os_SOURCE_DIR}/connectivity/libraries/nanostack-libservice/source/libip6string/stoip6.c + ${mbed-os_SOURCE_DIR}/connectivity/libraries/nanostack-libservice/source/libBits/common_functions.c + test_NetworkStack.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 "netsocket") diff --git a/connectivity/netsocket/tests/UNITTESTS/netsocket/PPPInterface/CMakeLists.txt b/connectivity/netsocket/tests/UNITTESTS/netsocket/PPPInterface/CMakeLists.txt new file mode 100644 index 0000000000..f78c6ccf6b --- /dev/null +++ b/connectivity/netsocket/tests/UNITTESTS/netsocket/PPPInterface/CMakeLists.txt @@ -0,0 +1,39 @@ +# Copyright (c) 2021 ARM Limited. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +set(TEST_NAME netsocket-ppp-interface-unittest) + +add_executable(${TEST_NAME}) + +target_compile_definitions(${TEST_NAME} + PRIVATE + MBED_CONF_NSAPI_DNS_ADDRESSES_LIMIT=10 +) + +target_sources(${TEST_NAME} + PRIVATE + ${mbed-os_SOURCE_DIR}/connectivity/netsocket/source/SocketAddress.cpp + ${mbed-os_SOURCE_DIR}/connectivity/netsocket/source/PPPInterface.cpp + ${mbed-os_SOURCE_DIR}/connectivity/netsocket/source/EMACInterface.cpp + ${mbed-os_SOURCE_DIR}/connectivity/netsocket/source/NetworkInterface.cpp + ${mbed-os_SOURCE_DIR}/connectivity/netsocket/source/NetworkStack.cpp + ${mbed-os_SOURCE_DIR}/connectivity/libraries/nanostack-libservice/source/libip4string/ip4tos.c + ${mbed-os_SOURCE_DIR}/connectivity/libraries/nanostack-libservice/source/libip6string/ip6tos.c + ${mbed-os_SOURCE_DIR}/connectivity/libraries/nanostack-libservice/source/libip4string/stoip4.c + ${mbed-os_SOURCE_DIR}/connectivity/libraries/nanostack-libservice/source/libip6string/stoip6.c + ${mbed-os_SOURCE_DIR}/connectivity/libraries/nanostack-libservice/source/libBits/common_functions.c + ${mbed-os_SOURCE_DIR}/connectivity/libraries/nanostack-libservice/source/libList/ns_list.c + test_PPPInterface.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 "netsocket") diff --git a/connectivity/netsocket/tests/UNITTESTS/netsocket/SocketAddress/CMakeLists.txt b/connectivity/netsocket/tests/UNITTESTS/netsocket/SocketAddress/CMakeLists.txt new file mode 100644 index 0000000000..5ac15b6a54 --- /dev/null +++ b/connectivity/netsocket/tests/UNITTESTS/netsocket/SocketAddress/CMakeLists.txt @@ -0,0 +1,29 @@ +# Copyright (c) 2021 ARM Limited. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +set(TEST_NAME netsocket-socket-address-unittest) + +add_executable(${TEST_NAME}) + +target_sources(${TEST_NAME} + PRIVATE + ${mbed-os_SOURCE_DIR}/connectivity/netsocket/source/SocketAddress.cpp + ${mbed-os_SOURCE_DIR}/connectivity/libraries/nanostack-libservice/source/libip4string/ip4tos.c + ${mbed-os_SOURCE_DIR}/connectivity/libraries/nanostack-libservice/source/libip6string/ip6tos.c + ${mbed-os_SOURCE_DIR}/connectivity/libraries/nanostack-libservice/source/libip4string/stoip4.c + ${mbed-os_SOURCE_DIR}/connectivity/libraries/nanostack-libservice/source/libip6string/stoip6.c + ${mbed-os_SOURCE_DIR}/connectivity/libraries/nanostack-libservice/source/libBits/common_functions.c + test_SocketAddress.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 "netsocket") diff --git a/connectivity/netsocket/tests/UNITTESTS/netsocket/TCPSocket/CMakeLists.txt b/connectivity/netsocket/tests/UNITTESTS/netsocket/TCPSocket/CMakeLists.txt new file mode 100644 index 0000000000..ca51a12f39 --- /dev/null +++ b/connectivity/netsocket/tests/UNITTESTS/netsocket/TCPSocket/CMakeLists.txt @@ -0,0 +1,37 @@ +# Copyright (c) 2021 ARM Limited. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +set(TEST_NAME netsocket-tcp-socket-unittest) + +add_executable(${TEST_NAME}) + +target_compile_definitions(${TEST_NAME} + PRIVATE + MBED_CONF_NSAPI_DNS_ADDRESSES_LIMIT=10 +) + +target_sources(${TEST_NAME} + PRIVATE + ${mbed-os_SOURCE_DIR}/connectivity/netsocket/source/SocketAddress.cpp + ${mbed-os_SOURCE_DIR}/connectivity/netsocket/source/NetworkStack.cpp + ${mbed-os_SOURCE_DIR}/connectivity/netsocket/source/InternetSocket.cpp + ${mbed-os_SOURCE_DIR}/connectivity/netsocket/source/TCPSocket.cpp + ${mbed-os_SOURCE_DIR}/connectivity/libraries/nanostack-libservice/source/libip4string/ip4tos.c + ${mbed-os_SOURCE_DIR}/connectivity/libraries/nanostack-libservice/source/libip6string/ip6tos.c + ${mbed-os_SOURCE_DIR}/connectivity/libraries/nanostack-libservice/source/libip4string/stoip4.c + ${mbed-os_SOURCE_DIR}/connectivity/libraries/nanostack-libservice/source/libip6string/stoip6.c + ${mbed-os_SOURCE_DIR}/connectivity/libraries/nanostack-libservice/source/libBits/common_functions.c + test_TCPSocket.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 "netsocket") diff --git a/connectivity/netsocket/tests/UNITTESTS/netsocket/TLSSocket/CMakeLists.txt b/connectivity/netsocket/tests/UNITTESTS/netsocket/TLSSocket/CMakeLists.txt new file mode 100644 index 0000000000..b9242f928c --- /dev/null +++ b/connectivity/netsocket/tests/UNITTESTS/netsocket/TLSSocket/CMakeLists.txt @@ -0,0 +1,44 @@ +# Copyright (c) 2021 ARM Limited. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +set(TEST_NAME netsocket-tls-socket-unittest) + +add_executable(${TEST_NAME}) + +target_compile_definitions(${TEST_NAME} + PRIVATE + MBED_CONF_NSAPI_DNS_ADDRESSES_LIMIT=10 +) + +target_sources(${TEST_NAME} + PRIVATE + ${mbed-os_SOURCE_DIR}/connectivity/netsocket/source/SocketAddress.cpp + ${mbed-os_SOURCE_DIR}/connectivity/netsocket/source/NetworkStack.cpp + ${mbed-os_SOURCE_DIR}/connectivity/netsocket/source/InternetSocket.cpp + ${mbed-os_SOURCE_DIR}/connectivity/netsocket/source/TCPSocket.cpp + ${mbed-os_SOURCE_DIR}/connectivity/netsocket/source/TLSSocket.cpp + ${mbed-os_SOURCE_DIR}/connectivity/netsocket/source/TLSSocketWrapper.cpp + ${mbed-os_SOURCE_DIR}/connectivity/libraries/nanostack-libservice/source/libip4string/ip4tos.c + ${mbed-os_SOURCE_DIR}/connectivity/libraries/nanostack-libservice/source/libip6string/ip6tos.c + ${mbed-os_SOURCE_DIR}/connectivity/libraries/nanostack-libservice/source/libip4string/stoip4.c + ${mbed-os_SOURCE_DIR}/connectivity/libraries/nanostack-libservice/source/libip6string/stoip6.c + ${mbed-os_SOURCE_DIR}/connectivity/libraries/nanostack-libservice/source/libBits/common_functions.c + test_TLSSocket.cpp +) + +target_link_libraries(${TEST_NAME} + PRIVATE + mbed-headers + mbed-stubs + mbed-stubs-headers + gmock_main +) + +set(MBEDTLS_USER_CONFIG_FILE_PATH "\"${mbed-os_SOURCE_DIR}/connectivity/netsocket/tests/UNITTESTS/netsocket/TLSSocket/tls_test_config.h\"") +set_source_files_properties(${CMAKE_CURRENT_LIST_DIR}/test_TLSSocket.cpp PROPERTIES COMPILE_DEFINITIONS MBEDTLS_USER_CONFIG_FILE=${MBEDTLS_USER_CONFIG_FILE_PATH}) +set_source_files_properties(${mbed-os_SOURCE_DIR}/connectivity/netsocket/source/TLSSocket.cpp PROPERTIES COMPILE_DEFINITIONS MBEDTLS_USER_CONFIG_FILE=${MBEDTLS_USER_CONFIG_FILE_PATH}) +set_source_files_properties(${mbed-os_SOURCE_DIR}/connectivity/netsocket/source/TLSSocketWrapper.cpp PROPERTIES COMPILE_DEFINITIONS MBEDTLS_USER_CONFIG_FILE=${MBEDTLS_USER_CONFIG_FILE_PATH}) + +add_test(NAME "${TEST_NAME}" COMMAND ${TEST_NAME}) + +set_tests_properties(${TEST_NAME} PROPERTIES LABELS "netsocket") diff --git a/connectivity/netsocket/tests/UNITTESTS/netsocket/TLSSocketWrapper/CMakeLists.txt b/connectivity/netsocket/tests/UNITTESTS/netsocket/TLSSocketWrapper/CMakeLists.txt new file mode 100644 index 0000000000..459d5c689b --- /dev/null +++ b/connectivity/netsocket/tests/UNITTESTS/netsocket/TLSSocketWrapper/CMakeLists.txt @@ -0,0 +1,42 @@ +# Copyright (c) 2021 ARM Limited. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +set(TEST_NAME netsocket-tls-socket-wrapper-unittest) + +add_executable(${TEST_NAME}) + +target_compile_definitions(${TEST_NAME} + PRIVATE + MBED_CONF_NSAPI_DNS_ADDRESSES_LIMIT=10 +) + +target_sources(${TEST_NAME} + PRIVATE + ${mbed-os_SOURCE_DIR}/connectivity/netsocket/source/SocketAddress.cpp + ${mbed-os_SOURCE_DIR}/connectivity/netsocket/source/NetworkStack.cpp + ${mbed-os_SOURCE_DIR}/connectivity/netsocket/source/InternetSocket.cpp + ${mbed-os_SOURCE_DIR}/connectivity/netsocket/source/TCPSocket.cpp + ${mbed-os_SOURCE_DIR}/connectivity/netsocket/source/TLSSocketWrapper.cpp + ${mbed-os_SOURCE_DIR}/connectivity/libraries/nanostack-libservice/source/libip4string/ip4tos.c + ${mbed-os_SOURCE_DIR}/connectivity/libraries/nanostack-libservice/source/libip6string/ip6tos.c + ${mbed-os_SOURCE_DIR}/connectivity/libraries/nanostack-libservice/source/libip4string/stoip4.c + ${mbed-os_SOURCE_DIR}/connectivity/libraries/nanostack-libservice/source/libip6string/stoip6.c + ${mbed-os_SOURCE_DIR}/connectivity/libraries/nanostack-libservice/source/libBits/common_functions.c + test_TLSSocketWrapper.cpp +) + +target_link_libraries(${TEST_NAME} + PRIVATE + mbed-headers + mbed-stubs + mbed-stubs-headers + gmock_main +) + +set(MBEDTLS_USER_CONFIG_FILE_PATH "\"${mbed-os_SOURCE_DIR}/connectivity/netsocket/tests/UNITTESTS/netsocket/TLSSocketWrapper/tls_test_config.h\"") +set_source_files_properties(${mbed-os_SOURCE_DIR}/connectivity/netsocket/tests/UNITTESTS/netsocket/TLSSocketWrapper/test_TLSSocketWrapper.cpp PROPERTIES COMPILE_DEFINITIONS MBEDTLS_USER_CONFIG_FILE=${MBEDTLS_USER_CONFIG_FILE_PATH}) +set_source_files_properties(${mbed-os_SOURCE_DIR}/connectivity/netsocket/source/TLSSocketWrapper.cpp PROPERTIES COMPILE_DEFINITIONS MBEDTLS_USER_CONFIG_FILE=${MBEDTLS_USER_CONFIG_FILE_PATH}) + +add_test(NAME "${TEST_NAME}" COMMAND ${TEST_NAME}) + +set_tests_properties(${TEST_NAME} PROPERTIES LABELS "netsocket") diff --git a/connectivity/netsocket/tests/UNITTESTS/netsocket/TLSSocketWrapper/test_TLSSocketWrapper.cpp b/connectivity/netsocket/tests/UNITTESTS/netsocket/TLSSocketWrapper/test_TLSSocketWrapper.cpp index 056317d7aa..b0e473a401 100644 --- a/connectivity/netsocket/tests/UNITTESTS/netsocket/TLSSocketWrapper/test_TLSSocketWrapper.cpp +++ b/connectivity/netsocket/tests/UNITTESTS/netsocket/TLSSocketWrapper/test_TLSSocketWrapper.cpp @@ -19,7 +19,7 @@ #include "netsocket/TCPSocket.h" #include "netsocket/TLSSocketWrapper.h" #include "NetworkStack_stub.h" -#include "connectivity/nanostack/coap-service/test/coap-service/unittest/stub/mbedtls_stub.h" +#include "mbedtls_stub.h" #include //memset #include "mbed_error.h" diff --git a/connectivity/netsocket/tests/UNITTESTS/netsocket/UDPSocket/CMakeLists.txt b/connectivity/netsocket/tests/UNITTESTS/netsocket/UDPSocket/CMakeLists.txt new file mode 100644 index 0000000000..e62438cd85 --- /dev/null +++ b/connectivity/netsocket/tests/UNITTESTS/netsocket/UDPSocket/CMakeLists.txt @@ -0,0 +1,38 @@ +# Copyright (c) 2021 ARM Limited. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +set(TEST_NAME netsocket-udp-socket-unittest) + +add_executable(${TEST_NAME}) + +target_compile_definitions(${TEST_NAME} + PRIVATE + MBED_CONF_NSAPI_DNS_ADDRESSES_LIMIT=10 +) + +target_sources(${TEST_NAME} + PRIVATE + ${mbed-os_SOURCE_DIR}/connectivity/netsocket/source/SocketAddress.cpp + ${mbed-os_SOURCE_DIR}/connectivity/netsocket/source/NetworkStack.cpp + ${mbed-os_SOURCE_DIR}/connectivity/netsocket/source/InternetSocket.cpp + ${mbed-os_SOURCE_DIR}/connectivity/netsocket/source/InternetDatagramSocket.cpp + ${mbed-os_SOURCE_DIR}/connectivity/netsocket/source/UDPSocket.cpp + ${mbed-os_SOURCE_DIR}/connectivity/libraries/nanostack-libservice/source/libip4string/ip4tos.c + ${mbed-os_SOURCE_DIR}/connectivity/libraries/nanostack-libservice/source/libip6string/ip6tos.c + ${mbed-os_SOURCE_DIR}/connectivity/libraries/nanostack-libservice/source/libip4string/stoip4.c + ${mbed-os_SOURCE_DIR}/connectivity/libraries/nanostack-libservice/source/libip6string/stoip6.c + ${mbed-os_SOURCE_DIR}/connectivity/libraries/nanostack-libservice/source/libBits/common_functions.c + test_UDPSocket.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 "netsocket") diff --git a/connectivity/netsocket/tests/UNITTESTS/netsocket/WiFiAccessPoint/CMakeLists.txt b/connectivity/netsocket/tests/UNITTESTS/netsocket/WiFiAccessPoint/CMakeLists.txt new file mode 100644 index 0000000000..d51f755464 --- /dev/null +++ b/connectivity/netsocket/tests/UNITTESTS/netsocket/WiFiAccessPoint/CMakeLists.txt @@ -0,0 +1,24 @@ +# Copyright (c) 2021 ARM Limited. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +set(TEST_NAME netsocket-wifi-access-point-unittest) + +add_executable(${TEST_NAME}) + +target_sources(${TEST_NAME} + PRIVATE + ${mbed-os_SOURCE_DIR}/connectivity/netsocket/source/WiFiAccessPoint.cpp + test_WiFiAccessPoint.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 "netsocket") diff --git a/drivers/CMakeLists.txt b/drivers/CMakeLists.txt index 83bb222309..4d26ac6dec 100644 --- a/drivers/CMakeLists.txt +++ b/drivers/CMakeLists.txt @@ -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() + target_include_directories(mbed-core INTERFACE . diff --git a/drivers/tests/UNITTESTS/CMakeLists.txt b/drivers/tests/UNITTESTS/CMakeLists.txt new file mode 100644 index 0000000000..b04c7f0be6 --- /dev/null +++ b/drivers/tests/UNITTESTS/CMakeLists.txt @@ -0,0 +1,5 @@ +# Copyright (c) 2021 ARM Limited. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +add_subdirectory(PwmOut) +add_subdirectory(Watchdog) diff --git a/drivers/tests/UNITTESTS/PwmOut/CMakeLists.txt b/drivers/tests/UNITTESTS/PwmOut/CMakeLists.txt new file mode 100644 index 0000000000..0981642f6b --- /dev/null +++ b/drivers/tests/UNITTESTS/PwmOut/CMakeLists.txt @@ -0,0 +1,29 @@ +# Copyright (c) 2021 ARM Limited. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +set(TEST_NAME pwmout-unittest) + +add_executable(${TEST_NAME}) + +target_compile_definitions(${TEST_NAME} + PRIVATE + DEVICE_PWMOUT +) + +target_sources(${TEST_NAME} + PRIVATE + ${mbed-os_SOURCE_DIR}/drivers/source/PwmOut.cpp + test_pwmout.cpp +) + +target_link_libraries(${TEST_NAME} + PRIVATE + mbed-headers + mbed-stubs-hal + mbed-stubs-platform + gmock_main +) + +add_test(NAME "${TEST_NAME}" COMMAND ${TEST_NAME}) + +set_tests_properties(${TEST_NAME} PROPERTIES LABELS "drivers") diff --git a/drivers/tests/UNITTESTS/Watchdog/CMakeLists.txt b/drivers/tests/UNITTESTS/Watchdog/CMakeLists.txt new file mode 100644 index 0000000000..1b8d3c2e5b --- /dev/null +++ b/drivers/tests/UNITTESTS/Watchdog/CMakeLists.txt @@ -0,0 +1,30 @@ +# Copyright (c) 2021 ARM Limited. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +set(TEST_NAME watchdog-unittest) + +add_executable(${TEST_NAME}) + +target_compile_definitions(${TEST_NAME} + PRIVATE + DEVICE_WATCHDOG + MBED_WDOG_ASSERT=1 +) + +target_sources(${TEST_NAME} + PRIVATE + ${mbed-os_SOURCE_DIR}/drivers/source/Watchdog.cpp + test_watchdog.cpp +) + +target_link_libraries(${TEST_NAME} + PRIVATE + mbed-headers + mbed-stubs-platform + mbed-stubs-hal + gmock_main +) + +add_test(NAME "${TEST_NAME}" COMMAND ${TEST_NAME}) + +set_tests_properties(${TEST_NAME} PROPERTIES LABELS "drivers") diff --git a/events/CMakeLists.txt b/events/CMakeLists.txt index 591b01259a..1cda3156d3 100644 --- a/events/CMakeLists.txt +++ b/events/CMakeLists.txt @@ -1,6 +1,9 @@ # Copyright (c) 2020 ARM Limited. All rights reserved. # SPDX-License-Identifier: Apache-2.0 +if(NOT ${CMAKE_CROSSCOMPILING}) + add_subdirectory(tests/UNITTESTS) +else() add_library(mbed-events INTERFACE) target_include_directories(mbed-events @@ -24,3 +27,4 @@ target_compile_definitions(mbed-events INTERFACE MBED_CONF_EVENTS_PRESENT=1 ) +endif() diff --git a/events/tests/UNITTESTS/CMakeLists.txt b/events/tests/UNITTESTS/CMakeLists.txt new file mode 100644 index 0000000000..0c295bbc93 --- /dev/null +++ b/events/tests/UNITTESTS/CMakeLists.txt @@ -0,0 +1,4 @@ +# Copyright (c) 2021 ARM Limited. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +add_subdirectory(equeue) diff --git a/events/tests/UNITTESTS/equeue/CMakeLists.txt b/events/tests/UNITTESTS/equeue/CMakeLists.txt new file mode 100644 index 0000000000..f5adf2057b --- /dev/null +++ b/events/tests/UNITTESTS/equeue/CMakeLists.txt @@ -0,0 +1,34 @@ +# Copyright (c) 2021 ARM Limited. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +set(TEST_NAME equeue-unittest) + +add_executable(${TEST_NAME}) + +target_compile_definitions(${TEST_NAME} + PRIVATE + EQUEUE_PLATFORM_POSIX +) + +target_compile_options(${TEST_NAME} + PRIVATE + "-pthread" +) + +target_sources(${TEST_NAME} + PRIVATE + ${mbed-os_SOURCE_DIR}/events/source/equeue.c + test_equeue.cpp +) + +target_link_libraries(${TEST_NAME} + PRIVATE + mbed-headers + mbed-stubs-events + mbed-stubs-platform + gmock_main +) + +add_test(NAME "${TEST_NAME}" COMMAND ${TEST_NAME}) + +set_tests_properties(${TEST_NAME} PROPERTIES LABELS "equeue") diff --git a/platform/CMakeLists.txt b/platform/CMakeLists.txt index c68f815223..b79a4a28cb 100644 --- a/platform/CMakeLists.txt +++ b/platform/CMakeLists.txt @@ -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() + # List of all optional platform libraries available. add_library(mbed-psa INTERFACE) diff --git a/platform/tests/UNITTESTS/ATCmdParser/CMakeLists.txt b/platform/tests/UNITTESTS/ATCmdParser/CMakeLists.txt new file mode 100644 index 0000000000..d2bc69e55b --- /dev/null +++ b/platform/tests/UNITTESTS/ATCmdParser/CMakeLists.txt @@ -0,0 +1,24 @@ +# Copyright (c) 2021 ARM Limited. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +set(TEST_NAME atcmdparser-unittest) + +add_executable(${TEST_NAME}) + +target_sources(${TEST_NAME} + PRIVATE + ${mbed-os_SOURCE_DIR}/platform/source/ATCmdParser.cpp + test_ATCmdParser.cpp +) + +target_link_libraries(${TEST_NAME} + PRIVATE + mbed-headers + mbed-stubs-headers + mbed-stubs-platform + gmock_main +) + +add_test(NAME "${TEST_NAME}" COMMAND ${TEST_NAME}) + +set_tests_properties(${TEST_NAME} PROPERTIES LABELS "platform") diff --git a/platform/tests/UNITTESTS/CMakeLists.txt b/platform/tests/UNITTESTS/CMakeLists.txt new file mode 100644 index 0000000000..65eb23055d --- /dev/null +++ b/platform/tests/UNITTESTS/CMakeLists.txt @@ -0,0 +1,5 @@ +# Copyright (c) 2021 ARM Limited. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +add_subdirectory(ATCmdParser) +add_subdirectory(CircularBuffer) diff --git a/platform/tests/UNITTESTS/CircularBuffer/CMakeLists.txt b/platform/tests/UNITTESTS/CircularBuffer/CMakeLists.txt new file mode 100644 index 0000000000..45fd750888 --- /dev/null +++ b/platform/tests/UNITTESTS/CircularBuffer/CMakeLists.txt @@ -0,0 +1,22 @@ +# Copyright (c) 2021 ARM Limited. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +set(TEST_NAME circularbuffer-unittest) + +add_executable(${TEST_NAME}) + +target_sources(${TEST_NAME} + PRIVATE + test_CircularBuffer.cpp +) + +target_link_libraries(${TEST_NAME} + PRIVATE + mbed-headers + mbed-stubs-platform + gmock_main +) + +add_test(NAME "${TEST_NAME}" COMMAND ${TEST_NAME}) + +set_tests_properties(${TEST_NAME} PROPERTIES LABELS "platform") diff --git a/storage/CMakeLists.txt b/storage/CMakeLists.txt index 95d984e077..df4d8a2932 100644 --- a/storage/CMakeLists.txt +++ b/storage/CMakeLists.txt @@ -26,11 +26,17 @@ add_library(mbed-storage-kv-config INTERFACE) add_library(mbed-storage-direct-access-devicekey INTERFACE) add_library(mbed-storage-kv-global-api INTERFACE) - -add_subdirectory(blockdevice) -add_subdirectory(filesystem) -add_subdirectory(kvstore) -add_subdirectory(platform) +if(${CMAKE_CROSSCOMPILING}) + # The directories below contain optional target libraries + add_subdirectory(blockdevice EXCLUDE_FROM_ALL) + add_subdirectory(filesystem EXCLUDE_FROM_ALL) + add_subdirectory(kvstore EXCLUDE_FROM_ALL) + add_subdirectory(platform EXCLUDE_FROM_ALL) +else() + # Add these subdirectories for the Unit test + add_subdirectory(blockdevice) + add_subdirectory(kvstore) +endif() target_include_directories(mbed-storage INTERFACE diff --git a/storage/blockdevice/CMakeLists.txt b/storage/blockdevice/CMakeLists.txt index 6181735cd3..cbbb76f0aa 100644 --- a/storage/blockdevice/CMakeLists.txt +++ b/storage/blockdevice/CMakeLists.txt @@ -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() + if("DATAFLASH" IN_LIST MBED_TARGET_LABELS) add_subdirectory(COMPONENT_DATAFLASH) endif() diff --git a/storage/blockdevice/tests/UNITTESTS/CMakeLists.txt b/storage/blockdevice/tests/UNITTESTS/CMakeLists.txt new file mode 100644 index 0000000000..c4980cb0db --- /dev/null +++ b/storage/blockdevice/tests/UNITTESTS/CMakeLists.txt @@ -0,0 +1,5 @@ +# Copyright (c) 2021 ARM Limited. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +add_subdirectory(blockdevice) +add_subdirectory(SFDP) diff --git a/storage/blockdevice/tests/UNITTESTS/SFDP/CMakeLists.txt b/storage/blockdevice/tests/UNITTESTS/SFDP/CMakeLists.txt new file mode 100644 index 0000000000..a2bbd95796 --- /dev/null +++ b/storage/blockdevice/tests/UNITTESTS/SFDP/CMakeLists.txt @@ -0,0 +1,28 @@ +# Copyright (c) 2021 ARM Limited. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +set(TEST_NAME sfdp-unittest) + +add_executable(${TEST_NAME}) + +target_compile_definitions(${TEST_NAME} + PRIVATE + DEVICE_SPI +) + +target_sources(${TEST_NAME} + PRIVATE + ${mbed-os_SOURCE_DIR}/storage/blockdevice/source/SFDP.cpp + test_sfdp.cpp +) + +target_link_libraries(${TEST_NAME} + PRIVATE + mbed-headers + mbed-stubs-platform + gmock_main +) + +add_test(NAME "${TEST_NAME}" COMMAND ${TEST_NAME}) + +set_tests_properties(${TEST_NAME} PROPERTIES LABELS "storage") diff --git a/storage/blockdevice/tests/UNITTESTS/blockdevice/BufferedBlockDevice/CMakeLists.txt b/storage/blockdevice/tests/UNITTESTS/blockdevice/BufferedBlockDevice/CMakeLists.txt new file mode 100644 index 0000000000..4fdbe0e969 --- /dev/null +++ b/storage/blockdevice/tests/UNITTESTS/blockdevice/BufferedBlockDevice/CMakeLists.txt @@ -0,0 +1,24 @@ +# Copyright (c) 2021 ARM Limited. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +set(TEST_NAME buffered-blockdevice-unittest) + +add_executable(${TEST_NAME}) + +target_sources(${TEST_NAME} + PRIVATE + ${mbed-os_SOURCE_DIR}/storage/blockdevice/source/BufferedBlockDevice.cpp + test_BufferedBlockDevice.cpp +) + +target_link_libraries(${TEST_NAME} + PRIVATE + mbed-headers + mbed-stubs-headers + mbed-stubs-platform + gmock_main +) + +add_test(NAME "${TEST_NAME}" COMMAND ${TEST_NAME}) + +set_tests_properties(${TEST_NAME} PROPERTIES LABELS "storage") diff --git a/storage/blockdevice/tests/UNITTESTS/blockdevice/BufferedBlockDevice/test_BufferedBlockDevice.cpp b/storage/blockdevice/tests/UNITTESTS/blockdevice/BufferedBlockDevice/test_BufferedBlockDevice.cpp index 8b4caa55f1..91658839b2 100644 --- a/storage/blockdevice/tests/UNITTESTS/blockdevice/BufferedBlockDevice/test_BufferedBlockDevice.cpp +++ b/storage/blockdevice/tests/UNITTESTS/blockdevice/BufferedBlockDevice/test_BufferedBlockDevice.cpp @@ -16,7 +16,7 @@ #include "gtest/gtest.h" #include "blockdevice/BufferedBlockDevice.h" -#include "stubs/BlockDevice_mock.h" +#include "BlockDevice_mock.h" using ::testing::_; using ::testing::Return; diff --git a/storage/blockdevice/tests/UNITTESTS/blockdevice/CMakeLists.txt b/storage/blockdevice/tests/UNITTESTS/blockdevice/CMakeLists.txt new file mode 100644 index 0000000000..ec2780a7b5 --- /dev/null +++ b/storage/blockdevice/tests/UNITTESTS/blockdevice/CMakeLists.txt @@ -0,0 +1,13 @@ +# Copyright (c) 2021 ARM Limited. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +add_subdirectory(ChainingBlockDevice) +add_subdirectory(BufferedBlockDevice) +add_subdirectory(SlicingBlockDevice) +add_subdirectory(ReadOnlyBlockDevice) +add_subdirectory(ProfilingBlockDevice) +add_subdirectory(ObservingBlockDevice) +add_subdirectory(MBRBlockDevice) +add_subdirectory(HeapBlockDevice) +add_subdirectory(FlashSimBlockDevice) +add_subdirectory(ExhaustibleBlockDevice) diff --git a/storage/blockdevice/tests/UNITTESTS/blockdevice/ChainingBlockDevice/CMakeLists.txt b/storage/blockdevice/tests/UNITTESTS/blockdevice/ChainingBlockDevice/CMakeLists.txt new file mode 100644 index 0000000000..f80de82a18 --- /dev/null +++ b/storage/blockdevice/tests/UNITTESTS/blockdevice/ChainingBlockDevice/CMakeLists.txt @@ -0,0 +1,25 @@ +# Copyright (c) 2021 ARM Limited. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +set(TEST_NAME chaining-blockdevice-unittest) + +add_executable(${TEST_NAME}) + +target_sources(${TEST_NAME} + PRIVATE + ${mbed-os_SOURCE_DIR}/storage/blockdevice/source/ChainingBlockDevice.cpp + ${mbed-os_SOURCE_DIR}/storage/blockdevice/source/HeapBlockDevice.cpp + test_ChainingBlockDevice.cpp +) + +target_link_libraries(${TEST_NAME} + PRIVATE + mbed-headers + mbed-stubs-headers + mbed-stubs-platform + gmock_main +) + +add_test(NAME "${TEST_NAME}" COMMAND ${TEST_NAME}) + +set_tests_properties(${TEST_NAME} PROPERTIES LABELS "storage") diff --git a/storage/blockdevice/tests/UNITTESTS/blockdevice/ChainingBlockDevice/test_ChainingBlockDevice.cpp b/storage/blockdevice/tests/UNITTESTS/blockdevice/ChainingBlockDevice/test_ChainingBlockDevice.cpp index a566084c06..e7dfb09d33 100644 --- a/storage/blockdevice/tests/UNITTESTS/blockdevice/ChainingBlockDevice/test_ChainingBlockDevice.cpp +++ b/storage/blockdevice/tests/UNITTESTS/blockdevice/ChainingBlockDevice/test_ChainingBlockDevice.cpp @@ -15,8 +15,8 @@ */ #include "gtest/gtest.h" -#include "ChainingBlockDevice.cpp" -#include "stubs/BlockDevice_mock.h" +#include "blockdevice/ChainingBlockDevice.h" +#include "BlockDevice_mock.h" using ::testing::_; using ::testing::Return; @@ -96,7 +96,7 @@ TEST_F(ChainingBlockModuleTest, init) EXPECT_EQ(b.read(buf, 0, BLOCK_SIZE), BD_ERROR_DEVICE_ERROR); // EXPECT_EQ(b.deinit(), BD_ERROR_OK); EXPECT_EQ(b.sync(), BD_ERROR_DEVICE_ERROR); - EXPECT_EQ(b.get_type(), "CHAINING"); + EXPECT_STREQ(b.get_type(), "CHAINING"); EXPECT_CALL(bd_mock1, init()); EXPECT_CALL(bd_mock1, size()).WillOnce(Return((SECTORS_NUM / 2)*BLOCK_SIZE)); diff --git a/storage/blockdevice/tests/UNITTESTS/blockdevice/ExhaustibleBlockDevice/CMakeLists.txt b/storage/blockdevice/tests/UNITTESTS/blockdevice/ExhaustibleBlockDevice/CMakeLists.txt new file mode 100644 index 0000000000..80c47486be --- /dev/null +++ b/storage/blockdevice/tests/UNITTESTS/blockdevice/ExhaustibleBlockDevice/CMakeLists.txt @@ -0,0 +1,24 @@ +# Copyright (c) 2021 ARM Limited. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +set(TEST_NAME exhaustible-blockdevice-unittest) + +add_executable(${TEST_NAME}) + +target_sources(${TEST_NAME} + PRIVATE + ${mbed-os_SOURCE_DIR}/storage/blockdevice/source/ExhaustibleBlockDevice.cpp + test_ExhaustibleBlockDevice.cpp +) + +target_link_libraries(${TEST_NAME} + PRIVATE + mbed-headers + mbed-stubs-headers + mbed-stubs-platform + gmock_main +) + +add_test(NAME "${TEST_NAME}" COMMAND ${TEST_NAME}) + +set_tests_properties(${TEST_NAME} PROPERTIES LABELS "storage") diff --git a/storage/blockdevice/tests/UNITTESTS/blockdevice/ExhaustibleBlockDevice/test_ExhaustibleBlockDevice.cpp b/storage/blockdevice/tests/UNITTESTS/blockdevice/ExhaustibleBlockDevice/test_ExhaustibleBlockDevice.cpp index a1625c125e..be8999a7a9 100644 --- a/storage/blockdevice/tests/UNITTESTS/blockdevice/ExhaustibleBlockDevice/test_ExhaustibleBlockDevice.cpp +++ b/storage/blockdevice/tests/UNITTESTS/blockdevice/ExhaustibleBlockDevice/test_ExhaustibleBlockDevice.cpp @@ -16,7 +16,7 @@ #include "gtest/gtest.h" #include "blockdevice/ExhaustibleBlockDevice.h" -#include "stubs/BlockDevice_mock.h" +#include "BlockDevice_mock.h" #define BLOCK_SIZE (512) #define DEVICE_SIZE (BLOCK_SIZE*10) diff --git a/storage/blockdevice/tests/UNITTESTS/blockdevice/FlashSimBlockDevice/CMakeLists.txt b/storage/blockdevice/tests/UNITTESTS/blockdevice/FlashSimBlockDevice/CMakeLists.txt new file mode 100644 index 0000000000..99e4a37809 --- /dev/null +++ b/storage/blockdevice/tests/UNITTESTS/blockdevice/FlashSimBlockDevice/CMakeLists.txt @@ -0,0 +1,24 @@ +# Copyright (c) 2021 ARM Limited. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +set(TEST_NAME flash-sim-blockdevice-unittest) + +add_executable(${TEST_NAME}) + +target_sources(${TEST_NAME} + PRIVATE + ${mbed-os_SOURCE_DIR}/storage/blockdevice/source/FlashSimBlockDevice.cpp + test_FlashSimBlockDevice.cpp +) + +target_link_libraries(${TEST_NAME} + PRIVATE + mbed-headers + mbed-stubs-headers + mbed-stubs-platform + gmock_main +) + +add_test(NAME "${TEST_NAME}" COMMAND ${TEST_NAME}) + +set_tests_properties(${TEST_NAME} PROPERTIES LABELS "storage") diff --git a/storage/blockdevice/tests/UNITTESTS/blockdevice/FlashSimBlockDevice/test_FlashSimBlockDevice.cpp b/storage/blockdevice/tests/UNITTESTS/blockdevice/FlashSimBlockDevice/test_FlashSimBlockDevice.cpp index be0e797dba..d9ce67d7ec 100644 --- a/storage/blockdevice/tests/UNITTESTS/blockdevice/FlashSimBlockDevice/test_FlashSimBlockDevice.cpp +++ b/storage/blockdevice/tests/UNITTESTS/blockdevice/FlashSimBlockDevice/test_FlashSimBlockDevice.cpp @@ -16,7 +16,7 @@ #include "gtest/gtest.h" #include "blockdevice/FlashSimBlockDevice.h" -#include "stubs/BlockDevice_mock.h" +#include "BlockDevice_mock.h" #define BLOCK_SIZE (512) #define DEVICE_SIZE (BLOCK_SIZE*10) diff --git a/storage/blockdevice/tests/UNITTESTS/blockdevice/HeapBlockDevice/CMakeLists.txt b/storage/blockdevice/tests/UNITTESTS/blockdevice/HeapBlockDevice/CMakeLists.txt new file mode 100644 index 0000000000..e2bbd7323d --- /dev/null +++ b/storage/blockdevice/tests/UNITTESTS/blockdevice/HeapBlockDevice/CMakeLists.txt @@ -0,0 +1,67 @@ +# Copyright (c) 2021 ARM Limited. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +set(TEST_NAME heap-blockdevice-unittest) + +add_executable(${TEST_NAME}) + +target_compile_definitions(${TEST_NAME} + PRIVATE + MBED_CONF_FAT_CHAN_FFS_DBG=0 + MBED_CONF_FAT_CHAN_FF_FS_READONLY=0 + MBED_CONF_FAT_CHAN_FF_FS_MINIMIZE=0 + MBED_CONF_FAT_CHAN_FF_USE_STRFUNC=0 + MBED_CONF_FAT_CHAN_FF_USE_FIND=0 + MBED_CONF_FAT_CHAN_FF_USE_MKFS=1 + MBED_CONF_FAT_CHAN_FF_USE_FASTSEEK=0 + MBED_CONF_FAT_CHAN_FF_USE_EXPAND=0 + MBED_CONF_FAT_CHAN_FF_USE_CHMOD=0 + MBED_CONF_FAT_CHAN_FF_USE_LABEL=0 + MBED_CONF_FAT_CHAN_FF_USE_FORWARD=0 + MBED_CONF_FAT_CHAN_FF_CODE_PAGE=437 + MBED_CONF_FAT_CHAN_FF_USE_LFN=3 + MBED_CONF_FAT_CHAN_FF_MAX_LFN=255 + MBED_CONF_FAT_CHAN_FF_LFN_UNICODE=0 + MBED_CONF_FAT_CHAN_FF_LFN_BUF=255 + MBED_CONF_FAT_CHAN_FF_SFN_BUF=12 + MBED_CONF_FAT_CHAN_FF_STRF_ENCODE=3 + MBED_CONF_FAT_CHAN_FF_FS_RPATH=1 + MBED_CONF_FAT_CHAN_FF_VOLUMES=4 + MBED_CONF_FAT_CHAN_FF_STR_VOLUME_ID=0 + MBED_CONF_FAT_CHAN_FF_VOLUME_STRS=\"RAM\",\"NAND\",\"CF\",\"SD\",\"SD2\",\"USB\",\"USB2\",\"USB3\" + MBED_CONF_FAT_CHAN_FF_MULTI_PARTITION=0 + MBED_CONF_FAT_CHAN_FF_MIN_SS=512 + MBED_CONF_FAT_CHAN_FF_MAX_SS=4096 + MBED_CONF_FAT_CHAN_FF_USE_TRIM=1 + MBED_CONF_FAT_CHAN_FF_FS_NOFSINFO=0 + MBED_CONF_FAT_CHAN_FF_FS_TINY=1 + MBED_CONF_FAT_CHAN_FF_FS_EXFAT=0 + MBED_CONF_FAT_CHAN_FF_FS_HEAPBUF=1 + MBED_CONF_FAT_CHAN_FF_FS_NORTC=0 + MBED_CONF_FAT_CHAN_FF_NORTC_MON=1 + MBED_CONF_FAT_CHAN_FF_NORTC_MDAY=1 + MBED_CONF_FAT_CHAN_FF_NORTC_YEAR=2017 + MBED_CONF_FAT_CHAN_FF_FS_LOCK=0 + MBED_CONF_FAT_CHAN_FF_FS_REENTRANT=0 + MBED_CONF_FAT_CHAN_FF_FS_TIMEOUT=1000 + MBED_CONF_FAT_CHAN_FF_SYNC_t=HANDLE + MBED_CONF_FAT_CHAN_FLUSH_ON_NEW_CLUSTER=0 + MBED_CONF_FAT_CHAN_FLUSH_ON_NEW_SECTOR=1 +) + +target_sources(${TEST_NAME} + PRIVATE + ${mbed-os_SOURCE_DIR}/storage/blockdevice/source/HeapBlockDevice.cpp + test.cpp +) + +target_link_libraries(${TEST_NAME} + PRIVATE + mbed-headers + mbed-stubs-platform + gmock_main +) + +add_test(NAME "${TEST_NAME}" COMMAND ${TEST_NAME}) + +set_tests_properties(${TEST_NAME} PROPERTIES LABELS "storage") diff --git a/storage/blockdevice/tests/UNITTESTS/blockdevice/MBRBlockDevice/CMakeLists.txt b/storage/blockdevice/tests/UNITTESTS/blockdevice/MBRBlockDevice/CMakeLists.txt new file mode 100644 index 0000000000..6a0fa5f8fa --- /dev/null +++ b/storage/blockdevice/tests/UNITTESTS/blockdevice/MBRBlockDevice/CMakeLists.txt @@ -0,0 +1,24 @@ +# Copyright (c) 2021 ARM Limited. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +set(TEST_NAME mbr-blockdevice-unittest) + +add_executable(${TEST_NAME}) + +target_sources(${TEST_NAME} + PRIVATE + ${mbed-os_SOURCE_DIR}/storage/blockdevice/source/MBRBlockDevice.cpp + test_MBRBlockDevice.cpp +) + +target_link_libraries(${TEST_NAME} + PRIVATE + mbed-headers + mbed-stubs-headers + mbed-stubs-platform + gmock_main +) + +add_test(NAME "${TEST_NAME}" COMMAND ${TEST_NAME}) + +set_tests_properties(${TEST_NAME} PROPERTIES LABELS "storage") diff --git a/storage/blockdevice/tests/UNITTESTS/blockdevice/MBRBlockDevice/test_MBRBlockDevice.cpp b/storage/blockdevice/tests/UNITTESTS/blockdevice/MBRBlockDevice/test_MBRBlockDevice.cpp index 663bb24990..c066aa127c 100644 --- a/storage/blockdevice/tests/UNITTESTS/blockdevice/MBRBlockDevice/test_MBRBlockDevice.cpp +++ b/storage/blockdevice/tests/UNITTESTS/blockdevice/MBRBlockDevice/test_MBRBlockDevice.cpp @@ -16,7 +16,7 @@ #include "gtest/gtest.h" #include "blockdevice/MBRBlockDevice.h" -#include "stubs/BlockDevice_mock.h" +#include "BlockDevice_mock.h" #define BLOCK_SIZE (512) #define PART_DESC_SIZE (16) diff --git a/storage/blockdevice/tests/UNITTESTS/blockdevice/ObservingBlockDevice/CMakeLists.txt b/storage/blockdevice/tests/UNITTESTS/blockdevice/ObservingBlockDevice/CMakeLists.txt new file mode 100644 index 0000000000..ab71b4e3f2 --- /dev/null +++ b/storage/blockdevice/tests/UNITTESTS/blockdevice/ObservingBlockDevice/CMakeLists.txt @@ -0,0 +1,25 @@ +# Copyright (c) 2021 ARM Limited. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +set(TEST_NAME observing-blockdevice-unittest) + +add_executable(${TEST_NAME}) + +target_sources(${TEST_NAME} + PRIVATE + ${mbed-os_SOURCE_DIR}/storage/blockdevice/source/ObservingBlockDevice.cpp + ${mbed-os_SOURCE_DIR}/storage/blockdevice/source/ReadOnlyBlockDevice.cpp + test_ObservingBlockDevice.cpp +) + +target_link_libraries(${TEST_NAME} + PRIVATE + mbed-headers + mbed-stubs-headers + mbed-stubs-platform + gmock_main +) + +add_test(NAME "${TEST_NAME}" COMMAND ${TEST_NAME}) + +set_tests_properties(${TEST_NAME} PROPERTIES LABELS "storage") diff --git a/storage/blockdevice/tests/UNITTESTS/blockdevice/ObservingBlockDevice/test_ObservingBlockDevice.cpp b/storage/blockdevice/tests/UNITTESTS/blockdevice/ObservingBlockDevice/test_ObservingBlockDevice.cpp index 860c808302..43dff8cf8a 100644 --- a/storage/blockdevice/tests/UNITTESTS/blockdevice/ObservingBlockDevice/test_ObservingBlockDevice.cpp +++ b/storage/blockdevice/tests/UNITTESTS/blockdevice/ObservingBlockDevice/test_ObservingBlockDevice.cpp @@ -17,7 +17,7 @@ #include "gtest/gtest.h" #include "blockdevice/ObservingBlockDevice.h" #include "blockdevice/ReadOnlyBlockDevice.h" -#include "stubs/BlockDevice_mock.h" +#include "BlockDevice_mock.h" using ::testing::_; using ::testing::Return; diff --git a/storage/blockdevice/tests/UNITTESTS/blockdevice/ProfilingBlockDevice/CMakeLists.txt b/storage/blockdevice/tests/UNITTESTS/blockdevice/ProfilingBlockDevice/CMakeLists.txt new file mode 100644 index 0000000000..9d60f63dd3 --- /dev/null +++ b/storage/blockdevice/tests/UNITTESTS/blockdevice/ProfilingBlockDevice/CMakeLists.txt @@ -0,0 +1,25 @@ +# Copyright (c) 2021 ARM Limited. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +set(TEST_NAME profiling-blockdevice-unittest) + +add_executable(${TEST_NAME}) + +target_sources(${TEST_NAME} + PRIVATE + ${mbed-os_SOURCE_DIR}/storage/blockdevice/source/ProfilingBlockDevice.cpp + ${mbed-os_SOURCE_DIR}/storage/blockdevice/source/HeapBlockDevice.cpp + test_ProfilingBlockDevice.cpp +) + +target_link_libraries(${TEST_NAME} + PRIVATE + mbed-headers + mbed-stubs-headers + mbed-stubs-platform + gmock_main +) + +add_test(NAME "${TEST_NAME}" COMMAND ${TEST_NAME}) + +set_tests_properties(${TEST_NAME} PROPERTIES LABELS "storage") diff --git a/storage/blockdevice/tests/UNITTESTS/blockdevice/ProfilingBlockDevice/test_ProfilingBlockDevice.cpp b/storage/blockdevice/tests/UNITTESTS/blockdevice/ProfilingBlockDevice/test_ProfilingBlockDevice.cpp index 883e50277d..4a1010e0bb 100644 --- a/storage/blockdevice/tests/UNITTESTS/blockdevice/ProfilingBlockDevice/test_ProfilingBlockDevice.cpp +++ b/storage/blockdevice/tests/UNITTESTS/blockdevice/ProfilingBlockDevice/test_ProfilingBlockDevice.cpp @@ -15,7 +15,7 @@ */ #include "gtest/gtest.h" -#include "stubs/BlockDevice_mock.h" +#include "BlockDevice_mock.h" #include "blockdevice/ProfilingBlockDevice.h" #define BLOCK_SIZE (512) diff --git a/storage/blockdevice/tests/UNITTESTS/blockdevice/ReadOnlyBlockDevice/CMakeLists.txt b/storage/blockdevice/tests/UNITTESTS/blockdevice/ReadOnlyBlockDevice/CMakeLists.txt new file mode 100644 index 0000000000..a8314edbe1 --- /dev/null +++ b/storage/blockdevice/tests/UNITTESTS/blockdevice/ReadOnlyBlockDevice/CMakeLists.txt @@ -0,0 +1,25 @@ +# Copyright (c) 2021 ARM Limited. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +set(TEST_NAME read-only-blockdevice-unittest) + +add_executable(${TEST_NAME}) + +target_sources(${TEST_NAME} + PRIVATE + ${mbed-os_SOURCE_DIR}/storage/blockdevice/source/ReadOnlyBlockDevice.cpp + ${mbed-os_SOURCE_DIR}/storage/blockdevice/source/HeapBlockDevice.cpp + test_ReadOnlyBlockDevice.cpp +) + +target_link_libraries(${TEST_NAME} + PRIVATE + mbed-headers + mbed-stubs-headers + mbed-stubs-platform + gmock_main +) + +add_test(NAME "${TEST_NAME}" COMMAND ${TEST_NAME}) + +set_tests_properties(${TEST_NAME} PROPERTIES LABELS "storage") diff --git a/storage/blockdevice/tests/UNITTESTS/blockdevice/ReadOnlyBlockDevice/test_ReadOnlyBlockDevice.cpp b/storage/blockdevice/tests/UNITTESTS/blockdevice/ReadOnlyBlockDevice/test_ReadOnlyBlockDevice.cpp index 1cde364abb..1523a951e7 100644 --- a/storage/blockdevice/tests/UNITTESTS/blockdevice/ReadOnlyBlockDevice/test_ReadOnlyBlockDevice.cpp +++ b/storage/blockdevice/tests/UNITTESTS/blockdevice/ReadOnlyBlockDevice/test_ReadOnlyBlockDevice.cpp @@ -15,7 +15,7 @@ */ #include "gtest/gtest.h" -#include "stubs/BlockDevice_mock.h" +#include "BlockDevice_mock.h" #include "blockdevice/ReadOnlyBlockDevice.h" #include "platform/mbed_error.h" diff --git a/storage/blockdevice/tests/UNITTESTS/blockdevice/SlicingBlockDevice/CMakeLists.txt b/storage/blockdevice/tests/UNITTESTS/blockdevice/SlicingBlockDevice/CMakeLists.txt new file mode 100644 index 0000000000..8d6e078392 --- /dev/null +++ b/storage/blockdevice/tests/UNITTESTS/blockdevice/SlicingBlockDevice/CMakeLists.txt @@ -0,0 +1,24 @@ +# Copyright (c) 2021 ARM Limited. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +set(TEST_NAME slicing-blockdevice-unittest) + +add_executable(${TEST_NAME}) + +target_sources(${TEST_NAME} + PRIVATE + ${mbed-os_SOURCE_DIR}/storage/blockdevice/source/SlicingBlockDevice.cpp + ${mbed-os_SOURCE_DIR}/storage/blockdevice/source/HeapBlockDevice.cpp + moduletest.cpp +) + +target_link_libraries(${TEST_NAME} + PRIVATE + mbed-headers + mbed-stubs-platform + gmock_main +) + +add_test(NAME "${TEST_NAME}" COMMAND ${TEST_NAME}) + +set_tests_properties(${TEST_NAME} PROPERTIES LABELS "storage") diff --git a/storage/filesystem/littlefs/include/littlefs/LittleFileSystem.h b/storage/filesystem/littlefs/include/littlefs/LittleFileSystem.h index 5cf5e71f45..c1e3a3c299 100644 --- a/storage/filesystem/littlefs/include/littlefs/LittleFileSystem.h +++ b/storage/filesystem/littlefs/include/littlefs/LittleFileSystem.h @@ -24,7 +24,7 @@ #include "filesystem/FileSystem.h" #include "blockdevice/BlockDevice.h" #include "platform/PlatformMutex.h" -#include "storage/filesystem/littlefs/littlefs/lfs.h" +#include "littlefs/lfs.h" namespace mbed { diff --git a/storage/filesystem/littlefs/source/LittleFileSystem.cpp b/storage/filesystem/littlefs/source/LittleFileSystem.cpp index 5f76a04861..752fa99aa5 100644 --- a/storage/filesystem/littlefs/source/LittleFileSystem.cpp +++ b/storage/filesystem/littlefs/source/LittleFileSystem.cpp @@ -17,8 +17,8 @@ #include "filesystem/mbed_filesystem.h" #include "littlefs/LittleFileSystem.h" #include "errno.h" -#include "storage/filesystem/littlefs/littlefs/lfs.h" -#include "storage/filesystem/littlefs/littlefs/lfs_util.h" +#include "littlefs/lfs.h" +#include "littlefs/lfs_util.h" #include "MbedCRC.h" namespace mbed { diff --git a/storage/kvstore/filesystemstore/CMakeLists.txt b/storage/kvstore/filesystemstore/CMakeLists.txt index 116a5abf2a..aeb8aef191 100644 --- a/storage/kvstore/filesystemstore/CMakeLists.txt +++ b/storage/kvstore/filesystemstore/CMakeLists.txt @@ -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() + target_include_directories(mbed-storage-filesystemstore INTERFACE . diff --git a/storage/kvstore/filesystemstore/tests/UNITTESTS/CMakeLists.txt b/storage/kvstore/filesystemstore/tests/UNITTESTS/CMakeLists.txt new file mode 100644 index 0000000000..d1af4569d2 --- /dev/null +++ b/storage/kvstore/filesystemstore/tests/UNITTESTS/CMakeLists.txt @@ -0,0 +1,4 @@ +# Copyright (c) 2021 ARM Limited. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +add_subdirectory(FileSystemStore) diff --git a/storage/kvstore/filesystemstore/tests/UNITTESTS/FileSystemStore/CMakeLists.txt b/storage/kvstore/filesystemstore/tests/UNITTESTS/FileSystemStore/CMakeLists.txt new file mode 100644 index 0000000000..bd120f19a5 --- /dev/null +++ b/storage/kvstore/filesystemstore/tests/UNITTESTS/FileSystemStore/CMakeLists.txt @@ -0,0 +1,43 @@ +# Copyright (c) 2021 ARM Limited. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +set(TEST_NAME filesystemstore-unittest) + +add_executable(${TEST_NAME}) + +target_compile_definitions(${TEST_NAME} + PRIVATE + UNITTEST + MBED_LFS_READ_SIZE=64 + MBED_LFS_PROG_SIZE=64 + MBED_LFS_BLOCK_SIZE=512 + MBED_LFS_LOOKAHEAD=512 +) + +target_sources(${TEST_NAME} + PRIVATE + ${mbed-os_SOURCE_DIR}/storage/blockdevice/source/HeapBlockDevice.cpp + ${mbed-os_SOURCE_DIR}/storage/kvstore/filesystemstore/source/FileSystemStore.cpp + ${mbed-os_SOURCE_DIR}/storage/filesystem/littlefs/source/LittleFileSystem.cpp + ${mbed-os_SOURCE_DIR}/storage/filesystem/source/Dir.cpp + ${mbed-os_SOURCE_DIR}/storage/filesystem/source/File.cpp + ${mbed-os_SOURCE_DIR}/storage/filesystem/source/FileSystem.cpp + ${mbed-os_SOURCE_DIR}/platform/mbed-trace/source/mbed_trace.c + ${mbed-os_SOURCE_DIR}/storage/filesystem/littlefs/littlefs/lfs.c + ${mbed-os_SOURCE_DIR}/platform/source/FileBase.cpp + ${mbed-os_SOURCE_DIR}/platform/source/FileSystemHandle.cpp + ${mbed-os_SOURCE_DIR}/platform/source/FileHandle.cpp + moduletest.cpp +) + +target_link_libraries(${TEST_NAME} + PRIVATE + mbed-headers + mbed-stubs-platform + mbed-stubs-storage + gmock_main +) + +add_test(NAME "${TEST_NAME}" COMMAND ${TEST_NAME}) + +set_tests_properties(${TEST_NAME} PROPERTIES LABELS "storage") diff --git a/storage/kvstore/tdbstore/CMakeLists.txt b/storage/kvstore/tdbstore/CMakeLists.txt index 38a992a488..a1cb048ad9 100644 --- a/storage/kvstore/tdbstore/CMakeLists.txt +++ b/storage/kvstore/tdbstore/CMakeLists.txt @@ -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() + target_include_directories(mbed-storage-tdbstore INTERFACE . diff --git a/storage/kvstore/tdbstore/tests/UNITTESTS/CMakeLists.txt b/storage/kvstore/tdbstore/tests/UNITTESTS/CMakeLists.txt new file mode 100644 index 0000000000..3c1fde3c16 --- /dev/null +++ b/storage/kvstore/tdbstore/tests/UNITTESTS/CMakeLists.txt @@ -0,0 +1,4 @@ +# Copyright (c) 2021 ARM Limited. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +add_subdirectory(TDBStore) diff --git a/storage/kvstore/tdbstore/tests/UNITTESTS/TDBStore/CMakeLists.txt b/storage/kvstore/tdbstore/tests/UNITTESTS/TDBStore/CMakeLists.txt new file mode 100644 index 0000000000..1c1606c41b --- /dev/null +++ b/storage/kvstore/tdbstore/tests/UNITTESTS/TDBStore/CMakeLists.txt @@ -0,0 +1,30 @@ +# Copyright (c) 2021 ARM Limited. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +set(TEST_NAME tdbstore-unittest) + +add_executable(${TEST_NAME}) + +target_compile_definitions(${TEST_NAME} + PRIVATE + UNITTEST +) + +target_sources(${TEST_NAME} + PRIVATE + ${mbed-os_SOURCE_DIR}/storage/blockdevice/source/HeapBlockDevice.cpp + ${mbed-os_SOURCE_DIR}/storage/blockdevice/source/BufferedBlockDevice.cpp + ${mbed-os_SOURCE_DIR}/storage/kvstore/tdbstore/source/TDBStore.cpp + moduletest.cpp +) + +target_link_libraries(${TEST_NAME} + PRIVATE + mbed-headers + mbed-stubs-platform + gmock_main +) + +add_test(NAME "${TEST_NAME}" COMMAND ${TEST_NAME}) + +set_tests_properties(${TEST_NAME} PROPERTIES LABELS "storage") diff --git a/targets/CMakeLists.txt b/targets/CMakeLists.txt index fce00d6fdb..36c9454e67 100644 --- a/targets/CMakeLists.txt +++ b/targets/CMakeLists.txt @@ -1,21 +1,23 @@ # Copyright (c) 2020-2021 ARM Limited. All rights reserved. # SPDX-License-Identifier: Apache-2.0 -include(mbed_set_linker_script) - -add_subdirectory(TARGET_Ambiq_Micro EXCLUDE_FROM_ALL) -add_subdirectory(TARGET_Analog_Devices EXCLUDE_FROM_ALL) -add_subdirectory(TARGET_ARM_FM EXCLUDE_FROM_ALL) -add_subdirectory(TARGET_ARM_SSG EXCLUDE_FROM_ALL) -add_subdirectory(TARGET_Cypress EXCLUDE_FROM_ALL) -add_subdirectory(TARGET_Freescale EXCLUDE_FROM_ALL) -add_subdirectory(TARGET_GigaDevice EXCLUDE_FROM_ALL) -add_subdirectory(TARGET_Maxim EXCLUDE_FROM_ALL) -add_subdirectory(TARGET_NORDIC EXCLUDE_FROM_ALL) -add_subdirectory(TARGET_NUVOTON EXCLUDE_FROM_ALL) -add_subdirectory(TARGET_NXP EXCLUDE_FROM_ALL) -add_subdirectory(TARGET_RENESAS EXCLUDE_FROM_ALL) -add_subdirectory(TARGET_Samsung EXCLUDE_FROM_ALL) -add_subdirectory(TARGET_Silicon_Labs EXCLUDE_FROM_ALL) -add_subdirectory(TARGET_STM EXCLUDE_FROM_ALL) -add_subdirectory(TARGET_TOSHIBA EXCLUDE_FROM_ALL) +if(${CMAKE_CROSSCOMPILING}) + include(mbed_set_linker_script) + + add_subdirectory(TARGET_Ambiq_Micro EXCLUDE_FROM_ALL) + add_subdirectory(TARGET_Analog_Devices EXCLUDE_FROM_ALL) + add_subdirectory(TARGET_ARM_FM EXCLUDE_FROM_ALL) + add_subdirectory(TARGET_ARM_SSG EXCLUDE_FROM_ALL) + add_subdirectory(TARGET_Cypress EXCLUDE_FROM_ALL) + add_subdirectory(TARGET_Freescale EXCLUDE_FROM_ALL) + add_subdirectory(TARGET_GigaDevice EXCLUDE_FROM_ALL) + add_subdirectory(TARGET_Maxim EXCLUDE_FROM_ALL) + add_subdirectory(TARGET_NORDIC EXCLUDE_FROM_ALL) + add_subdirectory(TARGET_NUVOTON EXCLUDE_FROM_ALL) + add_subdirectory(TARGET_NXP EXCLUDE_FROM_ALL) + add_subdirectory(TARGET_RENESAS EXCLUDE_FROM_ALL) + add_subdirectory(TARGET_Samsung EXCLUDE_FROM_ALL) + add_subdirectory(TARGET_Silicon_Labs EXCLUDE_FROM_ALL) + add_subdirectory(TARGET_STM EXCLUDE_FROM_ALL) + add_subdirectory(TARGET_TOSHIBA EXCLUDE_FROM_ALL) +endif()