diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 000000000000..9ab5d2c3d943 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,27 @@ +################################################################################# +## Copyright 2021 Pelion. +## +## SPDX-License-Identifier: Apache-2.0 +## +## Licensed under the Apache License, Version 2.0 (the "License"); +## you may not use this file except in compliance with the License. +## You may obtain a copy of the License at +## +## http://www.apache.org/licenses/LICENSE-2.0 +## +## Unless required by applicable law or agreed to in writing, software +## distributed under the License is distributed on an "AS IS" BASIS, +## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +## See the License for the specific language governing permissions and +## limitations under the License. +################################################################################# + +if(DEFINED MBED_TOOLCHAIN) + # Mbed OS target build + include(nanostack-libservice-mbed.cmake) +else() + cmake_minimum_required (VERSION 3.11) + project(nanostack-libservice) + include(nanostack-libservice.cmake) +endif() + diff --git a/nanostack-libservice-mbed.cmake b/nanostack-libservice-mbed.cmake new file mode 100644 index 000000000000..937cfa662da0 --- /dev/null +++ b/nanostack-libservice-mbed.cmake @@ -0,0 +1,54 @@ +################################################################################# +## Copyright 2020-2021 Pelion. +## +## SPDX-License-Identifier: Apache-2.0 +## +## Licensed under the Apache License, Version 2.0 (the "License"); +## you may not use this file except in compliance with the License. +## You may obtain a copy of the License at +## +## http://www.apache.org/licenses/LICENSE-2.0 +## +## Unless required by applicable law or agreed to in writing, software +## distributed under the License is distributed on an "AS IS" BASIS, +## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +## See the License for the specific language governing permissions and +## limitations under the License. +################################################################################# + +target_include_directories(mbed-nanostack-libservice + INTERFACE + . + ./mbed-client-libservice + ./mbed-client-libservice/platform +) + +target_sources(mbed-nanostack-libservice + INTERFACE + source/IPv6_fcf_lib/ip_fsc.c + source/libList/ns_list.c + source/libip4string/ip4tos.c + source/libip4string/stoip4.c + source/libip6string/stoip6.c + source/nsdynmemLIB/nsdynmemLIB.c + source/nsdynmemtracker/nsdynmem_tracker_lib.c + source/nvmHelper/ns_nvm_helper.c +) + +# The definition, source files and include directories below +# are needed by mbed-trace which is part of the mbed-core CMake target +target_compile_definitions(mbed-core + INTERFACE + MBED_CONF_NANOSTACK_LIBSERVICE_PRESENT=1 +) +target_include_directories(mbed-core + INTERFACE + . + ./mbed-client-libservice +) +target_sources(mbed-core + INTERFACE + source/libBits/common_functions.c + source/libip6string/ip6tos.c +) + diff --git a/nanostack-libservice.cmake b/nanostack-libservice.cmake new file mode 100644 index 000000000000..f4bf5b5c1410 --- /dev/null +++ b/nanostack-libservice.cmake @@ -0,0 +1,151 @@ +################################################################################# +## Copyright 2020-2021 Pelion. +## +## SPDX-License-Identifier: Apache-2.0 +## +## Licensed under the Apache License, Version 2.0 (the "License"); +## you may not use this file except in compliance with the License. +## You may obtain a copy of the License at +## +## http://www.apache.org/licenses/LICENSE-2.0 +## +## Unless required by applicable law or agreed to in writing, software +## distributed under the License is distributed on an "AS IS" BASIS, +## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +## See the License for the specific language governing permissions and +## limitations under the License. +################################################################################# + +cmake_minimum_required (VERSION 3.11) + +include(FindUnixCommands) + +project(nanostack-libservice) + +option(enable_coverage_data "Enable Coverage data" OFF) + +include(repositories.cmake) + +set(LS_SOURCES + source/IPv6_fcf_lib/ip_fsc.c + source/libBits/common_functions.c + source/libip6string/ip6tos.c + source/libip6string/stoip6.c + source/libList/ns_list.c + source/nsdynmemLIB/nsdynmemLIB.c + source/nsdynmemtracker/nsdynmem_tracker_lib.c + source/nvmHelper/ns_nvm_helper.c) + +add_library(nanostack-libservice + ${LS_SOURCES}) + +add_library(nanostack-libserviceInterface INTERFACE) +target_include_directories(nanostack-libserviceInterface INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/mbed-client-libservice) + +# some other projects include libservice stuff with path +target_include_directories(nanostack-libservice PUBLIC ${nanostack-libservice_SOURCE_DIR}) +target_include_directories(nanostack-libservice PUBLIC ${nanostack-libservice_SOURCE_DIR}/mbed-client-libservice) +target_include_directories(nanostack-libservice PUBLIC ${nanostack-libservice_SOURCE_DIR}/mbed-client-libservice/platform) + +if (test_all OR ${CMAKE_PROJECT_NAME} STREQUAL "nanostack-libservice") + # Tests after this line + enable_testing() + + if (enable_coverage_data) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --coverage") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage") + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --coverage") + endif () + + add_executable(ip6tos_test + source/libip6string/ip6tos.c + source/libBits/common_functions.c + test/ip6tos/ip6tos_test.cpp + ) + + add_test(ip6tos_test ip6tos_test) + + target_include_directories(ip6tos_test PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/mbed-client-libservice) + target_include_directories(ip6tos_test PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/mbed-client-libservice/platform) + + target_link_libraries( + ip6tos_test + gtest_main + ) + + include_directories(${CMAKE_CURRENT_SOURCE_DIR}/test/stubs) + + add_executable(stoip6_test + source/libip6string/stoip6.c + source/libBits/common_functions.c + test/stoip6/stoip6_test.cpp + ) + + add_test(stoip6_test stoip6_test) + + target_include_directories(stoip6_test PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/mbed-client-libservice) + target_include_directories(stoip6_test PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/mbed-client-libservice/platform) + + target_link_libraries( + stoip6_test + gtest_main + ) + + add_executable(dynmem_test + source/nsdynmemLIB/nsdynmemLIB.c + test/nsdynmem/dynmem_test.cpp + test/nsdynmem/error_callback.c + test/nsdynmem/error_callback.h + test/stubs/platform_critical.c + test/stubs/ns_list_stub.c + ) + + add_test(dynmem_test dynmem_test) + + target_include_directories(dynmem_test PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/mbed-client-libservice) + target_include_directories(dynmem_test PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/mbed-client-libservice/platform) + + target_link_libraries( + dynmem_test + gtest_main + ) + + add_executable(nsnvmhelper_test + source/nvmHelper/ns_nvm_helper.c + test/nsnvmhelper/nsnvmhelper_test.cpp + test/nsnvmhelper/test_ns_nvm_helper.c + test/nsnvmhelper/test_ns_nvm_helper.h + test/stubs/platform_nvm_stub.c + test/stubs/nsdynmemLIB_stub.c + test/stubs/ns_list_stub.c + ) + + target_include_directories(nsnvmhelper_test PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/mbed-client-libservice) + target_include_directories(nsnvmhelper_test PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/mbed-client-libservice/platform) + + target_link_libraries( + nsnvmhelper_test + gtest_main + ) + + # GTest framework requires C++ version 11 + set_target_properties(dynmem_test ip6tos_test stoip6_test nsnvmhelper_test + PROPERTIES + CXX_STANDARD 11 + ) + + include(GoogleTest) + gtest_discover_tests(ip6tos_test EXTRA_ARGS --gtest_output=xml: XML_OUTPUT_DIR ip6tos) + gtest_discover_tests(stoip6_test EXTRA_ARGS --gtest_output=xml: XML_OUTPUT_DIR stoip6) + gtest_discover_tests(dynmem_test EXTRA_ARGS --gtest_output=xml: XML_OUTPUT_DIR nsdynmem) + gtest_discover_tests(nsnvmhelper_test EXTRA_ARGS --gtest_output=xml: XML_OUTPUT_DIR nvmhelper) + + if (enable_coverage_data AND ${CMAKE_PROJECT_NAME} STREQUAL "nanostack-libservice") + file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/html") + + add_test(NAME ls_cov WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + COMMAND ${BASH} -c "gcovr -r . -e ${CMAKE_CURRENT_SOURCE_DIR}/build -e '.*test.*' --html --html-details -o build/html/coverity_index.html" + ) + endif () +endif() + diff --git a/repositories.cmake b/repositories.cmake new file mode 100644 index 000000000000..ae8d58196842 --- /dev/null +++ b/repositories.cmake @@ -0,0 +1,28 @@ +################################################################################# +## Copyright 2020-2021 Pelion. +## +## SPDX-License-Identifier: Apache-2.0 +## +## Licensed under the Apache License, Version 2.0 (the "License"); +## you may not use this file except in compliance with the License. +## You may obtain a copy of the License at +## +## http://www.apache.org/licenses/LICENSE-2.0 +## +## Unless required by applicable law or agreed to in writing, software +## distributed under the License is distributed on an "AS IS" BASIS, +## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +## See the License for the specific language governing permissions and +## limitations under the License. +################################################################################# + +#Googletest for testing +include(FetchContent) +FetchContent_Declare( + googletest + URL https://github.com/google/googletest/archive/refs/tags/v1.10.x.zip +) + +# For Windows: Prevent overriding the parent project's compiler/linker settings +set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) +FetchContent_MakeAvailable(googletest) diff --git a/run_unit_tests.sh b/run_unit_tests.sh new file mode 100755 index 000000000000..ab36c7d251a2 --- /dev/null +++ b/run_unit_tests.sh @@ -0,0 +1,30 @@ +#!/bin/bash +# +################################################################################# +## Copyright (c) 2021 Pelion. All rights reserved. +## +## SPDX-License-Identifier: Apache-2.0 +## +## Licensed under the Apache License, Version 2.0 (the "License"); +## you may not use this file except in compliance with the License. +## You may obtain a copy of the License at +## +## http://www.apache.org/licenses/LICENSE-2.0 +## +## Unless required by applicable law or agreed to in writing, software +## distributed under the License is distributed on an "AS IS" BASIS, +## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +## See the License for the specific language governing permissions and +## limitations under the License. +################################################################################# +# +# +# Run unit tests and produce *.xml output to build folder. +# + +TEST_DIR="build" + +mkdir -p ${TEST_DIR} +cd ${TEST_DIR} +cmake .. -DCMAKE_BUILD_TYPE=Debug -Denable_coverage_data=ON -Dtest_all=ON +make all test diff --git a/test/README.md b/test/README.md new file mode 100644 index 000000000000..eb3ceb468b50 --- /dev/null +++ b/test/README.md @@ -0,0 +1,48 @@ +# Unit tests + +You can run unit tests with script `run_unit_tests.sh`. + +The unit tests are implemented with GoogleTest (gtest) C++ test framework. + +## Prerequisites + +If you need to generate code coverage report, install `gcovr` tool: + +``` +pip install gcovr + +or... + +sudo apt-get install gcovr +``` + +## Building and running + +Prepare unit test build with `cmake ..` and then run the test with `make all test` as follows: + +``` +# clone repository if needed +git clone nanostack-libservice +cd nanostack-libservice +mkdir build +cd build +cmake .. + +make all test +``` + +### Code coverage + +Code coverage is optional feature and it is disabled by default. +To enable code coverage use the following command to build the tests: +``` +cmake .. -Denable_coverage_data=ON +``` + +### Debugging + +You can add mode debug information to the build by adding a `-DCMAKE_BUILD_TYPE=Debug` to the build command, like: +``` +cmake .. -Denable_coverage_data=ON -DCMAKE_BUILD_TYPE=Debug +``` +And then debug the generated executable with a debugger like `Visual code`, `gdb`, `Eclipse`. diff --git a/test/libService/unittest/ip6tos/ip6tos_test.cpp b/test/ip6tos/ip6tos_test.cpp similarity index 60% rename from test/libService/unittest/ip6tos/ip6tos_test.cpp rename to test/ip6tos/ip6tos_test.cpp index 2b1164912012..b89ad2dc9039 100644 --- a/test/libService/unittest/ip6tos/ip6tos_test.cpp +++ b/test/ip6tos/ip6tos_test.cpp @@ -14,52 +14,60 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include "CppUTest/TestHarness.h" +#include "gtest/gtest.h" #include "ip6string.h" #include #include #include -TEST_GROUP(ip6tos) -{ - void setup() { + +class ip6tos_test : public testing::Test { +protected: + void SetUp(void) + { + memset(buf, 0, 40); } - void teardown() { + void TearDown(void) + { + i++; } + + char buf[40]; + int i = 0; }; -TEST(ip6tos, ip6_prefix_tos_func) +TEST_F(ip6tos_test, ip6_prefix_tos_func) { char prefix_str[45] = {0}; char str_len = 0; - char *expected; + const char *expected; uint8_t prefix[] = { 0x14, 0x6e, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00 }; int prefix_len = 64; expected = "146e:a00::/64"; str_len = ip6_prefix_tos(prefix, prefix_len, prefix_str); - CHECK(str_len == 13); - STRCMP_EQUAL(expected, prefix_str); + ASSERT_EQ(str_len, 13); + ASSERT_STREQ(expected, prefix_str); memset(prefix_str, 0, 45); str_len = 0; expected = "::/0"; str_len = ip6_prefix_tos(NULL, 0, prefix_str); - CHECK(str_len == 4); - STRCMP_EQUAL(expected, prefix_str); + ASSERT_EQ(str_len, 4); + ASSERT_STREQ(expected, prefix_str); str_len = 0; uint8_t prefix_2[16]; memset(prefix_2, 0x88, 16); expected = "8888:8888:8888:8888:8888:8888:8888:8888/128"; str_len = ip6_prefix_tos(prefix_2, 128, prefix_str); - CHECK(str_len == 43); - STRCMP_EQUAL(expected, prefix_str); + ASSERT_EQ(str_len, 43); + ASSERT_STREQ(expected, prefix_str); memset(prefix_str, 0, 45); str_len = ip6_prefix_tos(prefix, 130, prefix_str); - CHECK(str_len == 0); + ASSERT_EQ(str_len, 0); } /***********************************************************/ @@ -96,78 +104,65 @@ const uint8_t hex_addr[][16] = { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, }; -char buf[40]; -int i = 0; - -TEST_GROUP(ip6tos_2) -{ - void setUp(void) { - memset(buf, 0, 40); - } - - void tearDown(void) { - i++; - } -}; -TEST(ip6tos_2, test_1) +TEST_F(ip6tos_test, test_1) { - CHECK(strlen(string_addr[i]) == ip6tos(hex_addr[i], buf)); - STRCMP_EQUAL(string_addr[i], buf); + ASSERT_EQ(strlen(string_addr[i]), ip6tos(hex_addr[i], buf)); + ASSERT_STREQ(string_addr[i], buf); } -TEST(ip6tos_2, test_2) +TEST_F(ip6tos_test, test_2) { - CHECK(strlen(string_addr[i]) == ip6tos(hex_addr[i], buf)); - STRCMP_EQUAL(string_addr[i], buf); + ASSERT_EQ(strlen(string_addr[i]), ip6tos(hex_addr[i], buf)); + ASSERT_STREQ(string_addr[i], buf); } -TEST(ip6tos_2, test_3) +TEST_F(ip6tos_test, test_3) { - CHECK(strlen(string_addr[i]) == ip6tos(hex_addr[i], buf)); - STRCMP_EQUAL(string_addr[i], buf); + ASSERT_EQ(strlen(string_addr[i]), ip6tos(hex_addr[i], buf)); + ASSERT_STREQ(string_addr[i], buf); } -TEST(ip6tos_2, test_4) +TEST_F(ip6tos_test, test_4) { - CHECK(strlen(string_addr[i]) == ip6tos(hex_addr[i], buf)); - STRCMP_EQUAL(string_addr[i], buf); + ASSERT_EQ(strlen(string_addr[i]), ip6tos(hex_addr[i], buf)); + ASSERT_STREQ(string_addr[i], buf); } -TEST(ip6tos_2, test_5) +TEST_F(ip6tos_test, test_5) { - CHECK(strlen(string_addr[i]) == ip6tos(hex_addr[i], buf)); - STRCMP_EQUAL(string_addr[i], buf); + ASSERT_EQ(strlen(string_addr[i]), ip6tos(hex_addr[i], buf)); + ASSERT_STREQ(string_addr[i], buf); } -TEST(ip6tos_2, test_6) +TEST_F(ip6tos_test, test_6) { - CHECK(strlen(string_addr[i]) == ip6tos(hex_addr[i], buf)); - STRCMP_EQUAL(string_addr[i], buf); + ASSERT_EQ(strlen(string_addr[i]), ip6tos(hex_addr[i], buf)); + ASSERT_STREQ(string_addr[i], buf); } -TEST(ip6tos_2, test_7) +TEST_F(ip6tos_test, test_7) { - CHECK(strlen(string_addr[i]) == ip6tos(hex_addr[i], buf)); - STRCMP_EQUAL(string_addr[i], buf); + ASSERT_EQ(strlen(string_addr[i]), ip6tos(hex_addr[i], buf)); + ASSERT_STREQ(string_addr[i], buf); } -TEST(ip6tos_2, test_8) +TEST_F(ip6tos_test, test_8) { - CHECK(strlen(string_addr[i]) == ip6tos(hex_addr[i], buf)); - STRCMP_EQUAL(string_addr[i], buf); + ASSERT_EQ(strlen(string_addr[i]), ip6tos(hex_addr[i], buf)); + ASSERT_STREQ(string_addr[i], buf); } -TEST(ip6tos_2, test_9) +TEST_F(ip6tos_test, test_9) { - CHECK(strlen(string_addr[i]) == ip6tos(hex_addr[i], buf)); - STRCMP_EQUAL(string_addr[i], buf); + ASSERT_EQ(strlen(string_addr[i]), ip6tos(hex_addr[i], buf)); + ASSERT_STREQ(string_addr[i], buf); } -TEST(ip6tos_2, test_10) +TEST_F(ip6tos_test, test_10) { - CHECK(strlen(string_addr[i]) == ip6tos(hex_addr[i], buf)); - STRCMP_EQUAL(string_addr[i], buf); + ASSERT_EQ(strlen(string_addr[i]), ip6tos(hex_addr[i], buf)); + ASSERT_STREQ(string_addr[i], buf); } -TEST(ip6tos_2, test_11) +TEST_F(ip6tos_test, test_11) { - CHECK(strlen(string_addr[i]) == ip6tos(hex_addr[i], buf)); - STRCMP_EQUAL(string_addr[i], buf); + ASSERT_EQ(strlen(string_addr[i]), ip6tos(hex_addr[i], buf)); + ASSERT_STREQ(string_addr[i], buf); } -TEST(ip6tos_2, test_12) +TEST_F(ip6tos_test, test_12) { - CHECK(strlen(string_addr[i]) == ip6tos(hex_addr[i], buf)); - STRCMP_EQUAL(string_addr[i], buf); + ASSERT_EQ(strlen(string_addr[i]), ip6tos(hex_addr[i], buf)); + ASSERT_STREQ(string_addr[i], buf); } diff --git a/test/libService/unittest/.gitignore b/test/libService/unittest/.gitignore deleted file mode 100644 index d68368ff6d14..000000000000 --- a/test/libService/unittest/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -coverages/* -*/gcov/* -results/* -*.xml -*/*_unit_tests -*/*_unit_tests.txt -*/lib -*/objs diff --git a/test/libService/unittest/Makefile b/test/libService/unittest/Makefile deleted file mode 100755 index b353517548f1..000000000000 --- a/test/libService/unittest/Makefile +++ /dev/null @@ -1,23 +0,0 @@ -#scan for folders having "Makefile" in them and remove 'this' to prevent loop -ifeq ($(OS),Windows_NT) -all: -clean: -else -DIRS := $(filter-out ./, $(sort $(dir $(shell find . -name 'Makefile')))) - -all: - for dir in $(DIRS); do \ - cd $$dir; make gcov; cd ..;\ - done - -clean: - for dir in $(DIRS); do \ - cd $$dir; make clean; cd ..;\ - done - rm -rf ../source/*gcov ../source/*gcda ../source/*o - rm -rf stubs/*gcov stubs/*gcda stubs/*o - rm -rf results/* - rm -rf coverages/* - rm -rf results - rm -rf coverages -endif diff --git a/test/libService/unittest/MakefileWorker.mk b/test/libService/unittest/MakefileWorker.mk deleted file mode 100755 index 2096ced03670..000000000000 --- a/test/libService/unittest/MakefileWorker.mk +++ /dev/null @@ -1,562 +0,0 @@ -#--------- -# -# MakefileWorker.mk -# -# Include this helper file in your makefile -# It makes -# A static library -# A test executable -# -# See this example for parameter settings -# examples/Makefile -# -#---------- -# Inputs - these variables describe what to build -# -# INCLUDE_DIRS - Directories used to search for include files. -# This generates a -I for each directory -# SRC_DIRS - Directories containing source file to built into the library -# SRC_FILES - Specific source files to build into library. Helpful when not all code -# in a directory can be built for test (hopefully a temporary situation) -# TEST_SRC_DIRS - Directories containing unit test code build into the unit test runner -# These do not go in a library. They are explicitly included in the test runner -# TEST_SRC_FILES - Specific source files to build into the unit test runner -# These do not go in a library. They are explicitly included in the test runner -# MOCKS_SRC_DIRS - Directories containing mock source files to build into the test runner -# These do not go in a library. They are explicitly included in the test runner -#---------- -# You can adjust these variables to influence how to build the test target -# and where to put and name outputs -# See below to determine defaults -# COMPONENT_NAME - the name of the thing being built -# TEST_TARGET - name the test executable. By default it is -# $(COMPONENT_NAME)_tests -# Helpful if you want 1 > make files in the same directory with different -# executables as output. -# CPPUTEST_HOME - where CppUTest home dir found -# TARGET_PLATFORM - Influences how the outputs are generated by modifying the -# CPPUTEST_OBJS_DIR and CPPUTEST_LIB_DIR to use a sub-directory under the -# normal objs and lib directories. Also modifies where to search for the -# CPPUTEST_LIB to link against. -# CPPUTEST_OBJS_DIR - a directory where o and d files go -# CPPUTEST_LIB_DIR - a directory where libs go -# CPPUTEST_ENABLE_DEBUG - build for debug -# CPPUTEST_USE_MEM_LEAK_DETECTION - Links with overridden new and delete -# CPPUTEST_USE_STD_CPP_LIB - Set to N to keep the standard C++ library out -# of the test harness -# CPPUTEST_USE_GCOV - Turn on coverage analysis -# Clean then build with this flag set to Y, then 'make gcov' -# CPPUTEST_MAPFILE - generate a map file -# CPPUTEST_WARNINGFLAGS - overly picky by default -# OTHER_MAKEFILE_TO_INCLUDE - a hook to use this makefile to make -# other targets. Like CSlim, which is part of fitnesse -# CPPUTEST_USE_VPATH - Use Make's VPATH functionality to support user -# specification of source files and directories that aren't below -# the user's Makefile in the directory tree, like: -# SRC_DIRS += ../../lib/foo -# It defaults to N, and shouldn't be necessary except in the above case. -#---------- -# -# Other flags users can initialize to sneak in their settings -# CPPUTEST_CXXFLAGS - flags for the C++ compiler -# CPPUTEST_CPPFLAGS - flags for the C++ AND C preprocessor -# CPPUTEST_CFLAGS - flags for the C complier -# CPPUTEST_LDFLAGS - Linker flags -#---------- - -# Some behavior is weird on some platforms. Need to discover the platform. - -# Platforms -UNAME_OUTPUT = "$(shell uname -a)" -MACOSX_STR = Darwin -MINGW_STR = MINGW -CYGWIN_STR = CYGWIN -LINUX_STR = Linux -SUNOS_STR = SunOS -UNKNWOWN_OS_STR = Unknown - -# Compilers -CC_VERSION_OUTPUT ="$(shell $(CXX) -v 2>&1)" -CLANG_STR = clang -SUNSTUDIO_CXX_STR = SunStudio - -UNAME_OS = $(UNKNWOWN_OS_STR) - -ifeq ($(findstring $(MINGW_STR),$(UNAME_OUTPUT)),$(MINGW_STR)) - UNAME_OS = $(MINGW_STR) -endif - -ifeq ($(findstring $(CYGWIN_STR),$(UNAME_OUTPUT)),$(CYGWIN_STR)) - UNAME_OS = $(CYGWIN_STR) -endif - -ifeq ($(findstring $(LINUX_STR),$(UNAME_OUTPUT)),$(LINUX_STR)) - UNAME_OS = $(LINUX_STR) -endif - -ifeq ($(findstring $(MACOSX_STR),$(UNAME_OUTPUT)),$(MACOSX_STR)) - UNAME_OS = $(MACOSX_STR) -#lion has a problem with the 'v' part of -a - UNAME_OUTPUT = "$(shell uname -pmnrs)" -endif - -ifeq ($(findstring $(SUNOS_STR),$(UNAME_OUTPUT)),$(SUNOS_STR)) - UNAME_OS = $(SUNOS_STR) - - SUNSTUDIO_CXX_ERR_STR = CC -flags -ifeq ($(findstring $(SUNSTUDIO_CXX_ERR_STR),$(CC_VERSION_OUTPUT)),$(SUNSTUDIO_CXX_ERR_STR)) - CC_VERSION_OUTPUT ="$(shell $(CXX) -V 2>&1)" - COMPILER_NAME = $(SUNSTUDIO_CXX_STR) -endif -endif - -ifeq ($(findstring $(CLANG_STR),$(CC_VERSION_OUTPUT)),$(CLANG_STR)) - COMPILER_NAME = $(CLANG_STR) -endif - -#Kludge for mingw, it does not have cc.exe, but gcc.exe will do -ifeq ($(UNAME_OS),$(MINGW_STR)) - CC := gcc -endif - -#And another kludge. Exception handling in gcc 4.6.2 is broken when linking the -# Standard C++ library as a shared library. Unbelievable. -ifeq ($(UNAME_OS),$(MINGW_STR)) - CPPUTEST_LDFLAGS += -static -endif -ifeq ($(UNAME_OS),$(CYGWIN_STR)) - CPPUTEST_LDFLAGS += -static -endif - - -#Kludge for MacOsX gcc compiler on Darwin9 who can't handle pendantic -ifeq ($(UNAME_OS),$(MACOSX_STR)) -ifeq ($(findstring Version 9,$(UNAME_OUTPUT)),Version 9) - CPPUTEST_PEDANTIC_ERRORS = N -endif -endif - -ifndef COMPONENT_NAME - COMPONENT_NAME = name_this_in_the_makefile -endif - -# Debug on by default -ifndef CPPUTEST_ENABLE_DEBUG - CPPUTEST_ENABLE_DEBUG = Y -endif - -# new and delete for memory leak detection on by default -ifndef CPPUTEST_USE_MEM_LEAK_DETECTION - CPPUTEST_USE_MEM_LEAK_DETECTION = Y -endif - -# Use the standard C library -ifndef CPPUTEST_USE_STD_C_LIB - CPPUTEST_USE_STD_C_LIB = Y -endif - -# Use the standard C++ library -ifndef CPPUTEST_USE_STD_CPP_LIB - CPPUTEST_USE_STD_CPP_LIB = Y -endif - -# Use gcov, off by default -ifndef CPPUTEST_USE_GCOV - CPPUTEST_USE_GCOV = N -endif - -ifndef CPPUTEST_PEDANTIC_ERRORS - CPPUTEST_PEDANTIC_ERRORS = Y -endif - -# Default warnings -ifndef CPPUTEST_WARNINGFLAGS - CPPUTEST_WARNINGFLAGS = -Wall -Wextra -Wshadow -Wswitch-default -Wswitch-enum -Wconversion -ifeq ($(CPPUTEST_PEDANTIC_ERRORS), Y) -# CPPUTEST_WARNINGFLAGS += -pedantic-errors - CPPUTEST_WARNINGFLAGS += -pedantic -endif -ifeq ($(UNAME_OS),$(LINUX_STR)) - CPPUTEST_WARNINGFLAGS += -Wsign-conversion -endif - CPPUTEST_CXX_WARNINGFLAGS = -Woverloaded-virtual - CPPUTEST_C_WARNINGFLAGS = -Wstrict-prototypes -endif - -#Wonderful extra compiler warnings with clang -ifeq ($(COMPILER_NAME),$(CLANG_STR)) -# -Wno-disabled-macro-expansion -> Have to disable the macro expansion warning as the operator new overload warns on that. -# -Wno-padded -> I sort-of like this warning but if there is a bool at the end of the class, it seems impossible to remove it! (except by making padding explicit) -# -Wno-global-constructors Wno-exit-time-destructors -> Great warnings, but in CppUTest it is impossible to avoid as the automatic test registration depends on the global ctor and dtor -# -Wno-weak-vtables -> The TEST_GROUP macro declares a class and will automatically inline its methods. Thats ok as they are only in one translation unit. Unfortunately, the warning can't detect that, so it must be disabled. - CPPUTEST_CXX_WARNINGFLAGS += -Weverything -Wno-disabled-macro-expansion -Wno-padded -Wno-global-constructors -Wno-exit-time-destructors -Wno-weak-vtables - CPPUTEST_C_WARNINGFLAGS += -Weverything -Wno-padded -endif - -# Uhm. Maybe put some warning flags for SunStudio here? -ifeq ($(COMPILER_NAME),$(SUNSTUDIO_CXX_STR)) - CPPUTEST_CXX_WARNINGFLAGS = - CPPUTEST_C_WARNINGFLAGS = -endif - -# Default dir for temporary files (d, o) -ifndef CPPUTEST_OBJS_DIR -ifndef TARGET_PLATFORM - CPPUTEST_OBJS_DIR = objs -else - CPPUTEST_OBJS_DIR = objs/$(TARGET_PLATFORM) -endif -endif - -# Default dir for the outout library -ifndef CPPUTEST_LIB_DIR -ifndef TARGET_PLATFORM - CPPUTEST_LIB_DIR = lib -else - CPPUTEST_LIB_DIR = lib/$(TARGET_PLATFORM) -endif -endif - -# No map by default -ifndef CPPUTEST_MAP_FILE - CPPUTEST_MAP_FILE = N -endif - -# No extentions is default -ifndef CPPUTEST_USE_EXTENSIONS - CPPUTEST_USE_EXTENSIONS = N -endif - -# No VPATH is default -ifndef CPPUTEST_USE_VPATH - CPPUTEST_USE_VPATH := N -endif -# Make empty, instead of 'N', for usage in $(if ) conditionals -ifneq ($(CPPUTEST_USE_VPATH), Y) - CPPUTEST_USE_VPATH := -endif - -ifndef TARGET_PLATFORM -#CPPUTEST_LIB_LINK_DIR = $(CPPUTEST_HOME)/lib -CPPUTEST_LIB_LINK_DIR = /usr/lib/x86_64-linux-gnu -else -CPPUTEST_LIB_LINK_DIR = $(CPPUTEST_HOME)/lib/$(TARGET_PLATFORM) -endif - -# -------------------------------------- -# derived flags in the following area -# -------------------------------------- - -# Without the C library, we'll need to disable the C++ library and ... -ifeq ($(CPPUTEST_USE_STD_C_LIB), N) - CPPUTEST_USE_STD_CPP_LIB = N - CPPUTEST_USE_MEM_LEAK_DETECTION = N - CPPUTEST_CPPFLAGS += -DCPPUTEST_STD_C_LIB_DISABLED - CPPUTEST_CPPFLAGS += -nostdinc -endif - -CPPUTEST_CPPFLAGS += -DCPPUTEST_COMPILATION - -ifeq ($(CPPUTEST_USE_MEM_LEAK_DETECTION), N) - CPPUTEST_CPPFLAGS += -DCPPUTEST_MEM_LEAK_DETECTION_DISABLED -else - ifndef CPPUTEST_MEMLEAK_DETECTOR_NEW_MACRO_FILE - CPPUTEST_MEMLEAK_DETECTOR_NEW_MACRO_FILE = -include $(CPPUTEST_HOME)/include/CppUTest/MemoryLeakDetectorNewMacros.h - endif - ifndef CPPUTEST_MEMLEAK_DETECTOR_MALLOC_MACRO_FILE - CPPUTEST_MEMLEAK_DETECTOR_MALLOC_MACRO_FILE = -include $(CPPUTEST_HOME)/include/CppUTest/MemoryLeakDetectorMallocMacros.h - endif -endif - -ifeq ($(CPPUTEST_ENABLE_DEBUG), Y) - CPPUTEST_CXXFLAGS += -g - CPPUTEST_CFLAGS += -g - CPPUTEST_LDFLAGS += -g -endif - -ifeq ($(CPPUTEST_USE_STD_CPP_LIB), N) - CPPUTEST_CPPFLAGS += -DCPPUTEST_STD_CPP_LIB_DISABLED -ifeq ($(CPPUTEST_USE_STD_C_LIB), Y) - CPPUTEST_CXXFLAGS += -nostdinc++ -endif -endif - -ifdef $(GMOCK_HOME) - GTEST_HOME = $(GMOCK_HOME)/gtest - CPPUTEST_CPPFLAGS += -I$(GMOCK_HOME)/include - GMOCK_LIBRARY = $(GMOCK_HOME)/lib/.libs/libgmock.a - LD_LIBRARIES += $(GMOCK_LIBRARY) - CPPUTEST_CPPFLAGS += -DINCLUDE_GTEST_TESTS - CPPUTEST_WARNINGFLAGS = - CPPUTEST_CPPFLAGS += -I$(GTEST_HOME)/include -I$(GTEST_HOME) - GTEST_LIBRARY = $(GTEST_HOME)/lib/.libs/libgtest.a - LD_LIBRARIES += $(GTEST_LIBRARY) -endif - - -ifeq ($(CPPUTEST_USE_GCOV), Y) - CPPUTEST_CXXFLAGS += -fprofile-arcs -ftest-coverage - CPPUTEST_CFLAGS += -fprofile-arcs -ftest-coverage -endif - -CPPUTEST_CXXFLAGS += $(CPPUTEST_WARNINGFLAGS) $(CPPUTEST_CXX_WARNINGFLAGS) -CPPUTEST_CPPFLAGS += $(CPPUTEST_WARNINGFLAGS) -CPPUTEST_CXXFLAGS += $(CPPUTEST_MEMLEAK_DETECTOR_NEW_MACRO_FILE) -CPPUTEST_CPPFLAGS += $(CPPUTEST_MEMLEAK_DETECTOR_MALLOC_MACRO_FILE) -CPPUTEST_CFLAGS += $(CPPUTEST_C_WARNINGFLAGS) - -TARGET_MAP = $(COMPONENT_NAME).map.txt -ifeq ($(CPPUTEST_MAP_FILE), Y) - CPPUTEST_LDFLAGS += -Wl,-map,$(TARGET_MAP) -endif - -# Link with CppUTest lib -CPPUTEST_LIB = $(CPPUTEST_LIB_LINK_DIR)/libCppUTest.a - -ifeq ($(CPPUTEST_USE_EXTENSIONS), Y) -CPPUTEST_LIB += $(CPPUTEST_LIB_LINK_DIR)/libCppUTestExt.a -endif - -ifdef CPPUTEST_STATIC_REALTIME - LD_LIBRARIES += -lrt -endif - -TARGET_LIB = \ - $(CPPUTEST_LIB_DIR)/lib$(COMPONENT_NAME).a - -ifndef TEST_TARGET - ifndef TARGET_PLATFORM - TEST_TARGET = $(COMPONENT_NAME)_tests - else - TEST_TARGET = $(COMPONENT_NAME)_$(TARGET_PLATFORM)_tests - endif -endif - -#Helper Functions -get_src_from_dir = $(wildcard $1/*.cpp) $(wildcard $1/*.cc) $(wildcard $1/*.c) -get_dirs_from_dirspec = $(wildcard $1) -get_src_from_dir_list = $(foreach dir, $1, $(call get_src_from_dir,$(dir))) -__src_to = $(subst .c,$1, $(subst .cc,$1, $(subst .cpp,$1,$(if $(CPPUTEST_USE_VPATH),$(notdir $2),$2)))) -src_to = $(addprefix $(CPPUTEST_OBJS_DIR)/,$(call __src_to,$1,$2)) -src_to_o = $(call src_to,.o,$1) -src_to_d = $(call src_to,.d,$1) -src_to_gcda = $(call src_to,.gcda,$1) -src_to_gcno = $(call src_to,.gcno,$1) -time = $(shell date +%s) -delta_t = $(eval minus, $1, $2) -debug_print_list = $(foreach word,$1,echo " $(word)";) echo; - -#Derived -STUFF_TO_CLEAN += $(TEST_TARGET) $(TEST_TARGET).exe $(TARGET_LIB) $(TARGET_MAP) - -SRC += $(call get_src_from_dir_list, $(SRC_DIRS)) $(SRC_FILES) -OBJ = $(call src_to_o,$(SRC)) - -STUFF_TO_CLEAN += $(OBJ) - -TEST_SRC += $(call get_src_from_dir_list, $(TEST_SRC_DIRS)) $(TEST_SRC_FILES) -TEST_OBJS = $(call src_to_o,$(TEST_SRC)) -STUFF_TO_CLEAN += $(TEST_OBJS) - - -MOCKS_SRC += $(call get_src_from_dir_list, $(MOCKS_SRC_DIRS)) -MOCKS_OBJS = $(call src_to_o,$(MOCKS_SRC)) -STUFF_TO_CLEAN += $(MOCKS_OBJS) - -ALL_SRC = $(SRC) $(TEST_SRC) $(MOCKS_SRC) - -# If we're using VPATH -ifeq ($(CPPUTEST_USE_VPATH), Y) -# gather all the source directories and add them - VPATH += $(sort $(dir $(ALL_SRC))) -# Add the component name to the objs dir path, to differentiate between same-name objects - CPPUTEST_OBJS_DIR := $(addsuffix /$(COMPONENT_NAME),$(CPPUTEST_OBJS_DIR)) -endif - -#Test coverage with gcov -GCOV_OUTPUT = gcov_output.txt -GCOV_REPORT = gcov_report.txt -GCOV_ERROR = gcov_error.txt -GCOV_GCDA_FILES = $(call src_to_gcda, $(ALL_SRC)) -GCOV_GCNO_FILES = $(call src_to_gcno, $(ALL_SRC)) -TEST_OUTPUT = $(TEST_TARGET).txt -STUFF_TO_CLEAN += \ - $(GCOV_OUTPUT)\ - $(GCOV_REPORT)\ - $(GCOV_REPORT).html\ - $(GCOV_ERROR)\ - $(GCOV_GCDA_FILES)\ - $(GCOV_GCNO_FILES)\ - $(TEST_OUTPUT) - -#The gcda files for gcov need to be deleted before each run -#To avoid annoying messages. -GCOV_CLEAN = $(SILENCE)rm -f $(GCOV_GCDA_FILES) $(GCOV_OUTPUT) $(GCOV_REPORT) $(GCOV_ERROR) -RUN_TEST_TARGET = $(SILENCE) $(GCOV_CLEAN) ; echo "Running $(TEST_TARGET)"; ./$(TEST_TARGET) $(CPPUTEST_EXE_FLAGS) -ojunit - -ifeq ($(CPPUTEST_USE_GCOV), Y) - - ifeq ($(COMPILER_NAME),$(CLANG_STR)) - LD_LIBRARIES += --coverage - else - LD_LIBRARIES += -lgcov - endif -endif - - -INCLUDES_DIRS_EXPANDED = $(call get_dirs_from_dirspec, $(INCLUDE_DIRS)) -INCLUDES += $(foreach dir, $(INCLUDES_DIRS_EXPANDED), -I$(dir)) -MOCK_DIRS_EXPANDED = $(call get_dirs_from_dirspec, $(MOCKS_SRC_DIRS)) -INCLUDES += $(foreach dir, $(MOCK_DIRS_EXPANDED), -I$(dir)) - -CPPUTEST_CPPFLAGS += $(INCLUDES) $(CPPUTESTFLAGS) - -DEP_FILES = $(call src_to_d, $(ALL_SRC)) -STUFF_TO_CLEAN += $(DEP_FILES) $(PRODUCTION_CODE_START) $(PRODUCTION_CODE_END) -STUFF_TO_CLEAN += $(STDLIB_CODE_START) $(MAP_FILE) cpputest_*.xml junit_run_output - -# We'll use the CPPUTEST_CFLAGS etc so that you can override AND add to the CppUTest flags -CFLAGS = $(CPPUTEST_CFLAGS) $(CPPUTEST_ADDITIONAL_CFLAGS) -CPPFLAGS = $(CPPUTEST_CPPFLAGS) $(CPPUTEST_ADDITIONAL_CPPFLAGS) -CXXFLAGS = $(CPPUTEST_CXXFLAGS) $(CPPUTEST_ADDITIONAL_CXXFLAGS) -LDFLAGS = $(CPPUTEST_LDFLAGS) $(CPPUTEST_ADDITIONAL_LDFLAGS) - -# Don't consider creating the archive a warning condition that does STDERR output -ARFLAGS := $(ARFLAGS)c - -DEP_FLAGS=-MMD -MP - -# Some macros for programs to be overridden. For some reason, these are not in Make defaults -RANLIB = ranlib - -# Targets - -.PHONY: all -all: start $(TEST_TARGET) - $(RUN_TEST_TARGET) - -.PHONY: start -start: $(TEST_TARGET) - $(SILENCE)START_TIME=$(call time) - -.PHONY: all_no_tests -all_no_tests: $(TEST_TARGET) - -.PHONY: flags -flags: - @echo - @echo "OS ${UNAME_OS}" - @echo "Compile C and C++ source with CPPFLAGS:" - @$(call debug_print_list,$(CPPFLAGS)) - @echo "Compile C++ source with CXXFLAGS:" - @$(call debug_print_list,$(CXXFLAGS)) - @echo "Compile C source with CFLAGS:" - @$(call debug_print_list,$(CFLAGS)) - @echo "Link with LDFLAGS:" - @$(call debug_print_list,$(LDFLAGS)) - @echo "Link with LD_LIBRARIES:" - @$(call debug_print_list,$(LD_LIBRARIES)) - @echo "Create libraries with ARFLAGS:" - @$(call debug_print_list,$(ARFLAGS)) - -TEST_DEPS = $(TEST_OBJS) $(MOCKS_OBJS) $(PRODUCTION_CODE_START) $(TARGET_LIB) $(USER_LIBS) $(PRODUCTION_CODE_END) $(CPPUTEST_LIB) $(STDLIB_CODE_START) -test-deps: $(TEST_DEPS) - -$(TEST_TARGET): $(TEST_DEPS) - @echo Linking $@ - $(SILENCE)$(CXX) -o $@ $^ $(LD_LIBRARIES) $(LDFLAGS) - -$(TARGET_LIB): $(OBJ) - @echo Building archive $@ - $(SILENCE)mkdir -p $(dir $@) - $(SILENCE)$(AR) $(ARFLAGS) $@ $^ - $(SILENCE)$(RANLIB) $@ - -test: $(TEST_TARGET) - $(RUN_TEST_TARGET) | tee $(TEST_OUTPUT) - -vtest: $(TEST_TARGET) - $(RUN_TEST_TARGET) -v | tee $(TEST_OUTPUT) - -$(CPPUTEST_OBJS_DIR)/%.o: %.cc - @echo compiling $(notdir $<) - $(SILENCE)mkdir -p $(dir $@) - $(SILENCE)$(COMPILE.cpp) $(DEP_FLAGS) $(OUTPUT_OPTION) $< - -$(CPPUTEST_OBJS_DIR)/%.o: %.cpp - @echo compiling $(notdir $<) - $(SILENCE)mkdir -p $(dir $@) - $(SILENCE)$(COMPILE.cpp) $(DEP_FLAGS) $(OUTPUT_OPTION) $< - -$(CPPUTEST_OBJS_DIR)/%.o: %.c - @echo compiling $(notdir $<) - $(SILENCE)mkdir -p $(dir $@) - $(SILENCE)$(COMPILE.c) $(DEP_FLAGS) $(OUTPUT_OPTION) $< - -ifneq "$(MAKECMDGOALS)" "clean" --include $(DEP_FILES) -endif - -.PHONY: clean -clean: - @echo Making clean - $(SILENCE)$(RM) $(STUFF_TO_CLEAN) - $(SILENCE)rm -rf gcov objs #$(CPPUTEST_OBJS_DIR) - $(SILENCE)rm -rf $(CPPUTEST_LIB_DIR) - $(SILENCE)find . -name "*.gcno" | xargs rm -f - $(SILENCE)find . -name "*.gcda" | xargs rm -f - -#realclean gets rid of all gcov, o and d files in the directory tree -#not just the ones made by this makefile -.PHONY: realclean -realclean: clean - $(SILENCE)rm -rf gcov - $(SILENCE)find . -name "*.gdcno" | xargs rm -f - $(SILENCE)find . -name "*.[do]" | xargs rm -f - -gcov: test -ifeq ($(CPPUTEST_USE_VPATH), Y) - $(SILENCE)gcov --object-directory $(CPPUTEST_OBJS_DIR) $(SRC) >> $(GCOV_OUTPUT) 2>> $(GCOV_ERROR) -else - $(SILENCE)for d in $(SRC_DIRS) ; do \ - gcov --object-directory $(CPPUTEST_OBJS_DIR)/$$d $$d/*.c $$d/*.cpp >> $(GCOV_OUTPUT) 2>>$(GCOV_ERROR) ; \ - done - $(SILENCE)for f in $(SRC_FILES) ; do \ - gcov --object-directory $(CPPUTEST_OBJS_DIR)/$$f $$f >> $(GCOV_OUTPUT) 2>>$(GCOV_ERROR) ; \ - done -endif -# $(CPPUTEST_HOME)/scripts/filterGcov.sh $(GCOV_OUTPUT) $(GCOV_ERROR) $(GCOV_REPORT) $(TEST_OUTPUT) - /usr/share/cpputest/scripts/filterGcov.sh $(GCOV_OUTPUT) $(GCOV_ERROR) $(GCOV_REPORT) $(TEST_OUTPUT) - $(SILENCE)cat $(GCOV_REPORT) - $(SILENCE)mkdir -p gcov - $(SILENCE)mv *.gcov gcov - $(SILENCE)mv gcov_* gcov - @echo "See gcov directory for details" - -.PHONEY: format -format: - $(CPPUTEST_HOME)/scripts/reformat.sh $(PROJECT_HOME_DIR) - -.PHONEY: debug -debug: - @echo - @echo "Target Source files:" - @$(call debug_print_list,$(SRC)) - @echo "Target Object files:" - @$(call debug_print_list,$(OBJ)) - @echo "Test Source files:" - @$(call debug_print_list,$(TEST_SRC)) - @echo "Test Object files:" - @$(call debug_print_list,$(TEST_OBJS)) - @echo "Mock Source files:" - @$(call debug_print_list,$(MOCKS_SRC)) - @echo "Mock Object files:" - @$(call debug_print_list,$(MOCKS_OBJS)) - @echo "All Input Dependency files:" - @$(call debug_print_list,$(DEP_FILES)) - @echo Stuff to clean: - @$(call debug_print_list,$(STUFF_TO_CLEAN)) - @echo Includes: - @$(call debug_print_list,$(INCLUDES)) - --include $(OTHER_MAKEFILE_TO_INCLUDE) diff --git a/test/libService/unittest/ip6tos/Makefile b/test/libService/unittest/ip6tos/Makefile deleted file mode 100644 index 7ec8277d7cf5..000000000000 --- a/test/libService/unittest/ip6tos/Makefile +++ /dev/null @@ -1,21 +0,0 @@ -include ../makefile_defines.txt - -COMPONENT_NAME = ip6tos_unit -SRC_FILES = \ - ../../../../source/libip6string/ip6tos.c - -TEST_SRC_FILES = \ - main.cpp \ - ip6tos_test.cpp \ - ../../../../source/libBits/common_functions.c -# ../stubs/some_stub.c \ - -# XXX: without this, the CppUTest complains for memory leak even without one. -# The funny thing is that the CppUTest does not find the memory leak on -# this app when there actually is one. -CPPUTEST_USE_MEM_LEAK_DETECTION = N - -include ../MakefileWorker.mk - -CPPUTESTFLAGS += -DFEA_TRACE_SUPPORT - diff --git a/test/libService/unittest/ip6tos/main.cpp b/test/libService/unittest/ip6tos/main.cpp deleted file mode 100644 index 072edf7e98b9..000000000000 --- a/test/libService/unittest/ip6tos/main.cpp +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 2015-2016, Pelion and affiliates. - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "CppUTest/CommandLineTestRunner.h" -#include "CppUTest/TestPlugin.h" -#include "CppUTest/TestRegistry.h" -#include "CppUTestExt/MockSupportPlugin.h" -int main(int ac, char **av) -{ - return CommandLineTestRunner::RunAllTests(ac, av); -} - -IMPORT_TEST_GROUP(ip6tos); -IMPORT_TEST_GROUP(ip6tos_2); diff --git a/test/libService/unittest/makefile_defines.txt b/test/libService/unittest/makefile_defines.txt deleted file mode 100755 index 46410f7762c6..000000000000 --- a/test/libService/unittest/makefile_defines.txt +++ /dev/null @@ -1,20 +0,0 @@ -#--- Inputs ----# -MBED_TRACE_HOME = ../../../../../mbed-trace -CPPUTEST_HOME = /usr -CPPUTEST_USE_EXTENSIONS = Y -CPPUTEST_USE_VPATH = Y -CPPUTEST_USE_GCOV = Y -CPP_PLATFORM = gcc -INCLUDE_DIRS =\ - .\ - ../common\ - ../stubs\ - ../../../..\ - ../../../../source\ - ../../../../mbed-client-libservice\ - $(MBED_TRACE_HOME)\ - /usr/include\ - $(CPPUTEST_HOME)/include\ - -CPPUTESTFLAGS = -D__thumb2__ -w -CPPUTEST_CFLAGS += -std=gnu99 diff --git a/test/libService/unittest/nsdynmem/Makefile b/test/libService/unittest/nsdynmem/Makefile deleted file mode 100644 index 8178c5d51585..000000000000 --- a/test/libService/unittest/nsdynmem/Makefile +++ /dev/null @@ -1,25 +0,0 @@ -include ../makefile_defines.txt - -COMPONENT_NAME = dynmem_unit -SRC_FILES = \ - ../../../../source/nsdynmemLIB/nsdynmemLIB.c - -TEST_SRC_FILES = \ - main.cpp \ - dynmemtest.cpp \ - error_callback.c \ - ../stubs/platform_critical.c \ - ../stubs/ns_list_stub.c - -# ../../../../source/libBits/common_functions.c -# ../stubs/some_stub.c \ - -# XXX: without this, the CppUTest complains for memory leak even without one. -# The funny thing is that the CppUTest does not find the memory leak on -# this app when there actually is one. -CPPUTEST_USE_MEM_LEAK_DETECTION = Y - -include ../MakefileWorker.mk - -CPPUTESTFLAGS += -DFEA_TRACE_SUPPORT - diff --git a/test/libService/unittest/nsdynmem/main.cpp b/test/libService/unittest/nsdynmem/main.cpp deleted file mode 100644 index 5844a2b85e59..000000000000 --- a/test/libService/unittest/nsdynmem/main.cpp +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (c) 2015, Pelion and affiliates. - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "CppUTest/CommandLineTestRunner.h" -#include "CppUTest/TestPlugin.h" -#include "CppUTest/TestRegistry.h" -#include "CppUTestExt/MockSupportPlugin.h" -int main(int ac, char **av) -{ - return CommandLineTestRunner::RunAllTests(ac, av); -} - -IMPORT_TEST_GROUP(dynmem); diff --git a/test/libService/unittest/nsnvmhelper/Makefile b/test/libService/unittest/nsnvmhelper/Makefile deleted file mode 100644 index f931a090c973..000000000000 --- a/test/libService/unittest/nsnvmhelper/Makefile +++ /dev/null @@ -1,18 +0,0 @@ -include ../makefile_defines.txt - -COMPONENT_NAME = ns_nvm_helper_unit - -SRC_FILES = ../../../../source/nvmHelper/ns_nvm_helper.c - -TEST_SRC_FILES = main.cpp \ - nsnvmhelpertest.cpp \ - test_ns_nvm_helper.c \ - ../stubs/platform_nvm_stub.c \ - ../stubs/nsdynmemLIB_stub.c \ - ../stubs/mbed_trace_stub.c \ - ../stubs/ns_list_stub.c - -include ../MakefileWorker.mk - -CPPUTESTFLAGS += -DFEA_TRACE_SUPPORT - diff --git a/test/libService/unittest/nsnvmhelper/main.cpp b/test/libService/unittest/nsnvmhelper/main.cpp deleted file mode 100644 index 6501174929e1..000000000000 --- a/test/libService/unittest/nsnvmhelper/main.cpp +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 2015-2016, 2020, Pelion and affiliates. - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "CppUTest/CommandLineTestRunner.h" -#include "CppUTest/TestPlugin.h" -#include "CppUTest/TestRegistry.h" -#include "CppUTestExt/MockSupportPlugin.h" -int main(int ac, char **av) -{ - return CommandLineTestRunner::RunAllTests(ac, av); -} - -IMPORT_TEST_GROUP(NS_NVM_HELPER); - diff --git a/test/libService/unittest/nsnvmhelper/nsnvmhelpertest.cpp b/test/libService/unittest/nsnvmhelper/nsnvmhelpertest.cpp deleted file mode 100644 index 34aabd386f07..000000000000 --- a/test/libService/unittest/nsnvmhelper/nsnvmhelpertest.cpp +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright (c) 2016, 2020, Pelion and affiliates. - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#include "CppUTest/TestHarness.h" -#include "test_ns_nvm_helper.h" - -TEST_GROUP(NS_NVM_HELPER) -{ - void setup() { - - } - - void teardown() { - - } -}; - -TEST(NS_NVM_HELPER, test_ns_nvm_helper_platform_error_in_write) -{ - CHECK(test_ns_nvm_helper_platform_error_in_write() == true); -} - -TEST(NS_NVM_HELPER, test_ns_nvm_helper_platform_error) -{ - CHECK(test_ns_nvm_helper_platform_error() == true); -} - -TEST(NS_NVM_HELPER, test_ns_nvm_helper_concurrent_requests) -{ - CHECK(test_ns_nvm_helper_concurrent_requests() == true); -} - -TEST(NS_NVM_HELPER, test_ns_nvm_helper_read) -{ - CHECK(test_ns_nvm_helper_read() == true); -} - -TEST(NS_NVM_HELPER, test_ns_nvm_helper_delete) -{ - CHECK(test_ns_nvm_helper_delete() == true); -} - -/* Write must be the last test (executed first) as it initialized the platform NVM */ -TEST(NS_NVM_HELPER, test_ns_nvm_helper_write) -{ - CHECK(test_ns_nvm_helper_write() == true); -} - diff --git a/test/libService/unittest/run_tests b/test/libService/unittest/run_tests deleted file mode 100755 index 94ec5b9f63f5..000000000000 --- a/test/libService/unittest/run_tests +++ /dev/null @@ -1,43 +0,0 @@ -#!/bin/bash -echo -echo Build M2M API unit tests -echo - -# Remember to add new test folder to Makefile -make clean -make all - -echo -echo Create results -echo -mkdir results - -find ./ -name '*.xml' | xargs cp -t ./results/ - -echo -echo Create coverage document -echo -mkdir coverages -cd coverages - -#copy the .gcda & .gcno for all test projects (no need to modify -#cp ../../../source/*.gc* . -#find ../ -name '*.gcda' | xargs cp -t . -#find ../ -name '*.gcno' | xargs cp -t . -#find . -name "test*" -type f -delete -#find . -name "*test*" -type f -delete -#find . -name "*stub*" -type f -delete -#rm -rf main.* - -lcov -q -d ../. -c -o app.info -lcov -q -r app.info "/test*" -o app.info -lcov -q -r app.info "/usr*" -o app.info -genhtml --no-branch-coverage app.info -cd .. -echo -echo -echo -echo Have a nice bug hunt! -echo -echo -echo diff --git a/test/libService/unittest/stoip6/Makefile b/test/libService/unittest/stoip6/Makefile deleted file mode 100644 index 68964c0d40dd..000000000000 --- a/test/libService/unittest/stoip6/Makefile +++ /dev/null @@ -1,21 +0,0 @@ -include ../makefile_defines.txt - -COMPONENT_NAME = stoip6_unit -SRC_FILES = \ - ../../../../source/libip6string/stoip6.c - -TEST_SRC_FILES = \ - main.cpp \ - stoip6test.cpp \ - ../../../../source/libBits/common_functions.c -# ../stubs/some_stub.c \ - -# XXX: without this, the CppUTest complains for memory leak even without one. -# The funny thing is that the CppUTest does not find the memory leak on -# this app when there actually is one. -CPPUTEST_USE_MEM_LEAK_DETECTION = N - -include ../MakefileWorker.mk - -CPPUTESTFLAGS += -DFEA_TRACE_SUPPORT - diff --git a/test/libService/unittest/stoip6/main.cpp b/test/libService/unittest/stoip6/main.cpp deleted file mode 100644 index dd24579f2b1f..000000000000 --- a/test/libService/unittest/stoip6/main.cpp +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright (c) 2015-2016, 2018, Pelion and affiliates. - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "CppUTest/CommandLineTestRunner.h" -#include "CppUTest/TestPlugin.h" -#include "CppUTest/TestRegistry.h" -#include "CppUTestExt/MockSupportPlugin.h" -int main(int ac, char **av) -{ - return CommandLineTestRunner::RunAllTests(ac, av); -} - -IMPORT_TEST_GROUP(stoip6); -IMPORT_TEST_GROUP(stoip6_2); -IMPORT_TEST_GROUP(stoip6_3); diff --git a/test/libService/unittest/stubs/mbed_trace_stub.c b/test/libService/unittest/stubs/mbed_trace_stub.c deleted file mode 100644 index 84f4bf3dc5d2..000000000000 --- a/test/libService/unittest/stubs/mbed_trace_stub.c +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Copyright (c) 2014-2017, 2019, Pelion and affiliates. - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#include -#include -#include -#include - -#ifndef MBED_CONF_MBED_TRACE_ENABLE -#define MBED_CONF_MBED_TRACE_ENABLE 1 -#define MBED_CONF_MBED_TRACE_FEA_IPV6 1 -#endif - -#include "mbed-trace/mbed_trace.h" -#if MBED_CONF_MBED_TRACE_FEA_IPV6 == 1 -#include "mbed-client-libservice/ip6string.h" -#include "mbed-client-libservice/common_functions.h" -#endif - - -int mbed_trace_init(void) -{ - return 0; -} -void mbed_trace_free(void) -{ -} - -void mbed_trace_buffer_sizes(int lineLength, int tmpLength) -{ -} - -void mbed_trace_config_set(uint8_t config) -{ -} - -uint8_t mbed_trace_config_get(void) -{ - return 0; -} - -void mbed_trace_prefix_function_set(char *(*pref_f)(size_t)) -{ -} - -void mbed_trace_suffix_function_set(char *(*suffix_f)(void)) -{ -} - -void mbed_trace_print_function_set(void (*printf)(const char *)) -{ -} - -void mbed_trace_cmdprint_function_set(void (*printf)(const char *)) -{ -} - -void mbed_trace_exclude_filters_set(char *filters) -{ - -} - -const char *mbed_trace_exclude_filters_get(void) -{ - return NULL; -} - -const char *mbed_trace_include_filters_get(void) -{ - return NULL; -} - -void mbed_trace_include_filters_set(char *filters) -{ - -} - -void mbed_tracef(uint8_t dlevel, const char *grp, const char *fmt, ...) -{ -} - -void mbed_vtracef(uint8_t dlevel, const char *grp, const char *fmt, va_list ap) -{ -} - -const char *mbed_trace_last(void) -{ - return NULL; -} - -/* Helping functions */ -#if MBED_CONF_MBED_TRACE_FEA_IPV6 == 1 -char *mbed_trace_ipv6(const void *addr_ptr) -{ - return NULL; -} - -char *mbed_trace_ipv6_prefix(const uint8_t *prefix, uint8_t prefix_len) -{ - return NULL; -} -#endif //MBED_CONF_MBED_TRACE_FEA_IPV6 - -char *mbed_trace_array(const uint8_t *buf, uint16_t len) -{ - return NULL; -} diff --git a/test/libService/unittest/nsdynmem/dynmemtest.cpp b/test/nsdynmem/dynmem_test.cpp similarity index 63% rename from test/libService/unittest/nsdynmem/dynmemtest.cpp rename to test/nsdynmem/dynmem_test.cpp index 36be9104ad9c..a5f252705117 100644 --- a/test/libService/unittest/nsdynmem/dynmemtest.cpp +++ b/test/nsdynmem/dynmem_test.cpp @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include "CppUTest/TestHarness.h" +#include "gtest/gtest.h" #include "nsdynmemLIB.h" #include #include @@ -29,63 +29,65 @@ int ret_val; -TEST_GROUP(dynmem) -{ - void setup() { +class dynmem_test : public testing::Test { +protected: + void SetUp() + { reset_heap_error(); } - void teardown() { + void TearDown() + { } }; -TEST(dynmem, init) +TEST_F(dynmem_test, init) { uint16_t size = 1000; uint8_t *heap = (uint8_t *)malloc(size); - CHECK(NULL != heap); + ASSERT_TRUE(heap); mem_stat_t info; reset_heap_error(); ns_dyn_mem_init(heap, size, &heap_fail_callback, &info); - CHECK(info.heap_sector_size == (size - NS_MEM_BOOK_SIZE)); - CHECK(!heap_have_failed()); - CHECK(ns_dyn_mem_get_mem_stat() == &info); + ASSERT_EQ(info.heap_sector_size, (size - NS_MEM_BOOK_SIZE)); + ASSERT_EQ(false, heap_have_failed()); + ASSERT_EQ(ns_dyn_mem_get_mem_stat(), &info); free(heap); } -TEST(dynmem, different_sizes) +TEST_F(dynmem_test, different_sizes) { reset_heap_error(); for (uint16_t size = 1000; size < 32768; size++) { mem_stat_t info; uint8_t *heap = (uint8_t *)malloc(size); ns_dyn_mem_init(heap, size, &heap_fail_callback, &info); - CHECK(info.heap_sector_size >= (size - NS_MEM_BOOK_SIZE_WITH_HOLE)); - CHECK(!heap_have_failed()); - CHECK(ns_dyn_mem_alloc(10)); + ASSERT_GE(info.heap_sector_size, (size - NS_MEM_BOOK_SIZE_WITH_HOLE)); + ASSERT_EQ(false, heap_have_failed()); + ASSERT_TRUE(ns_dyn_mem_alloc(10)); free(heap); } } -TEST(dynmem, diff_alignment) +TEST_F(dynmem_test, diff_alignment) { uint16_t size = 1000; mem_stat_t info; uint8_t *heap = (uint8_t *)malloc(size); uint8_t *ptr = heap; - CHECK(NULL != heap); + ASSERT_TRUE(heap); reset_heap_error(); for (int i = 0; i < 16; i++) { ptr++; size--; ns_dyn_mem_init(ptr, size, &heap_fail_callback, &info); - CHECK(info.heap_sector_size >= (size - NS_MEM_BOOK_SIZE_WITH_HOLE)); - CHECK(!heap_have_failed()); + ASSERT_GE(info.heap_sector_size, (size - NS_MEM_BOOK_SIZE_WITH_HOLE)); + ASSERT_EQ(false, heap_have_failed()); } free(heap); } -TEST(dynmem, heap_add_region_api) +TEST_F(dynmem_test, heap_add_region_api) { #if (NS_MEM_REGION_CNT > 1) uint16_t size = 1000; @@ -97,32 +99,32 @@ TEST(dynmem, heap_add_region_api) reset_heap_error(); ns_dyn_mem_init(heap, size, &heap_fail_callback, &info); - CHECK(info.heap_sector_size == (size - NS_MEM_BOOK_SIZE)) + ASSERT_EQ(info.heap_sector_size, (size - NS_MEM_BOOK_SIZE)); // param error, return <0 ret_val = ns_dyn_mem_region_add(NULL, size); - CHECK(0 != ret_val); + ASSERT_NE(0, ret_val); // param error, return <0 ret_val = ns_dyn_mem_region_add(heap2add, 0); - CHECK(0 != ret_val); + ASSERT_NE(0, ret_val); // param error, return <0 ret_val = ns_dyn_mem_region_add(heap2add, 8); - CHECK(0 != ret_val); + ASSERT_NE(0, ret_val); // All OK - success, 1 reserved for bookkeeping ret_val = ns_dyn_mem_region_add(heap2add, size); - CHECK(0 == ret_val); + ASSERT_EQ(0, ret_val); - CHECK(!heap_have_failed()); - CHECK(ns_dyn_mem_get_mem_stat() == &info); - CHECK(info.heap_sector_size == (2 * size - NS_MEM_BOOK_SIZE)) + ASSERT_EQ(false, heap_have_failed()); + ASSERT_EQ(ns_dyn_mem_get_mem_stat(), &info); + ASSERT_EQ(info.heap_sector_size, (2 * size - NS_MEM_BOOK_SIZE)); // All OK - add more memory again success ret_val = ns_dyn_mem_region_add(heap2add2, size); - CHECK(0 == ret_val); - CHECK(info.heap_sector_size == (3 * size - NS_MEM_BOOK_SIZE)) + ASSERT_EQ(0, ret_val); + ASSERT_EQ(info.heap_sector_size, (3 * size - NS_MEM_BOOK_SIZE)); free(heap); free(heap2add); @@ -130,7 +132,7 @@ TEST(dynmem, heap_add_region_api) #endif } -TEST(dynmem, heap_add_region) +TEST_F(dynmem_test, heap_add_region) { #if (NS_MEM_REGION_CNT > 1 && NS_MEM_REGION_CNT < 4) uint16_t size = 200; @@ -144,25 +146,25 @@ TEST(dynmem, heap_add_region) reset_heap_error(); ns_dyn_mem_init(heap, size, &heap_fail_callback, &info); - CHECK(info.heap_sector_size == (size - NS_MEM_BOOK_SIZE)) + ASSERT_EQ(info.heap_sector_size, (size - NS_MEM_BOOK_SIZE)); ret_val = ns_dyn_mem_region_add(heap_add1, size); - CHECK(0 == ret_val); + ASSERT_EQ(0, ret_val); // region already added, therefore fails ret_val = ns_dyn_mem_region_add(heap_add1, size); - CHECK(0 != ret_val); + ASSERT_NE(0, ret_val); ret_val = ns_dyn_mem_region_add(heap_add3, size); - CHECK(0 == ret_val); + ASSERT_EQ(0, ret_val); // There is room for 2 additional regions , therfore fails ret_val = ns_dyn_mem_region_add(heap_add2, size); - CHECK(0 != ret_val); + ASSERT_NE(0, ret_val); - CHECK(info.heap_sector_size == (3 * size - NS_MEM_BOOK_SIZE)) + ASSERT_EQ(info.heap_sector_size, (3 * size - NS_MEM_BOOK_SIZE)); - CHECK(!heap_have_failed()); + ASSERT_EQ(false, heap_have_failed()); int block_size = 10; int i; @@ -174,16 +176,16 @@ TEST(dynmem, heap_add_region) break; } } - CHECK(!heap_have_failed()); - CHECK(info.heap_alloc_fail_cnt == 1); - CHECK(info.heap_sector_alloc_cnt == i); - CHECK(info.heap_sector_allocated_bytes == info.heap_sector_allocated_bytes_max); + ASSERT_EQ(false, heap_have_failed()); + ASSERT_EQ(info.heap_alloc_fail_cnt, 1); + ASSERT_EQ(info.heap_sector_alloc_cnt, i); + ASSERT_EQ(info.heap_sector_allocated_bytes, info.heap_sector_allocated_bytes_max); for (; i >= 0; i--) { ns_dyn_mem_free(p[i]); } - CHECK(!heap_have_failed()); - CHECK(info.heap_sector_alloc_cnt == 0); + ASSERT_EQ(false, heap_have_failed()); + ASSERT_EQ(info.heap_sector_alloc_cnt, 0); free(heap); free(heap_add1); @@ -192,7 +194,7 @@ TEST(dynmem, heap_add_region) #endif } -TEST(dynmem, heap_add_region_randomized) +TEST_F(dynmem_test, heap_add_region_randomized) { /** * Test: @@ -219,20 +221,20 @@ TEST(dynmem, heap_add_region_randomized) reset_heap_error(); ns_dyn_mem_init(heap_ptr[0], size, &heap_fail_callback, &info); - CHECK(info.heap_sector_size == (size - NS_MEM_BOOK_SIZE)) + ASSERT_EQ(info.heap_sector_size, (size - NS_MEM_BOOK_SIZE)); for (int cnt = NS_MEM_REGION_CNT - 1; cnt > 0; cnt--) { ret_val = ns_dyn_mem_region_add(heap_ptr[cnt], size); - CHECK(0 == ret_val); + ASSERT_EQ(0, ret_val); } - CHECK(info.heap_sector_size == (NS_MEM_REGION_CNT * size - NS_MEM_BOOK_SIZE)) + ASSERT_EQ(info.heap_sector_size, (NS_MEM_REGION_CNT * size - NS_MEM_BOOK_SIZE)); - CHECK(!heap_have_failed()); + ASSERT_EQ(false, heap_have_failed()); srand(time(NULL)); int block_size; - int i; + uint32_t i; for (i = 0; i < size * NS_MEM_REGION_CNT; i++) { // allocate huge amount of small blocks until allocation fails block_size = (rand() % 4) + 1; @@ -243,10 +245,10 @@ TEST(dynmem, heap_add_region_randomized) break; } } - CHECK(!heap_have_failed()); - CHECK(info.heap_alloc_fail_cnt == 1); - CHECK(info.heap_sector_alloc_cnt == i); - CHECK(info.heap_sector_allocated_bytes == info.heap_sector_allocated_bytes_max); + ASSERT_EQ(false, heap_have_failed()); + ASSERT_EQ(info.heap_alloc_fail_cnt, 1); + ASSERT_EQ(info.heap_sector_alloc_cnt, i); + ASSERT_EQ(info.heap_sector_allocated_bytes, info.heap_sector_allocated_bytes_max); // free allocated memmory blocks in random order int block_id; @@ -259,9 +261,9 @@ TEST(dynmem, heap_add_region_randomized) } while (info.heap_sector_alloc_cnt != 0); - CHECK(!heap_have_failed()); - CHECK(info.heap_sector_alloc_cnt == 0); - CHECK(info.heap_sector_allocated_bytes == 0); + ASSERT_EQ(false, heap_have_failed()); + ASSERT_EQ(info.heap_sector_alloc_cnt, 0); + ASSERT_EQ(info.heap_sector_allocated_bytes, 0); for (int cnt = 0; cnt < NS_MEM_REGION_CNT; cnt++) { free(heap_ptr[cnt]); @@ -269,16 +271,16 @@ TEST(dynmem, heap_add_region_randomized) #endif } -TEST(dynmem, ns_dyn_mem_alloc) +TEST_F(dynmem_test, ns_dyn_mem_alloc) { uint16_t size = 1000; mem_stat_t info; void *p[size]; uint8_t *heap = (uint8_t *)malloc(size); - CHECK(NULL != heap); + ASSERT_TRUE(heap); reset_heap_error(); ns_dyn_mem_init(heap, size, &heap_fail_callback, &info); - CHECK(!heap_have_failed()); + ASSERT_EQ(false, heap_have_failed()); int block = 1; int i; @@ -291,29 +293,29 @@ TEST(dynmem, ns_dyn_mem_alloc) break; } } - CHECK(!heap_have_failed()); - CHECK(info.heap_alloc_fail_cnt == 1); - CHECK(info.heap_sector_alloc_cnt == i); - CHECK(info.heap_sector_allocated_bytes == info.heap_sector_allocated_bytes_max); + ASSERT_EQ(false, heap_have_failed()); + ASSERT_EQ(info.heap_alloc_fail_cnt, 1); + ASSERT_EQ(info.heap_sector_alloc_cnt, i); + ASSERT_EQ(info.heap_sector_allocated_bytes, info.heap_sector_allocated_bytes_max); for (; i >= 0; i--) { ns_dyn_mem_free(p[i]); } - CHECK(!heap_have_failed()); - CHECK(info.heap_sector_alloc_cnt == 0); + ASSERT_EQ(false, heap_have_failed()); + ASSERT_EQ(info.heap_sector_alloc_cnt, 0); free(heap); } -TEST(dynmem, ns_dyn_mem_temporary_alloc) +TEST_F(dynmem_test, ns_dyn_mem_temporary_alloc) { uint16_t size = 1000; mem_stat_t info; void *p[size]; uint8_t *heap = (uint8_t *)malloc(size); - CHECK(NULL != heap); + ASSERT_TRUE(heap); reset_heap_error(); ns_dyn_mem_init(heap, size, &heap_fail_callback, &info); - CHECK(!heap_have_failed()); + ASSERT_EQ(false, heap_have_failed()); int block = 1; int i; @@ -323,111 +325,110 @@ TEST(dynmem, ns_dyn_mem_temporary_alloc) break; } } - CHECK(!heap_have_failed()); - CHECK(info.heap_alloc_fail_cnt == 1); - CHECK(info.heap_sector_alloc_cnt == i); - CHECK(info.heap_sector_allocated_bytes == info.heap_sector_allocated_bytes_max); + ASSERT_EQ(false, heap_have_failed()); + ASSERT_EQ(info.heap_alloc_fail_cnt, 1); + ASSERT_EQ(info.heap_sector_alloc_cnt, i); + ASSERT_EQ(info.heap_sector_allocated_bytes, info.heap_sector_allocated_bytes_max); for (; i >= 0; i--) { ns_dyn_mem_free(p[i]); } - CHECK(!heap_have_failed()); - CHECK(info.heap_sector_alloc_cnt == 0); + ASSERT_EQ(false, heap_have_failed()); + ASSERT_EQ(info.heap_sector_alloc_cnt, 0); free(heap); } -TEST(dynmem, ns_dyn_mem_temporary_alloc_with_heap_threshold) +TEST_F(dynmem_test, ns_dyn_mem_temporary_alloc_with_heap_threshold) { uint16_t size = 1000; mem_stat_t info; void *p1, *p2; int ret_val; uint8_t *heap = (uint8_t *)malloc(size); - CHECK(NULL != heap); + ASSERT_TRUE(heap); reset_heap_error(); ns_dyn_mem_init(heap, size, &heap_fail_callback, &info); - CHECK(!heap_have_failed()); + ASSERT_EQ(false, heap_have_failed()); // test1: temporary alloc will fail if there is less than 5% heap free p1 = ns_dyn_mem_temporary_alloc((size - NS_MEM_BOOK_SIZE_WITH_HOLE) * 0.96); - CHECK(!heap_have_failed()); - CHECK(p1); + ASSERT_EQ(false, heap_have_failed()); + ASSERT_TRUE(p1); p2 = ns_dyn_mem_temporary_alloc((size - NS_MEM_BOOK_SIZE_WITH_HOLE) * 0.02); - CHECK(p2 == NULL); - CHECK(!heap_have_failed()); - CHECK(info.heap_alloc_fail_cnt == 1); + ASSERT_EQ(NULL, p2); + ASSERT_EQ(false, heap_have_failed()); + ASSERT_EQ(info.heap_alloc_fail_cnt, 1); // Test2, disable threshold feature and try p2 allocation again ns_dyn_mem_set_temporary_alloc_free_heap_threshold(0, 0); p2 = ns_dyn_mem_temporary_alloc((size - NS_MEM_BOOK_SIZE_WITH_HOLE) * 0.02); - CHECK(!heap_have_failed()); - CHECK(p2); + ASSERT_EQ(false, heap_have_failed()); + ASSERT_TRUE(p2); ns_dyn_mem_free(p1); ns_dyn_mem_free(p2); - CHECK(info.heap_alloc_fail_cnt == 1); - CHECK(info.heap_sector_alloc_cnt == 0); + ASSERT_EQ(info.heap_alloc_fail_cnt, 1); + ASSERT_EQ(info.heap_sector_alloc_cnt, 0); // Test3, enable feature by free heap percentage ns_dyn_mem_set_temporary_alloc_free_heap_threshold(40, 0); p1 = ns_dyn_mem_temporary_alloc((size - NS_MEM_BOOK_SIZE_WITH_HOLE) * 0.65); - CHECK(p1); + ASSERT_TRUE(p1); p2 = ns_dyn_mem_temporary_alloc((size - NS_MEM_BOOK_SIZE_WITH_HOLE) * 0.10); - CHECK(p2 == NULL); + ASSERT_EQ(NULL, p2); ns_dyn_mem_free(p1); - CHECK(!heap_have_failed()); - CHECK(info.heap_alloc_fail_cnt == 2); - CHECK(info.heap_sector_alloc_cnt == 0); + ASSERT_EQ(false, heap_have_failed()); + ASSERT_EQ(info.heap_alloc_fail_cnt, 2); + ASSERT_EQ(info.heap_sector_alloc_cnt, 0); // Test4, enable feature by free heap amount ns_dyn_mem_set_temporary_alloc_free_heap_threshold(0, 200); p1 = ns_dyn_mem_temporary_alloc(size - NS_MEM_BOOK_SIZE_WITH_HOLE - 100); - CHECK(p1); + ASSERT_TRUE(p1); p2 = ns_dyn_mem_temporary_alloc(1); - CHECK(p2 == NULL); + ASSERT_EQ(NULL, p2); ns_dyn_mem_free(p1); // Test5, illegal API parameters ret_val = ns_dyn_mem_set_temporary_alloc_free_heap_threshold(0, size / 2); - CHECK(ret_val == -2); + ASSERT_EQ(ret_val, -2); ret_val = ns_dyn_mem_set_temporary_alloc_free_heap_threshold(0, size * 2); - CHECK(ret_val == -2); + ASSERT_EQ(ret_val, -2); ret_val = ns_dyn_mem_set_temporary_alloc_free_heap_threshold(51, 0); - CHECK(ret_val == -2); + ASSERT_EQ(ret_val, -2); ret_val = ns_dyn_mem_set_temporary_alloc_free_heap_threshold(255, 0); - CHECK(ret_val == -2); + ASSERT_EQ(ret_val, -2); - CHECK(!heap_have_failed()); - CHECK(info.heap_alloc_fail_cnt == 3); - CHECK(info.heap_sector_alloc_cnt == 0); + ASSERT_EQ(false, heap_have_failed()); + ASSERT_EQ(info.heap_alloc_fail_cnt, 3); + ASSERT_EQ(info.heap_sector_alloc_cnt, 0); free(heap); // Test6, feature is disabled if info is coming anyway heap = (uint8_t *)malloc(size); - CHECK(NULL != heap); + ASSERT_TRUE(heap); ns_dyn_mem_init(heap, size, &heap_fail_callback, NULL); ret_val = ns_dyn_mem_set_temporary_alloc_free_heap_threshold(0, 0); - CHECK(ret_val == 0); - CHECK(!heap_have_failed()); + ASSERT_EQ(ret_val, 0); + ASSERT_EQ(false, heap_have_failed()); free(heap); } -TEST(dynmem, test_both_allocs_with_hole_usage) +TEST_F(dynmem_test, test_both_allocs_with_hole_usage) { uint16_t size = NS_MEM_BOOK_SIZE_WITH_HOLE + 15 + 5; mem_stat_t info; - void *p[size]; uint8_t *heap = (uint8_t *)malloc(size); - CHECK(NULL != heap); + ASSERT_TRUE(heap); reset_heap_error(); ns_dyn_mem_init(heap, size, &heap_fail_callback, &info); - CHECK(!heap_have_failed()); + ASSERT_EQ(false, heap_have_failed()); void *ptr = ns_dyn_mem_alloc(15); void *ptr2 = ns_dyn_mem_alloc(4); ns_dyn_mem_free(ptr); ns_dyn_mem_free(ptr2); - CHECK(info.heap_sector_allocated_bytes == 0); + ASSERT_EQ(info.heap_sector_allocated_bytes, 0); void *ptr3 = ns_dyn_mem_temporary_alloc(15); void *ptr4 = ns_dyn_mem_temporary_alloc(5); @@ -436,21 +437,20 @@ TEST(dynmem, test_both_allocs_with_hole_usage) ns_dyn_mem_free(ptr4); - CHECK(info.heap_sector_allocated_bytes == 0); + ASSERT_EQ(info.heap_sector_allocated_bytes, 0); free(heap); } -TEST(dynmem, test_temp_alloc_with_skipping_hole) +TEST_F(dynmem_test, test_temp_alloc_with_skipping_hole) { uint16_t size = 1000; mem_stat_t info; - void *p[size]; uint8_t *heap = (uint8_t *)malloc(size); - CHECK(NULL != heap); + ASSERT_TRUE(heap); reset_heap_error(); ns_dyn_mem_init(heap, size, &heap_fail_callback, &info); - CHECK(!heap_have_failed()); + ASSERT_EQ(false, heap_have_failed()); void *ptr1 = ns_dyn_mem_temporary_alloc(15); void *ptr2 = ns_dyn_mem_temporary_alloc(5); @@ -461,72 +461,68 @@ TEST(dynmem, test_temp_alloc_with_skipping_hole) ns_dyn_mem_free(ptr3); - CHECK(info.heap_sector_allocated_bytes == 0); + ASSERT_EQ(info.heap_sector_allocated_bytes, 0); free(heap); } -TEST(dynmem, zero_allocate) +TEST_F(dynmem_test, zero_allocate) { uint16_t size = 1000; mem_stat_t info; uint8_t *heap = (uint8_t *)malloc(size); - uint8_t *ptr = heap; - CHECK(NULL != heap); + ASSERT_TRUE(heap); reset_heap_error(); ns_dyn_mem_init(heap, size, &heap_fail_callback, &info); - CHECK(!heap_have_failed()); + ASSERT_EQ(false, heap_have_failed()); ns_dyn_mem_alloc(0); - CHECK(heap_have_failed()); - CHECK(NS_DYN_MEM_ALLOCATE_SIZE_NOT_VALID == current_heap_error); + ASSERT_EQ(true, heap_have_failed()); + ASSERT_EQ(NS_DYN_MEM_ALLOCATE_SIZE_NOT_VALID, current_heap_error); free(heap); } -TEST(dynmem, too_big) +TEST_F(dynmem_test, too_big) { uint16_t size = 1000; mem_stat_t info; uint8_t *heap = (uint8_t *)malloc(size); - uint8_t *ptr = heap; - CHECK(NULL != heap); + ASSERT_TRUE(heap); reset_heap_error(); ns_dyn_mem_init(heap, size, &heap_fail_callback, &info); - CHECK(!heap_have_failed()); + ASSERT_EQ(false, heap_have_failed()); ns_dyn_mem_alloc(size); - CHECK(heap_have_failed()); - CHECK(NS_DYN_MEM_ALLOCATE_SIZE_NOT_VALID == current_heap_error); + ASSERT_EQ(true, heap_have_failed()); + ASSERT_EQ(NS_DYN_MEM_ALLOCATE_SIZE_NOT_VALID, current_heap_error); free(heap); } -TEST(dynmem, corrupted_memory) +TEST_F(dynmem_test, corrupted_memory) { uint16_t size = 1000; mem_stat_t info; uint8_t *heap = (uint8_t *)malloc(size); - uint8_t *ptr = heap; - CHECK(NULL != heap); + ASSERT_TRUE(heap); reset_heap_error(); ns_dyn_mem_init(heap, size, &heap_fail_callback, &info); - CHECK(!heap_have_failed()); + ASSERT_EQ(false, heap_have_failed()); int *pt = (int *)ns_dyn_mem_alloc(8); - CHECK(!heap_have_failed()); + ASSERT_EQ(false, heap_have_failed()); pt -= 2; *pt = 0; ns_dyn_mem_alloc(8); - CHECK(NS_DYN_MEM_HEAP_SECTOR_CORRUPTED == current_heap_error); + ASSERT_EQ(NS_DYN_MEM_HEAP_SECTOR_CORRUPTED, current_heap_error); free(heap); } -TEST(dynmem, no_big_enough_sector) +TEST_F(dynmem_test, no_big_enough_sector) { uint16_t size = NS_MEM_BOOK_SIZE_WITH_HOLE + (5 * 8); mem_stat_t info; uint8_t *heap = (uint8_t *)malloc(size); - uint8_t *ptr = heap; - CHECK(NULL != heap); + ASSERT_TRUE(heap); reset_heap_error(); ns_dyn_mem_init(heap, size, &heap_fail_callback, &info); - CHECK(!heap_have_failed()); + ASSERT_EQ(false, heap_have_failed()); int *pt = (int *)ns_dyn_mem_alloc(8); pt = (int *)ns_dyn_mem_alloc(8); ns_dyn_mem_alloc(8); @@ -536,165 +532,164 @@ TEST(dynmem, no_big_enough_sector) ns_dyn_mem_free(pt); pt = (int *)ns_dyn_mem_temporary_alloc(32); - CHECK(NULL == pt); + ASSERT_EQ(NULL, pt); free(heap); } -TEST(dynmem, diff_sizes) +TEST_F(dynmem_test, diff_sizes) { uint16_t size = 1000; mem_stat_t info; void *p; uint8_t *heap = (uint8_t *)malloc(size); - CHECK(NULL != heap); + ASSERT_TRUE(heap); reset_heap_error(); ns_dyn_mem_init(heap, size, &heap_fail_callback, &info); - CHECK(!heap_have_failed()); - int i; + ASSERT_EQ(false, heap_have_failed()); + uint32_t i; for (i = 1; i < (size - NS_MEM_BOOK_SIZE_WITH_HOLE); i++) { p = ns_dyn_mem_temporary_alloc(i); - CHECK(p); + ASSERT_TRUE(p); ns_dyn_mem_free(p); - CHECK(!heap_have_failed()); + ASSERT_EQ(false, heap_have_failed()); } - CHECK(!heap_have_failed()); - CHECK(info.heap_sector_alloc_cnt == 0); + ASSERT_EQ(false, heap_have_failed()); + ASSERT_EQ(info.heap_sector_alloc_cnt, 0); free(heap); } -TEST(dynmem, double_free) +TEST_F(dynmem_test, double_free) { uint16_t size = 1000; mem_stat_t info; uint8_t *heap = (uint8_t *)malloc(size); void *p; - CHECK(NULL != heap); + ASSERT_TRUE(heap); reset_heap_error(); ns_dyn_mem_init(heap, size, &heap_fail_callback, &info); - CHECK(!heap_have_failed()); + ASSERT_EQ(false, heap_have_failed()); p = ns_dyn_mem_alloc(100); - CHECK(p); + ASSERT_TRUE(p); ns_dyn_mem_free(p); - CHECK(!heap_have_failed()); + ASSERT_EQ(false, heap_have_failed()); ns_dyn_mem_free(p); - CHECK(heap_have_failed()); - CHECK(NS_DYN_MEM_DOUBLE_FREE == current_heap_error); + ASSERT_EQ(true, heap_have_failed()); + ASSERT_EQ(NS_DYN_MEM_DOUBLE_FREE, current_heap_error); free(heap); } -TEST(dynmem, middle_free) +TEST_F(dynmem_test, middle_free) { uint16_t size = 1000; mem_stat_t info; uint8_t *heap = (uint8_t *)malloc(size); void *p[3]; - CHECK(NULL != heap); + ASSERT_TRUE(heap); reset_heap_error(); ns_dyn_mem_init(heap, size, &heap_fail_callback, &info); - CHECK(!heap_have_failed()); + ASSERT_EQ(false, heap_have_failed()); for (int i = 0; i < 3; i++) { p[i] = ns_dyn_mem_temporary_alloc(100); - CHECK(p); + ASSERT_TRUE(p); } ns_dyn_mem_free(p[1]); - CHECK(!heap_have_failed()); + ASSERT_EQ(false, heap_have_failed()); ns_dyn_mem_free(p[0]); - CHECK(!heap_have_failed()); + ASSERT_EQ(false, heap_have_failed()); ns_dyn_mem_free(p[2]); - CHECK(!heap_have_failed()); + ASSERT_EQ(false, heap_have_failed()); free(heap); } -TEST(dynmem, over_by_one) +TEST_F(dynmem_test, over_by_one) { uint16_t size = 1000; mem_stat_t info; uint8_t *heap = (uint8_t *)malloc(size); uint8_t *p; - CHECK(NULL != heap); + ASSERT_TRUE(heap); reset_heap_error(); ns_dyn_mem_init(heap, size, &heap_fail_callback, &info); - CHECK(!heap_have_failed()); + ASSERT_EQ(false, heap_have_failed()); p = (uint8_t *)ns_dyn_mem_alloc(100); - CHECK(p); + ASSERT_TRUE(p); p[100] = 0xff; ns_dyn_mem_free(p); - CHECK(heap_have_failed()); - CHECK(NS_DYN_MEM_HEAP_SECTOR_CORRUPTED == current_heap_error); + ASSERT_EQ(true, heap_have_failed()); + ASSERT_EQ(NS_DYN_MEM_HEAP_SECTOR_CORRUPTED, current_heap_error); free(heap); } -TEST(dynmem, not_from_this_heap) +TEST_F(dynmem_test, not_from_this_heap) { uint16_t size = 1000; mem_stat_t info; uint8_t *heap = (uint8_t *)malloc(size); uint8_t *p; - CHECK(NULL != heap); + ASSERT_TRUE(heap); reset_heap_error(); ns_dyn_mem_init(heap, size, &heap_fail_callback, &info); - CHECK(!heap_have_failed()); + ASSERT_EQ(false, heap_have_failed()); p = (uint8_t *)ns_dyn_mem_alloc(100); - CHECK(p); + ASSERT_TRUE(p); ns_dyn_mem_free(&heap[-1]); - CHECK(heap_have_failed()); - CHECK(NS_DYN_MEM_POINTER_NOT_VALID == current_heap_error); + ASSERT_EQ(true, heap_have_failed()); + ASSERT_EQ(NS_DYN_MEM_POINTER_NOT_VALID, current_heap_error); reset_heap_error(); ns_dyn_mem_free(&heap[1001]); - CHECK(heap_have_failed()); - CHECK(NS_DYN_MEM_POINTER_NOT_VALID == current_heap_error); + ASSERT_EQ(true, heap_have_failed()); + ASSERT_EQ(NS_DYN_MEM_POINTER_NOT_VALID, current_heap_error); free(heap); } -TEST(dynmem, free_on_empty_heap) +TEST_F(dynmem_test, free_on_empty_heap) { uint16_t size = 1000; mem_stat_t info; uint8_t *heap = (uint8_t *)malloc(size); - uint8_t *p; - CHECK(NULL != heap); + ASSERT_TRUE(heap); reset_heap_error(); ns_dyn_mem_init(heap, size, &heap_fail_callback, &info); - CHECK(!heap_have_failed()); + ASSERT_EQ(false, heap_have_failed()); ns_dyn_mem_free(&heap[1]); - CHECK(heap_have_failed()); - CHECK(NS_DYN_MEM_POINTER_NOT_VALID == current_heap_error); + ASSERT_EQ(true, heap_have_failed()); + ASSERT_EQ(NS_DYN_MEM_POINTER_NOT_VALID, current_heap_error); free(heap); } -TEST(dynmem, not_negative_stats) +TEST_F(dynmem_test, not_negative_stats) { uint16_t size = 1000; mem_stat_t info; uint8_t *heap = (uint8_t *)malloc(size); void *p; - CHECK(NULL != heap); + ASSERT_TRUE(heap); reset_heap_error(); ns_dyn_mem_init(heap, size, &heap_fail_callback, &info); - CHECK(!heap_have_failed()); - CHECK(info.heap_sector_allocated_bytes == 0); + ASSERT_EQ(false, heap_have_failed()); + ASSERT_EQ(info.heap_sector_allocated_bytes, 0); ns_dyn_mem_alloc(8); p = ns_dyn_mem_alloc(8); ns_dyn_mem_alloc(8); - CHECK(info.heap_sector_allocated_bytes >= 24); + ASSERT_GE(info.heap_sector_allocated_bytes, 24); int16_t last_value = info.heap_sector_allocated_bytes; ns_dyn_mem_free(p); - CHECK(info.heap_sector_allocated_bytes >= 16); - CHECK(info.heap_sector_allocated_bytes < last_value); + ASSERT_GE(info.heap_sector_allocated_bytes, 16); + ASSERT_LT(info.heap_sector_allocated_bytes, last_value); last_value = info.heap_sector_allocated_bytes; for (int i = 0; i < 10; i++) { p = ns_dyn_mem_alloc(1); ns_dyn_mem_free(p); } - CHECK(info.heap_sector_allocated_bytes == last_value); + ASSERT_EQ(info.heap_sector_allocated_bytes, last_value); free(heap); } -TEST(dynmem, test_invalid_pointer_freed) +TEST_F(dynmem_test, test_invalid_pointer_freed) { uint16_t size = 1000; uint8_t *heap = (uint8_t *)malloc(size); - CHECK(NULL != heap); + ASSERT_TRUE(heap); reset_heap_error(); ns_dyn_mem_init(heap, size, &heap_fail_callback, NULL); int *ptr = (int *)ns_dyn_mem_alloc(4); @@ -702,20 +697,19 @@ TEST(dynmem, test_invalid_pointer_freed) *ptr = 16; ptr++; ns_dyn_mem_free(ptr); - CHECK(NS_DYN_MEM_POINTER_NOT_VALID == current_heap_error); + ASSERT_EQ(NS_DYN_MEM_POINTER_NOT_VALID, current_heap_error); free(heap); } -TEST(dynmem, test_merge_corrupted_previous_block) +TEST_F(dynmem_test, test_merge_corrupted_previous_block) { uint16_t size = 1000; uint8_t *heap = (uint8_t *)malloc(size); - uint8_t *p; - CHECK(NULL != heap); + ASSERT_TRUE(heap); reset_heap_error(); ns_dyn_mem_init(heap, size, &heap_fail_callback, NULL); - CHECK(!heap_have_failed()); + ASSERT_EQ(false, heap_have_failed()); int *ptr = (int *)ns_dyn_mem_alloc(4); int *ptr2 = (int *)ns_dyn_mem_alloc(4); @@ -724,20 +718,19 @@ TEST(dynmem, test_merge_corrupted_previous_block) *ptr = -2; ns_dyn_mem_free(ptr2); - CHECK(NS_DYN_MEM_HEAP_SECTOR_CORRUPTED == current_heap_error); + ASSERT_EQ(NS_DYN_MEM_HEAP_SECTOR_CORRUPTED, current_heap_error); free(heap); } -TEST(dynmem, test_free_corrupted_next_block) +TEST_F(dynmem_test, test_free_corrupted_next_block) { uint16_t size = 1000; uint8_t *heap = (uint8_t *)malloc(size); - uint8_t *p; - CHECK(NULL != heap); + ASSERT_TRUE(heap); reset_heap_error(); ns_dyn_mem_init(heap, size, &heap_fail_callback, NULL); - CHECK(!heap_have_failed()); + ASSERT_EQ(false, heap_have_failed()); int *ptr = (int *)ns_dyn_mem_temporary_alloc(4); int *ptr2 = (int *)ns_dyn_mem_temporary_alloc(4); @@ -746,15 +739,15 @@ TEST(dynmem, test_free_corrupted_next_block) *ptr = -2; ns_dyn_mem_free(ptr2); - CHECK(NS_DYN_MEM_HEAP_SECTOR_CORRUPTED == current_heap_error); + ASSERT_EQ(NS_DYN_MEM_HEAP_SECTOR_CORRUPTED, current_heap_error); free(heap); } //NOTE! This test must be last! -TEST(dynmem, uninitialized_test) +TEST_F(dynmem_test, uninitialized_test) { void *p = ns_dyn_mem_alloc(4); ns_dyn_mem_free(p); - CHECK(p == NULL); + ASSERT_EQ(NULL, p); } diff --git a/test/libService/unittest/nsdynmem/error_callback.c b/test/nsdynmem/error_callback.c similarity index 100% rename from test/libService/unittest/nsdynmem/error_callback.c rename to test/nsdynmem/error_callback.c diff --git a/test/libService/unittest/nsdynmem/error_callback.h b/test/nsdynmem/error_callback.h similarity index 100% rename from test/libService/unittest/nsdynmem/error_callback.h rename to test/nsdynmem/error_callback.h diff --git a/test/nsnvmhelper/nsnvmhelper_test.cpp b/test/nsnvmhelper/nsnvmhelper_test.cpp new file mode 100644 index 000000000000..e9fc8463d248 --- /dev/null +++ b/test/nsnvmhelper/nsnvmhelper_test.cpp @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2016, 2020, Pelion and affiliates. + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "gtest/gtest.h" +#include "test_ns_nvm_helper.h" + +class nsnvmhelper_test : public testing::Test { +protected: + void SetUp() + { + } + + void TearDown() + { + } +}; + +TEST_F(nsnvmhelper_test, test_ns_nvm_helper) +{ + ASSERT_EQ(true, test_ns_nvm_helper_write()); + ASSERT_EQ(true, test_ns_nvm_helper_delete()); + ASSERT_EQ(true, test_ns_nvm_helper_read()); + ASSERT_EQ(true, test_ns_nvm_helper_concurrent_requests()); + ASSERT_EQ(true, test_ns_nvm_helper_platform_error()); + ASSERT_EQ(true, test_ns_nvm_helper_platform_error_in_write()); +} + diff --git a/test/libService/unittest/nsnvmhelper/test_ns_nvm_helper.c b/test/nsnvmhelper/test_ns_nvm_helper.c similarity index 84% rename from test/libService/unittest/nsnvmhelper/test_ns_nvm_helper.c rename to test/nsnvmhelper/test_ns_nvm_helper.c index 160cef795485..d2885ecae521 100644 --- a/test/libService/unittest/nsnvmhelper/test_ns_nvm_helper.c +++ b/test/nsnvmhelper/test_ns_nvm_helper.c @@ -16,6 +16,7 @@ */ #include +#include #include "test_ns_nvm_helper.h" #include "ns_nvm_helper.h" #include "nsdynmemLIB_stub.h" @@ -37,6 +38,8 @@ static void *write_callback_context = NULL; static int delete_callback_status = 0; static void *delete_callback_context = NULL; +extern void test_platform_nvm_api_callback(); + extern void test_platform_nvm_api_set_retval(platform_nvm_status return_value); void test_ns_nvm_helper_write_callback(int status, void *context) @@ -66,28 +69,28 @@ bool test_ns_nvm_helper_write() // test with invalid parameters - callback NULL test_platform_nvm_api_set_retval(PLATFORM_NVM_ERROR); - ret_val = ns_nvm_data_write(NULL, key1, &buf, &buf_len, TEST_NS_NVM_HELPER_CONTEXT1); + ret_val = ns_nvm_data_write(NULL, key1, buf, &buf_len, (void *)TEST_NS_NVM_HELPER_CONTEXT1); if (ret_val == NS_NVM_OK) { return false; } // test with invalid parameters - key NULL test_platform_nvm_api_set_retval(PLATFORM_NVM_ERROR); - ret_val = ns_nvm_data_write(test_ns_nvm_helper_write_callback, NULL, &buf, &buf_len, TEST_NS_NVM_HELPER_CONTEXT1); + ret_val = ns_nvm_data_write(test_ns_nvm_helper_write_callback, NULL, buf, &buf_len, (void *)TEST_NS_NVM_HELPER_CONTEXT1); if (ret_val == NS_NVM_OK) { return false; } // test with invalid parameters - buf NULL test_platform_nvm_api_set_retval(PLATFORM_NVM_ERROR); - ret_val = ns_nvm_data_write(test_ns_nvm_helper_write_callback, key1, NULL, &buf_len, TEST_NS_NVM_HELPER_CONTEXT1); + ret_val = ns_nvm_data_write(test_ns_nvm_helper_write_callback, key1, NULL, &buf_len, (void *)TEST_NS_NVM_HELPER_CONTEXT1); if (ret_val == NS_NVM_OK) { return false; } // test with invalid parameters - buf_len NULL test_platform_nvm_api_set_retval(PLATFORM_NVM_ERROR); - ret_val = ns_nvm_data_write(test_ns_nvm_helper_write_callback, key1, &buf, NULL, TEST_NS_NVM_HELPER_CONTEXT1); + ret_val = ns_nvm_data_write(test_ns_nvm_helper_write_callback, key1, buf, NULL, (void *)TEST_NS_NVM_HELPER_CONTEXT1); if (ret_val == NS_NVM_OK) { return false; } @@ -95,7 +98,7 @@ bool test_ns_nvm_helper_write() // test with valid parameters - memory allocation fails 1 test_platform_nvm_api_set_retval(PLATFORM_NVM_OK); nsdynmemlib_stub.returnCounter = 0; - ret_val = ns_nvm_data_write(test_ns_nvm_helper_write_callback, key1, &buf, &buf_len, TEST_NS_NVM_HELPER_CONTEXT1); + ret_val = ns_nvm_data_write(test_ns_nvm_helper_write_callback, key1, buf, &buf_len, (void *)TEST_NS_NVM_HELPER_CONTEXT1); if (ret_val != NS_NVM_MEMORY) { return false; } @@ -103,7 +106,7 @@ bool test_ns_nvm_helper_write() // test with valid parameters - memory allocation fails 2 test_platform_nvm_api_set_retval(PLATFORM_NVM_OK); nsdynmemlib_stub.returnCounter = 1; - ret_val = ns_nvm_data_write(test_ns_nvm_helper_write_callback, key1, &buf, &buf_len, TEST_NS_NVM_HELPER_CONTEXT1); + ret_val = ns_nvm_data_write(test_ns_nvm_helper_write_callback, key1, buf, &buf_len, (void *)TEST_NS_NVM_HELPER_CONTEXT1); if (ret_val != NS_NVM_MEMORY) { return false; } @@ -111,7 +114,7 @@ bool test_ns_nvm_helper_write() // test with valid parameters - platform_init fails test_platform_nvm_api_set_retval(PLATFORM_NVM_ERROR); nsdynmemlib_stub.returnCounter = 2; - ret_val = ns_nvm_data_write(test_ns_nvm_helper_write_callback, key1, &buf, &buf_len, TEST_NS_NVM_HELPER_CONTEXT1); + ret_val = ns_nvm_data_write(test_ns_nvm_helper_write_callback, key1, buf, &buf_len, (void *)TEST_NS_NVM_HELPER_CONTEXT1); if (ret_val != NS_NVM_ERROR) { return false; } @@ -119,7 +122,7 @@ bool test_ns_nvm_helper_write() // test with valid parameters - OK test_platform_nvm_api_set_retval(PLATFORM_NVM_OK); nsdynmemlib_stub.returnCounter = 2; - ret_val = ns_nvm_data_write(test_ns_nvm_helper_write_callback, key1, &buf, &buf_len, TEST_NS_NVM_HELPER_CONTEXT1); + ret_val = ns_nvm_data_write(test_ns_nvm_helper_write_callback, key1, buf, &buf_len, (void *)TEST_NS_NVM_HELPER_CONTEXT1); if (ret_val != NS_NVM_OK) { return false; } @@ -136,7 +139,7 @@ bool test_ns_nvm_helper_write() // make flush callback test_platform_nvm_api_callback(); - if (write_callback_status != NS_NVM_OK || write_callback_context != TEST_NS_NVM_HELPER_CONTEXT1) { + if (write_callback_status != NS_NVM_OK || write_callback_context != (void *)TEST_NS_NVM_HELPER_CONTEXT1) { return false; } @@ -152,28 +155,28 @@ bool test_ns_nvm_helper_read() // test with invalid parameters - callback NULL test_platform_nvm_api_set_retval(PLATFORM_NVM_ERROR); - ret_val = ns_nvm_data_read(NULL, key1, &buf, &buf_len, TEST_NS_NVM_HELPER_CONTEXT2); + ret_val = ns_nvm_data_read(NULL, key1, buf, &buf_len, (void *)TEST_NS_NVM_HELPER_CONTEXT2); if (ret_val == NS_NVM_OK) { return false; } // test with invalid parameters - key NULL test_platform_nvm_api_set_retval(PLATFORM_NVM_ERROR); - ret_val = ns_nvm_data_read(test_ns_nvm_helper_read_callback, NULL, &buf, &buf_len, TEST_NS_NVM_HELPER_CONTEXT2); + ret_val = ns_nvm_data_read(test_ns_nvm_helper_read_callback, NULL, buf, &buf_len, (void *)TEST_NS_NVM_HELPER_CONTEXT2); if (ret_val == NS_NVM_OK) { return false; } // test with invalid parameters - buf NULL test_platform_nvm_api_set_retval(PLATFORM_NVM_ERROR); - ret_val = ns_nvm_data_read(test_ns_nvm_helper_read_callback, key1, NULL, &buf_len, TEST_NS_NVM_HELPER_CONTEXT2); + ret_val = ns_nvm_data_read(test_ns_nvm_helper_read_callback, key1, NULL, &buf_len, (void *)TEST_NS_NVM_HELPER_CONTEXT2); if (ret_val == NS_NVM_OK) { return false; } // test with invalid parameters - buf_len NULL test_platform_nvm_api_set_retval(PLATFORM_NVM_ERROR); - ret_val = ns_nvm_data_read(test_ns_nvm_helper_read_callback, key1, &buf, NULL, TEST_NS_NVM_HELPER_CONTEXT2); + ret_val = ns_nvm_data_read(test_ns_nvm_helper_read_callback, key1, buf, NULL, (void *)TEST_NS_NVM_HELPER_CONTEXT2); if (ret_val == NS_NVM_OK) { return false; } @@ -181,7 +184,7 @@ bool test_ns_nvm_helper_read() // test with valid parameters - memory allocation fails 1 test_platform_nvm_api_set_retval(PLATFORM_NVM_OK); nsdynmemlib_stub.returnCounter = 0; - ret_val = ns_nvm_data_read(test_ns_nvm_helper_read_callback, key1, &buf, &buf_len, TEST_NS_NVM_HELPER_CONTEXT2); + ret_val = ns_nvm_data_read(test_ns_nvm_helper_read_callback, key1, buf, &buf_len, (void *)TEST_NS_NVM_HELPER_CONTEXT2); if (ret_val != NS_NVM_MEMORY) { return false; } @@ -189,7 +192,7 @@ bool test_ns_nvm_helper_read() // test with valid parameters - read ok test_platform_nvm_api_set_retval(PLATFORM_NVM_OK); nsdynmemlib_stub.returnCounter = 1; - ret_val = ns_nvm_data_read(test_ns_nvm_helper_read_callback, key1, &buf, &buf_len, TEST_NS_NVM_HELPER_CONTEXT2); + ret_val = ns_nvm_data_read(test_ns_nvm_helper_read_callback, key1, buf, &buf_len, (void *)TEST_NS_NVM_HELPER_CONTEXT2); if (ret_val != NS_NVM_OK) { return false; } @@ -197,7 +200,7 @@ bool test_ns_nvm_helper_read() // make read callback test_platform_nvm_api_callback(); - if (read_callback_status != NS_NVM_OK || read_callback_context != TEST_NS_NVM_HELPER_CONTEXT2) { + if (read_callback_status != NS_NVM_OK || read_callback_context != (void *)TEST_NS_NVM_HELPER_CONTEXT2) { return false; } @@ -213,14 +216,14 @@ bool test_ns_nvm_helper_delete() // test with invalid parameters - callback NULL test_platform_nvm_api_set_retval(PLATFORM_NVM_ERROR); - ret_val = ns_nvm_key_delete(NULL, key1, TEST_NS_NVM_HELPER_CONTEXT3); + ret_val = ns_nvm_key_delete(NULL, key1, (void *)TEST_NS_NVM_HELPER_CONTEXT3); if (ret_val == NS_NVM_OK) { return false; } // test with invalid parameters - key NULL test_platform_nvm_api_set_retval(PLATFORM_NVM_ERROR); - ret_val = ns_nvm_key_delete(test_ns_nvm_helper_delete_callback, NULL, TEST_NS_NVM_HELPER_CONTEXT3); + ret_val = ns_nvm_key_delete(test_ns_nvm_helper_delete_callback, NULL, (void *)TEST_NS_NVM_HELPER_CONTEXT3); if (ret_val == NS_NVM_OK) { return false; } @@ -228,7 +231,7 @@ bool test_ns_nvm_helper_delete() // test with valid parameters - memory allocation fails test_platform_nvm_api_set_retval(PLATFORM_NVM_ERROR); nsdynmemlib_stub.returnCounter = 0; - ret_val = ns_nvm_key_delete(test_ns_nvm_helper_delete_callback, key1, TEST_NS_NVM_HELPER_CONTEXT3); + ret_val = ns_nvm_key_delete(test_ns_nvm_helper_delete_callback, key1, (void *)TEST_NS_NVM_HELPER_CONTEXT3); if (ret_val != NS_NVM_MEMORY) { return false; } @@ -236,7 +239,7 @@ bool test_ns_nvm_helper_delete() // test with valid parameters - OK test_platform_nvm_api_set_retval(PLATFORM_NVM_OK); nsdynmemlib_stub.returnCounter = 1; - ret_val = ns_nvm_key_delete(test_ns_nvm_helper_delete_callback, key1, TEST_NS_NVM_HELPER_CONTEXT3); + ret_val = ns_nvm_key_delete(test_ns_nvm_helper_delete_callback, key1, (void *)TEST_NS_NVM_HELPER_CONTEXT3); if (ret_val != NS_NVM_OK) { return false; } @@ -247,7 +250,7 @@ bool test_ns_nvm_helper_delete() // make flush callback test_platform_nvm_api_callback(); - if (delete_callback_status != NS_NVM_OK || delete_callback_context != TEST_NS_NVM_HELPER_CONTEXT3) { + if (delete_callback_status != NS_NVM_OK || delete_callback_context != (void *)TEST_NS_NVM_HELPER_CONTEXT3) { return false; } @@ -268,7 +271,7 @@ bool test_ns_nvm_helper_concurrent_requests() // read ok test_platform_nvm_api_set_retval(PLATFORM_NVM_OK); nsdynmemlib_stub.returnCounter = 1; - ret_val = ns_nvm_data_read(test_ns_nvm_helper_read_callback, key1, &buf, &buf_len, TEST_NS_NVM_HELPER_CONTEXT1); + ret_val = ns_nvm_data_read(test_ns_nvm_helper_read_callback, key1, buf, &buf_len, (void *)TEST_NS_NVM_HELPER_CONTEXT1); if (ret_val != NS_NVM_OK) { return false; } @@ -276,14 +279,14 @@ bool test_ns_nvm_helper_concurrent_requests() // write ok test_platform_nvm_api_set_retval(PLATFORM_NVM_OK); nsdynmemlib_stub.returnCounter = 2; - ret_val = ns_nvm_data_write(test_ns_nvm_helper_write_callback, key1, &buf, &buf_len, TEST_NS_NVM_HELPER_CONTEXT2); + ret_val = ns_nvm_data_write(test_ns_nvm_helper_write_callback, key1, buf, &buf_len, (void *)TEST_NS_NVM_HELPER_CONTEXT2); if (ret_val != NS_NVM_OK) { return false; } // delete ok nsdynmemlib_stub.returnCounter = 1; - ret_val = ns_nvm_key_delete(test_ns_nvm_helper_delete_callback, key1, TEST_NS_NVM_HELPER_CONTEXT3); + ret_val = ns_nvm_key_delete(test_ns_nvm_helper_delete_callback, key1, (void *)TEST_NS_NVM_HELPER_CONTEXT3); if (ret_val != NS_NVM_OK) { return false; } @@ -291,7 +294,7 @@ bool test_ns_nvm_helper_concurrent_requests() // Read - should complete first, make callback test_platform_nvm_api_callback(); - if (read_callback_status != NS_NVM_OK || read_callback_context != TEST_NS_NVM_HELPER_CONTEXT1) { + if (read_callback_status != NS_NVM_OK || read_callback_context != (void *)TEST_NS_NVM_HELPER_CONTEXT1) { return false; } @@ -305,12 +308,12 @@ bool test_ns_nvm_helper_concurrent_requests() test_platform_nvm_api_set_retval(PLATFORM_NVM_ERROR); test_platform_nvm_api_callback(); - if (write_callback_status != NS_NVM_ERROR || write_callback_context != TEST_NS_NVM_HELPER_CONTEXT2) { + if (write_callback_status != NS_NVM_ERROR || write_callback_context != (void *)TEST_NS_NVM_HELPER_CONTEXT2) { return false; } // delete callback is called after write because write was failing - if (delete_callback_status != NS_NVM_ERROR || delete_callback_context != TEST_NS_NVM_HELPER_CONTEXT3) { + if (delete_callback_status != NS_NVM_ERROR || delete_callback_context != (void *)TEST_NS_NVM_HELPER_CONTEXT3) { return false; } @@ -331,7 +334,7 @@ bool test_ns_nvm_helper_platform_error() // read request fails directly in platform_nvm_api test_platform_nvm_api_set_retval(PLATFORM_NVM_ERROR); nsdynmemlib_stub.returnCounter = 1; - ret_val = ns_nvm_data_read(test_ns_nvm_helper_read_callback, key1, &buf, &buf_len, TEST_NS_NVM_HELPER_CONTEXT1); + ret_val = ns_nvm_data_read(test_ns_nvm_helper_read_callback, key1, buf, &buf_len, (void *)TEST_NS_NVM_HELPER_CONTEXT1); if (ret_val != NS_NVM_ERROR) { return false; } @@ -339,21 +342,21 @@ bool test_ns_nvm_helper_platform_error() // read request fails in platform_nvm_api callback test_platform_nvm_api_set_retval(PLATFORM_NVM_OK); nsdynmemlib_stub.returnCounter = 1; - ret_val = ns_nvm_data_read(test_ns_nvm_helper_read_callback, key1, &buf, &buf_len, TEST_NS_NVM_HELPER_CONTEXT1); + ret_val = ns_nvm_data_read(test_ns_nvm_helper_read_callback, key1, buf, &buf_len, (void *)TEST_NS_NVM_HELPER_CONTEXT1); if (ret_val != NS_NVM_OK) { return false; } // make read callback test_platform_nvm_api_set_retval(PLATFORM_NVM_KEY_NOT_FOUND); test_platform_nvm_api_callback(); - if (read_callback_status != NS_NVM_DATA_NOT_FOUND || read_callback_context != TEST_NS_NVM_HELPER_CONTEXT1) { + if (read_callback_status != NS_NVM_DATA_NOT_FOUND || read_callback_context != (void *)TEST_NS_NVM_HELPER_CONTEXT1) { return false; } // delete fails in platform api callback test_platform_nvm_api_set_retval(PLATFORM_NVM_OK); nsdynmemlib_stub.returnCounter = 1; - ret_val = ns_nvm_key_delete(test_ns_nvm_helper_delete_callback, key1, TEST_NS_NVM_HELPER_CONTEXT3); + ret_val = ns_nvm_key_delete(test_ns_nvm_helper_delete_callback, key1, (void *)TEST_NS_NVM_HELPER_CONTEXT3); if (ret_val != NS_NVM_OK) { return false; } @@ -361,7 +364,7 @@ bool test_ns_nvm_helper_platform_error() test_platform_nvm_api_set_retval(PLATFORM_NVM_ERROR); // make delete callback test_platform_nvm_api_callback(); - if (delete_callback_status != NS_NVM_ERROR || delete_callback_context != TEST_NS_NVM_HELPER_CONTEXT3) { + if (delete_callback_status != NS_NVM_ERROR || delete_callback_context != (void *)TEST_NS_NVM_HELPER_CONTEXT3) { return false; } @@ -379,14 +382,14 @@ bool test_ns_nvm_helper_platform_error_in_write() // create callback fails test_platform_nvm_api_set_retval(PLATFORM_NVM_OK); nsdynmemlib_stub.returnCounter = 2; - ret_val = ns_nvm_data_write(test_ns_nvm_helper_write_callback, key1, &buf, &buf_len, TEST_NS_NVM_HELPER_CONTEXT1); + ret_val = ns_nvm_data_write(test_ns_nvm_helper_write_callback, key1, buf, &buf_len, (void *)TEST_NS_NVM_HELPER_CONTEXT1); if (ret_val != NS_NVM_OK) { return false; } test_platform_nvm_api_set_retval(PLATFORM_NVM_ERROR); test_platform_nvm_api_callback(); - if (write_callback_status != NS_NVM_ERROR || write_callback_context != TEST_NS_NVM_HELPER_CONTEXT1) { + if (write_callback_status != NS_NVM_ERROR || write_callback_context != (void *)TEST_NS_NVM_HELPER_CONTEXT1) { return false; } @@ -396,7 +399,7 @@ bool test_ns_nvm_helper_platform_error_in_write() // write calback fails test_platform_nvm_api_set_retval(PLATFORM_NVM_OK); nsdynmemlib_stub.returnCounter = 2; - ret_val = ns_nvm_data_write(test_ns_nvm_helper_write_callback, key1, &buf, &buf_len, TEST_NS_NVM_HELPER_CONTEXT1); + ret_val = ns_nvm_data_write(test_ns_nvm_helper_write_callback, key1, buf, &buf_len, (void *)TEST_NS_NVM_HELPER_CONTEXT1); if (ret_val != NS_NVM_OK) { return false; } @@ -407,7 +410,7 @@ bool test_ns_nvm_helper_platform_error_in_write() // make write callback with error test_platform_nvm_api_set_retval(PLATFORM_NVM_ERROR); test_platform_nvm_api_callback(); - if (write_callback_status != NS_NVM_ERROR || write_callback_context != TEST_NS_NVM_HELPER_CONTEXT1) { + if (write_callback_status != NS_NVM_ERROR || write_callback_context != (void *)TEST_NS_NVM_HELPER_CONTEXT1) { return false; } @@ -417,7 +420,7 @@ bool test_ns_nvm_helper_platform_error_in_write() // flush calback fails test_platform_nvm_api_set_retval(PLATFORM_NVM_OK); nsdynmemlib_stub.returnCounter = 2; - ret_val = ns_nvm_data_write(test_ns_nvm_helper_write_callback, key1, &buf, &buf_len, TEST_NS_NVM_HELPER_CONTEXT1); + ret_val = ns_nvm_data_write(test_ns_nvm_helper_write_callback, key1, buf, &buf_len, (void *)TEST_NS_NVM_HELPER_CONTEXT1); if (ret_val != NS_NVM_OK) { return false; } @@ -431,7 +434,7 @@ bool test_ns_nvm_helper_platform_error_in_write() // make flush callback with error test_platform_nvm_api_set_retval(PLATFORM_NVM_ERROR); test_platform_nvm_api_callback(); - if (write_callback_status != NS_NVM_ERROR || write_callback_context != TEST_NS_NVM_HELPER_CONTEXT1) { + if (write_callback_status != NS_NVM_ERROR || write_callback_context != (void *)TEST_NS_NVM_HELPER_CONTEXT1) { return false; } diff --git a/test/libService/unittest/nsnvmhelper/test_ns_nvm_helper.h b/test/nsnvmhelper/test_ns_nvm_helper.h similarity index 100% rename from test/libService/unittest/nsnvmhelper/test_ns_nvm_helper.h rename to test/nsnvmhelper/test_ns_nvm_helper.h diff --git a/test/libService/unittest/stoip6/stoip6test.cpp b/test/stoip6/stoip6_test.cpp similarity index 62% rename from test/libService/unittest/stoip6/stoip6test.cpp rename to test/stoip6/stoip6_test.cpp index 7a9fdacd0a29..d48099cdfaa9 100644 --- a/test/libService/unittest/stoip6/stoip6test.cpp +++ b/test/stoip6/stoip6_test.cpp @@ -14,75 +14,83 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include "CppUTest/TestHarness.h" +#include "gtest/gtest.h" #include "ip6string.h" #include "ipv6_test_values.h" #include #include -TEST_GROUP(stoip6) +class stoip6_test : public testing::Test + { - void setup() { +protected: + void SetUp(void) + { + memset(buf, 0, 40); } - void teardown() { + void TearDown(void) + { + i++; } + char buf[40]; + int i = 0; }; -TEST(stoip6, ZeroAddress) +TEST_F(stoip6_test, ZeroAddress) { for (int i = 0; ipv6_test_values[i].addr; i++) { uint8_t ip[16]; - char *addr = ipv6_test_values[i].addr; + const char *addr = ipv6_test_values[i].addr; stoip6(addr, strlen(addr), ip); - CHECK(0 == memcmp(ip, ipv6_test_values[i].bin, 16)); + ASSERT_EQ(0, memcmp(ip, ipv6_test_values[i].bin, 16)); } } -TEST(stoip6, TooShort) +TEST_F(stoip6_test, TooShort) { - char *addr = "FFFF:FFFF:"; + const char *addr = "FFFF:FFFF:"; uint8_t ip[16]; uint8_t correct[16] = {0}; // This should stop parsing when too short address given. // Despite partial parsing, the entire buffer should be filled with zeroes - CHECK(false == stoip6(addr, strlen(addr), ip)); - CHECK(0 == memcmp(ip, correct, 16)); + ASSERT_EQ(false, stoip6(addr, strlen(addr), ip)); + ASSERT_EQ(0, memcmp(ip, correct, 16)); } -TEST(stoip6, TooLongString) +TEST_F(stoip6_test, TooLongString) { // String len must be less than 40, otherwise not valid - char *addr = "FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:"; + const char *addr = "FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:"; uint8_t ip[16] = {0}; uint8_t correct[16] = {0}; // This should not fill anything, too long string. // This is basically only validation we do - CHECK(false == stoip6(addr, strlen(addr), ip)); - CHECK(0 == memcmp(ip, correct, 16)); + ASSERT_EQ(false, stoip6(addr, strlen(addr), ip)); + ASSERT_EQ(0, memcmp(ip, correct, 16)); } -TEST(stoip6, TooManyFields) +TEST_F(stoip6_test, TooManyFields) { // String len must be less than 40 - char *addr = "FF:FF:FF:FF:FF:FF:FFFF:FFFF:FFFF:FFFF:"; + const char *addr = "FF:FF:FF:FF:FF:FF:FFFF:FFFF:FFFF:FFFF:"; uint8_t ip[16] = {0}; uint8_t correct[16] = {0}; - CHECK(false == stoip6(addr, strlen(addr), ip)); - CHECK(0 == memcmp(ip, correct, 16)); + ASSERT_EQ(false, stoip6(addr, strlen(addr), ip)); + ASSERT_EQ(0, memcmp(ip, correct, 16)); } -TEST(stoip6, Prefixlen) +TEST_F(stoip6_test, Prefixlen) { - CHECK(0 == sipv6_prefixlength("::")); - CHECK(64 == sipv6_prefixlength("::/64")); + ASSERT_EQ(0, sipv6_prefixlength("::")); + ASSERT_EQ(64, sipv6_prefixlength("::/64")); } // This test revealed a off-by-one error in stoip6() when the code was ran under valgrind. // The IP address is copied from the test_2duts_ping -test, where the valgrind message // was originally spotted. -TEST(stoip6, RegressionTestForOffByOne) +TEST_F(stoip6_test, RegressionTestForOffByOne) { const char *sourceAddr = "fd00:db8::643f:f54a:ec29:cdbb"; @@ -95,14 +103,14 @@ TEST(stoip6, RegressionTestForOffByOne) 0x64, 0x3f, 0xf5, 0x4a, 0xec, 0x29, 0xcd, 0xbb }; - CHECK(true == stoip6(sourceTemp, sourceTempLen, ip)); - CHECK(0 == memcmp(ip, correct, 16)); + ASSERT_EQ(true, stoip6(sourceTemp, sourceTempLen, ip)); + ASSERT_EQ(0, memcmp(ip, correct, 16)); free(sourceTemp); } // Test various illegal formats to ensure proper rejection -TEST(stoip6, InvalidAddresses) +TEST_F(stoip6_test, InvalidAddresses) { uint8_t ip[16]; uint8_t correct[16] = {0}; @@ -114,8 +122,8 @@ TEST(stoip6, InvalidAddresses) }; for (uint8_t i = 0; i < 3; ++i) { - CHECK(false == stoip6(invalidArray[i], strlen(invalidArray[i]), ip)); - CHECK(0 == memcmp(ip, correct, 16)); + ASSERT_EQ(false, stoip6(invalidArray[i], strlen(invalidArray[i]), ip)); + ASSERT_EQ(0, memcmp(ip, correct, 16)); } } @@ -153,84 +161,70 @@ const uint8_t hex_addr[][16] = { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, }; -char buf[40]; -int i = 0; - -TEST_GROUP(stoip6_2) -{ - void setUp(void) { - memset(buf, 0, 40); - } - - void tearDown(void) { - i++; - } -}; - /* Unity test code starts */ -TEST(stoip6_2, test_2_1) +TEST_F(stoip6_test, test_2_1) { i = 0; - CHECK(true == stoip6(string_addr[i], strlen(string_addr[i]), buf)); - CHECK(0 == memcmp(hex_addr[i], buf, strlen(buf))); + ASSERT_EQ(true, stoip6(string_addr[i], strlen(string_addr[i]), buf)); + ASSERT_EQ(0, memcmp(hex_addr[i], buf, strlen(buf))); } -TEST(stoip6_2, test_2_2) +TEST_F(stoip6_test, test_2_2) { - CHECK(true == stoip6(string_addr[i], strlen(string_addr[i]), buf)); - CHECK(0 == memcmp(hex_addr[i], buf, strlen(buf))); + ASSERT_EQ(true, stoip6(string_addr[i], strlen(string_addr[i]), buf)); + ASSERT_EQ(0, memcmp(hex_addr[i], buf, strlen(buf))); } -TEST(stoip6_2, test_2_3) +TEST_F(stoip6_test, test_2_3) { - CHECK(true == stoip6(string_addr[i], strlen(string_addr[i]), buf)); - CHECK(0 == memcmp(hex_addr[i], buf, strlen(buf))); + ASSERT_EQ(true, stoip6(string_addr[i], strlen(string_addr[i]), buf)); + ASSERT_EQ(0, memcmp(hex_addr[i], buf, strlen(buf))); } -TEST(stoip6_2, test_2_4) +TEST_F(stoip6_test, test_2_4) { - CHECK(true == stoip6(string_addr[i], strlen(string_addr[i]), buf)); - CHECK(0 == memcmp(hex_addr[i], buf, strlen(buf))); + ASSERT_EQ(true, stoip6(string_addr[i], strlen(string_addr[i]), buf)); + ASSERT_EQ(0, memcmp(hex_addr[i], buf, strlen(buf))); } -TEST(stoip6_2, test_2_5) +TEST_F(stoip6_test, test_2_5) { - CHECK(true == stoip6(string_addr[i], strlen(string_addr[i]), buf)); - CHECK(0 == memcmp(hex_addr[i], buf, strlen(buf))); + ASSERT_EQ(true, stoip6(string_addr[i], strlen(string_addr[i]), buf)); + ASSERT_EQ(0, memcmp(hex_addr[i], buf, strlen(buf))); } -TEST(stoip6_2, test_2_6) +TEST_F(stoip6_test, test_2_6) { - CHECK(true == stoip6(string_addr[i], strlen(string_addr[i]), buf)); - CHECK(0 == memcmp(hex_addr[i], buf, strlen(buf))); + ASSERT_EQ(true, stoip6(string_addr[i], strlen(string_addr[i]), buf)); + ASSERT_EQ(0, memcmp(hex_addr[i], buf, strlen(buf))); } -TEST(stoip6_2, test_2_7) +TEST_F(stoip6_test, test_2_7) { - CHECK(true == stoip6(string_addr[i], strlen(string_addr[i]), buf)); - CHECK(0 == memcmp(hex_addr[i], buf, strlen(buf))); + ASSERT_EQ(true, stoip6(string_addr[i], strlen(string_addr[i]), buf)); + ASSERT_EQ(0, memcmp(hex_addr[i], buf, strlen(buf))); } -TEST(stoip6_2, test_2_8) +TEST_F(stoip6_test, test_2_8) { - CHECK(true == stoip6(string_addr[i], strlen(string_addr[i]), buf)); - CHECK(0 == memcmp(hex_addr[i], buf, strlen(buf))); + ASSERT_EQ(true, stoip6(string_addr[i], strlen(string_addr[i]), buf)); + ASSERT_EQ(0, memcmp(hex_addr[i], buf, strlen(buf))); } -TEST(stoip6_2, test_2_9) +TEST_F(stoip6_test, test_2_9) { - CHECK(true == stoip6(string_addr[i], strlen(string_addr[i]), buf)); - CHECK(0 == memcmp(hex_addr[i], buf, strlen(buf))); + ASSERT_EQ(true, stoip6(string_addr[i], strlen(string_addr[i]), buf)); + ASSERT_EQ(0, memcmp(hex_addr[i], buf, strlen(buf))); } -TEST(stoip6_2, test_2_10) +TEST_F(stoip6_test, test_2_10) { - CHECK(true == stoip6(string_addr[i], strlen(string_addr[i]), buf)); - CHECK(0 == memcmp(hex_addr[i], buf, 16)); + ASSERT_EQ(true, stoip6(string_addr[i], strlen(string_addr[i]), buf)); + ASSERT_EQ(0, memcmp(hex_addr[i], buf, 16)); } -TEST(stoip6_2, test_2_11) +TEST_F(stoip6_test, test_2_11) { - CHECK(true == stoip6(string_addr[i], strlen(string_addr[i]), buf)); - CHECK(0 == memcmp(hex_addr[i], buf, 16)); + ASSERT_EQ(true, stoip6(string_addr[i], strlen(string_addr[i]), buf)); + ASSERT_EQ(0, memcmp(hex_addr[i], buf, 16)); } -TEST(stoip6_2, test_2_12) +TEST_F(stoip6_test, test_2_12) { - CHECK(true == stoip6(string_addr[i], strlen(string_addr[i]), buf)); - CHECK(0 == memcmp(hex_addr[i], buf, 16)); + ASSERT_EQ(true, stoip6(string_addr[i], strlen(string_addr[i]), buf)); + ASSERT_EQ(0, memcmp(hex_addr[i], buf, 16)); } /***********************************************************/ @@ -264,16 +258,7 @@ const uint8_t hex_prefix_addr[][16] = { const int_fast16_t prefix_len_tbl[] = {64, 60, 48, 0, 99, 0, -1, -1, -1}; const int prefix_status_tbl[] = {0, 0, 0, 0, 0, 0, 0, -1, -1}; -TEST_GROUP(stoip6_3) -{ - void setup() { - } - - void teardown() { - } -}; - -TEST(stoip6_3, stoip6_prefix_test) +TEST_F(stoip6_test, stoip6_prefix_test) { for (int i = 0; i < 9; i++) { uint8_t ip[16]; @@ -282,10 +267,10 @@ TEST(stoip6_3, stoip6_prefix_test) const char *addr = &string_prefix_addr[i][0]; result = stoip6_prefix(addr, ip, &prefix_len); - CHECK(result == prefix_status_tbl[i]); + ASSERT_EQ(result, prefix_status_tbl[i]); if (result == 0) { - CHECK(0 == memcmp(ip, &hex_prefix_addr[i][0], 16)); - CHECK(prefix_len == prefix_len_tbl[i]) + ASSERT_EQ(0, memcmp(ip, &hex_prefix_addr[i][0], 16)); + ASSERT_EQ(prefix_len, prefix_len_tbl[i]); } } } diff --git a/test/libService/unittest/stubs/common_functions_stub.c b/test/stubs/common_functions_stub.c similarity index 100% rename from test/libService/unittest/stubs/common_functions_stub.c rename to test/stubs/common_functions_stub.c diff --git a/test/libService/unittest/stubs/ip6tos_stub.c b/test/stubs/ip6tos_stub.c similarity index 100% rename from test/libService/unittest/stubs/ip6tos_stub.c rename to test/stubs/ip6tos_stub.c diff --git a/test/libService/unittest/stubs/ip6tos_stub.h b/test/stubs/ip6tos_stub.h similarity index 100% rename from test/libService/unittest/stubs/ip6tos_stub.h rename to test/stubs/ip6tos_stub.h diff --git a/test/libService/unittest/stubs/ipv6_test_values.h b/test/stubs/ipv6_test_values.h similarity index 99% rename from test/libService/unittest/stubs/ipv6_test_values.h rename to test/stubs/ipv6_test_values.h index f409241f5298..a262c47b8f32 100644 --- a/test/libService/unittest/stubs/ipv6_test_values.h +++ b/test/stubs/ipv6_test_values.h @@ -20,7 +20,7 @@ #include struct ip6_addresses_and_its_binary_form_t { - char *addr; + const char *addr; uint8_t bin[16]; } ipv6_test_values[] = { { "2001:db8::1:0:0:1", { 0x20, 0x01, 0xd, 0xb8, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1 }}, diff --git a/test/libService/unittest/stubs/ns_list_stub.c b/test/stubs/ns_list_stub.c similarity index 100% rename from test/libService/unittest/stubs/ns_list_stub.c rename to test/stubs/ns_list_stub.c diff --git a/test/libService/unittest/stubs/nsdynmemLIB_stub.c b/test/stubs/nsdynmemLIB_stub.c similarity index 98% rename from test/libService/unittest/stubs/nsdynmemLIB_stub.c rename to test/stubs/nsdynmemLIB_stub.c index 4643a1a697ab..7a108ae36237 100644 --- a/test/libService/unittest/stubs/nsdynmemLIB_stub.c +++ b/test/stubs/nsdynmemLIB_stub.c @@ -18,6 +18,7 @@ #include "nsdynmemLIB_stub.h" #include #include +#include #include #include "platform/arm_hal_interrupt.h" #ifdef STANDARD_MALLOC diff --git a/test/libService/unittest/stubs/nsdynmemLIB_stub.h b/test/stubs/nsdynmemLIB_stub.h similarity index 100% rename from test/libService/unittest/stubs/nsdynmemLIB_stub.h rename to test/stubs/nsdynmemLIB_stub.h diff --git a/test/libService/unittest/stubs/platform_critical.c b/test/stubs/platform_critical.c similarity index 100% rename from test/libService/unittest/stubs/platform_critical.c rename to test/stubs/platform_critical.c diff --git a/test/libService/unittest/stubs/platform_nvm_stub.c b/test/stubs/platform_nvm_stub.c similarity index 100% rename from test/libService/unittest/stubs/platform_nvm_stub.c rename to test/stubs/platform_nvm_stub.c