From 0e667b8e031f8b5a1b6187bbfa4d4007ce587688 Mon Sep 17 00:00:00 2001 From: Yakun Xu Date: Fri, 10 Feb 2023 02:19:01 +0800 Subject: [PATCH] [test] use cmake to run unit tests (#8724) This commit migrates unit tests to cmake. * build unit tests with cmake * add missing tests in cmake * use ctest * add platform udp stubs for test platform * skip some static_assert with gcc-4 --- .github/workflows/unit.yml | 66 +++++ CMakeLists.txt | 5 +- configure.ac | 1 - script/check-scan-build | 1 + script/package | 1 + src/lib/spinel/CMakeLists.txt | 8 + src/lib/spinel/Makefile.am | 12 - src/lib/url/CMakeLists.txt | 11 + src/lib/url/Makefile.am | 17 -- src/posix/platform/CMakeLists.txt | 15 ++ src/posix/platform/Makefile.am | 19 -- tests/CMakeLists.txt | 6 +- tests/Makefile.am | 5 - tests/unit/CMakeLists.txt | 96 +++++++ tests/unit/Makefile.am | 404 ----------------------------- tests/unit/test_binary_search.cpp | 3 + tests/unit/test_platform.cpp | 60 +++++ tests/unit/test_spinel_encoder.cpp | 12 +- tests/unit/test_string.cpp | 3 + 19 files changed, 273 insertions(+), 472 deletions(-) delete mode 100644 tests/unit/Makefile.am diff --git a/.github/workflows/unit.yml b/.github/workflows/unit.yml index 8df8e9243..fa5be3fb6 100644 --- a/.github/workflows/unit.yml +++ b/.github/workflows/unit.yml @@ -60,3 +60,69 @@ jobs: run: make -C third_party/tcplp/lib/test/ - name: Run run: third_party/tcplp/lib/test/test_all + + unit-tests: + runs-on: ubuntu-20.04 + steps: + - name: Harden Runner + uses: step-security/harden-runner@18bf8ad2ca49c14cbb28b91346d626ccfb00c518 # v2.1.0 + with: + egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs + + - uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0 + with: + submodules: true + - name: Bootstrap + run: | + sudo rm /etc/apt/sources.list.d/* && sudo apt-get update + sudo apt-get --no-install-recommends install -y ninja-build + - name: Build Simulation + run: ./script/cmake-build simulation + - name: Test Simulation + run: cd build/simulation && ninja test + - name: Build POSIX + run: ./script/cmake-build posix + - name: Test POSIX + run: cd build/posix && ninja test + + upload-coverage: + needs: + - unittests + runs-on: ubuntu-20.04 + steps: + - name: Harden Runner + uses: step-security/harden-runner@18bf8ad2ca49c14cbb28b91346d626ccfb00c518 # v2.1.0 + with: + egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs + + - uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0 + with: + submodules: true + - name: Bootstrap + run: | + sudo apt-get --no-install-recommends install -y lcov + - uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2 + with: + path: coverage/ + - name: Combine Coverage + run: | + script/test combine_coverage + - name: Upload Coverage + uses: codecov/codecov-action@d9f34f8cd5cb3b3eb79b3e4b5dae3a16df499a70 # v3.1.1 + with: + files: final.info + fail_ci_if_error: true + + delete-coverage-artifacts: + needs: upload-coverage + runs-on: ubuntu-20.04 + steps: + - name: Harden Runner + uses: step-security/harden-runner@18bf8ad2ca49c14cbb28b91346d626ccfb00c518 # v2.1.0 + with: + egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs + + - uses: geekyeggo/delete-artifact@54ab544f12cdb7b71613a16a2b5a37a9ade990af # v2.0.0 + with: + name: cov-* + useGlob: true diff --git a/CMakeLists.txt b/CMakeLists.txt index 84b90d8b6..993d886e2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -33,6 +33,7 @@ file(READ .default-version OT_DEFAULT_VERSION) string(STRIP ${OT_DEFAULT_VERSION} OT_DEFAULT_VERSION) project(openthread VERSION ${OT_DEFAULT_VERSION}) +include(CTest) option(OT_BUILD_EXECUTABLES "Build executables" ON) option(OT_COVERAGE "enable coverage" OFF) @@ -204,10 +205,6 @@ endif() add_subdirectory(src) add_subdirectory(third_party EXCLUDE_FROM_ALL) -if(OT_PLATFORM STREQUAL "simulation") - enable_testing() -endif() - add_subdirectory(tests) add_subdirectory(tools) diff --git a/configure.ac b/configure.ac index 5ee4e4ad7..798949d6f 100644 --- a/configure.ac +++ b/configure.ac @@ -1031,7 +1031,6 @@ tests/Makefile tests/fuzz/Makefile tests/scripts/Makefile tests/scripts/thread-cert/Makefile -tests/unit/Makefile doc/Makefile ]) diff --git a/script/check-scan-build b/script/check-scan-build index c93755b56..b126d1719 100755 --- a/script/check-scan-build +++ b/script/check-scan-build @@ -33,6 +33,7 @@ OT_SRCDIR="$(pwd)" readonly OT_SRCDIR OT_BUILD_OPTIONS=( + "-DBUILD_TESTING=OFF" "-DOT_ANYCAST_LOCATOR=ON" "-DOT_BUILD_EXECUTABLES=OFF" "-DOT_BORDER_AGENT=ON" diff --git a/script/package b/script/package index 65df10bab..2cd8eef94 100755 --- a/script/package +++ b/script/package @@ -39,6 +39,7 @@ main() { local builddir local options=( + "-DBUILD_TESTING=OFF" "-DCMAKE_BUILD_TYPE=Release" "-DOT_COVERAGE=OFF" "-DOT_LOG_LEVEL=INFO" diff --git a/src/lib/spinel/CMakeLists.txt b/src/lib/spinel/CMakeLists.txt index a2019efc5..9e8339768 100644 --- a/src/lib/spinel/CMakeLists.txt +++ b/src/lib/spinel/CMakeLists.txt @@ -84,3 +84,11 @@ target_link_libraries(openthread-spinel-rcp ot-config-radio ot-config ) + +add_executable(ot-test-spinel + spinel.c +) +target_compile_definitions(ot-test-spinel + PRIVATE -DSPINEL_SELF_TEST=1 -D_GNU_SOURCE +) +add_test(NAME ot-test-spinel COMMAND ot-test-spinel) diff --git a/src/lib/spinel/Makefile.am b/src/lib/spinel/Makefile.am index 04061f603..1540424fb 100644 --- a/src/lib/spinel/Makefile.am +++ b/src/lib/spinel/Makefile.am @@ -99,18 +99,6 @@ libopenthread_spinel_rcp_a_SOURCES = \ if OPENTHREAD_BUILD_TESTS -check_PROGRAMS = spinel-test -spinel_test_SOURCES = spinel.c -spinel_test_CFLAGS = \ - $(COMMON_CPPFLAGS) \ - -DSPINEL_SELF_TEST=1 \ - -D_GNU_SOURCE \ - -I$(top_srcdir)/src/core \ - -I$(top_srcdir)/include \ - $(NULL) - -TESTS = spinel-test - install-headers: install-includeHEADERS if OPENTHREAD_BUILD_COVERAGE diff --git a/src/lib/url/CMakeLists.txt b/src/lib/url/CMakeLists.txt index ed74f5c8f..8dd0f2fd0 100644 --- a/src/lib/url/CMakeLists.txt +++ b/src/lib/url/CMakeLists.txt @@ -31,3 +31,14 @@ add_library(openthread-url EXCLUDE_FROM_ALL ) target_link_libraries(openthread-url PRIVATE ot-config) + +add_executable(ot-test-url + url.cpp +) +target_compile_definitions(ot-test-url + PRIVATE -DSELF_TEST=1 +) +target_link_libraries(ot-test-url + PRIVATE ot-config +) +add_test(NAME ot-test-url COMMAND ot-test-url) diff --git a/src/lib/url/Makefile.am b/src/lib/url/Makefile.am index 11037e2a9..d90e96e75 100644 --- a/src/lib/url/Makefile.am +++ b/src/lib/url/Makefile.am @@ -41,21 +41,4 @@ libopenthread_url_a_SOURCES = \ url.hpp \ $(NULL) -check_PROGRAMS = test-url - -test_url_CPPFLAGS = \ - -I$(top_srcdir)/include \ - -I$(top_srcdir)/src \ - -I$(top_srcdir)/src/core \ - -DSELF_TEST \ - $(NULL) - -test_url_SOURCES = \ - url.cpp \ - $(NULL) - -TESTS = \ - test-url \ - $(NULL) - include $(abs_top_nlbuild_autotools_dir)/automake/post.am diff --git a/src/posix/platform/CMakeLists.txt b/src/posix/platform/CMakeLists.txt index e9d13c09e..668f6c605 100644 --- a/src/posix/platform/CMakeLists.txt +++ b/src/posix/platform/CMakeLists.txt @@ -170,3 +170,18 @@ target_include_directories(openthread-posix PRIVATE PUBLIC ${PROJECT_SOURCE_DIR}/src/posix/platform/include ) + +add_executable(ot-posix-test-settings + settings.cpp +) +target_compile_definitions(ot-posix-test-settings + PRIVATE -DSELF_TEST=1 -DOPENTHREAD_CONFIG_LOG_PLATFORM=0 +) +target_include_directories(ot-posix-test-settings + PRIVATE + ${PROJECT_SOURCE_DIR}/include + ${PROJECT_SOURCE_DIR}/src + ${PROJECT_SOURCE_DIR}/src/core + ${PROJECT_SOURCE_DIR}/src/posix/platform/include +) +add_test(NAME ot-posix-test-settings COMMAND ot-posix-test-settings) diff --git a/src/posix/platform/Makefile.am b/src/posix/platform/Makefile.am index 8c87d234a..c23a9286b 100644 --- a/src/posix/platform/Makefile.am +++ b/src/posix/platform/Makefile.am @@ -97,23 +97,4 @@ if OPENTHREAD_BUILD_COVERAGE CLEANFILES = $(wildcard *.gcda *.gcno) endif # OPENTHREAD_BUILD_COVERAGE -check_PROGRAMS = test-settings - -test_settings_CPPFLAGS = \ - -I$(top_srcdir)/include \ - -I$(top_srcdir)/src \ - -I$(top_srcdir)/src/core \ - -I$(top_srcdir)/src/posix/platform/include \ - -DOPENTHREAD_CONFIG_LOG_PLATFORM=0 \ - -DSELF_TEST \ - $(NULL) - -test_settings_SOURCES = \ - settings.cpp \ - $(NULL) - -TESTS = \ - test-settings \ - $(NULL) - include $(abs_top_nlbuild_autotools_dir)/automake/post.am diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 2b00f1c86..840537647 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -26,10 +26,8 @@ # POSSIBILITY OF SUCH DAMAGE. # -if(OT_PLATFORM STREQUAL "simulation") - if(OT_FTD) - add_subdirectory(unit) - endif() +if(OT_FTD AND BUILD_TESTING) + add_subdirectory(unit) endif() option(OT_FUZZ_TARGETS "enable fuzz targets" OFF) diff --git a/tests/Makefile.am b/tests/Makefile.am index 7d0459ca7..e63331ae9 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -31,7 +31,6 @@ include $(abs_top_nlbuild_autotools_dir)/automake/pre.am # Always package (e.g. for 'make dist') these subdirectories. DIST_SUBDIRS = \ - unit \ scripts \ fuzz \ $(NULL) @@ -41,10 +40,6 @@ DIST_SUBDIRS = \ SUBDIRS = \ $(NULL) -SUBDIRS += \ - unit \ - $(NULL) - if OPENTHREAD_POSIX if OPENTHREAD_ENABLE_CLI SUBDIRS += \ diff --git a/tests/unit/CMakeLists.txt b/tests/unit/CMakeLists.txt index e2246c1e5..80c22e8a7 100644 --- a/tests/unit/CMakeLists.txt +++ b/tests/unit/CMakeLists.txt @@ -60,6 +60,8 @@ target_link_libraries(ot-test-platform ) set(COMMON_LIBS + openthread-spinel-ncp + openthread-hdlc ot-test-platform openthread-ftd ot-test-platform @@ -1006,6 +1008,15 @@ add_executable(ot-test-timer test_timer.cpp ) +add_executable(ot-test-toolchain + test_toolchain.cpp test_toolchain_c.c +) +target_include_directories(ot-test-toolchain + PRIVATE + ${COMMON_INCLUDES} +) +add_test(NAME ot-test-toolchain COMMAND ot-test-toolchain) + target_include_directories(ot-test-timer PRIVATE ${COMMON_INCLUDES} @@ -1043,3 +1054,88 @@ target_link_libraries(ot-test-tlv ) add_test(NAME ot-test-tlv COMMAND ot-test-tlv) + +add_executable(ot-test-hdlc + test_hdlc.cpp +) +target_include_directories(ot-test-hdlc + PRIVATE + ${COMMON_INCLUDES} +) +target_compile_options(ot-test-hdlc + PRIVATE + ${COMMON_COMPILE_OPTIONS} +) +target_link_libraries(ot-test-hdlc + PRIVATE + ${COMMON_LIBS} +) +add_test(NAME ot-test-hdlc COMMAND ot-test-hdlc) + +add_executable(ot-test-spinel-buffer + test_spinel_buffer.cpp +) +target_include_directories(ot-test-spinel-buffer + PRIVATE + ${COMMON_INCLUDES} +) +target_compile_options(ot-test-spinel-buffer + PRIVATE + ${COMMON_COMPILE_OPTIONS} +) +target_link_libraries(ot-test-spinel-buffer + PRIVATE + ${COMMON_LIBS} +) +add_test(NAME ot-test-spinel-buffer COMMAND ot-test-spinel-buffer) + +add_executable(ot-test-spinel-decoder + test_spinel_decoder.cpp +) +target_include_directories(ot-test-spinel-decoder + PRIVATE + ${COMMON_INCLUDES} +) +target_compile_options(ot-test-spinel-decoder + PRIVATE + ${COMMON_COMPILE_OPTIONS} +) +target_link_libraries(ot-test-spinel-decoder + PRIVATE + ${COMMON_LIBS} +) +add_test(NAME ot-test-spinel-decoder COMMAND ot-test-spinel-decoder) + +add_executable(ot-test-spinel-encoder + test_spinel_encoder.cpp +) +target_include_directories(ot-test-spinel-encoder + PRIVATE + ${COMMON_INCLUDES} +) +target_compile_options(ot-test-spinel-encoder + PRIVATE + ${COMMON_COMPILE_OPTIONS} +) +target_link_libraries(ot-test-spinel-encoder + PRIVATE + ${COMMON_LIBS} +) +add_test(NAME ot-test-spinel-encoder COMMAND ot-test-spinel-encoder) + +add_executable(ot-test-address-sanitizer + test_address_sanitizer.cpp +) +target_include_directories(ot-test-address-sanitizer + PRIVATE + ${COMMON_INCLUDES} +) +target_compile_options(ot-test-address-sanitizer + PRIVATE + ${COMMON_COMPILE_OPTIONS} +) +target_link_libraries(ot-test-address-sanitizer + PRIVATE + ${COMMON_LIBS} +) +add_test(NAME ot-test-address-sanitizer COMMAND ot-test-address-sanitizer) diff --git a/tests/unit/Makefile.am b/tests/unit/Makefile.am deleted file mode 100644 index c1a5e76fb..000000000 --- a/tests/unit/Makefile.am +++ /dev/null @@ -1,404 +0,0 @@ -# -# Copyright (c) 2016, The OpenThread Authors. -# All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are met: -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution. -# 3. Neither the name of the copyright holder nor the -# names of its contributors may be used to endorse or promote products -# derived from this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE -# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -# POSSIBILITY OF SUCH DAMAGE. -# - -include $(abs_top_nlbuild_autotools_dir)/automake/pre.am - -COMMON_LIBTOOLFLAGS = --preserve-dup-deps - -# -# Local headers to build against and distribute but not to install -# since they are not part of the package. -# -noinst_HEADERS = \ - test_lowpan.hpp \ - test_platform.h \ - test_util.h \ - test_util.hpp \ - $(NULL) - -# -# Other files we do want to distribute with the package. -# -EXTRA_DIST = \ - $(NULL) - -if OPENTHREAD_BUILD_TESTS -# C preprocessor option flags that will apply to all compiled objects in this -# makefile. - -AM_CPPFLAGS = \ - -DOPENTHREAD_FTD=1 \ - -DOPENTHREAD_MTD=0 \ - -DOPENTHREAD_RADIO=0 \ - -DOPENTHREAD_RADIO_CLI=0 \ - -DOPENTHREAD_SPINEL_CONFIG_OPENTHREAD_MESSAGE_ENABLE=1 \ - -I$(top_srcdir)/include \ - -I$(top_srcdir)/src \ - -I$(top_srcdir)/src/core \ - $(NULL) - -if OPENTHREAD_EXAMPLES_SIMULATION -AM_CPPFLAGS += \ - -I$(top_srcdir)/examples/platforms \ - $(NULL) -endif - -if OPENTHREAD_PLATFORM_POSIX -AM_CPPFLAGS += \ - -DOPENTHREAD_PLATFORM_POSIX=1 \ - -I$(top_srcdir)/src/posix/platform \ - $(NULL) -endif - -COMMON_LDADD = \ - $(NULL) - -if OPENTHREAD_ENABLE_NCP -COMMON_LDADD += \ - $(top_builddir)/src/ncp/libopenthread-ncp-ftd.a \ - $(NULL) -endif - -COMMON_LDADD += \ - $(top_builddir)/src/core/libopenthread-ftd.a \ - $(top_builddir)/third_party/tcplp/libtcplp.a \ - $(top_builddir)/src/core/libopenthread-ftd.a \ - -lpthread \ - $(NULL) - -if OPENTHREAD_ENABLE_BUILTIN_MBEDTLS -COMMON_LDADD += \ - $(top_builddir)/third_party/mbedtls/libmbedcrypto.a \ - $(NULL) -endif - -if OPENTHREAD_PLATFORM_POSIX -COMMON_LDADD += \ - -lutil - $(NULL) -endif - -# Test applications that should be run when the 'check' target is run. - -check_PROGRAMS = \ - ot-test-toolchain \ - $(NULL) - -if OPENTHREAD_ENABLE_FTD -check_PROGRAMS += \ - ot-test-aes \ - ot-test-array \ - ot-test-binary-search \ - ot-test-checksum \ - ot-test-child \ - ot-test-child-table \ - ot-test-cmd-line-parser \ - ot-test-data \ - ot-test-dns \ - ot-test-dso \ - ot-test-ecdsa \ - ot-test-flash \ - ot-test-frame-builder \ - ot-test-heap \ - ot-test-heap-array \ - ot-test-heap-string \ - ot-test-hkdf-sha256 \ - ot-test-hmac-sha256 \ - ot-test-ip4-header \ - ot-test-ip6-header \ - ot-test-ip-address \ - ot-test-link-quality \ - ot-test-linked-list \ - ot-test-lowpan \ - ot-test-mac-frame \ - ot-test-macros \ - ot-test-meshcop \ - ot-test-message \ - ot-test-message-queue \ - ot-test-multicast-listeners-table \ - ot-test-nat64 \ - ot-test-ndproxy-table \ - ot-test-netif \ - ot-test-network-data \ - ot-test-network-name \ - ot-test-pool \ - ot-test-priority-queue \ - ot-test-pskc \ - ot-test-serial-number \ - ot-test-routing-manager \ - ot-test-smart-ptrs \ - ot-test-srp-server \ - ot-test-string \ - ot-test-timer \ - ot-test-tlv \ - $(NULL) - -if OPENTHREAD_ENABLE_NCP -check_PROGRAMS += \ - ot-test-hdlc \ - ot-test-spinel-buffer \ - ot-test-spinel-decoder \ - ot-test-spinel-encoder \ - $(NULL) -endif -endif # OPENTHREAD_ENABLE_FTD - -XFAIL_TESTS = \ - $(NULL) - -if OPENTHREAD_WITH_ADDRESS_SANITIZER -check_PROGRAMS += ot-test-address-sanitizer -XFAIL_TESTS += ot-test-address-sanitizer -ot_test_address_sanitizer_SOURCES = test_address_sanitizer.cpp -endif # OPENTHREAD_WITH_ADDRESS_SANITIZER - - -# Test applications and scripts that should be built and run when the -# 'check' target is run. - -TESTS = \ - $(check_PROGRAMS) \ - $(NULL) - -# The additional environment variables and their values that will be -# made available to all programs and scripts in TESTS. - -TESTS_ENVIRONMENT = \ - top_srcdir='$(top_srcdir)' \ - $(NULL) - -COMMON_SOURCES = test_platform.cpp test_util.cpp - -# Source, compiler, and linker options for test programs. - -ot_test_aes_LDADD = $(COMMON_LDADD) -ot_test_aes_LIBTOOLFLAGS = $(COMMON_LIBTOOLFLAGS) -ot_test_aes_SOURCES = $(COMMON_SOURCES) test_aes.cpp - -ot_test_array_LDADD = $(COMMON_LDADD) -ot_test_array_LIBTOOLFLAGS = $(COMMON_LIBTOOLFLAGS) -ot_test_array_SOURCES = $(COMMON_SOURCES) test_array.cpp - -ot_test_binary_search_LDADD = $(COMMON_LDADD) -ot_test_binary_search_LIBTOOLFLAGS = $(COMMON_LIBTOOLFLAGS) -ot_test_binary_search_SOURCES = $(COMMON_SOURCES) test_binary_search.cpp - -ot_test_checksum_LDADD = $(COMMON_LDADD) -ot_test_checksum_LIBTOOLFLAGS = $(COMMON_LIBTOOLFLAGS) -ot_test_checksum_SOURCES = $(COMMON_SOURCES) test_checksum.cpp - -ot_test_child_LDADD = $(COMMON_LDADD) -ot_test_child_LIBTOOLFLAGS = $(COMMON_LIBTOOLFLAGS) -ot_test_child_SOURCES = $(COMMON_SOURCES) test_child.cpp - -ot_test_child_table_LDADD = $(COMMON_LDADD) -ot_test_child_table_LIBTOOLFLAGS = $(COMMON_LIBTOOLFLAGS) -ot_test_child_table_SOURCES = $(COMMON_SOURCES) test_child_table.cpp - -ot_test_cmd_line_parser_LDADD = $(COMMON_LDADD) -ot_test_cmd_line_parser_LIBTOOLFLAGS = $(COMMON_LIBTOOLFLAGS) -ot_test_cmd_line_parser_SOURCES = $(COMMON_SOURCES) test_cmd_line_parser.cpp - -ot_test_data_LDADD = $(COMMON_LDADD) -ot_test_data_LIBTOOLFLAGS = $(COMMON_LIBTOOLFLAGS) -ot_test_data_SOURCES = $(COMMON_SOURCES) test_data.cpp - -ot_test_dns_LDADD = $(COMMON_LDADD) -ot_test_dns_LIBTOOLFLAGS = $(COMMON_LIBTOOLFLAGS) -ot_test_dns_SOURCES = $(COMMON_SOURCES) test_dns.cpp - -ot_test_dso_LDADD = $(COMMON_LDADD) -ot_test_dso_LIBTOOLFLAGS = $(COMMON_LIBTOOLFLAGS) -ot_test_dso_SOURCES = $(COMMON_SOURCES) test_dso.cpp - -ot_test_ecdsa_LDADD = $(COMMON_LDADD) -ot_test_ecdsa_LIBTOOLFLAGS = $(COMMON_LIBTOOLFLAGS) -ot_test_ecdsa_SOURCES = $(COMMON_SOURCES) test_ecdsa.cpp - -ot_test_flash_LDADD = $(COMMON_LDADD) -ot_test_flash_LIBTOOLFLAGS = $(COMMON_LIBTOOLFLAGS) -ot_test_flash_SOURCES = $(COMMON_SOURCES) test_flash.cpp - -ot_test_frame_builder_LDADD = $(COMMON_LDADD) -ot_test_frame_builder_LIBTOOLFLAGS = $(COMMON_LIBTOOLFLAGS) -ot_test_frame_builder_SOURCES = $(COMMON_SOURCES) test_frame_builder.cpp - -ot_test_hdlc_LDADD = $(COMMON_LDADD) -ot_test_hdlc_LIBTOOLFLAGS = $(COMMON_LIBTOOLFLAGS) -ot_test_hdlc_SOURCES = $(COMMON_SOURCES) test_hdlc.cpp - -ot_test_heap_LDADD = $(COMMON_LDADD) -ot_test_heap_LIBTOOLFLAGS = $(COMMON_LIBTOOLFLAGS) -ot_test_heap_SOURCES = $(COMMON_SOURCES) test_heap.cpp - -ot_test_heap_array_LDADD = $(COMMON_LDADD) -ot_test_heap_array_LIBTOOLFLAGS = $(COMMON_LIBTOOLFLAGS) -ot_test_heap_array_SOURCES = $(COMMON_SOURCES) test_heap_array.cpp - -ot_test_heap_string_LDADD = $(COMMON_LDADD) -ot_test_heap_string_LIBTOOLFLAGS = $(COMMON_LIBTOOLFLAGS) -ot_test_heap_string_SOURCES = $(COMMON_SOURCES) test_heap_string.cpp - -ot_test_hkdf_sha256_LDADD = $(COMMON_LDADD) -ot_test_hkdf_sha256_LIBTOOLFLAGS = $(COMMON_LIBTOOLFLAGS) -ot_test_hkdf_sha256_SOURCES = $(COMMON_SOURCES) test_hkdf_sha256.cpp - -ot_test_hmac_sha256_LDADD = $(COMMON_LDADD) -ot_test_hmac_sha256_LIBTOOLFLAGS = $(COMMON_LIBTOOLFLAGS) -ot_test_hmac_sha256_SOURCES = $(COMMON_SOURCES) test_hmac_sha256.cpp - -ot_test_ip4_header_LDADD = $(COMMON_LDADD) -ot_test_ip4_header_LIBTOOLFLAGS = $(COMMON_LIBTOOLFLAGS) -ot_test_ip4_header_SOURCES = $(COMMON_SOURCES) test_ip4_header.cpp - -ot_test_ip6_header_LDADD = $(COMMON_LDADD) -ot_test_ip6_header_LIBTOOLFLAGS = $(COMMON_LIBTOOLFLAGS) -ot_test_ip6_header_SOURCES = $(COMMON_SOURCES) test_ip6_header.cpp - -ot_test_ip_address_LDADD = $(COMMON_LDADD) -ot_test_ip_address_LIBTOOLFLAGS = $(COMMON_LIBTOOLFLAGS) -ot_test_ip_address_SOURCES = $(COMMON_SOURCES) test_ip_address.cpp - -ot_test_link_quality_LDADD = $(COMMON_LDADD) -ot_test_link_quality_LIBTOOLFLAGS = $(COMMON_LIBTOOLFLAGS) -ot_test_link_quality_SOURCES = $(COMMON_SOURCES) test_link_quality.cpp - -ot_test_linked_list_LDADD = $(COMMON_LDADD) -ot_test_linked_list_LIBTOOLFLAGS = $(COMMON_LIBTOOLFLAGS) -ot_test_linked_list_SOURCES = $(COMMON_SOURCES) test_linked_list.cpp - -ot_test_lowpan_LDADD = $(COMMON_LDADD) -ot_test_lowpan_LIBTOOLFLAGS = $(COMMON_LIBTOOLFLAGS) -ot_test_lowpan_SOURCES = $(COMMON_SOURCES) test_lowpan.cpp - -ot_test_mac_frame_LDADD = $(COMMON_LDADD) -ot_test_mac_frame_LIBTOOLFLAGS = $(COMMON_LIBTOOLFLAGS) -ot_test_mac_frame_SOURCES = $(COMMON_SOURCES) test_mac_frame.cpp - -ot_test_macros_LDADD = $(COMMON_LDADD) -ot_test_macros_LIBTOOLFLAGS = $(COMMON_LIBTOOLFLAGS) -ot_test_macros_SOURCES = $(COMMON_SOURCES) test_macros.cpp - -ot_test_message_LDADD = $(COMMON_LDADD) -ot_test_message_LIBTOOLFLAGS = $(COMMON_LIBTOOLFLAGS) -ot_test_message_SOURCES = $(COMMON_SOURCES) test_message.cpp - -ot_test_message_queue_LDADD = $(COMMON_LDADD) -ot_test_message_queue_LIBTOOLFLAGS = $(COMMON_LIBTOOLFLAGS) -ot_test_message_queue_SOURCES = $(COMMON_SOURCES) test_message_queue.cpp - -ot_test_multicast_listeners_table_LDADD = $(COMMON_LDADD) -ot_test_multicast_listeners_table_LIBTOOLFLAGS = $(COMMON_LIBTOOLFLAGS) -ot_test_multicast_listeners_table_SOURCES = $(COMMON_SOURCES) test_multicast_listeners_table.cpp - -ot_test_nat64_LDADD = $(COMMON_LDADD) -ot_test_nat64_LIBTOOLFLAGS = $(COMMON_LIBTOOLFLAGS) -ot_test_nat64_SOURCES = $(COMMON_SOURCES) test_nat64.cpp - -ot_test_network_name_LDADD = $(COMMON_LDADD) -ot_test_network_name_LIBTOOLFLAGS = $(COMMON_LIBTOOLFLAGS) -ot_test_network_name_SOURCES = $(COMMON_SOURCES) test_network_name.cpp - -ot_test_spinel_buffer_LDADD = $(COMMON_LDADD) -ot_test_spinel_buffer_LIBTOOLFLAGS = $(COMMON_LIBTOOLFLAGS) -ot_test_spinel_buffer_SOURCES = $(COMMON_SOURCES) test_spinel_buffer.cpp - -ot_test_ndproxy_table_LDADD = $(COMMON_LDADD) -ot_test_ndproxy_table_LIBTOOLFLAGS = $(COMMON_LIBTOOLFLAGS) -ot_test_ndproxy_table_SOURCES = $(COMMON_SOURCES) test_ndproxy_table.cpp - -ot_test_netif_LDADD = $(COMMON_LDADD) -ot_test_netif_LIBTOOLFLAGS = $(COMMON_LIBTOOLFLAGS) -ot_test_netif_SOURCES = $(COMMON_SOURCES) test_netif.cpp - -ot_test_network_data_LDADD = $(COMMON_LDADD) -ot_test_network_data_LIBTOOLFLAGS = $(COMMON_LIBTOOLFLAGS) -ot_test_network_data_SOURCES = $(COMMON_SOURCES) test_network_data.cpp - -ot_test_pool_LDADD = $(COMMON_LDADD) -ot_test_pool_LIBTOOLFLAGS = $(COMMON_LIBTOOLFLAGS) -ot_test_pool_SOURCES = $(COMMON_SOURCES) test_pool.cpp - -ot_test_priority_queue_LDADD = $(COMMON_LDADD) -ot_test_priority_queue_LIBTOOLFLAGS = $(COMMON_LIBTOOLFLAGS) -ot_test_priority_queue_SOURCES = $(COMMON_SOURCES) test_priority_queue.cpp - -ot_test_pskc_LDADD = $(COMMON_LDADD) -ot_test_pskc_LIBTOOLFLAGS = $(COMMON_LIBTOOLFLAGS) -ot_test_pskc_SOURCES = $(COMMON_SOURCES) test_pskc.cpp - -ot_test_smart_ptrs_LDADD = $(COMMON_LDADD) -ot_test_smart_ptrs_LIBTOOLFLAGS = $(COMMON_LIBTOOLFLAGS) -ot_test_smart_ptrs_SOURCES = $(COMMON_SOURCES) test_smart_ptrs.cpp - -ot_test_meshcop_LDADD = $(COMMON_LDADD) -ot_test_meshcop_LIBTOOLFLAGS = $(COMMON_LIBTOOLFLAGS) -ot_test_meshcop_SOURCES = $(COMMON_SOURCES) test_meshcop.cpp - -ot_test_routing_manager_LDADD = $(COMMON_LDADD) -ot_test_routing_manager_LIBTOOLFLAGS = $(COMMON_LIBTOOLFLAGS) -ot_test_routing_manager_SOURCES = $(COMMON_SOURCES) test_routing_manager.cpp - -ot_test_serial_number_LDADD = $(COMMON_LDADD) -ot_test_serial_number_LIBTOOLFLAGS = $(COMMON_LIBTOOLFLAGS) -ot_test_serial_number_SOURCES = $(COMMON_SOURCES) test_serial_number.cpp - -ot_test_srp_server_LDADD = $(COMMON_LDADD) -ot_test_srp_server_LIBTOOLFLAGS = $(COMMON_LIBTOOLFLAGS) -ot_test_srp_server_SOURCES = $(COMMON_SOURCES) test_srp_server.cpp - -ot_test_string_LDADD = $(COMMON_LDADD) -ot_test_string_LIBTOOLFLAGS = $(COMMON_LIBTOOLFLAGS) -ot_test_string_SOURCES = $(COMMON_SOURCES) test_string.cpp - -ot_test_spinel_decoder_LDADD = $(COMMON_LDADD) -ot_test_spinel_decoder_LIBTOOLFLAGS = $(COMMON_LIBTOOLFLAGS) -ot_test_spinel_decoder_SOURCES = $(COMMON_SOURCES) test_spinel_decoder.cpp - -ot_test_spinel_encoder_LDADD = $(COMMON_LDADD) -ot_test_spinel_encoder_LIBTOOLFLAGS = $(COMMON_LIBTOOLFLAGS) -ot_test_spinel_encoder_SOURCES = $(COMMON_SOURCES) test_spinel_encoder.cpp - -ot_test_timer_LDADD = $(COMMON_LDADD) -ot_test_timer_LIBTOOLFLAGS = $(COMMON_LIBTOOLFLAGS) -ot_test_timer_SOURCES = $(COMMON_SOURCES) test_timer.cpp - -ot_test_tlv_LDADD = $(COMMON_LDADD) -ot_test_tlv_LIBTOOLFLAGS = $(COMMON_LIBTOOLFLAGS) -ot_test_tlv_SOURCES = $(COMMON_SOURCES) test_tlv.cpp - -ot_test_toolchain_LDADD = $(NULL) -ot_test_toolchain_SOURCES = test_toolchain.cpp test_toolchain_c.c - -if OPENTHREAD_BUILD_COVERAGE -CLEANFILES = $(wildcard *.gcda *.gcno) -endif # OPENTHREAD_BUILD_COVERAGE - -endif # OPENTHREAD_BUILD_TESTS - -include $(abs_top_nlbuild_autotools_dir)/automake/post.am diff --git a/tests/unit/test_binary_search.cpp b/tests/unit/test_binary_search.cpp index bf05d9f63..d2d022495 100644 --- a/tests/unit/test_binary_search.cpp +++ b/tests/unit/test_binary_search.cpp @@ -64,9 +64,12 @@ void TestBinarySearch(void) constexpr Entry kUnsortedTable[] = {{"z", 0}, {"a", 0}, {"b", 0}}; constexpr Entry kDuplicateEntryTable[] = {{"duplicate", 1}, {"duplicate", 2}}; +// gcc-4 does not support constexpr function +#if __GNUC__ > 4 static_assert(BinarySearch::IsSorted(kTable), "IsSorted() failed"); static_assert(!BinarySearch::IsSorted(kUnsortedTable), "failed for unsorted table"); static_assert(!BinarySearch::IsSorted(kDuplicateEntryTable), "failed for table with duplicate entries"); +#endif for (const Entry &tableEntry : kTable) { diff --git a/tests/unit/test_platform.cpp b/tests/unit/test_platform.cpp index bf196d0f5..81e73da2f 100644 --- a/tests/unit/test_platform.cpp +++ b/tests/unit/test_platform.cpp @@ -445,4 +445,64 @@ OT_TOOL_WEAK void otPlatDsoDisconnect(otPlatDsoConnection *aConnection, otPlatDs #endif // #if OPENTHREAD_CONFIG_DNS_DSO_ENABLE +#if OPENTHREAD_CONFIG_PLATFORM_UDP_ENABLE +otError otPlatUdpSocket(otUdpSocket *aUdpSocket) +{ + OT_UNUSED_VARIABLE(aUdpSocket); + return OT_ERROR_NONE; +} + +otError otPlatUdpClose(otUdpSocket *aUdpSocket) +{ + OT_UNUSED_VARIABLE(aUdpSocket); + return OT_ERROR_NONE; +} + +otError otPlatUdpBind(otUdpSocket *aUdpSocket) +{ + OT_UNUSED_VARIABLE(aUdpSocket); + return OT_ERROR_NONE; +} + +otError otPlatUdpBindToNetif(otUdpSocket *aUdpSocket, otNetifIdentifier aNetifIdentifier) +{ + OT_UNUSED_VARIABLE(aUdpSocket); + OT_UNUSED_VARIABLE(aNetifIdentifier); + return OT_ERROR_NONE; +} + +otError otPlatUdpConnect(otUdpSocket *aUdpSocket) +{ + OT_UNUSED_VARIABLE(aUdpSocket); + return OT_ERROR_NONE; +} + +otError otPlatUdpSend(otUdpSocket *aUdpSocket, otMessage *aMessage, const otMessageInfo *aMessageInfo) +{ + OT_UNUSED_VARIABLE(aUdpSocket); + OT_UNUSED_VARIABLE(aMessageInfo); + return OT_ERROR_NONE; +} + +otError otPlatUdpJoinMulticastGroup(otUdpSocket *aUdpSocket, + otNetifIdentifier aNetifIdentifier, + const otIp6Address *aAddress) +{ + OT_UNUSED_VARIABLE(aUdpSocket); + OT_UNUSED_VARIABLE(aNetifIdentifier); + OT_UNUSED_VARIABLE(aAddress); + return OT_ERROR_NONE; +} + +otError otPlatUdpLeaveMulticastGroup(otUdpSocket *aUdpSocket, + otNetifIdentifier aNetifIdentifier, + const otIp6Address *aAddress) +{ + OT_UNUSED_VARIABLE(aUdpSocket); + OT_UNUSED_VARIABLE(aNetifIdentifier); + OT_UNUSED_VARIABLE(aAddress); + return OT_ERROR_NONE; +} +#endif // OPENTHREAD_CONFIG_PLATFORM_UDP_ENABLE + } // extern "C" diff --git a/tests/unit/test_spinel_encoder.cpp b/tests/unit/test_spinel_encoder.cpp index e15157c90..7acb0d015 100644 --- a/tests/unit/test_spinel_encoder.cpp +++ b/tests/unit/test_spinel_encoder.cpp @@ -145,7 +145,7 @@ void TestEncoder(void) DumpBuffer("Frame", frame, frameLen); parsedLen = spinel_datatype_unpack( - frame, (spinel_size_t)frameLen, + frame, static_cast(frameLen), (SPINEL_DATATYPE_BOOL_S SPINEL_DATATYPE_BOOL_S SPINEL_DATATYPE_UINT8_S SPINEL_DATATYPE_INT8_S SPINEL_DATATYPE_UINT16_S SPINEL_DATATYPE_INT16_S SPINEL_DATATYPE_UINT32_S SPINEL_DATATYPE_INT32_S SPINEL_DATATYPE_UINT64_S SPINEL_DATATYPE_INT64_S SPINEL_DATATYPE_UINT_PACKED_S @@ -200,7 +200,7 @@ void TestEncoder(void) DumpBuffer("Frame", frame, frameLen); parsedLen = spinel_datatype_unpack( - frame, (spinel_size_t)frameLen, + frame, static_cast(frameLen), (SPINEL_DATATYPE_UINT8_S SPINEL_DATATYPE_STRUCT_S( SPINEL_DATATYPE_UINT32_S SPINEL_DATATYPE_EUI48_S SPINEL_DATATYPE_UINT_PACKED_S) SPINEL_DATATYPE_INT16_S @@ -215,7 +215,7 @@ void TestEncoder(void) VerifyOrQuit(memcmp(eui48, &kEui48, sizeof(spinel_eui48_t)) == 0); // Parse the struct as a "data with len". - parsedLen = spinel_datatype_unpack(frame, (spinel_size_t)frameLen, + parsedLen = spinel_datatype_unpack(frame, static_cast(frameLen), (SPINEL_DATATYPE_UINT8_S SPINEL_DATATYPE_DATA_WLEN_S SPINEL_DATATYPE_INT16_S ), @@ -258,7 +258,7 @@ void TestEncoder(void) SuccessOrQuit(ReadFrame(ncpBuffer, frame, frameLen)); parsedLen = spinel_datatype_unpack( - frame, (spinel_size_t)frameLen, + frame, static_cast(frameLen), (SPINEL_DATATYPE_STRUCT_S(SPINEL_DATATYPE_UINT8_S SPINEL_DATATYPE_UTF8_S SPINEL_DATATYPE_STRUCT_S( SPINEL_DATATYPE_BOOL_S SPINEL_DATATYPE_IPv6ADDR_S) SPINEL_DATATYPE_UINT16_S) SPINEL_DATATYPE_EUI48_S SPINEL_DATATYPE_STRUCT_S(SPINEL_DATATYPE_UINT32_S) SPINEL_DATATYPE_INT32_S), @@ -296,7 +296,7 @@ void TestEncoder(void) SuccessOrQuit(ReadFrame(ncpBuffer, frame, frameLen)); parsedLen = spinel_datatype_unpack( - frame, (spinel_size_t)frameLen, + frame, static_cast(frameLen), (SPINEL_DATATYPE_UINT8_S SPINEL_DATATYPE_STRUCT_S( SPINEL_DATATYPE_UINT32_S SPINEL_DATATYPE_STRUCT_S(SPINEL_DATATYPE_EUI48_S SPINEL_DATATYPE_UINT_PACKED_S))), &u8, &u32, &eui48, &u_3); @@ -340,7 +340,7 @@ void TestEncoder(void) SuccessOrQuit(ReadFrame(ncpBuffer, frame, frameLen)); parsedLen = spinel_datatype_unpack( - frame, (spinel_size_t)frameLen, + frame, static_cast(frameLen), (SPINEL_DATATYPE_UINT8_S SPINEL_DATATYPE_STRUCT_S( SPINEL_DATATYPE_UINT32_S SPINEL_DATATYPE_IPv6ADDR_S SPINEL_DATATYPE_EUI64_S) SPINEL_DATATYPE_UTF8_S), &u8, &u32, &ip6Addr, &eui64, &utf_1); diff --git a/tests/unit/test_string.cpp b/tests/unit/test_string.cpp index b32a11126..bd7fb8d77 100644 --- a/tests/unit/test_string.cpp +++ b/tests/unit/test_string.cpp @@ -309,12 +309,15 @@ void TestStringToLowercase(void) printf(" -- PASS\n"); } +// gcc-4 does not support constexpr function +#if __GNUC__ > 4 static_assert(ot::AreStringsInOrder("a", "b"), "AreStringsInOrder() failed"); static_assert(ot::AreStringsInOrder("aa", "aaa"), "AreStringsInOrder() failed"); static_assert(ot::AreStringsInOrder("", "a"), "AreStringsInOrder() failed"); static_assert(!ot::AreStringsInOrder("cd", "cd"), "AreStringsInOrder() failed"); static_assert(!ot::AreStringsInOrder("z", "abcd"), "AreStringsInOrder() failed"); static_assert(!ot::AreStringsInOrder("0", ""), "AreStringsInOrder() failed"); +#endif } // namespace ot