From 1be07de395e4ddf969db2b90328cdf4fb73e9a64 Mon Sep 17 00:00:00 2001 From: Erik Boasson Date: Fri, 14 Jul 2023 10:06:32 +0200 Subject: [PATCH] Eliminate Conan, CUnit --- .azure/templates/build-test.yml | 21 +- .azure/templates/install-conan.yml | 66 ---- CMakeLists.txt | 33 +- README.md | 19 +- azure-pipelines.yml | 26 +- cmake/Modules/CUnit.cmake | 12 +- cmake/Modules/CUnit/src/main.c.in | 51 +-- cmake/Modules/FindCUnit.cmake | 120 ------- conanfile.txt | 9 - conanfile102.txt | 9 - docs/dev/debugging.md | 19 +- package.xml | 1 - ports/freertos-posix/README.md | 18 +- src/CMakeLists.txt | 3 + src/core/ddsc/tests/cdr.c | 1 - src/core/ddsc/tests/domain.c | 1 - src/core/ddsc/tests/instance_get_key.c | 3 - src/core/ddsc/tests/liveliness.c | 6 +- src/core/ddsc/tests/loan.c | 3 - src/core/ddsc/tests/multi_sertopic.c | 2 +- src/core/ddsc/tests/pp_lease_dur.c | 1 - src/core/ddsc/tests/publisher.c | 1 + src/core/ddsc/tests/qos.c | 10 +- src/core/ddsc/tests/typelookup.c | 3 - src/core/ddsc/tests/whc.c | 2 +- src/core/ddsi/tests/plist_generic.c | 6 +- src/core/ddsi/tests/security_msg.c | 1 - src/ddsrt/tests/environ.c | 6 +- src/ddsrt/tests/hopscotch.c | 2 +- src/ddsrt/tests/ifaddrs.c | 3 - src/ddsrt/tests/log.c | 4 + src/ddsrt/tests/string.c | 1 - src/idl/tests/union.c | 1 + .../src/decode_serialized_payload_utests.c | 1 - .../src/encode_datareader_submessage_utests.c | 7 - .../src/encode_datawriter_submessage_utests.c | 8 - .../src/encode_rtps_message_utests.c | 4 - .../src/encode_serialized_payload_utests.c | 3 - ...thenticated_peer_credential_token_utests.c | 24 +- .../src/listeners_authentication_utests.c | 4 - .../src/process_handshake_utests.c | 21 -- .../src/register_local_datareader_utests.c | 9 +- .../src/register_local_datawriter_utests.c | 5 +- .../src/register_local_participant_utests.c | 1 - ...egister_matched_remote_datareader_utests.c | 5 +- ...egister_matched_remote_datawriter_utests.c | 7 +- .../validate_begin_handshake_reply_utests.c | 1 - .../src/validate_local_identity_utests.c | 3 - .../src/validate_local_permissions_utests.c | 1 - .../src/validate_remote_permissions_utests.c | 2 - src/security/core/tests/CMakeLists.txt | 2 +- src/security/core/tests/common/test_utils.c | 2 - src/security/core/tests/fsm.c | 4 +- src/tools/idlc/tests/test_common.c | 2 - src/ucunit/CMakeLists.txt | 45 +++ src/ucunit/include/CUnit/Automated.h | 6 + src/ucunit/include/CUnit/Basic.h | 6 + src/ucunit/include/CUnit/CUError.h | 6 + src/ucunit/include/CUnit/CUnit.h | 6 + .../CUnit => src/ucunit}/include/CUnit/Test.h | 5 +- .../ucunit}/include/CUnit/Theory.h | 0 src/ucunit/include/ucunit/ucunit.h | 320 ++++++++++++++++++ src/ucunit/src/ucunit.c | 274 +++++++++++++++ src/ucunit/tests/test_ucunit.c | 300 ++++++++++++++++ 64 files changed, 1044 insertions(+), 504 deletions(-) delete mode 100644 .azure/templates/install-conan.yml delete mode 100644 cmake/Modules/FindCUnit.cmake delete mode 100644 conanfile.txt delete mode 100644 conanfile102.txt create mode 100644 src/ucunit/CMakeLists.txt create mode 100644 src/ucunit/include/CUnit/Automated.h create mode 100644 src/ucunit/include/CUnit/Basic.h create mode 100644 src/ucunit/include/CUnit/CUError.h create mode 100644 src/ucunit/include/CUnit/CUnit.h rename {cmake/Modules/CUnit => src/ucunit}/include/CUnit/Test.h (97%) rename {cmake/Modules/CUnit => src/ucunit}/include/CUnit/Theory.h (100%) create mode 100644 src/ucunit/include/ucunit/ucunit.h create mode 100644 src/ucunit/src/ucunit.c create mode 100644 src/ucunit/tests/test_ucunit.c diff --git a/.azure/templates/build-test.yml b/.azure/templates/build-test.yml index 5caec2bc7d..d6076685d8 100644 --- a/.azure/templates/build-test.yml +++ b/.azure/templates/build-test.yml @@ -30,15 +30,15 @@ steps: echo "###vso[task.setvariable variable=pip_cache;]${HOME}/.cache/pip" echo "###vso[task.setvariable variable=PATH;]$(python3 -m site --user-base)/bin:${PATH}" echo "###vso[task.setvariable variable=build_tool_options;]-j 4" - sudo apt-get install -y clang clang-tools clang-tidy + sudo apt install -y clang clang-tools clang-tidy condition: eq(variables['Agent.OS'], 'Linux') name: setup_linux - bash: | + set -e -x + sudo /usr/libexec/ApplicationFirewall/socketfilterfw --setglobalstate off echo "###vso[task.setvariable variable=pip_cache;]${HOME}/Library/Caches/pip" echo "###vso[task.setvariable variable=PATH;]$(python3 -m site --user-base)/bin:${PATH}" echo "###vso[task.setvariable variable=build_tool_options;]-j 4" - sudo /usr/libexec/ApplicationFirewall/socketfilterfw --setglobalstate off - brew install bison condition: eq(variables['Agent.OS'], 'Darwin') name: setup_macos # Use PowerShell rather than Bash to ensure Windows-style paths @@ -62,8 +62,6 @@ steps: } else { Write-Host "###vso[task.setvariable variable=build_tool_options;]-j 4" } - # On purpose do not install bison on windows to test the fallback to the parser.y in tree. - # choco install winflexbison3 condition: eq(variables['Agent.OS'], 'Windows_NT') name: setup_windows - task: Cache@2 @@ -71,7 +69,6 @@ steps: key: pip | 2 | $(Agent.OS) path: $(pip_cache) name: cache_pip - - template: /.azure/templates/install-conan.yml - bash: | set -e -x python -m pip install pip wheel setuptools --user --upgrade @@ -90,6 +87,7 @@ steps: iceoryx mkdir iceoryx/build cd iceoryx/build + [[ "${AGENT_OS}" == 'Darwin' ]] && BUILD_TOOL_OPTIONS="-j 4" cmake -DCMAKE_BUILD_TYPE=${BUILD_TYPE} \ -DCMAKE_BUILD_SHARED_LIBS=on \ -DCMAKE_INSTALL_PREFIX=install \ @@ -101,10 +99,15 @@ steps: set -e -x mkdir build cd build - conan install -b missing -pr:b ${BUILD_PROFILE} -pr:h ${HOST_PROFILE} -s build_type=${BUILD_TYPE} ../${CONANFILE:-conanfile.txt} + prefix_path="${BUILD_SOURCESDIRECTORY}/iceoryx/build/install" + if [[ "${AGENT_OS}" == 'Darwin' ]] ; then + prefix_path="${prefix_path}:`brew --prefix openssl`" + # Azure sometimes adds a spurious ' to BUILD_TOOL_OPTIONS + BUILD_TOOL_OPTIONS="-j 4" + fi cmake -DCMAKE_BUILD_TYPE=${BUILD_TYPE} \ -DCMAKE_INSTALL_PREFIX=install \ - -DCMAKE_PREFIX_PATH="${BUILD_SOURCESDIRECTORY}/iceoryx/build/install" \ + -DCMAKE_PREFIX_PATH="${prefix_path//:/;}" \ -DANALYZER=${ANALYZER:-off} \ -DSANITIZER=${SANITIZER:-none} \ -DENABLE_SSL=${SSL:-on} \ @@ -142,11 +145,13 @@ steps: -DCMAKE_BUILD_TYPE=${BUILD_TYPE} \ ${GENERATOR:+-G} "${GENERATOR}" -A "${PLATFORM}" -T "${TOOLSET}" "${INSTALLPREFIX}/share/CycloneDDS/examples/helloworld" cmake --build . --config ${BUILD_TYPE} -- ${BUILD_TOOL_OPTIONS} + condition: ne(variables['testing'], 'off') name: test displayName: Test - bash: | set -e -x cd build + [[ "${AGENT_OS}" == 'Darwin' ]] && BUILD_TOOL_OPTIONS="-j 4" cmake --build . --config ${BUILD_TYPE} --target gcov -- ${BUILD_TOOL_OPTIONS} gcovr --exclude '.*/tests/.*' --root "${BUILD_SOURCESDIRECTORY}" --json "$(System.DefaultWorkingDirectory)/coverage-$(Agent.JobName).json" name: generate_code_coverage diff --git a/.azure/templates/install-conan.yml b/.azure/templates/install-conan.yml deleted file mode 100644 index 4eb38cdb47..0000000000 --- a/.azure/templates/install-conan.yml +++ /dev/null @@ -1,66 +0,0 @@ -# -# Copyright(c) 2021 ZettaScale Technology and others -# -# This program and the accompanying materials are made available under the -# terms of the Eclipse Public License v. 2.0 which is available at -# http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License -# v. 1.0 which is available at -# http://www.eclipse.org/org/documents/edl-v10.php. -# -# SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause -# - -steps: - - bash: | - echo "###vso[task.setvariable variable=conan_cache;]${HOME}/.conan/data" - condition: ne(variables['Agent.OS'], 'Windows_NT') - name: set_conan_cache_unix - - pwsh: | - Write-Host "###vso[task.setvariable variable=conan_cache;]${env:USERPROFILE}\\.conan\\data" - # Set CONAN_BASH_PATH to avoid having to build msys2 for Conan packages. - Write-Host "###vso[task.setvariable variable=CONAN_BASH_PATH;]C:\\msys64\\usr\\bin\\bash.exe" - condition: eq(variables['Agent.OS'], 'Windows_NT') - name: set_conan_cache_windows - # Caching - - task: Cache@2 - inputs: - key: conan | 4 | $(Agent.OS) | $(arch) | $(cc) | $(build_type) - path: $(conan_cache) - name: cache_conan - - bash: | - set -e - pip install "conan==1.59.0" --user - # Derive build profile architechture from system architecture. - case "${AGENT_OSARCHITECTURE}" in - X86) build_arch=x86 ;; - X64) build_arch=x86_64 ;; - ARM) build_arch=armv8 ;; - esac - # Export Conan profile names for convenience. - # * Build platform: Platform on which the compilation tools will run. - # * Host platform: Platform on which the generated binaries will run. - # - # https://docs.conan.io/en/latest/systems_cross_building/cross_building.html - echo "###vso[task.setvariable variable=build_profile;]${build_arch}" - echo "###vso[task.setvariable variable=host_profile;]${ARCH}" - # Automatically detect the build profile. Make sure CC and CXX - # environment variables are set correctly on Microsoft Windows if a - # different compiler than Visual Studio is desired. - conan profile new ${build_arch} --detect - [[ "$(conan profile get settings.compiler ${build_arch})" != "gcc" ]] || \ - conan profile update settings.compiler.libcxx=libstdc++11 ${build_arch} - [[ "$(conan profile get settings.compiler ${build_arch})" != "Visual Studio" ]] || \ - [[ "${TOOLSET}" = "" ]] || \ - conan profile update settings.compiler.toolset=${TOOLSET} ${build_arch} - # Generate a host profile if the architectures diverge. - if [ "${ARCH}" != "${build_arch}" ]; then - conan profile new ${ARCH} --detect - conan profile update settings.arch=${ARCH} ${ARCH} - conan profile update settings.arch_build=${ARCH} ${ARCH} - [[ "$(conan profile get settings.compiler ${ARCH})" != "gcc" ]] || \ - conan profile update settings.compiler.libcxx=libstdc++11 ${ARCH} - [[ "$(conan profile get settings.compiler ${build_arch})" != "Visual Studio" ]] || \ - [[ "${TOOLSET}" = "" ]] || \ - conan profile update settings.compiler.toolset=${TOOLSET} ${ARCH} - fi - name: install_conan diff --git a/CMakeLists.txt b/CMakeLists.txt index e5400582d4..33aa9420a1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -72,33 +72,6 @@ if(APPLE) endif() endif() -# Conan -if(EXISTS "${CMAKE_BINARY_DIR}/conanbuildinfo.cmake") - include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) - if(APPLE) - # By default Conan strips all RPATHs (see conanbuildinfo.cmake), which - # causes tests to fail as the executables cannot find the library target. - # By setting KEEP_RPATHS, Conan does not set CMAKE_SKIP_RPATH and the - # resulting binaries still have the RPATH information. This is fine because - # CMake will strip the build RPATH information in the install step. - # - # NOTE: - # Conan's default approach is to use the "imports" feature, which copies - # all the dependencies into the bin directory. Of course, this doesn't work - # quite that well for libraries generated in this Project (see Conan - # documentation). - # - # See the links below for more information. - # https://github.com/conan-io/conan/issues/337 - # https://docs.conan.io/en/latest/howtos/manage_shared_libraries/rpaths.html - # https://gitlab.kitware.com/cmake/community/wikis/doc/cmake/RPATH-handling - conan_basic_setup(KEEP_RPATHS) - else() - conan_basic_setup() - endif() - conan_define_targets() -endif() - # Set reasonably strict warning options for clang, gcc, msvc # Enable coloured ouput if Ninja is used for building if("${CMAKE_C_COMPILER_ID}" STREQUAL "Clang" OR @@ -227,9 +200,9 @@ endif() find_package(codecov) set(MEMORYCHECK_COMMAND_OPTIONS "--track-origins=yes --leak-check=full --trace-children=yes --child-silent-after-fork=yes --xml=yes --xml-file=TestResultValgrind_%p.xml --tool=memcheck --show-reachable=yes --leak-resolution=high") -# By default building the testing tree is enabled by including CTest, but -# since not everybody has CUnit, and because it is not strictly required to -# build the product itself, switch to off by default. +# Tests (integrated with CTest) are not built by default: not only are they not useful to +# most people, building the test suite also forces exporting way more symbols from the +# library so we can actually build the tests. option(BUILD_TESTING "Build the testing tree." OFF) # Include the tests for idlc. These tests use the idl compiler (C back-end) to diff --git a/README.md b/README.md index f50d45e6f1..4f65558542 100644 --- a/README.md +++ b/README.md @@ -69,7 +69,7 @@ while True: sleep(rng.exponential()) ``` -Today DDS is also popular in robotics and autonomous vehicles because those really depend on high-throuhgput, low-latency control systems without introducing a single point of failure by having a message broker in the middle. +Today DDS is also popular in robotics and autonomous vehicles because those really depend on high-throughput, low-latency control systems without introducing a single point of failure by having a message broker in the middle. Indeed, it is by far the most used and the default middleware choice in ROS 2. It is used to transfer commands, sensor data and even video and point clouds between components. @@ -99,7 +99,7 @@ With references to the individual OMG specifications, the following is available - [DDS XTypes](https://www.omg.org/spec/DDS-XTypes/1.3/PDF) - the structural type system (some [caveats](docs/dev/xtypes_relnotes.md) here) - [DDSI-RTPS](https://www.omg.org/spec/DDSI-RTPS/2.5/PDF) - the interoperable network protocol -The network stack in Cyclone DDS has been around for over a decade in one form or another and has proven itself in many systems, including large, high-availability ones and systems where interoperation with other implementations was needed. +The network stack in Cyclone DDS has been around for over a decade in one form or another and has proven itself in many systems, including large, high-availability ones and systems where interoperatibility with other implementations was needed. This repository provides the core of Cyclone DDS including its C API, the [OMG C++](https://github.com/eclipse-cyclonedds/cyclonedds-cxx) and the [Python](https://github.com/eclipse-cyclonedds/cyclonedds-python) language bindings are in sibling repositories. @@ -134,7 +134,7 @@ Depending on whether you want to develop applications using Cyclone DDS or contr There are some configuration options specified using CMake defines in addition to the standard options like `CMAKE_BUILD_TYPE`: * `-DBUILD_EXAMPLES=ON`: to build the included examples -* `-DBUILD_TESTING=ON`: to build the test suite (this requires [CUnit](http://cunit.sourceforge.net/), see [Contributing to Eclipse Cyclone DDS](#contributing-to-eclipse-cyclone-dds) below for more information) +* `-DBUILD_TESTING=ON`: to build the test suite (forces exporting all symbols from the library) * `-DBUILD_IDLC=NO`: to disable building the IDL compiler (affects building examples, tests and `ddsperf`) * `-DBUILD_DDSPERF=NO`: to disable building the [`ddsperf`](https://github.com/eclipse-cyclonedds/cyclonedds/tree/master/src/tools/ddsperf) tool for performance measurement * `-DENABLE_SSL=NO`: to not look for OpenSSL, remove TLS/TCP support and avoid building the plugins that implement authentication and encryption (default is `AUTO` to enable them if OpenSSL is found) @@ -189,7 +189,7 @@ Note that the default build type is a release build with debug information inclu We very much welcome all contributions to the project, whether that is questions, examples, bug fixes, enhancements or improvements to the documentation, or anything else really. -When considering contributing code, it might be good to know that build configurations for Azure pipelines are present in the repository and that there is a test suite using CTest and CUnit that can be built locally if desired. +When considering contributing code, it might be good to know that build configurations for Azure pipelines are present in the repository and that there is a test suite built using a simple testing framework and CTest that can be built locally if desired. To build it, set the cmake variable `BUILD_TESTING` to on when configuring, e.g.: $ cd build @@ -197,17 +197,6 @@ To build it, set the cmake variable `BUILD_TESTING` to on when configuring, e.g. $ cmake --build . $ ctest -Such a build requires the presence of [CUnit](http://cunit.sourceforge.net/). -You can install this yourself, or you can choose to instead rely on the [Conan](https://conan.io) packaging system that the CI build infrastructure also uses. -In that case, install Conan and do: - - $ conan install .. --build missing - -in the build directory prior to running cmake. - -For Windows, depending on the generator, you might also need to add switches to select the architecture and build type, e.g., `conan install -s arch=x86_64 -s build_type=Debug ..` -This will automatically download and/or build CUnit (and, at the moment, OpenSSL). - ## Documentation The [documentation](https://cyclonedds.io/docs) is still rather limited and some parts of it are still only available in the form of text files in the `docs` directory. diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 3eea09d95f..ee6f38816b 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -52,12 +52,13 @@ jobs: topic_discovery: off idlc_testing: off # temporary dislabled because of passing -t option to idlc in this test for recursive types cc: gcc-10 - 'Ubuntu 18.04 LTS with GCC 7 (Debug, x86_64)': - image: ubuntu-18.04 - conanfile: conanfile102.txt - cc: gcc-7 - 'Ubuntu 20.04 LTS with Clang 10 (Debug, x86_64)': - image: ubuntu-20.04 + 'Ubuntu 22.04 LTS with GCC 10 (Debug, x86_64, no tests)': + image: ubuntu-22.04 + cc: gcc-10 + testing: off + idlc_xtests: off + 'Ubuntu 22.04 LTS with Clang 12 (Debug, x86_64)': + image: ubuntu-22.04 analyzer: on sanitizer: address,undefined cc: clang-10 @@ -88,10 +89,19 @@ jobs: sanitizer: undefined cc: clang coverage: on - 'Windows 2019 with Visual Studio 2019 (Visual Studio 2017, Debug, x86)': + 'macOS 12 with gcc 12 (Debug, analyzer, x86_64)': + image: macOS-12 + sanitizer: undefined + deadline_update_skip: on + cc: gcc-12 + analyzer: on + # 32-bit Windows: without SSL/security because Chocolateley only provides 64-bit OpenSSL + 'Windows 2019 with Visual Studio 2019 (Visual Studio 2017, Debug, x86, no security)': arch: x86 image: windows-2019 - idlc_testing: off + ssl: off + security: off + idlc_xtests: off generator: 'Visual Studio 16 2019' toolset: v141 'Windows 2019 with Visual Studio 2019 (Debug, x86_64)': diff --git a/cmake/Modules/CUnit.cmake b/cmake/Modules/CUnit.cmake index 601887c8c2..8b5e49a4d5 100644 --- a/cmake/Modules/CUnit.cmake +++ b/cmake/Modules/CUnit.cmake @@ -9,7 +9,6 @@ # # SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause # -find_package(CUnit REQUIRED) set(CUNIT_DIR "${CMAKE_CURRENT_LIST_DIR}/CUnit") @@ -227,14 +226,6 @@ function(set_test_library_paths TEST_NAME) endfunction() function(add_cunit_executable TARGET) - # Retrieve location of shared libary, which is need to extend the PATH - # environment variable on Microsoft Windows, so that the operating - # system can locate the .dll that it was linked against. - # On macOS, this mechanism is used to set the DYLD_LIBRARY_PATH. - get_target_property(CUNIT_LIBRARY_TYPE CUnit TYPE) - get_target_property(CUNIT_IMPORTED_LOCATION CUnit IMPORTED_LOCATION) - get_filename_component(CUNIT_LIBRARY_DIR "${CUNIT_IMPORTED_LOCATION}" PATH) - set(decls) set(defns) set(sources) @@ -322,8 +313,7 @@ function(add_cunit_executable TARGET) add_executable( ${TARGET} "${CMAKE_CURRENT_BINARY_DIR}/${TARGET}.c" ${sources}) - target_link_libraries(${TARGET} PRIVATE CUnit) - target_include_directories(${TARGET} PRIVATE "${CUNIT_DIR}/include") + target_link_libraries(${TARGET} PRIVATE CycloneDDS::ucunit) if(MSVC) target_compile_definitions(${TARGET} PRIVATE _CRT_SECURE_NO_WARNINGS) endif() diff --git a/cmake/Modules/CUnit/src/main.c.in b/cmake/Modules/CUnit/src/main.c.in index 37bd1363e9..c7b4746739 100644 --- a/cmake/Modules/CUnit/src/main.c.in +++ b/cmake/Modules/CUnit/src/main.c.in @@ -22,20 +22,10 @@ static struct { bool print_help; - bool automated; - bool junit; - const char *results; - CU_BasicRunMode mode; - CU_ErrorAction error_action; const char *suite; const char *test; } opts = { false, - false, - false, - NULL, - CU_BRM_NORMAL, - CUEA_IGNORE, "*", "*" }; @@ -88,11 +78,7 @@ static void help(const char *name) printf("Usage: %s [OPTIONS]\n", name); printf("\n"); printf("Possible options:\n"); - printf(" -a run in automated mode\n"); - printf(" -f fail fast\n"); printf(" -h display this help and exit\n"); - printf(" -j junit format results \n"); - printf(" -r FILENAME results file for automated run\n"); printf(" -s PATTERN run only tests in suites matching pattern\n"); printf(" -t PATTERN run only test matching pattern\n"); printf("\n"); @@ -109,24 +95,9 @@ static int parse_options(int argc, char *argv[]) for (int i = 1; err == 0 && i < argc; i++) { switch ((argv[i][0] == '-') ? argv[i][1] : 0) { - case 'a': - opts.automated = true; - break; - case 'f': - opts.error_action = CUEA_FAIL; - break; case 'h': opts.print_help = true; break; - case 'j': - opts.junit = true; - break; - case 'r': - if((i+1) < argc){ - opts.results = argv[++i]; - break; - } - /* FALLS THROUGH */ case 's': if ((i+1) < argc) { opts.suite = argv[++i]; @@ -205,27 +176,7 @@ int main(int argc, char *argv[]) /* CMake will expand the macro below to register all suites and tests. */ @defns@ - CU_set_error_action(opts.error_action); - - if (opts.automated) { - if (opts.results != NULL) { - CU_set_output_filename(opts.results); - } - -#if defined(HAVE_ENABLE_JUNIT_XML) - if (opts.junit) { - CU_automated_enable_junit_xml(CU_TRUE); - } else -#endif - { - CU_list_tests_to_file(); - } - CU_automated_run_tests(); - } else { - CU_set_fail_on_inactive(0); - CU_basic_set_mode(opts.mode); - CU_basic_run_tests(); - } + CU_basic_run_tests(); if (CU_get_error() != CUE_SUCCESS) { ret = EX_SOFTWARE; diff --git a/cmake/Modules/FindCUnit.cmake b/cmake/Modules/FindCUnit.cmake deleted file mode 100644 index 5925ab481f..0000000000 --- a/cmake/Modules/FindCUnit.cmake +++ /dev/null @@ -1,120 +0,0 @@ -# -# Copyright(c) 2006 to 2021 ZettaScale Technology and others -# -# This program and the accompanying materials are made available under the -# terms of the Eclipse Public License v. 2.0 which is available at -# http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License -# v. 1.0 which is available at -# http://www.eclipse.org/org/documents/edl-v10.php. -# -# SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause -# -find_package(CUnit CONFIG QUIET) -if(CUnit_FOUND) - message(STATUS "Found CUnit via Config file: ${CUnit_DIR}") - set(CUNIT_FOUND ${CUnit_FOUND}) -else() - set(CUNIT_HEADER "CUnit/CUnit.h") - - if(CONAN_INCLUDE_DIRS) - find_path(CUNIT_INCLUDE_DIR ${CUNIT_HEADER} HINTS ${CONAN_INCLUDE_DIRS}) - else() - find_path(CUNIT_INCLUDE_DIR ${CUNIT_HEADER}) - endif() - - mark_as_advanced(CUNIT_INCLUDE_DIR) - - if(CUNIT_INCLUDE_DIR AND EXISTS "${CUNIT_INCLUDE_DIR}/${CUNIT_HEADER}") - set(PATTERN "^#define CU_VERSION \"([0-9]+)\\.([0-9]+)\\-([0-9]+)\"$") - file(STRINGS "${CUNIT_INCLUDE_DIR}/${CUNIT_HEADER}" CUNIT_H REGEX "${PATTERN}") - - string(REGEX REPLACE "${PATTERN}" "\\1" CUNIT_VERSION_MAJOR "${CUNIT_H}") - string(REGEX REPLACE "${PATTERN}" "\\2" CUNIT_VERSION_MINOR "${CUNIT_H}") - string(REGEX REPLACE "${PATTERN}" "\\3" CUNIT_VERSION_PATCH "${CUNIT_H}") - - set(CUNIT_VERSION "${CUNIT_VERSION_MAJOR}.${CUNIT_VERSION_MINOR}-${CUNIT_VERSION_PATCH}") - endif() - - if(CONAN_LIB_DIRS_CUNIT) - # CUnit package in ConanCenter contains a cunit.dll.lib on Windows if - # shared=True. Probably a bug not to simply name it cunit.lib, but strip - # the last extension from each library and use it as input. - foreach(path ${CONAN_LIBS_CUNIT}) - get_filename_component(name "${path}" NAME) - # NAME_WLE mode for get_filename_component available since CMake >= 3.14 - string(REGEX REPLACE "\.[^\.]+$" "" name_wle "${name}") - list(APPEND names ${name_wle}) - endforeach() - find_library(CUNIT_LIBRARY NAMES cunit ${names} HINTS ${CONAN_LIB_DIRS_CUNIT}) - else() - find_library(CUNIT_LIBRARY NAMES cunit) - endif() -endif() - -include(FindPackageHandleStandardArgs) -find_package_handle_standard_args( - CUnit - REQUIRED_VARS - CUNIT_LIBRARY CUNIT_INCLUDE_DIR - VERSION_VAR - CUNIT_VERSION) - -if(CUNIT_FOUND) - set(CUNIT_INCLUDE_DIRS ${CUNIT_INCLUDE_DIR}) - set(CUNIT_LIBRARIES ${CUNIT_LIBRARY}) - - if(WIN32) - get_filename_component(CUNIT_LIBRARY_DIR "${CUNIT_LIBRARY}}" PATH) - get_filename_component(CUNIT_BASENAME "${CUNIT_LIBRARY}}" NAME_WE) - get_filename_component(CUNIT_PREFIX "${CUNIT_LIBRARY_DIR}" PATH) - - if(CONAN_LIB_DIRS_CUNIT) - # CUnit package in ConanCenter shipped cunit-1.dll on Windows with - # shared=True. Probably a bug. Especially since the other file was named - # cunit.dll.lib. - set(_expr "${CUNIT_PREFIX}/${CUNIT_BASENAME}*${CMAKE_SHARED_LIBRARY_SUFFIX}") - file(GLOB_RECURSE _paths FALSE "${_expr}") - foreach(_path "${CMAKE_SHARED_LIBRARY_PREFIX}${CUNIT_BASENAME}" ${_paths}) - get_filename_component(_name "${_path}" NAME) - string(REGEX REPLACE "\.[^\.]+$" "" _name_wle "${_name}") - find_program( - CUNIT_DLL - "${_name_wle}${CMAKE_SHARED_LIBRARY_SUFFIX}" - HINTS - "${CUNIT_PREFIX}" - PATH_SUFFIXES - bin - NO_DEFAULT_PATH) - if(CUNIT_DLL) - break() - endif() - endforeach() - endif() - - mark_as_advanced(CUNIT_DLL) - - # IMPORTANT: - # Providing a .dll file as the value for IMPORTED_LOCATION can only be - # done for "SHARED" libraries, otherwise the location of the .dll will be - # passed to linker, causing it to fail. - if(CUNIT_DLL) - add_library(CUnit SHARED IMPORTED) - set_target_properties( - CUnit PROPERTIES IMPORTED_IMPLIB "${CUNIT_LIBRARY}") - set_target_properties( - CUnit PROPERTIES IMPORTED_LOCATION "${CUNIT_DLL}") - else() - add_library(CUnit STATIC IMPORTED) - set_target_properties( - CUnit PROPERTIES IMPORTED_LOCATION "${CUNIT_LIBRARY}") - endif() - else() - add_library(CUnit UNKNOWN IMPORTED) - set_target_properties( - CUnit PROPERTIES IMPORTED_LOCATION "${CUNIT_LIBRARY}") - endif() - - set_target_properties( - CUnit PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${CUNIT_INCLUDE_DIR}") -endif() - diff --git a/conanfile.txt b/conanfile.txt deleted file mode 100644 index 68f020213e..0000000000 --- a/conanfile.txt +++ /dev/null @@ -1,9 +0,0 @@ -[requires] -cunit/2.1-3 -openssl/1.1.1j - -[generators] -cmake - -[options] -cunit:shared=True diff --git a/conanfile102.txt b/conanfile102.txt deleted file mode 100644 index 8fc9cedcdf..0000000000 --- a/conanfile102.txt +++ /dev/null @@ -1,9 +0,0 @@ -[requires] -cunit/2.1-3 -openssl/1.0.2u - -[generators] -cmake - -[options] -cunit:shared=True diff --git a/docs/dev/debugging.md b/docs/dev/debugging.md index c1b0bf160a..4e69526eca 100644 --- a/docs/dev/debugging.md +++ b/docs/dev/debugging.md @@ -53,27 +53,13 @@ $ apt-get install gcc-8 g++-8 clang-6.0 bison su - travis ``` -5. Install The [Conan C/C++ Package Manager](https://conan.io). - - ``` -$ pip install conan --upgrade --user -$ conan user -``` - -6. Add the required repositories. - - ``` -$ conan remote add atolab https://api.bintray.com/conan/atolab/public-conan -$ conan remote add bincrafters https://api.bintray.com/conan/bincrafters/public-conan -``` - -7. Clone the git repository. +5. Clone the git repository. ``` $ git clone https://github.com/eclipse-cyclonedds/cyclonedds.git ``` -8. Build the project and run the tests. +6. Build the project and run the tests. > By default CMake and Conan will choose *gcc*. To switch to *clang*, set the > CC and CXX environment variables to clang and clang++ respectively. @@ -83,7 +69,6 @@ $ export CC=gcc-8 $ export CXX=g++-8 $ cd cyclonedds $ mkdir build -$ conan install .. $ cmake -DBUILD_TESTING=on ../src $ cmake --build . $ ctest -T test diff --git a/package.xml b/package.xml index 49cf011e49..0620fece6d 100644 --- a/package.xml +++ b/package.xml @@ -20,7 +20,6 @@ iceoryx_binding_c iceoryx_posh iceoryx_hoofs - libcunit-dev doxygen python3-breathe diff --git a/ports/freertos-posix/README.md b/ports/freertos-posix/README.md index f812374607..7978acb22f 100644 --- a/ports/freertos-posix/README.md +++ b/ports/freertos-posix/README.md @@ -58,23 +58,7 @@ cmake --build . --target install ``` mkdir build cd build -conan install -s arch=x86 .. -``` - -> For actual cross-compilation environments the instructions above will not -> install the correct packages. Even when e.g. Clang instead of GCC was used -> to build the simulator, the mismatch between Conan and CMake will break the -> build. To install the correct packages for the target, specify the required -> settings e.g. when the simulator was built using Clang 7.0, use -> `conan install -s arch=x86 -s compiler=clang -s compiler.version=7.0 ..`. -> If packages are not yet available for the target, as is usually the case -> with actual embedded targets, export the path to the toolchain file in the -> `CONAN_CMAKE_TOOLCHAIN_FILE` environment variable and add the `-b` flag to -> build the packages. - -2. Build Eclipse Cyclone DDS. - ``` -$ cmake -DCMAKE_TOOLCHAIN_FILE=/path/to/toolchain/file -DWITH_FREERTOS=on ../src +cmake -DCMAKE_TOOLCHAIN_FILE=/path/to/toolchain/file -DWITH_FREERTOS=on ../src ``` > Examples (and tests) can be executed like usual. The simulator provides a diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index fa08094a89..a0edd71a46 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -94,6 +94,9 @@ if(NOT ENABLE_SECURITY) message(STATUS "Building without OMG DDS Security support") endif() +if(BUILD_TESTING) + add_subdirectory(ucunit) +endif() add_subdirectory(tools) add_subdirectory(ddsrt) if(BUILD_IDLC) diff --git a/src/core/ddsc/tests/cdr.c b/src/core/ddsc/tests/cdr.c index 14897a614c..952080349a 100644 --- a/src/core/ddsc/tests/cdr.c +++ b/src/core/ddsc/tests/cdr.c @@ -326,7 +326,6 @@ static struct ddsi_serdata *sd_from_ser (const struct ddsi_sertype *tpcmn, enum }; const ddsi_keyhash_t *kh = ddsi_serdata_keyhash_from_fragchain (fragchain); CU_ASSERT_FATAL (kh != NULL); - assert (kh != NULL); // for Clang's static analyzer printf ("kh rcv %02x%02x%02x%02x:%02x%02x%02x%02x:%02x%02x%02x%02x:%02x%02x%02x%02x\n", kh->value[0], kh->value[1], kh->value[2], kh->value[3], kh->value[4], kh->value[5], kh->value[6], kh->value[7], diff --git a/src/core/ddsc/tests/domain.c b/src/core/ddsc/tests/domain.c index e106de6ea8..623a7ebc13 100644 --- a/src/core/ddsc/tests/domain.c +++ b/src/core/ddsc/tests/domain.c @@ -317,7 +317,6 @@ static void logsink (void *varg, const dds_log_data_t *msg) // do by rewriting the {0} to {} char *p = strchr (arg->buf[arg->size], '{'); CU_ASSERT_FATAL (p != NULL); - assert (p != NULL); // Clang static analyzer p++; CU_ASSERT_FATAL (strcmp (p, "}\n") == 0 || strcmp (p, "0}\n") == 0); if (*p == '0') diff --git a/src/core/ddsc/tests/instance_get_key.c b/src/core/ddsc/tests/instance_get_key.c index c9f40c5bc6..49d98dbb0b 100644 --- a/src/core/ddsc/tests/instance_get_key.c +++ b/src/core/ddsc/tests/instance_get_key.c @@ -132,7 +132,6 @@ CU_Test(ddsc_instance_get_key, registered_instance, .init=setup, .fini=teardown) ret = dds_instance_get_key(writer, handle, &key_data); CU_ASSERT_PTR_NOT_NULL_FATAL(key_data.ip); - assert (key_data.ip != NULL); /* for the benefit of clang's static analyzer */ CU_ASSERT_STRING_EQUAL_FATAL(key_data.ip, data.ip); CU_ASSERT_EQUAL_FATAL(key_data.port, data.port); CU_ASSERT_EQUAL_FATAL(ret, DDS_RETCODE_OK); @@ -163,7 +162,6 @@ CU_Test(ddsc_instance_get_key, readcondition, .init=setup, .fini=teardown) ret = dds_instance_get_key(readcondition, handle, &key_data); CU_ASSERT_PTR_NOT_NULL_FATAL(key_data.ip); - assert (key_data.ip != NULL); /* for the benefit of clang's static analyzer */ CU_ASSERT_STRING_EQUAL_FATAL(key_data.ip, data.ip); CU_ASSERT_EQUAL_FATAL(key_data.port, data.port); CU_ASSERT_EQUAL_FATAL(ret, DDS_RETCODE_OK); @@ -194,7 +192,6 @@ CU_Test(ddsc_instance_get_key, querycondition, .init=setup, .fini=teardown) ret = dds_instance_get_key(querycondition, handle, &key_data); CU_ASSERT_PTR_NOT_NULL_FATAL(key_data.ip); - assert (key_data.ip != NULL); /* for the benefit of clang's static analyzer */ CU_ASSERT_STRING_EQUAL_FATAL(key_data.ip, data.ip); CU_ASSERT_EQUAL_FATAL(key_data.port, data.port); CU_ASSERT_EQUAL_FATAL(ret, DDS_RETCODE_OK); diff --git a/src/core/ddsc/tests/liveliness.c b/src/core/ddsc/tests/liveliness.c index 61fca4a542..1601c657ca 100644 --- a/src/core/ddsc/tests/liveliness.c +++ b/src/core/ddsc/tests/liveliness.c @@ -93,7 +93,6 @@ static seqno_t get_pmd_seqno(dds_entity_t participant) pp = entidx_lookup_participant_guid(pp_entity->m_domain->gv.entity_index, &pp_entity->m_guid); wr = ddsi_get_builtin_writer (pp, NN_ENTITYID_P2P_BUILTIN_PARTICIPANT_MESSAGE_WRITER); CU_ASSERT_FATAL(wr != NULL); - assert(wr != NULL); /* for Clang's static analyzer */ seqno = wr->seq; thread_state_asleep(lookup_thread_state()); dds_entity_unpin(pp_entity); @@ -204,9 +203,9 @@ static void test_pmd_count(dds_liveliness_kind_t kind, uint32_t ldur, double mul /* End-start should be mult - 1 under ideal circumstances, but consider the test successful when at least 50% of the expected PMD's was sent. This checks that the frequency for sending PMDs was increased when the writer was added. */ - CU_ASSERT_FATAL((double) (end_seqno - start_seqno) >= (kind == DDS_LIVELINESS_AUTOMATIC ? (50 * (mult - 1)) / 100 : 0)) + CU_ASSERT_FATAL((double) (end_seqno - start_seqno) >= (kind == DDS_LIVELINESS_AUTOMATIC ? (50 * (mult - 1)) / 100 : 0)); if (kind != DDS_LIVELINESS_AUTOMATIC) - CU_ASSERT_FATAL((double) (get_pmd_seqno(g_pub_participant) - start_seqno) < mult) + CU_ASSERT_FATAL((double) (get_pmd_seqno(g_pub_participant) - start_seqno) < mult); /* cleanup */ if (remote_reader) @@ -499,7 +498,6 @@ static void test_lease_duration_pwr(bool remote_reader) dds_builtintopic_endpoint_t *ep; ep = dds_get_matched_publication_data(reader, wrs[0]); CU_ASSERT_FATAL(ep != NULL); - assert(ep != NULL); /* for Clang's static analyzer */ CU_ASSERT_EQUAL_FATAL(ep->qos->liveliness.lease_duration, DDS_MSECS(ldur)); dds_builtintopic_free_endpoint (ep); diff --git a/src/core/ddsc/tests/loan.c b/src/core/ddsc/tests/loan.c index 2860132918..29445a2461 100644 --- a/src/core/ddsc/tests/loan.c +++ b/src/core/ddsc/tests/loan.c @@ -106,7 +106,6 @@ CU_Test (ddsc_loan, success, .init = create_entities, .fini = delete_entities) CU_ASSERT_FATAL (result == DDS_RETCODE_OK); /* return resets buf[0] (so that it picks up the loan the next time) and zeros the data */ CU_ASSERT_FATAL (ptrs[0] == NULL); - assert (ptr0copy != NULL); /* clang static analyzer */ CU_ASSERT_FATAL (memcmp (ptr0copy, zeros, sizeof (s)) == 0); /* read 3, return: should work fine, causes realloc */ @@ -118,7 +117,6 @@ CU_Test (ddsc_loan, success, .init = create_entities, .fini = delete_entities) result = dds_return_loan (reader, ptrs, n); CU_ASSERT_FATAL (result == DDS_RETCODE_OK); CU_ASSERT_FATAL (ptrs[0] == NULL); - assert (ptr0copy != NULL); /* clang static analyzer */ CU_ASSERT_FATAL (memcmp (ptr0copy, zeros, 3 * sizeof (s)) == 0); /* read 1 using loan, expecting to get the same address (no realloc needed), defer return. @@ -143,7 +141,6 @@ CU_Test (ddsc_loan, success, .init = create_entities, .fini = delete_entities) { const struct RoundTripModule_DataType *a = ptrs[0]; const struct RoundTripModule_DataType *b = ptrs2[0]; - assert (a != NULL && b != NULL); /* clang static analyzer */ CU_ASSERT_FATAL (a->payload._length == b->payload._length); CU_ASSERT_FATAL (a->payload._buffer != b->payload._buffer); CU_ASSERT_FATAL (a->payload._buffer[0] == b->payload._buffer[0]); diff --git a/src/core/ddsc/tests/multi_sertopic.c b/src/core/ddsc/tests/multi_sertopic.c index 5b5689dcaf..e05be1591b 100644 --- a/src/core/ddsc/tests/multi_sertopic.c +++ b/src/core/ddsc/tests/multi_sertopic.c @@ -587,7 +587,7 @@ static void ddsc_multi_sertype_impl (dds_entity_t pp_pub, dds_entity_t pp_sub, e CU_ASSERT_FATAL (si.source_timestamp >= 1 && si.source_timestamp <= 3); CU_ASSERT_FATAL (u._d == 3); CU_ASSERT_FATAL (u._u.a._length == 1); - assert (u._u.a._buffer != NULL); /* for Clang static analyzer */ + CU_ASSERT_FATAL (u._u.a._buffer != NULL); CU_ASSERT_FATAL (u._u.a._buffer[0].v[0] == 4); CU_ASSERT_FATAL (u._u.a._buffer[0].v[1] == 2); dds_free (u._u.a._buffer); diff --git a/src/core/ddsc/tests/pp_lease_dur.c b/src/core/ddsc/tests/pp_lease_dur.c index a7ac4d3a57..cf7c8fd396 100644 --- a/src/core/ddsc/tests/pp_lease_dur.c +++ b/src/core/ddsc/tests/pp_lease_dur.c @@ -151,7 +151,6 @@ CU_Test(ddsc_participant_lease_duration, builtin_topic) if (memcmp (&ppg[i], &s->key, sizeof (s->key)) == 0) break; CU_ASSERT_FATAL (i < 3); // thanks to domain tag - assert (i < 3); // Clang static analyzer doesn't get CU_ASSERT_FATAL if (!si.valid_data) continue; nseen += !seen[i]; diff --git a/src/core/ddsc/tests/publisher.c b/src/core/ddsc/tests/publisher.c index 72b109e22e..4934632c7a 100644 --- a/src/core/ddsc/tests/publisher.c +++ b/src/core/ddsc/tests/publisher.c @@ -293,6 +293,7 @@ CU_Test(ddsc_publisher, wait_for_acks) CU_Test(ddsc_publisher, coherency) { + CU_PASS ("coherency not implemented yet"); return; } diff --git a/src/core/ddsc/tests/qos.c b/src/core/ddsc/tests/qos.c index 1b5538a726..dd6b82731e 100644 --- a/src/core/ddsc/tests/qos.c +++ b/src/core/ddsc/tests/qos.c @@ -761,7 +761,7 @@ CU_Test(ddsc_qos, bproperty, .init=qos_init, .fini=qos_fini) CU_ASSERT_FATAL(dds_qget_bprop (g_qos, c_bproperty_names[0], &bvalue, &size)); CU_ASSERT_FATAL (bvalue != NULL); CU_ASSERT_EQUAL_FATAL (size, 3); - assert (c_bproperty_values[0] != NULL); /* for Clang static analyzer */ + CU_ASSERT_FATAL (c_bproperty_values[0] != NULL); CU_ASSERT_EQUAL_FATAL (memcmp (bvalue, c_bproperty_values[0], size), 0); dds_free (bvalue); @@ -770,7 +770,7 @@ CU_Test(ddsc_qos, bproperty, .init=qos_init, .fini=qos_fini) CU_ASSERT_FATAL (dds_qget_bprop (g_qos, c_bproperty_names[0], &bvalue, &size)); CU_ASSERT_FATAL (bvalue != NULL); CU_ASSERT_EQUAL_FATAL (size, 3); - assert (c_bproperty_values[1] != NULL); /* for Clang static analyzer */ + CU_ASSERT_FATAL (c_bproperty_values[1] != NULL); CU_ASSERT_EQUAL_FATAL (memcmp (bvalue, c_bproperty_values[1], size), 0); dds_free (bvalue); dds_qset_bprop (g_qos, c_bproperty_names[0], &c_bproperty_values[0], 3); @@ -799,13 +799,13 @@ CU_Test(ddsc_qos, bproperty, .init=qos_init, .fini=qos_fini) CU_ASSERT_FATAL (dds_qget_bprop (g_qos, c_bproperty_names[0], &bvalue, &size)); CU_ASSERT_FATAL (bvalue != NULL); CU_ASSERT_EQUAL_FATAL (size, 3); - assert (c_bproperty_values[0] != NULL); /* for Clang static analyzer */ + CU_ASSERT_FATAL (c_bproperty_values[0] != NULL); CU_ASSERT_EQUAL_FATAL (memcmp (bvalue, c_bproperty_values[0], size), 0); dds_free (bvalue); CU_ASSERT_FATAL (dds_qget_bprop (g_qos, c_bproperty_names[2], &bvalue, &size)); CU_ASSERT_FATAL (bvalue != NULL); CU_ASSERT_EQUAL_FATAL (size, 3); - assert (c_bproperty_values[2] != NULL); /* for Clang static analyzer */ + CU_ASSERT_FATAL (c_bproperty_values[2] != NULL); CU_ASSERT_EQUAL_FATAL (memcmp (bvalue, c_bproperty_values[2], size), 0); dds_free (bvalue); dds_qunset_bprop (g_qos, c_bproperty_names[0]); @@ -828,7 +828,7 @@ CU_Test(ddsc_qos, property_mixed, .init=qos_init, .fini=qos_fini) CU_ASSERT_FATAL (dds_qget_bprop (g_qos, c_property_names[0], &bvalue, &size)); CU_ASSERT_FATAL (bvalue != NULL); CU_ASSERT_EQUAL_FATAL (size, 3); - assert (c_bproperty_values[0] != NULL); /* for Clang static analyzer */ + CU_ASSERT_FATAL (c_bproperty_values[0] != NULL); CU_ASSERT_EQUAL_FATAL (memcmp (bvalue, c_bproperty_values[0], size), 0); dds_free (bvalue); CU_ASSERT_FATAL (dds_qget_prop (g_qos, c_property_names[0], &value)); diff --git a/src/core/ddsc/tests/typelookup.c b/src/core/ddsc/tests/typelookup.c index a161f5d023..1de97a3627 100644 --- a/src/core/ddsc/tests/typelookup.c +++ b/src/core/ddsc/tests/typelookup.c @@ -277,7 +277,6 @@ CU_Test(ddsc_typelookup, get_typeobj, .init = typelookup_init, .fini = typelooku endpoint_info_t *reader_ep = find_typeid_match (g_participant2, DDS_BUILTIN_TOPIC_DCPSSUBSCRIPTION, rd_type_id, topic_name_rd, DDSI_TYPEID_KIND_MINIMAL); CU_ASSERT_FATAL (writer_ep != NULL); CU_ASSERT_FATAL (reader_ep != NULL); - assert (writer_ep && reader_ep); // clang static analyzer endpoint_info_free (writer_ep); endpoint_info_free (reader_ep); @@ -331,7 +330,6 @@ CU_Test(ddsc_typelookup, api_resolve, .init = typelookup_init, .fini = typelooku /* wait for DCPSPublication to be received */ endpoint_info_t *writer_ep = find_typeid_match (g_participant2, DDS_BUILTIN_TOPIC_DCPSPUBLICATION, type_id, name, DDSI_TYPEID_KIND_COMPLETE); CU_ASSERT_FATAL (writer_ep != NULL); - assert (writer_ep); // clang static analyzer /* check if type can be resolved */ dds_topic_descriptor_t *desc; @@ -389,7 +387,6 @@ CU_Test(ddsc_typelookup, api_resolve_invalid, .init = typelookup_init, .fini = t /* wait for DCPSPublication to be received */ endpoint_info_t *writer_ep = find_typeid_match (g_participant2, DDS_BUILTIN_TOPIC_DCPSPUBLICATION, type_id, name, DDSI_TYPEID_KIND_COMPLETE); CU_ASSERT_FATAL (writer_ep != NULL); - assert (writer_ep); // clang static analyzer /* confirm that invalid type id cannot be resolved */ struct dds_entity *e; diff --git a/src/core/ddsc/tests/whc.c b/src/core/ddsc/tests/whc.c index 145b23a1a2..5179089b19 100644 --- a/src/core/ddsc/tests/whc.c +++ b/src/core/ddsc/tests/whc.c @@ -175,7 +175,7 @@ static void test_whc_end_state(dds_durability_kind_t d, dds_reliability_kind_t r writer = dds_create_writer (g_publisher, topic, g_qos, NULL); CU_ASSERT_FATAL(writer > 0); ret = dds_set_status_mask(writer, DDS_PUBLICATION_MATCHED_STATUS); - CU_ASSERT_FATAL (ret == DDS_RETCODE_OK) + CU_ASSERT_FATAL (ret == DDS_RETCODE_OK); reader = lrd ? create_and_sync_reader (g_subscriber, topic, g_qos, writer) : 0; reader_remote = rrd ? create_and_sync_reader (g_remote_subscriber, remote_topic, g_qos, writer) : 0; diff --git a/src/core/ddsi/tests/plist_generic.c b/src/core/ddsi/tests/plist_generic.c index a0c5be97d8..85670f5699 100644 --- a/src/core/ddsi/tests/plist_generic.c +++ b/src/core/ddsi/tests/plist_generic.c @@ -168,8 +168,7 @@ CU_Test (ddsi_plist_generic, ser_and_deser) size_t sersize; dds_return_t ret; ret = plist_ser_generic (&ser, &sersize, descs[i].data, descs[i].desc); - if (ret != DDS_RETCODE_OK) - CU_ASSERT_FATAL (ret == DDS_RETCODE_OK); + CU_ASSERT_FATAL (ret == DDS_RETCODE_OK); if (sersize != descs[i].exp_sersize) CU_ASSERT (sersize == descs[i].exp_sersize); /* if sizes don't match, still check prefix */ @@ -279,8 +278,7 @@ CU_Test (ddsi_plist_generic, invalid_input) { dds_return_t ret; ret = plist_deser_generic (&mem, descs_invalid[i].ser, descs_invalid[i].sersize, false, descs_invalid[i].desc); - if (ret == DDS_RETCODE_OK) - CU_ASSERT_FATAL (ret != DDS_RETCODE_OK); + CU_ASSERT_FATAL (ret != DDS_RETCODE_OK); } } diff --git a/src/core/ddsi/tests/security_msg.c b/src/core/ddsi/tests/security_msg.c index 4513ccc016..844ae8f284 100644 --- a/src/core/ddsi/tests/security_msg.c +++ b/src/core/ddsi/tests/security_msg.c @@ -303,7 +303,6 @@ CU_Test (ddsi_security_msg, serializer) /* Check serialization result. */ size_t cmpsize = (len < sizeof(test_msg_ser)) ? len : sizeof(test_msg_ser); - assert(data != NULL); /* for Clang static analyzer */ if (memcmp (data, test_msg_ser, cmpsize) != 0) { printf ("memcmp(%d)\n", (int)cmpsize); diff --git a/src/ddsrt/tests/environ.c b/src/ddsrt/tests/environ.c index 6f7dd89e6a..46ba738fb7 100644 --- a/src/ddsrt/tests/environ.c +++ b/src/ddsrt/tests/environ.c @@ -49,14 +49,12 @@ CU_Test(ddsrt_environ, setenv) rc = ddsrt_setenv(name, value); CU_ASSERT_EQUAL(rc, DDS_RETCODE_OK); ptr = getenv(name); - CU_ASSERT_PTR_NOT_NULL(ptr); - assert (ptr != NULL); /* for the benefit of clang's static analyzer */ + CU_ASSERT_PTR_NOT_NULL_FATAL(ptr); CU_ASSERT_STRING_EQUAL(ptr, "bar"); /* Ensure value is copied into the environment. */ value[2] = 'z'; ptr = getenv(name); - CU_ASSERT_PTR_NOT_NULL(ptr); - assert (ptr != NULL); /* for the benefit of clang's static analyzer */ + CU_ASSERT_PTR_NOT_NULL_FATAL(ptr); CU_ASSERT_STRING_EQUAL(ptr, "bar"); rc = ddsrt_setenv(name, ""); CU_ASSERT_EQUAL(rc, DDS_RETCODE_OK); diff --git a/src/ddsrt/tests/hopscotch.c b/src/ddsrt/tests/hopscotch.c index 3ece3e36f5..36e22fb2f5 100644 --- a/src/ddsrt/tests/hopscotch.c +++ b/src/ddsrt/tests/hopscotch.c @@ -298,7 +298,7 @@ static uint32_t chhtest_thread (void *varg) { const uint32_t ix = (raw_oper >> 2) % arg->nkeys; bool x = ddsrt_chh_lookup (arg->chh, ksptrs[ix]); - if (arg->check && ((ix < n) ? !x : x)) { CU_ASSERT_FATAL (0) }; + if (arg->check && ((ix < n) ? !x : x)) { CU_ASSERT_FATAL (0); } arg->lookups++; } break; diff --git a/src/ddsrt/tests/ifaddrs.c b/src/ddsrt/tests/ifaddrs.c index 471e01fe7b..cd33aa284d 100644 --- a/src/ddsrt/tests/ifaddrs.c +++ b/src/ddsrt/tests/ifaddrs.c @@ -74,7 +74,6 @@ CU_Test(ddsrt_getifaddrs, ipv4) CU_ASSERT_EQUAL_FATAL(ret, DDS_RETCODE_OK); for (ifa = ifa_root; ifa; ifa = ifa->next) { CU_ASSERT_PTR_NOT_EQUAL_FATAL(ifa->addr, NULL); - assert (ifa->addr != NULL); /* for the benefit of clang's static analyzer */ CU_ASSERT_EQUAL(ifa->addr->sa_family, AF_INET); if (ifa->addr->sa_family == AF_INET) { if (ifa->flags & IFF_LOOPBACK) { @@ -132,7 +131,6 @@ CU_Test(ddsrt_getifaddrs, ipv6) CU_ASSERT_EQUAL_FATAL(ret, DDS_RETCODE_OK); for (ifa = ifa_root; ifa; ifa = ifa->next) { CU_ASSERT_PTR_NOT_EQUAL_FATAL(ifa->addr, NULL); - assert (ifa->addr != NULL); /* for the benefit of clang's static analyzer */ CU_ASSERT_EQUAL(ifa->addr->sa_family, AF_INET6); if (ifa->addr->sa_family == AF_INET6) { have_ipv6 = 1; @@ -173,7 +171,6 @@ CU_Test(ddsrt_getifaddrs, ipv4_n_ipv6) CU_ASSERT_EQUAL_FATAL(ret, DDS_RETCODE_OK); for (ifa = ifa_root; ifa; ifa = ifa->next) { CU_ASSERT_PTR_NOT_EQUAL_FATAL(ifa->addr, NULL); - assert (ifa->addr != NULL); /* for the benefit of clang's static analyzer */ CU_ASSERT(ifa->addr->sa_family == AF_INET || ifa->addr->sa_family == AF_INET6); if (ifa->addr->sa_family == AF_INET) { diff --git a/src/ddsrt/tests/log.c b/src/ddsrt/tests/log.c index ec4cb06065..f47c7c6c89 100644 --- a/src/ddsrt/tests/log.c +++ b/src/ddsrt/tests/log.c @@ -13,6 +13,7 @@ #include #include #include +#include #ifdef __APPLE__ #include @@ -316,6 +317,7 @@ CU_Test(dds_log, newline_terminates, .fini=reset) CU_ASSERT_PTR_NULL_FATAL(msg); DDS_ERROR("baz\n"); CU_ASSERT_PTR_NOT_NULL_FATAL(msg); + assert(msg); CU_ASSERT(strcmp(msg, "foobarbaz\n") == 0); ddsrt_free(msg); #endif @@ -332,6 +334,7 @@ CU_Test(dds_log, disabled_categories_discarded, .fini=reset) dds_set_log_mask(DDS_LC_FATAL | DDS_LC_ERROR | DDS_LC_INFO); DDS_INFO("foobar\n"); CU_ASSERT_PTR_NOT_NULL_FATAL(msg); + assert(msg); CU_ASSERT(strcmp(msg, "foobar\n") == 0); ddsrt_free(msg); #endif @@ -506,5 +509,6 @@ CU_Theory((bool local, int mode, bool expect_in_trace), dds_log, fatal_aborts) (void) local; (void) mode; (void) expect_in_trace; + CU_PASS ("test skipped on this platform"); #endif } diff --git a/src/ddsrt/tests/string.c b/src/ddsrt/tests/string.c index 898cf84d7f..9e36feda04 100644 --- a/src/ddsrt/tests/string.c +++ b/src/ddsrt/tests/string.c @@ -83,7 +83,6 @@ CU_Theory((const char *str, const char *srch, const char *subst, size_t max, con if (exp != NULL) { CU_ASSERT_FATAL(r != NULL); - assert(r != NULL); /* for Clang static analyzer */ CU_ASSERT(strcmp(r, exp) == 0); ddsrt_free(r); } diff --git a/src/idl/tests/union.c b/src/idl/tests/union.c index e9fe07e4e6..2ec1ef9c25 100644 --- a/src/idl/tests/union.c +++ b/src/idl/tests/union.c @@ -466,6 +466,7 @@ CU_Test(idl_union, default_discriminator_unsigned_int) CU_ASSERT(u->default_case && u->default_case->const_expr); CU_ASSERT_PTR_EQUAL(idl_parent(u->default_case), u); } + CU_ASSERT_FATAL(u->default_case->const_expr); CU_ASSERT_FATAL(idl_is_literal(u->default_case->const_expr)); l = u->default_case->const_expr; CU_ASSERT_FATAL(idl_type(l) == IDL_UINT8); diff --git a/src/security/builtin_plugins/tests/decode_serialized_payload/src/decode_serialized_payload_utests.c b/src/security/builtin_plugins/tests/decode_serialized_payload/src/decode_serialized_payload_utests.c index 8fd5998809..66f762c46b 100644 --- a/src/security/builtin_plugins/tests/decode_serialized_payload/src/decode_serialized_payload_utests.c +++ b/src/security/builtin_plugins/tests/decode_serialized_payload/src/decode_serialized_payload_utests.c @@ -784,7 +784,6 @@ CU_Test(ddssec_builtin_decode_serialized_payload, invalid_data, .init = suite_de } CU_ASSERT_FATAL(result); - assert(result); // for Clang's static analyzer CU_ASSERT(exception.code == 0); CU_ASSERT(exception.message == NULL); diff --git a/src/security/builtin_plugins/tests/encode_datareader_submessage/src/encode_datareader_submessage_utests.c b/src/security/builtin_plugins/tests/encode_datareader_submessage/src/encode_datareader_submessage_utests.c index 8487dfc5a7..499ade5e50 100644 --- a/src/security/builtin_plugins/tests/encode_datareader_submessage/src/encode_datareader_submessage_utests.c +++ b/src/security/builtin_plugins/tests/encode_datareader_submessage/src/encode_datareader_submessage_utests.c @@ -825,7 +825,6 @@ static void encode_datareader_submessage_not_signed(uint32_t transformation_kind reader_crypto = register_local_datareader(&datareader_security_attributes, &datareader_properties); CU_ASSERT_FATAL(reader_crypto != 0); - assert(reader_crypto != 0); // for Clang's static analyzer session_keys = get_datareader_session(reader_crypto); @@ -851,7 +850,6 @@ static void encode_datareader_submessage_not_signed(uint32_t transformation_kind } CU_ASSERT_FATAL(result); - assert(result); // for Clang's static analyzer CU_ASSERT(exception.code == 0); CU_ASSERT(exception.message == NULL); @@ -859,7 +857,6 @@ static void encode_datareader_submessage_not_signed(uint32_t transformation_kind result = check_encoded_data(&encoded_buffer, is_encrypted, &header, &footer, &data); CU_ASSERT_FATAL(result); - assert(result); // for Clang's static analyzer CU_ASSERT(header->transform_identifier.transformation_kind[3] == transformation_kind); @@ -978,7 +975,6 @@ static void encode_datareader_submessage_sign(uint32_t transformation_kind) reader_crypto = register_local_datareader(&datareader_security_attributes, &datareader_properties); CU_ASSERT_FATAL(reader_crypto != 0); - assert(reader_crypto != 0); // for Clang's static analyzer session_keys = get_datareader_session(reader_crypto); @@ -988,7 +984,6 @@ static void encode_datareader_submessage_sign(uint32_t transformation_kind) { writer_crypto = register_remote_datawriter(reader_crypto); CU_ASSERT_FATAL(writer_crypto != 0); - assert(writer_crypto != 0); // for Clang's static analyzer writer_list._buffer[i] = writer_crypto; } @@ -1009,7 +1004,6 @@ static void encode_datareader_submessage_sign(uint32_t transformation_kind) } CU_ASSERT_FATAL(result); - assert(result); // for Clang's static analyzer CU_ASSERT(exception.code == 0); CU_ASSERT(exception.message == NULL); @@ -1018,7 +1012,6 @@ static void encode_datareader_submessage_sign(uint32_t transformation_kind) result = check_encoded_data(&encoded_buffer, is_encrypted, &header, &footer, &data); CU_ASSERT_FATAL(result); - assert(result); // for Clang's static analyzer CU_ASSERT(header->transform_identifier.transformation_kind[3] == transformation_kind); diff --git a/src/security/builtin_plugins/tests/encode_datawriter_submessage/src/encode_datawriter_submessage_utests.c b/src/security/builtin_plugins/tests/encode_datawriter_submessage/src/encode_datawriter_submessage_utests.c index d5c40c7064..a15ba39f56 100644 --- a/src/security/builtin_plugins/tests/encode_datawriter_submessage/src/encode_datawriter_submessage_utests.c +++ b/src/security/builtin_plugins/tests/encode_datawriter_submessage/src/encode_datawriter_submessage_utests.c @@ -799,13 +799,11 @@ static void encode_datawriter_submessage_not_signed(DDS_Security_CryptoTransform writer_crypto = register_local_datawriter(&datawriter_security_attributes, &datawriter_properties); CU_ASSERT_FATAL(writer_crypto != 0); - assert(writer_crypto != 0); // for Clang's static analyzer session_keys = get_datawriter_session(writer_crypto); reader_crypto = register_remote_datareader(writer_crypto); CU_ASSERT_FATAL(reader_crypto != 0); - assert(reader_crypto != 0); // for Clang's static analyzer reader_list._length = reader_list._maximum = 1; reader_list._buffer = DDS_Security_DatareaderCryptoHandleSeq_allocbuf(1); @@ -828,7 +826,6 @@ static void encode_datawriter_submessage_not_signed(DDS_Security_CryptoTransform } CU_ASSERT_FATAL(result); - assert(result != 0); // for Clang's static analyzer CU_ASSERT(exception.code == 0); CU_ASSERT(exception.message == NULL); @@ -837,7 +834,6 @@ static void encode_datawriter_submessage_not_signed(DDS_Security_CryptoTransform result = check_encoded_data(&encoded_buffer, is_encrypted, &header, &footer, &data); CU_ASSERT_FATAL(result); - assert(result); // for Clang's static analyzer CU_ASSERT(header->transform_identifier.transformation_kind[3] == transformation_kind); @@ -958,7 +954,6 @@ static void encode_datawriter_submessage_sign(DDS_Security_CryptoTransformKind_E writer_crypto = register_local_datawriter(&datawriter_security_attributes, &datawriter_properties); CU_ASSERT_FATAL(writer_crypto != 0); - assert(writer_crypto != 0); // for Clang's static analyzer session_keys = get_datawriter_session(writer_crypto); @@ -968,7 +963,6 @@ static void encode_datawriter_submessage_sign(DDS_Security_CryptoTransformKind_E { reader_crypto = register_remote_datareader(writer_crypto); CU_ASSERT_FATAL(reader_crypto != 0); - assert(reader_crypto != 0); // for Clang's static analyzer reader_list._buffer[i] = reader_crypto; } index = 0; @@ -993,7 +987,6 @@ static void encode_datawriter_submessage_sign(DDS_Security_CryptoTransformKind_E } CU_ASSERT_FATAL(result); - assert(result); // for Clang's static analyzer CU_ASSERT(exception.code == 0); CU_ASSERT(exception.message == NULL); @@ -1003,7 +996,6 @@ static void encode_datawriter_submessage_sign(DDS_Security_CryptoTransformKind_E result = check_encoded_data(&encoded_buffer, is_encrypted, &header, &footer, &data); CU_ASSERT_FATAL(result); - assert(result); // for Clang's static analyzer CU_ASSERT(header->transform_identifier.transformation_kind[3] == transformation_kind); diff --git a/src/security/builtin_plugins/tests/encode_rtps_message/src/encode_rtps_message_utests.c b/src/security/builtin_plugins/tests/encode_rtps_message/src/encode_rtps_message_utests.c index 89a35ea7c2..552787baf5 100644 --- a/src/security/builtin_plugins/tests/encode_rtps_message/src/encode_rtps_message_utests.c +++ b/src/security/builtin_plugins/tests/encode_rtps_message/src/encode_rtps_message_utests.c @@ -827,7 +827,6 @@ static void encode_rtps_message_not_authenticated(DDS_Security_CryptoTransformKi } CU_ASSERT_FATAL(result); - assert(result); // for Clang's static analyzer CU_ASSERT(exception.code == 0); CU_ASSERT(exception.message == NULL); @@ -835,7 +834,6 @@ static void encode_rtps_message_not_authenticated(DDS_Security_CryptoTransformKi result = check_encoded_data(&encoded_buffer, encrypted, &header, &footer, &data); CU_ASSERT_FATAL(result); - assert(result); // for Clang's static analyzer CU_ASSERT(header->transform_identifier.transformation_kind[3] == transformation_kind); @@ -1090,7 +1088,6 @@ CU_Test(ddssec_builtin_encode_rtps_message, invalid_args, .init = suite_encode_r memset(&empty_reader_list, 0, sizeof(empty_reader_list)); CU_ASSERT_FATAL(local_particpant_crypto != 0); - assert(local_particpant_crypto != 0); // for Clang's static analyzer register_remote_participants(); for (i = 0; i < sizeof (remote_particpant_cryptos) / sizeof (remote_particpant_cryptos[0]); i++) @@ -1100,7 +1097,6 @@ CU_Test(ddssec_builtin_encode_rtps_message, invalid_args, .init = suite_encode_r } CU_ASSERT_FATAL(remote_particpant_cryptos[0] != 0); - assert(remote_particpant_cryptos[0] != 0); // for Clang's static analyzer reader_list._length = reader_list._maximum = 1; reader_list._buffer = DDS_Security_ParticipantCryptoHandleSeq_allocbuf(1); diff --git a/src/security/builtin_plugins/tests/encode_serialized_payload/src/encode_serialized_payload_utests.c b/src/security/builtin_plugins/tests/encode_serialized_payload/src/encode_serialized_payload_utests.c index f0b6256ae1..56ad5c4e69 100644 --- a/src/security/builtin_plugins/tests/encode_serialized_payload/src/encode_serialized_payload_utests.c +++ b/src/security/builtin_plugins/tests/encode_serialized_payload/src/encode_serialized_payload_utests.c @@ -564,7 +564,6 @@ static void encode_serialized_payload_check(uint32_t key_size, bool encrypted) writer_crypto = register_local_datawriter(encrypted); CU_ASSERT_FATAL(writer_crypto != 0); - assert(writer_crypto != 0); // for Clang's static analyzer CU_ASSERT(check_protection_kind(writer_crypto, encrypted ? DDS_SECURITY_BASICPROTECTION_KIND_ENCRYPT : DDS_SECURITY_BASICPROTECTION_KIND_SIGN)); @@ -586,14 +585,12 @@ static void encode_serialized_payload_check(uint32_t key_size, bool encrypted) printf("[ERROR] encode_serialized_payload: %s\n", exception.message ? exception.message : "Error message missing"); } CU_ASSERT_FATAL(result); - assert(result); // for Clang's static analyzer CU_ASSERT(exception.code == 0); CU_ASSERT(exception.message == NULL); reset_exception(&exception); result = split_encoded_data(encoded_buffer._buffer, encoded_buffer._length, &header, &encoded_payload, &footer, encrypted); CU_ASSERT_FATAL(result == true); - assert(result); // for Clang's static analyzer CU_ASSERT(check_payload_encoded(&encoded_payload, &plain_buffer, encrypted)); session_id = ddsrt_fromBE4u(*(uint32_t *)header->session_id); diff --git a/src/security/builtin_plugins/tests/get_authenticated_peer_credential_token/src/get_authenticated_peer_credential_token_utests.c b/src/security/builtin_plugins/tests/get_authenticated_peer_credential_token/src/get_authenticated_peer_credential_token_utests.c index 77dd71d1f6..c750b0018b 100644 --- a/src/security/builtin_plugins/tests/get_authenticated_peer_credential_token/src/get_authenticated_peer_credential_token_utests.c +++ b/src/security/builtin_plugins/tests/get_authenticated_peer_credential_token/src/get_authenticated_peer_credential_token_utests.c @@ -1232,9 +1232,8 @@ fill_handshake_message_token( dh2 = &tokens[idx++]; hash_c2 = &tokens[idx++]; - CU_ASSERT(hash1_from_request != NULL); - CU_ASSERT(hash2_from_reply != NULL); - assert(hash1_from_request && hash2_from_reply); // for Clang's static analyzer + CU_ASSERT_FATAL(hash1_from_request != NULL); + CU_ASSERT_FATAL(hash2_from_reply != NULL); set_binary_property_value(hash_c1, DDS_AUTHTOKEN_PROP_HASH_C1, hash1_from_request->value._buffer, hash1_from_request->value._length); set_binary_property_value(hash_c2, DDS_AUTHTOKEN_PROP_HASH_C2, hash2_from_reply->value._buffer, hash2_from_reply->value._length); @@ -1361,7 +1360,6 @@ CU_Test(ddssec_builtin_get_authenticated_peer_credential,token_after_request ) &exception); CU_ASSERT_FATAL(result == DDS_SECURITY_VALIDATION_PENDING_HANDSHAKE_MESSAGE); - assert(result == DDS_SECURITY_VALIDATION_PENDING_HANDSHAKE_MESSAGE); // for Clang's static analyzer /* mock reply */ dh1 = find_binary_property(&handshake_token_out, DDS_AUTHTOKEN_PROP_DH1); @@ -1394,7 +1392,6 @@ CU_Test(ddssec_builtin_get_authenticated_peer_credential,token_after_request ) handshake_handle, &exception); CU_ASSERT_FATAL(result == DDS_SECURITY_VALIDATION_OK_FINAL_MESSAGE); - assert(result == DDS_SECURITY_VALIDATION_OK_FINAL_MESSAGE); // for Clang's static analyzer /* * Actual test. @@ -1405,27 +1402,22 @@ CU_Test(ddssec_builtin_get_authenticated_peer_credential,token_after_request ) handshake_handle, &exception); - CU_ASSERT_TRUE (success); - assert(success); // for Clang's static analyzer + CU_ASSERT_TRUE_FATAL (success); CU_ASSERT_FATAL(credential_token.class_id != NULL); - assert(credential_token.class_id); // for Clang's static analyzer CU_ASSERT(strcmp(credential_token.class_id, DDS_AUTHTOKEN_CLASS_ID) == 0); CU_ASSERT(credential_token.properties._length == 2); CU_ASSERT(credential_token.binary_properties._length == 0); c_id = find_property(&credential_token, DDS_AUTHTOKEN_PROP_C_ID); CU_ASSERT_FATAL(c_id != NULL); - assert(c_id); // for GCC's static analyzer CU_ASSERT_FATAL(c_id->value != NULL); - assert(c_id && c_id->value); // for Clang's static analyzer //printf("c_id->value: %s\n", c_id->value); CU_ASSERT(strcmp(c_id->value, REMOTE_IDENTITY_CERTIFICATE) == 0); c_perm = find_property(&credential_token, DDS_AUTHTOKEN_PROP_C_PERM); CU_ASSERT_FATAL(c_perm != NULL); CU_ASSERT_FATAL(c_perm->value != NULL); - assert(c_perm && c_perm->value); // for Clang's static analyzer //printf("c_perm->value: %s\n", c_perm->value); CU_ASSERT(strcmp(c_perm->value, PERMISSIONS_DOCUMENT) == 0); @@ -1492,7 +1484,6 @@ CU_Test(ddssec_builtin_get_authenticated_peer_credential,token_after_reply ) &exception); CU_ASSERT_FATAL(result == DDS_SECURITY_VALIDATION_PENDING_HANDSHAKE_MESSAGE); - assert(result == DDS_SECURITY_VALIDATION_PENDING_HANDSHAKE_MESSAGE); // for Clang's static analyzer /* mock final */ dh2 = find_binary_property(&handshake_token_out, DDS_AUTHTOKEN_PROP_DH2); @@ -1526,7 +1517,6 @@ CU_Test(ddssec_builtin_get_authenticated_peer_credential,token_after_reply ) &exception); CU_ASSERT_FATAL(result == DDS_SECURITY_VALIDATION_OK); - assert(result == DDS_SECURITY_VALIDATION_OK); // for Clang's static analyzer /* * Actual test. @@ -1537,8 +1527,7 @@ CU_Test(ddssec_builtin_get_authenticated_peer_credential,token_after_reply ) handshake_handle, &exception); - CU_ASSERT_TRUE (success); - assert(success); // for Clang's static analyzer + CU_ASSERT_TRUE_FATAL (success); CU_ASSERT_FATAL(credential_token.class_id != NULL); CU_ASSERT(strcmp(credential_token.class_id, DDS_AUTHTOKEN_CLASS_ID) == 0); @@ -1547,9 +1536,7 @@ CU_Test(ddssec_builtin_get_authenticated_peer_credential,token_after_reply ) c_id = find_property(&credential_token, DDS_AUTHTOKEN_PROP_C_ID); CU_ASSERT_FATAL(c_id != NULL); - assert(c_id); // for GCC's static analyzer CU_ASSERT_FATAL(c_id->value != NULL); - assert(c_id && c_id->value); // for Clang's static analyzer //printf("c_id->value: %s\n", c_id->value); CU_ASSERT(strcmp(c_id->value, REMOTE_IDENTITY_CERTIFICATE) == 0); @@ -1572,8 +1559,7 @@ CU_Test(ddssec_builtin_get_authenticated_peer_credential,token_after_reply ) CU_ASSERT(credential_token.binary_properties._length == 0); success = g_auth->return_handshake_handle(g_auth, handshake_handle, &exception); - CU_ASSERT_TRUE (success); - assert(success); // for Clang's static analyzer + CU_ASSERT_TRUE_FATAL (success); reset_exception(&exception); diff --git a/src/security/builtin_plugins/tests/listeners_authentication/src/listeners_authentication_utests.c b/src/security/builtin_plugins/tests/listeners_authentication/src/listeners_authentication_utests.c index 4b4891df45..0e0076851a 100644 --- a/src/security/builtin_plugins/tests/listeners_authentication/src/listeners_authentication_utests.c +++ b/src/security/builtin_plugins/tests/listeners_authentication/src/listeners_authentication_utests.c @@ -1677,7 +1677,6 @@ fill_handshake_message_token( } CU_ASSERT_FATAL(hash1_from_request != NULL); - assert(hash1_from_request != NULL); // for Clang's static analyzer set_binary_property_value(hash_c1, DDS_AUTHTOKEN_PROP_HASH_C1, hash1_from_request->value._buffer, hash1_from_request->value._length); @@ -1764,7 +1763,6 @@ fill_handshake_message_token( else { CU_ASSERT_FATAL (rc == DDS_SECURITY_VALIDATION_OK); - assert(rc == DDS_SECURITY_VALIDATION_OK); // for Clang's static analyzer set_binary_property_value(signature, DDS_AUTHTOKEN_PROP_SIGNATURE, sign, (uint32_t)signlen); ddsrt_free(sign); } @@ -1967,10 +1965,8 @@ CU_Test(ddssec_builtin_listeners_auth, local_remote_set_before_validation) hash1_sent_in_request = find_binary_property(&handshake_token_out, DDS_AUTHTOKEN_PROP_HASH_C1); CU_ASSERT_FATAL(dh1 != NULL); - assert(dh1 != NULL); // for Clang's static analyzer CU_ASSERT_FATAL(dh1->value._length > 0); CU_ASSERT_FATAL(dh1->value._buffer != NULL); - assert(dh1->value._length > 0 && dh1->value._buffer != NULL); // for Clang's static analyzer dh1_pub_key.data = dh1->value._buffer; dh1_pub_key.length = dh1->value._length; diff --git a/src/security/builtin_plugins/tests/process_handshake/src/process_handshake_utests.c b/src/security/builtin_plugins/tests/process_handshake/src/process_handshake_utests.c index 40ce02ee9c..e8dae33634 100644 --- a/src/security/builtin_plugins/tests/process_handshake/src/process_handshake_utests.c +++ b/src/security/builtin_plugins/tests/process_handshake/src/process_handshake_utests.c @@ -1407,7 +1407,6 @@ fill_handshake_message_token( } CU_ASSERT_FATAL(hash1_from_request != NULL); - assert(hash1_from_request != NULL); // for Clang's static analyzer set_binary_property_value(hash_c1, DDS_AUTHTOKEN_PROP_HASH_C1, hash1_from_request->value._buffer, hash1_from_request->value._length); @@ -1710,10 +1709,8 @@ CU_Test(ddssec_builtin_process_handshake,happy_day_after_request) hash1_sentrequest = find_binary_property(&handshake_token_out, DDS_AUTHTOKEN_PROP_HASH_C1); CU_ASSERT_FATAL(dh1 != NULL); - assert(dh1 != NULL); // for Clang's static analyzer CU_ASSERT_FATAL(dh1->value._length > 0); CU_ASSERT_FATAL(dh1->value._buffer != NULL); - assert(dh1->value._length > 0 && dh1->value._buffer != NULL); // for Clang's static analyzer dh1_pub_key.data = dh1->value._buffer; dh1_pub_key.length = dh1->value._length; @@ -2004,10 +2001,8 @@ CU_Test(ddssec_builtin_process_handshake,invalid_certificate) hash1_sentrequest = find_binary_property(&handshake_token_out, DDS_AUTHTOKEN_PROP_HASH_C1); CU_ASSERT_FATAL(dh1 != NULL); - assert(dh1 != NULL); // for Clang's static analyzer CU_ASSERT_FATAL(dh1->value._length > 0); CU_ASSERT_FATAL(dh1->value._buffer != NULL); - assert(dh1->value._length > 0 && dh1->value._buffer != NULL); // for Clang's static analyzer /* prepare reply */ dh1_pub_key.data = dh1->value._buffer; @@ -2094,10 +2089,8 @@ CU_Test(ddssec_builtin_process_handshake,invalid_dsign_algo) hash1_sentrequest = find_binary_property(&handshake_token_out, DDS_AUTHTOKEN_PROP_HASH_C1); CU_ASSERT_FATAL(dh1 != NULL); - assert(dh1 != NULL); // for Clang's static analyzer CU_ASSERT_FATAL(dh1->value._length > 0); CU_ASSERT_FATAL(dh1->value._buffer != NULL); - assert(dh1->value._length > 0 && dh1->value._buffer != NULL); // for Clang's static analyzer /* prepare reply */ dh1_pub_key.data = dh1->value._buffer; @@ -2178,10 +2171,8 @@ CU_Test(ddssec_builtin_process_handshake,invalid_kagree_algo) hash1_sentrequest = find_binary_property(&handshake_token_out, DDS_AUTHTOKEN_PROP_HASH_C1); CU_ASSERT_FATAL(dh1 != NULL); - assert (dh1 != NULL); // for Clang's static analyzer CU_ASSERT_FATAL(dh1->value._length > 0); CU_ASSERT_FATAL(dh1->value._buffer != NULL); - assert (dh1->value._length > 0 && dh1->value._buffer != NULL); // for Clang's static analyzer /* prepare reply */ dh1_pub_key.data = dh1->value._buffer; @@ -2261,10 +2252,8 @@ CU_Test(ddssec_builtin_process_handshake,invalid_diffie_hellman) hash1_sentrequest = find_binary_property(&handshake_token_out, DDS_AUTHTOKEN_PROP_HASH_C1); CU_ASSERT_FATAL(dh1 != NULL); - assert (dh1 != NULL); // for Clang's static analyzer CU_ASSERT_FATAL(dh1->value._length > 0); CU_ASSERT_FATAL(dh1->value._buffer != NULL); - assert (dh1->value._length > 0 && dh1->value._buffer != NULL); // for Clang's static analyzer /* prepare reply */ fill_handshake_message_token( @@ -2399,7 +2388,6 @@ CU_Test(ddssec_builtin_process_handshake,extended_certificate_check) printf("begin_handshake_request failed: %s\n", exception.message ? exception.message : "Error message missing"); } CU_ASSERT_FATAL(result == DDS_SECURITY_VALIDATION_PENDING_HANDSHAKE_MESSAGE); - assert(result == DDS_SECURITY_VALIDATION_PENDING_HANDSHAKE_MESSAGE); // for Clang's static analyzer /* get challenge 1 from the message */ challenge1_glb = find_binary_property(&handshake_token_out, DDS_AUTHTOKEN_PROP_CHALLENGE1); @@ -2410,10 +2398,8 @@ CU_Test(ddssec_builtin_process_handshake,extended_certificate_check) hash1_sentrequest = find_binary_property(&handshake_token_out, DDS_AUTHTOKEN_PROP_HASH_C1); CU_ASSERT_FATAL(dh1 != NULL); - assert(dh1 != NULL); // for Clang's static analyzer CU_ASSERT_FATAL(dh1->value._length > 0); CU_ASSERT_FATAL(dh1->value._buffer != NULL); - assert(dh1->value._length > 0 && dh1->value._buffer != NULL); // for Clang's static analyzer dh1_pub_key.data = dh1->value._buffer; dh1_pub_key.length = dh1->value._length; @@ -2489,10 +2475,8 @@ CU_Test(ddssec_builtin_process_handshake,extended_certificate_check) hash1_sentrequest = find_binary_property(&handshake_token_out, DDS_AUTHTOKEN_PROP_HASH_C1); CU_ASSERT_FATAL(dh1 != NULL); - assert (dh1 != NULL); // for Clang's static analyzer CU_ASSERT_FATAL(dh1->value._length > 0); CU_ASSERT_FATAL(dh1->value._buffer != NULL); - assert (dh1->value._length > 0 && dh1->value._buffer != NULL); // for Clang's static analyzer dh1_pub_key.data = dh1->value._buffer; dh1_pub_key.length = dh1->value._length; @@ -2563,10 +2547,8 @@ CU_Test(ddssec_builtin_process_handshake,extended_certificate_check) hash1_sentrequest = find_binary_property(&handshake_token_out, DDS_AUTHTOKEN_PROP_HASH_C1); CU_ASSERT_FATAL(dh1 != NULL); - assert (dh1 != NULL); // for Clang's static analyzer CU_ASSERT_FATAL(dh1->value._length > 0); CU_ASSERT_FATAL(dh1->value._buffer != NULL); - assert (dh1->value._length > 0 && dh1->value._buffer != NULL); // for Clang's static analyzer dh1_pub_key.data = dh1->value._buffer; dh1_pub_key.length = dh1->value._length; @@ -2644,7 +2626,6 @@ CU_Test(ddssec_builtin_process_handshake,crl) printf("begin_handshake_request failed: %s\n", exception.message ? exception.message : "Error message missing"); } CU_ASSERT_FATAL(result == DDS_SECURITY_VALIDATION_PENDING_HANDSHAKE_MESSAGE); - assert(result == DDS_SECURITY_VALIDATION_PENDING_HANDSHAKE_MESSAGE); // for Clang's static analyzer /* get challenge 1 from the message */ challenge1_glb = find_binary_property(&handshake_token_out, "challenge1"); @@ -2655,10 +2636,8 @@ CU_Test(ddssec_builtin_process_handshake,crl) hash1_sentrequest = find_binary_property(&handshake_token_out, "hash_c1"); CU_ASSERT_FATAL(dh1 != NULL); - assert(dh1 != NULL); // for Clang's static analyzer CU_ASSERT_FATAL(dh1->value._length > 0); CU_ASSERT_FATAL(dh1->value._buffer != NULL); - assert(dh1->value._length > 0 && dh1->value._buffer != NULL); // for Clang's static analyzer dh1_pub_key.data = dh1->value._buffer; dh1_pub_key.length = dh1->value._length; diff --git a/src/security/builtin_plugins/tests/register_local_datareader/src/register_local_datareader_utests.c b/src/security/builtin_plugins/tests/register_local_datareader/src/register_local_datareader_utests.c index c29f3cc18a..09cdd1c835 100644 --- a/src/security/builtin_plugins/tests/register_local_datareader/src/register_local_datareader_utests.c +++ b/src/security/builtin_plugins/tests/register_local_datareader/src/register_local_datareader_utests.c @@ -101,7 +101,7 @@ static void suite_register_local_datareader_init(void) participant_permissions, &participant_properties, &participant_security_attributes, - &exception)) != DDS_SECURITY_HANDLE_NIL) + &exception)) != DDS_SECURITY_HANDLE_NIL); /* Now call the function. */ remote_participant_crypto_handle = crypto->crypto_key_factory->register_matched_remote_participant( @@ -174,8 +174,7 @@ CU_Test(ddssec_builtin_register_local_datareader, happy_day, .init = suite_regis &exception); /* A valid handle to be returned */ - CU_ASSERT(result != 0); - assert(result != 0); // for Clang's static analyzer + CU_ASSERT_FATAL(result != 0); CU_ASSERT(exception.code == DDS_SECURITY_ERR_OK_CODE); @@ -231,9 +230,8 @@ CU_Test(ddssec_builtin_register_local_datareader, builtin_endpoint, .init = suit printf("register_local_datareader: %s\n", exception.message ? exception.message : "Error message missing"); /* A valid handle to be returned */ - CU_ASSERT(result != 0); + CU_ASSERT_FATAL(result != 0); CU_ASSERT(exception.code == DDS_SECURITY_ERR_OK_CODE); - assert(result != 0); // for Clang's static analyzer /* NOTE: It would be better to check if the keys have been generated but there is no interface to get them from handle */ reader_crypto = (local_datareader_crypto *)result; @@ -286,7 +284,6 @@ CU_Test(ddssec_builtin_register_local_datareader, special_endpoint_name, .init = /* A valid handle to be returned */ CU_ASSERT_FATAL(result != 0); - assert(result != 0); // for Clang's static analyzer CU_ASSERT_FATAL(exception.code == DDS_SECURITY_ERR_OK_CODE); CU_ASSERT_FATAL(((local_datareader_crypto *)result)->is_builtin_participant_volatile_message_secure_reader); reset_exception(&exception); diff --git a/src/security/builtin_plugins/tests/register_local_datawriter/src/register_local_datawriter_utests.c b/src/security/builtin_plugins/tests/register_local_datawriter/src/register_local_datawriter_utests.c index 0852990388..6eab539b7d 100644 --- a/src/security/builtin_plugins/tests/register_local_datawriter/src/register_local_datawriter_utests.c +++ b/src/security/builtin_plugins/tests/register_local_datawriter/src/register_local_datawriter_utests.c @@ -180,9 +180,8 @@ CU_Test(ddssec_builtin_register_local_datawriter, happy_day, .init = suite_regis printf("register_local_datawriter: %s\n", exception.message ? exception.message : "Error message missing"); /* A valid handle to be returned */ - CU_ASSERT(result != 0); + CU_ASSERT_FATAL(result != 0); CU_ASSERT(exception.code == DDS_SECURITY_ERR_OK_CODE); - assert(result != 0); // for Clang's static analyzer /* NOTE: It would be better to check if the keys have been generated but there is no interface to get them from handle */ writer_crypto = (local_datawriter_crypto *)result; @@ -246,7 +245,6 @@ CU_Test(ddssec_builtin_register_local_datawriter, builtin_endpoint, .init = suit /* A valid handle to be returned */ CU_ASSERT_FATAL(result != 0); CU_ASSERT_FATAL(exception.code == DDS_SECURITY_ERR_OK_CODE); - assert(result != 0); // for Clang's static analyzer /* NOTE: It would be better to check if the keys have been generated but there is no interface to get them from handle */ writer_crypto = (local_datawriter_crypto *)result; @@ -309,7 +307,6 @@ CU_Test(ddssec_builtin_register_local_datawriter, special_endpoint_name, .init = /* A valid handle to be returned */ CU_ASSERT_FATAL(result != 0); CU_ASSERT_FATAL(exception.code == DDS_SECURITY_ERR_OK_CODE); - assert(result != 0); // for Clang's static analyzer CU_ASSERT_FATAL(((local_datawriter_crypto *)result)->is_builtin_participant_volatile_message_secure_writer); reset_exception(&exception); diff --git a/src/security/builtin_plugins/tests/register_local_participant/src/register_local_participant_utests.c b/src/security/builtin_plugins/tests/register_local_participant/src/register_local_participant_utests.c index 8a5dfcac85..1730d195d1 100644 --- a/src/security/builtin_plugins/tests/register_local_participant/src/register_local_participant_utests.c +++ b/src/security/builtin_plugins/tests/register_local_participant/src/register_local_participant_utests.c @@ -152,7 +152,6 @@ CU_Test(ddssec_builtin_register_local_participant, empty_identity, .init = suite CU_ASSERT(exception.code == DDS_SECURITY_ERR_IDENTITY_EMPTY_CODE); CU_ASSERT_FATAL(exception.message != NULL); - assert(exception.message != NULL); // for Clang's static analyzer CU_ASSERT(!strcmp(exception.message, DDS_SECURITY_ERR_IDENTITY_EMPTY_MESSAGE)); CU_ASSERT(result == 0); diff --git a/src/security/builtin_plugins/tests/register_matched_remote_datareader/src/register_matched_remote_datareader_utests.c b/src/security/builtin_plugins/tests/register_matched_remote_datareader/src/register_matched_remote_datareader_utests.c index ea9075018d..9c4b2287b7 100644 --- a/src/security/builtin_plugins/tests/register_matched_remote_datareader/src/register_matched_remote_datareader_utests.c +++ b/src/security/builtin_plugins/tests/register_matched_remote_datareader/src/register_matched_remote_datareader_utests.c @@ -204,7 +204,6 @@ CU_Test(ddssec_builtin_register_remote_datareader, happy_day, .init = suite_regi /* A valid handle to be returned */ CU_ASSERT_FATAL(result != 0); CU_ASSERT_FATAL(exception.code == DDS_SECURITY_ERR_OK_CODE); - assert(result != 0); // for Clang's static analyzer /* NOTE: It would be better to check if the keys have been generated but there is no interface to get them from handle */ reader_crypto = (remote_datareader_crypto *)result; @@ -268,7 +267,6 @@ CU_Test(ddssec_builtin_register_remote_datareader, volatile_secure, .init = suit /* A valid handle to be returned */ CU_ASSERT_FATAL(result != 0); - assert(result != 0); // for Clang's static analyzer CU_ASSERT_FATAL(((remote_datareader_crypto *)result)->is_builtin_participant_volatile_message_secure_reader); CU_ASSERT_FATAL(exception.code == DDS_SECURITY_ERR_OK_CODE); reset_exception(&exception); @@ -314,9 +312,8 @@ CU_Test(ddssec_builtin_register_remote_datareader, with_origin_authentication, . printf("register_remote_datareader: %s\n", exception.message ? exception.message : "Error message missing"); /* A valid handle to be returned */ - CU_ASSERT(result != 0); + CU_ASSERT_FATAL(result != 0); CU_ASSERT(exception.code == DDS_SECURITY_ERR_OK_CODE); - assert(result != 0); // for Clang's static analyzer /* NOTE: It would be better to check if the keys have been generated but there is no interface to get them from handle */ reader_crypto = (remote_datareader_crypto *)result; diff --git a/src/security/builtin_plugins/tests/register_matched_remote_datawriter/src/register_matched_remote_datawriter_utests.c b/src/security/builtin_plugins/tests/register_matched_remote_datawriter/src/register_matched_remote_datawriter_utests.c index 6806402649..b68063a49d 100644 --- a/src/security/builtin_plugins/tests/register_matched_remote_datawriter/src/register_matched_remote_datawriter_utests.c +++ b/src/security/builtin_plugins/tests/register_matched_remote_datawriter/src/register_matched_remote_datawriter_utests.c @@ -112,7 +112,7 @@ static void suite_register_matched_remote_datawriter_init(void) shared_secret_handle = (DDS_Security_SharedSecretHandle)shared_secret_handle_impl; /* Check if we actually have the validate_local_identity() function. */ - CU_ASSERT_FATAL (crypto != NULL && crypto->crypto_key_factory != NULL && crypto->crypto_key_factory->register_local_participant != NULL) + CU_ASSERT_FATAL (crypto != NULL && crypto->crypto_key_factory != NULL && crypto->crypto_key_factory->register_local_participant != NULL); memset(&exception, 0, sizeof(DDS_Security_SecurityException)); memset(&participant_properties, 0, sizeof(participant_properties)); @@ -198,12 +198,10 @@ CU_Test(ddssec_builtin_register_remote_datawriter, happy_day, .init = suite_regi /* A valid handle to be returned */ CU_ASSERT_FATAL(result != 0); CU_ASSERT_FATAL(exception.code == DDS_SECURITY_ERR_OK_CODE); - assert(result != 0); // for Clang's static analyzer /* NOTE: It would be better to check if the keys have been generated but there is no interface to get them from handle */ writer_crypto = (remote_datawriter_crypto *)result; CU_ASSERT_FATAL(writer_crypto->reader2writer_key_material != NULL); - assert(writer_crypto->reader2writer_key_material != NULL); // for Clang's static analyzer CU_ASSERT(master_salt_not_empty(writer_crypto->reader2writer_key_material)); CU_ASSERT(master_key_not_empty(writer_crypto->reader2writer_key_material)); CU_ASSERT_FATAL(writer_crypto->reader2writer_key_material->receiver_specific_key_id == 0); @@ -255,7 +253,6 @@ CU_Test(ddssec_builtin_register_remote_datawriter, volatile_secure, .init = suit /* A valid handle to be returned */ CU_ASSERT_FATAL(result != 0); - assert(result != 0); // for Clang's static analyzer CU_ASSERT_FATAL(((remote_datawriter_crypto *)result)->is_builtin_participant_volatile_message_secure_writer); CU_ASSERT_FATAL(exception.code == DDS_SECURITY_ERR_OK_CODE); reset_exception(&exception); @@ -302,12 +299,10 @@ CU_Test(ddssec_builtin_register_remote_datawriter, with_origin_authentication, . /* A valid handle to be returned */ CU_ASSERT_FATAL(result != 0); CU_ASSERT_FATAL(exception.code == DDS_SECURITY_ERR_OK_CODE); - assert(result != 0); // for Clang's static analyzer /* NOTE: It would be better to check if the keys have been generated but there is no interface to get them from handle */ writer_crypto = (remote_datawriter_crypto *)result; CU_ASSERT_FATAL(writer_crypto->reader2writer_key_material != NULL); - assert(writer_crypto->reader2writer_key_material != NULL); // for Clang's static analyzer CU_ASSERT(master_salt_not_empty(writer_crypto->reader2writer_key_material)); CU_ASSERT(master_key_not_empty(writer_crypto->reader2writer_key_material)); CU_ASSERT_FATAL(writer_crypto->reader2writer_key_material->receiver_specific_key_id != 0); diff --git a/src/security/builtin_plugins/tests/validate_begin_handshake_reply/src/validate_begin_handshake_reply_utests.c b/src/security/builtin_plugins/tests/validate_begin_handshake_reply/src/validate_begin_handshake_reply_utests.c index b411047b46..bc5dda1374 100644 --- a/src/security/builtin_plugins/tests/validate_begin_handshake_reply/src/validate_begin_handshake_reply_utests.c +++ b/src/security/builtin_plugins/tests/validate_begin_handshake_reply/src/validate_begin_handshake_reply_utests.c @@ -1618,7 +1618,6 @@ CU_Test(ddssec_builtin_validate_begin_handshake_reply,invalid_participant_data , property = find_binary_property(&handshake_token_in, "c.pdata"); CU_ASSERT_FATAL(property != NULL); - assert(property != NULL); // for Clang's static analyzer ddsrt_free(property->name); property->name = ddsrt_strdup("c.pdatax"); diff --git a/src/security/builtin_plugins/tests/validate_local_identity/src/validate_local_identity_utests.c b/src/security/builtin_plugins/tests/validate_local_identity/src/validate_local_identity_utests.c index 3421796e9b..9527edd353 100644 --- a/src/security/builtin_plugins/tests/validate_local_identity/src/validate_local_identity_utests.c +++ b/src/security/builtin_plugins/tests/validate_local_identity/src/validate_local_identity_utests.c @@ -1219,7 +1219,6 @@ CU_Test(ddssec_builtin_validate_local_identity,missing_certificate_property) CU_ASSERT (result != DDS_SECURITY_VALIDATION_OK); CU_ASSERT (exception.minor_code != 0); CU_ASSERT_FATAL (exception.message != NULL); - assert(exception.message != NULL); // for Clang's static analyzer CU_ASSERT(strcmp(exception.message, "validate_local_identity: missing property '" DDS_SEC_PROP_AUTH_IDENTITY_CERT "'") == 0); dds_security_property_deinit(&participant_qos.property.value); @@ -1278,7 +1277,6 @@ CU_Test(ddssec_builtin_validate_local_identity,missing_ca_property) CU_ASSERT (result != DDS_SECURITY_VALIDATION_OK); CU_ASSERT (exception.minor_code != 0); CU_ASSERT_FATAL (exception.message != NULL); - assert(exception.message != NULL); // for Clang's static analyzer CU_ASSERT(strcmp(exception.message, "validate_local_identity: missing property '" DDS_SEC_PROP_AUTH_IDENTITY_CA "'") == 0); dds_security_property_deinit(&participant_qos.property.value); @@ -1332,7 +1330,6 @@ CU_Test(ddssec_builtin_validate_local_identity,missing_private_key_property) CU_ASSERT (result != DDS_SECURITY_VALIDATION_OK); CU_ASSERT (exception.minor_code != 0); CU_ASSERT_FATAL (exception.message != NULL); - assert(exception.message != NULL); // for Clang's static analyzer CU_ASSERT(strcmp(exception.message, "validate_local_identity: missing property '" DDS_SEC_PROP_AUTH_PRIV_KEY "'") == 0); dds_security_property_deinit(&participant_qos.property.value); diff --git a/src/security/builtin_plugins/tests/validate_local_permissions/src/validate_local_permissions_utests.c b/src/security/builtin_plugins/tests/validate_local_permissions/src/validate_local_permissions_utests.c index 3eb2802aaf..116ad7a0f1 100644 --- a/src/security/builtin_plugins/tests/validate_local_permissions/src/validate_local_permissions_utests.c +++ b/src/security/builtin_plugins/tests/validate_local_permissions/src/validate_local_permissions_utests.c @@ -603,7 +603,6 @@ static DDS_Security_long test_corrupted_signature(bool corrupt_permissions, bool /* Just some (hardcoded) sanity checks. */ CU_ASSERT_FATAL(prop != NULL); CU_ASSERT_FATAL(prop->value != NULL); - assert(prop && prop->value); // for Clang's static analyzer len = strlen(prop->value); CU_ASSERT_FATAL(len > 2250); diff --git a/src/security/builtin_plugins/tests/validate_remote_permissions/src/validate_remote_permissions_utests.c b/src/security/builtin_plugins/tests/validate_remote_permissions/src/validate_remote_permissions_utests.c index c1004cdfff..6dd10c51c1 100644 --- a/src/security/builtin_plugins/tests/validate_remote_permissions/src/validate_remote_permissions_utests.c +++ b/src/security/builtin_plugins/tests/validate_remote_permissions/src/validate_remote_permissions_utests.c @@ -261,7 +261,6 @@ static void corrupt_permission_signature(DDS_Security_AuthenticatedPeerCredentia /* It is expected that the permissions are available in a fixed location. */ CU_ASSERT_FATAL(token != NULL); CU_ASSERT_FATAL(token->properties._buffer != NULL); - assert(token->properties._buffer != NULL); // for Clang's static analyzer CU_ASSERT_FATAL(token->properties._length == 2); CU_ASSERT_FATAL(token->properties._buffer[1].name != NULL); CU_ASSERT_FATAL(token->properties._buffer[1].value != NULL); @@ -270,7 +269,6 @@ static void corrupt_permission_signature(DDS_Security_AuthenticatedPeerCredentia /* Corrupt a byte somewhere in the signature. */ permissions = token->properties._buffer[1].value; CU_ASSERT_FATAL(permissions != NULL); - assert(permissions != NULL); // for Clang's static analyzer len = strlen(permissions); CU_ASSERT_FATAL(len > 100); permissions[len - 75]--; diff --git a/src/security/core/tests/CMakeLists.txt b/src/security/core/tests/CMakeLists.txt index 7ed15798e0..855f82d065 100644 --- a/src/security/core/tests/CMakeLists.txt +++ b/src/security/core/tests/CMakeLists.txt @@ -46,7 +46,7 @@ function(add_wrapper libname linklibs) set_target_properties("dds_security_${libname}_wrapper" PROPERTIES LINK_FLAGS "-undefined dynamic_lookup") endif() - target_link_libraries("dds_security_${libname}_wrapper" PRIVATE CUnit) + target_link_libraries("dds_security_${libname}_wrapper" PRIVATE CycloneDDS::ucunit) target_include_directories("dds_security_${libname}_wrapper" PRIVATE "${CUNIT_DIR}/include") target_link_libraries("dds_security_${libname}_wrapper" PUBLIC ddsc ${linklibs}) diff --git a/src/security/core/tests/common/test_utils.c b/src/security/core/tests/common/test_utils.c index 48d1ab0f5e..65e0729e9a 100644 --- a/src/security/core/tests/common/test_utils.c +++ b/src/security/core/tests/common/test_utils.c @@ -634,7 +634,6 @@ DDS_Security_DatawriterCryptoHandle get_builtin_writer_crypto_handle(dds_entity_ pp = entidx_lookup_participant_guid(pp_entity->m_domain->gv.entity_index, &pp_entity->m_guid); wr = ddsi_get_builtin_writer (pp, entityid); CU_ASSERT_FATAL(wr != NULL); - assert(wr != NULL); /* for Clang's static analyzer */ crypto_handle = wr->sec_attr->crypto_handle; thread_state_asleep(lookup_thread_state()); dds_entity_unpin(pp_entity); @@ -650,7 +649,6 @@ DDS_Security_DatawriterCryptoHandle get_writer_crypto_handle(dds_entity_t writer thread_state_awake(lookup_thread_state(), &wr_entity->m_domain->gv); wr = entidx_lookup_writer_guid(wr_entity->m_domain->gv.entity_index, &wr_entity->m_guid); CU_ASSERT_FATAL(wr != NULL); - assert(wr != NULL); /* for Clang's static analyzer */ crypto_handle = wr->sec_attr->crypto_handle; thread_state_asleep(lookup_thread_state()); dds_entity_unpin(wr_entity); diff --git a/src/security/core/tests/fsm.c b/src/security/core/tests/fsm.c index 6790d29a58..bae701110a 100644 --- a/src/security/core/tests/fsm.c +++ b/src/security/core/tests/fsm.c @@ -404,7 +404,7 @@ CU_Test(ddssec_fsm, create, .init = fsm_control_init, .fini = fsm_control_fini) { /* Test single running state machine. Check creation of a single State Machine */ fsm_auth = dds_security_fsm_create (g_fsm_control, HandshakeTransistions, HandshakeTransistionsSize, &fsm_arg); - CU_ASSERT_FATAL (fsm_auth != NULL) + CU_ASSERT_FATAL (fsm_auth != NULL); /* set a delay that doesn't expire. Should be terminate when fsm is freed. */ dds_security_fsm_set_timeout (fsm_auth, timeout_cb, DDS_SECS(30)); @@ -560,7 +560,7 @@ CU_Test(ddssec_fsm, parallel_timeout, .init = fsm_control_init, .fini = fsm_cont CU_Test(ddssec_fsm, delete_with_timeout, .init = fsm_control_init, .fini = fsm_control_fini) { fsm_timeout = dds_security_fsm_create (g_fsm_control, timeout_transitions, timeout_transitionsSize, &fsm_arg); - CU_ASSERT_FATAL (fsm_timeout != NULL) + CU_ASSERT_FATAL (fsm_timeout != NULL); dds_security_fsm_start (fsm_timeout); ddsrt_mutex_lock (&g_lock); while (visited_timeout == 0) diff --git a/src/tools/idlc/tests/test_common.c b/src/tools/idlc/tests/test_common.c index e9b6eabe9f..c45b11101f 100644 --- a/src/tools/idlc/tests/test_common.c +++ b/src/tools/idlc/tests/test_common.c @@ -47,7 +47,5 @@ idl_retcode_t generate_test_descriptor (idl_pstate_t *pstate, const char *idl, s if ((ret = generate_descriptor_impl(pstate, topic, descriptor)) != IDL_RETCODE_OK) return ret; CU_ASSERT_PTR_NOT_NULL_FATAL (descriptor); - assert (descriptor); /* static analyzer */ - return ret; } diff --git a/src/ucunit/CMakeLists.txt b/src/ucunit/CMakeLists.txt new file mode 100644 index 0000000000..0d31f2191b --- /dev/null +++ b/src/ucunit/CMakeLists.txt @@ -0,0 +1,45 @@ +# +# Copyright(c) 2023 ZettaScale Technology and others +# +# This program and the accompanying materials are made available under the +# terms of the Eclipse Public License v. 2.0 which is available at +# http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License +# v. 1.0 which is available at +# http://www.eclipse.org/org/documents/edl-v10.php. +# +# SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause +# +include (GenerateExportHeader) + +if (BUILD_SHARED_LIBS OR NOT DEFINED BUILD_SHARED_LIBS) + add_library(ucunit SHARED "") +else() + add_library(ucunit) +endif() +add_library(${PROJECT_NAME}::ucunit ALIAS ucunit) + +set(srcs_ucunit + "${CMAKE_CURRENT_LIST_DIR}/src/ucunit.c") +set(hdrs_ucunit + "${CMAKE_CURRENT_LIST_DIR}/include/ucunit/ucunit.h") + +target_sources(ucunit PRIVATE ${srcs_ucunit} ${hdrs_ucunit}) + +target_include_directories(ucunit + PUBLIC + "$" + "$" + "$" + PRIVATE + "${CMAKE_CURRENT_LIST_DIR}/src" + INTERFACE + $) + +generate_export_header( + ucunit BASE_NAME UCUNIT EXPORT_FILE_NAME include/ucunit/export.h) + +add_executable(test_ucunit) +target_sources(test_ucunit PRIVATE tests/test_ucunit.c) +target_link_libraries(test_ucunit CycloneDDS::ucunit) + +add_test(NAME ucunit COMMAND $/test_ucunit) diff --git a/src/ucunit/include/CUnit/Automated.h b/src/ucunit/include/CUnit/Automated.h new file mode 100644 index 0000000000..5fcbc720e9 --- /dev/null +++ b/src/ucunit/include/CUnit/Automated.h @@ -0,0 +1,6 @@ +#ifndef CUNIT_AUTOMATED_H +#define CUNIT_AUTOMATED_H + +#include "ucunit/ucunit.h" + +#endif /* CUNIT_AUTOMATED_H */ diff --git a/src/ucunit/include/CUnit/Basic.h b/src/ucunit/include/CUnit/Basic.h new file mode 100644 index 0000000000..aacd68b989 --- /dev/null +++ b/src/ucunit/include/CUnit/Basic.h @@ -0,0 +1,6 @@ +#ifndef CUNIT_BASIC_H +#define CUNIT_BASIC_H + +#include "ucunit/ucunit.h" + +#endif /* CUNIT_BASIC_H */ diff --git a/src/ucunit/include/CUnit/CUError.h b/src/ucunit/include/CUnit/CUError.h new file mode 100644 index 0000000000..12f85c18bc --- /dev/null +++ b/src/ucunit/include/CUnit/CUError.h @@ -0,0 +1,6 @@ +#ifndef CUNIT_CUERROR_H +#define CUNIT_CUERROR_H + +#include "ucunit/ucunit.h" + +#endif /* CUNIT_CUERROR_H */ diff --git a/src/ucunit/include/CUnit/CUnit.h b/src/ucunit/include/CUnit/CUnit.h new file mode 100644 index 0000000000..000516036b --- /dev/null +++ b/src/ucunit/include/CUnit/CUnit.h @@ -0,0 +1,6 @@ +#ifndef CUNIT_CUNIT_H +#define CUNIT_CUNIT_H + +#include "ucunit/ucunit.h" + +#endif /* CUNIT_CUNIT_H */ diff --git a/cmake/Modules/CUnit/include/CUnit/Test.h b/src/ucunit/include/CUnit/Test.h similarity index 97% rename from cmake/Modules/CUnit/include/CUnit/Test.h rename to src/ucunit/include/CUnit/Test.h index 4797c35dca..6d2b02139b 100644 --- a/cmake/Modules/CUnit/include/CUnit/Test.h +++ b/src/ucunit/include/CUnit/Test.h @@ -1,9 +1,7 @@ #ifndef CUNIT_TEST_H #define CUNIT_TEST_H -#include -#include -#include +#include "ucunit/ucunit.h" #if defined (__cplusplus) extern "C" { @@ -93,4 +91,3 @@ typedef struct { #endif #endif /* CUNIT_TEST_H */ - diff --git a/cmake/Modules/CUnit/include/CUnit/Theory.h b/src/ucunit/include/CUnit/Theory.h similarity index 100% rename from cmake/Modules/CUnit/include/CUnit/Theory.h rename to src/ucunit/include/CUnit/Theory.h diff --git a/src/ucunit/include/ucunit/ucunit.h b/src/ucunit/include/ucunit/ucunit.h new file mode 100644 index 0000000000..d2504ef6ed --- /dev/null +++ b/src/ucunit/include/ucunit/ucunit.h @@ -0,0 +1,320 @@ +// Copyright(c) 2023 ZettaScale Technology and others +// +// This program and the accompanying materials are made available under the +// terms of the Eclipse Public License v. 2.0 which is available at +// http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License +// v. 1.0 which is available at +// http://www.eclipse.org/org/documents/edl-v10.php. +// +// SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause + +#ifndef UCUNIT_H +#define UCUNIT_H + +#include +#include +#include +#include +#include +#include + +#include "ucunit/export.h" + +#if defined (__cplusplus) +extern "C" { +#endif + +#ifdef __GNUC__ +#define CU_UNREACHABLE __builtin_unreachable () +#else +#define CU_UNREACHABLE ((void)0) +#endif + +#define CU_ASSERT_IMPLEMENTATION(value_, line, expr, file, something, fatal_) do { \ + const bool cu_assert_impl_value = (value_); \ + const bool cu_assert_impl_fatal = (fatal_); \ + CU_assertImplementation (cu_assert_impl_value, (line), (expr), (file), (something), cu_assert_impl_fatal); \ + if (!cu_assert_impl_value && cu_assert_impl_fatal) \ + CU_UNREACHABLE; \ +} while (0) + +/** Record a pass condition without performing a logical test. */ +#define CU_PASS(msg) \ + CU_ASSERT_IMPLEMENTATION(true, __LINE__, ("CU_PASS(" #msg ")"), __FILE__, "", false) + +/** Simple assertion. + * Reports failure with no other action. + */ +#define CU_ASSERT(value) \ + CU_ASSERT_IMPLEMENTATION((value), __LINE__, #value, __FILE__, "", false) + +/** Simple assertion. + * Reports failure and causes test to abort. + */ +#define CU_ASSERT_FATAL(value) \ + CU_ASSERT_IMPLEMENTATION((value), __LINE__, #value, __FILE__, "", true) + +/** Simple assertion. + * Reports failure with no other action. + */ +#define CU_TEST(value) \ + CU_ASSERT_IMPLEMENTATION((value), __LINE__, #value, __FILE__, "", false) + +/** Simple assertion. + * Reports failure and causes test to abort. + */ +#define CU_TEST_FATAL(value) \ + CU_ASSERT_IMPLEMENTATION((value), __LINE__, #value, __FILE__, "", true) + +/** Record a failure without performing a logical test. */ +#define CU_FAIL(msg) \ + CU_ASSERT_IMPLEMENTATION(false, __LINE__, ("CU_FAIL(" #msg ")"), __FILE__, "", false) + +/** Record a failure without performing a logical test, and abort test. */ +#define CU_FAIL_FATAL(msg) \ + CU_ASSERT_IMPLEMENTATION(false, __LINE__, ("CU_FAIL_FATAL(" #msg ")"), __FILE__, "", true) + +/** Asserts that value is true. + * Reports failure with no other action. + */ +#define CU_ASSERT_TRUE(value) \ + CU_ASSERT_IMPLEMENTATION((value), __LINE__, ("CU_ASSERT_TRUE(" #value ")"), __FILE__, "", false) + +/** Asserts that value is true. + * Reports failure and causes test to abort. + */ +#define CU_ASSERT_TRUE_FATAL(value) \ + CU_ASSERT_IMPLEMENTATION((value), __LINE__, ("CU_ASSERT_TRUE_FATAL(" #value ")"), __FILE__, "", true) + +/** Asserts that value is false. + * Reports failure with no other action. + */ +#define CU_ASSERT_FALSE(value) \ + CU_ASSERT_IMPLEMENTATION(!(value), __LINE__, ("CU_ASSERT_FALSE(" #value ")"), __FILE__, "", false) + +/** Asserts that value is false. + * Reports failure and causes test to abort. + */ +#define CU_ASSERT_FALSE_FATAL(value) \ + CU_ASSERT_IMPLEMENTATION(!(value), __LINE__, ("CU_ASSERT_FALSE_FATAL(" #value ")"), __FILE__, "", true) + +/** Asserts that actual == expected. + * Reports failure with no other action. + */ +#define CU_ASSERT_EQUAL(actual, expected) \ + CU_ASSERT_IMPLEMENTATION(((actual) == (expected)), __LINE__, ("CU_ASSERT_EQUAL(" #actual "," #expected ")"), __FILE__, "", false) + +/** Asserts that actual == expected. + * Reports failure and causes test to abort. + */ +#define CU_ASSERT_EQUAL_FATAL(actual, expected) \ + CU_ASSERT_IMPLEMENTATION(((actual) == (expected)), __LINE__, ("CU_ASSERT_EQUAL_FATAL(" #actual "," #expected ")"), __FILE__, "", true) + +/** Asserts that actual != expected. + * Reports failure with no other action. + */ +#define CU_ASSERT_NOT_EQUAL(actual, expected) \ + CU_ASSERT_IMPLEMENTATION(((actual) != (expected)), __LINE__, ("CU_ASSERT_NOT_EQUAL(" #actual "," #expected ")"), __FILE__, "", false) + +/** Asserts that actual != expected. + * Reports failure and causes test to abort. + */ +#define CU_ASSERT_NOT_EQUAL_FATAL(actual, expected) \ + CU_ASSERT_IMPLEMENTATION(((actual) != (expected)), __LINE__, ("CU_ASSERT_NOT_EQUAL_FATAL(" #actual "," #expected ")"), __FILE__, "", true) + +/** Asserts that pointers actual == expected. + * Reports failure with no other action. + */ +#define CU_ASSERT_PTR_EQUAL(actual, expected) \ + CU_ASSERT_IMPLEMENTATION(((const void*)(actual) == (const void*)(expected)), __LINE__, ("CU_ASSERT_PTR_EQUAL(" #actual "," #expected ")"), __FILE__, "", false) + +/** Asserts that pointers actual == expected. + * Reports failure and causes test to abort. + */ +#define CU_ASSERT_PTR_EQUAL_FATAL(actual, expected) \ + CU_ASSERT_IMPLEMENTATION(((const void*)(actual) == (const void*)(expected)), __LINE__, ("CU_ASSERT_PTR_EQUAL_FATAL(" #actual "," #expected ")"), __FILE__, "", true) + +/** Asserts that pointers actual != expected. + * Reports failure with no other action. + */ +#define CU_ASSERT_PTR_NOT_EQUAL(actual, expected) \ + CU_ASSERT_IMPLEMENTATION(((const void*)(actual) != (const void*)(expected)), __LINE__, ("CU_ASSERT_PTR_NOT_EQUAL(" #actual "," #expected ")"), __FILE__, "", false) + +/** Asserts that pointers actual != expected. + * Reports failure and causes test to abort. + */ +#define CU_ASSERT_PTR_NOT_EQUAL_FATAL(actual, expected) \ + CU_ASSERT_IMPLEMENTATION(((const void*)(actual) != (const void*)(expected)), __LINE__, ("CU_ASSERT_PTR_NOT_EQUAL_FATAL(" #actual "," #expected ")"), __FILE__, "", true) + +/** Asserts that pointer value is NULL. + * Reports failure with no other action. + */ +#define CU_ASSERT_PTR_NULL(value) \ + CU_ASSERT_IMPLEMENTATION((NULL == (const void*)(value)), __LINE__, ("CU_ASSERT_PTR_NULL(" #value")"), __FILE__, "", false) + +/** Asserts that pointer value is NULL. + * Reports failure and causes test to abort. + */ +#define CU_ASSERT_PTR_NULL_FATAL(value) \ + CU_ASSERT_IMPLEMENTATION((NULL == (const void*)(value)), __LINE__, ("CU_ASSERT_PTR_NULL_FATAL(" #value")"), __FILE__, "", true) + +/** Asserts that pointer value is not NULL. + * Reports failure with no other action. + */ +#define CU_ASSERT_PTR_NOT_NULL(value) \ + CU_ASSERT_IMPLEMENTATION((NULL != (const void*)(value)), __LINE__, ("CU_ASSERT_PTR_NOT_NULL(" #value")"), __FILE__, "", false) + +/** Asserts that pointer value is not NULL. + * Reports failure and causes test to abort. + */ +#define CU_ASSERT_PTR_NOT_NULL_FATAL(value) \ + CU_ASSERT_IMPLEMENTATION((NULL != (const void*)(value)), __LINE__, ("CU_ASSERT_PTR_NOT_NULL_FATAL(" #value")"), __FILE__, "", true) + +/** Asserts that string actual == expected. + * Reports failure with no other action. + */ +#define CU_ASSERT_STRING_EQUAL(actual, expected) \ + CU_ASSERT_IMPLEMENTATION(!(strcmp((const char*)(actual), (const char*)(expected))), __LINE__, ("CU_ASSERT_STRING_EQUAL(" #actual "," #expected ")"), __FILE__, "", false) + +/** Asserts that string actual == expected. + * Reports failure and causes test to abort. + */ +#define CU_ASSERT_STRING_EQUAL_FATAL(actual, expected) \ + CU_ASSERT_IMPLEMENTATION(!(strcmp((const char*)(actual), (const char*)(expected))), __LINE__, ("CU_ASSERT_STRING_EQUAL_FATAL(" #actual "," #expected ")"), __FILE__, "", true) + +/** Asserts that string actual != expected. + * Reports failure with no other action. + */ +#define CU_ASSERT_STRING_NOT_EQUAL(actual, expected) \ + CU_ASSERT_IMPLEMENTATION((strcmp((const char*)(actual), (const char*)(expected))), __LINE__, ("CU_ASSERT_STRING_NOT_EQUAL(" #actual "," #expected ")"), __FILE__, "", false) + +/** Asserts that string actual != expected. + * Reports failure and causes test to abort. + */ +#define CU_ASSERT_STRING_NOT_EQUAL_FATAL(actual, expected) \ + CU_ASSERT_IMPLEMENTATION((strcmp((const char*)(actual), (const char*)(expected))), __LINE__, ("CU_ASSERT_STRING_NOT_EQUAL_FATAL(" #actual "," #expected ")"), __FILE__, "", true) + +/** Asserts that string actual == expected with length specified. + * The comparison is limited to count characters. + * Reports failure with no other action. + */ +#define CU_ASSERT_NSTRING_EQUAL(actual, expected, count) \ + CU_ASSERT_IMPLEMENTATION(!(strncmp((const char*)(actual), (const char*)(expected), (size_t)(count))), __LINE__, ("CU_ASSERT_NSTRING_EQUAL(" #actual "," #expected "," #count ")"), __FILE__, "", false) + +/** Asserts that string actual == expected with length specified. + * The comparison is limited to count characters. + * Reports failure and causes test to abort. + */ +#define CU_ASSERT_NSTRING_EQUAL_FATAL(actual, expected, count) \ + CU_ASSERT_IMPLEMENTATION(!(strncmp((const char*)(actual), (const char*)(expected), (size_t)(count))), __LINE__, ("CU_ASSERT_NSTRING_EQUAL_FATAL(" #actual "," #expected "," #count ")"), __FILE__, "", true) + +/** Asserts that string actual != expected with length specified. + * The comparison is limited to count characters. + * Reports failure with no other action. + */ +#define CU_ASSERT_NSTRING_NOT_EQUAL(actual, expected, count) \ + CU_ASSERT_IMPLEMENTATION((strncmp((const char*)(actual), (const char*)(expected), (size_t)(count))), __LINE__, ("CU_ASSERT_NSTRING_NOT_EQUAL(" #actual "," #expected "," #count ")"), __FILE__, "", false) + +/** Asserts that string actual != expected with length specified. + * The comparison is limited to count characters. + * Reports failure and causes test to abort. + */ +#define CU_ASSERT_NSTRING_NOT_EQUAL_FATAL(actual, expected, count) \ + CU_ASSERT_IMPLEMENTATION((strncmp((const char*)(actual), (const char*)(expected), (size_t)(count))), __LINE__, ("CU_ASSERT_NSTRING_NOT_EQUAL_FATAL(" #actual "," #expected "," #count ")"), __FILE__, "", true) + +/** Asserts that double actual == expected within the specified tolerance. + * If actual is within granularity of expected, the assertion passes. + * Reports failure with no other action. + */ +#define CU_ASSERT_DOUBLE_EQUAL(actual, expected, granularity) \ + CU_ASSERT_IMPLEMENTATION(((fabs((double)(actual) - (expected)) <= fabs((double)(granularity)))), __LINE__, ("CU_ASSERT_DOUBLE_EQUAL(" #actual "," #expected "," #granularity ")"), __FILE__, "", false) + +/** Asserts that double actual == expected within the specified tolerance. + * If actual is within granularity of expected, the assertion passes. + * Reports failure and causes test to abort. + */ +#define CU_ASSERT_DOUBLE_EQUAL_FATAL(actual, expected, granularity) \ + CU_ASSERT_IMPLEMENTATION(((fabs((double)(actual) - (expected)) <= fabs((double)(granularity)))), __LINE__, ("CU_ASSERT_DOUBLE_EQUAL_FATAL(" #actual "," #expected "," #granularity ")"), __FILE__, "", true) + +/** Asserts that double actual != expected within the specified tolerance. + * If actual is within granularity of expected, the assertion fails. + * Reports failure with no other action. + */ +#define CU_ASSERT_DOUBLE_NOT_EQUAL(actual, expected, granularity) \ + CU_ASSERT_IMPLEMENTATION(((fabs((double)(actual) - (expected)) > fabs((double)(granularity)))), __LINE__, ("CU_ASSERT_DOUBLE_NOT_EQUAL(" #actual "," #expected "," #granularity ")"), __FILE__, "", false) + +/** Asserts that double actual != expected within the specified tolerance. + * If actual is within granularity of expected, the assertion fails. + * Reports failure and causes test to abort. + */ +#define CU_ASSERT_DOUBLE_NOT_EQUAL_FATAL(actual, expected, granularity) \ + CU_ASSERT_IMPLEMENTATION(((fabs((double)(actual) - (expected)) > fabs((double)(granularity)))), __LINE__, ("CU_ASSERT_DOUBLE_NOT_EQUAL_FATAL(" #actual "," #expected "," #granularity ")"), __FILE__, "", true) + +typedef void (*CU_TestFunc) (void); +typedef int (*CU_InitializeFunc) (void); +typedef int (*CU_CleanupFunc) (void); + +struct CU_FailureRecord { + struct CU_FailureRecord *next; + const char *file; + int line; + const char *expr; +}; + +typedef struct CU_Test { + struct CU_Test *next; + char *name; + bool active; + CU_TestFunc testfunc; + uint32_t nasserts; + uint32_t nfailures; + struct CU_FailureRecord *failures, *latest_failure; +} *CU_pTest; + +typedef struct CU_Suite { + struct CU_Suite *next; + char *name; + bool active; + bool initfailed; + CU_InitializeFunc init; + CU_CleanupFunc cleanup; + struct CU_Test *tests; + uint32_t ntests; + uint32_t ntests_pass; + uint32_t ntests_failed; +} *CU_pSuite; + +typedef enum CU_ErrorCode { + CUE_SUCCESS, + CUE_ERROR +} CU_ErrorCode; + +UCUNIT_EXPORT CU_ErrorCode CU_initialize_registry (void); + +UCUNIT_EXPORT CU_pSuite CU_add_suite(const char *strName, CU_InitializeFunc pInit, CU_CleanupFunc pClean); + +UCUNIT_EXPORT CU_pSuite CU_get_suite (const char* strName); + +UCUNIT_EXPORT CU_ErrorCode CU_set_suite_active (CU_pSuite pSuite, bool fNewActive); + +UCUNIT_EXPORT CU_pTest CU_add_test(CU_pSuite pSuite, const char* strName, CU_TestFunc pTestFunc); + +UCUNIT_EXPORT void CU_set_test_active(CU_pTest pTest, bool fNewActive); + +UCUNIT_EXPORT CU_ErrorCode CU_get_error (void); + +UCUNIT_EXPORT const char *CU_get_error_msg (void); + +UCUNIT_EXPORT CU_ErrorCode CU_basic_run_tests (void); + +UCUNIT_EXPORT uint32_t CU_get_number_of_failures (void); + +UCUNIT_EXPORT void CU_cleanup_registry (void); + +UCUNIT_EXPORT void CU_assertImplementation (bool value, int line, const char *expr, const char *file, const char *something, bool isfatal); + +#if defined (__cplusplus) +} +#endif + +#endif diff --git a/src/ucunit/src/ucunit.c b/src/ucunit/src/ucunit.c new file mode 100644 index 0000000000..5fc484528f --- /dev/null +++ b/src/ucunit/src/ucunit.c @@ -0,0 +1,274 @@ +// Copyright(c) 2023 ZettaScale Technology and others +// +// This program and the accompanying materials are made available under the +// terms of the Eclipse Public License v. 2.0 which is available at +// http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License +// v. 1.0 which is available at +// http://www.eclipse.org/org/documents/edl-v10.php. +// +// SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause + +#include +#include +#include +#include +#include +#include +#include + +#include "ucunit/ucunit.h" + +static const char *output_filename_root; +static CU_ErrorCode last_error; +static struct CU_Suite *suites; + +static struct CU_Suite *cur_suite; +static struct CU_Test *cur_test; +static jmp_buf fatal_jmpbuf; +static uint32_t failure_count; + +void CU_assertImplementation (bool value, int line, const char *expr, const char *file, const char *something, bool isfatal) +{ + (void)something; + assert (cur_suite && cur_test); + cur_test->nasserts++; + if (value) + return; + + fprintf (stderr, "suite %s test %s: assertion failure: %s:%d: %s\n", cur_suite->name, cur_test->name, file, line, expr); + failure_count++; + cur_test->nfailures++; + struct CU_FailureRecord *fr = malloc (sizeof (*fr)); + fr->file = file; + fr->line = line; + fr->expr = expr; + fr->next = NULL; + if (cur_test->latest_failure) + cur_test->latest_failure->next = fr; + else + cur_test->failures = fr; + cur_test->latest_failure = fr; + + if (isfatal) + longjmp (fatal_jmpbuf, 1); +} + +CU_ErrorCode CU_initialize_registry (void) +{ + output_filename_root = NULL; + failure_count = 0; + last_error = CUE_SUCCESS; + suites = NULL; + cur_suite = NULL; + cur_test = NULL; + return CUE_SUCCESS; +} + +const char *CU_get_error_msg (void) +{ + switch (last_error) + { + case CUE_SUCCESS: return "success"; + case CUE_ERROR: return "error"; + } + return "?"; +} + +static char *ucunit_strdup (const char *s) +{ + size_t l = strlen (s) + 1; + char *n = malloc (l); + memcpy (n, s, l); + return n; +} + +CU_pSuite CU_add_suite (const char *strName, CU_InitializeFunc pInit, CU_CleanupFunc pClean) +{ + struct CU_Suite *cur, *last; + for (cur = suites, last = NULL; cur && strcmp (cur->name, strName) != 0; last = cur, cur = cur->next) + ; + if (cur != NULL) + return cur; + cur = malloc (sizeof (*cur)); + cur->name = ucunit_strdup (strName); + cur->init = pInit; + cur->cleanup = pClean; + cur->next = NULL; + cur->active = true; + cur->tests = NULL; + cur->ntests = 0; + cur->ntests_pass = 0; + cur->ntests_failed = 0; + cur->initfailed = false; + if (last) + last->next = cur; + else + suites = cur; + return cur; +} + +CU_pSuite CU_get_suite (const char *strName) +{ + struct CU_Suite *cur; + for (cur = suites; cur; cur = cur->next) + if (strcmp (cur->name, strName) == 0) + return cur; + return NULL; +} + +CU_ErrorCode CU_set_suite_active (CU_pSuite pSuite, bool fNewActive) +{ + pSuite->active = fNewActive; + return CUE_SUCCESS; +} + +CU_pTest CU_add_test (CU_pSuite pSuite, const char *strName, CU_TestFunc pTestFunc) +{ + struct CU_Test *cur, *last; + for (cur = pSuite->tests, last = NULL; cur && strcmp (cur->name, strName) != 0; last = cur, cur = cur->next) + ; + if (cur != NULL) + return cur; + cur = malloc (sizeof (*cur)); + cur->name = ucunit_strdup (strName); + cur->testfunc = pTestFunc; + cur->next = NULL; + cur->active = true; + cur->nasserts = 0; + cur->nfailures = 0; + cur->failures = NULL; + cur->latest_failure = NULL; + if (last) + last->next = cur; + else + pSuite->tests = cur; + pSuite->ntests++; + return cur; +} + +void CU_set_test_active (CU_pTest pTest, bool fNewActive) +{ + pTest->active = fNewActive; +} + +CU_ErrorCode CU_get_error (void) +{ + return last_error; +} + +static bool runtest (struct CU_Test *test) +{ + volatile int v = setjmp (fatal_jmpbuf); + if (v == 0) + test->testfunc (); + return (v == 0 && test->nfailures == 0 && test->nasserts > 0); +} + +CU_ErrorCode CU_basic_run_tests (void) +{ + uint32_t ntests_defined = 0, ntests_failed = 0, ntests_pass = 0; + uint32_t nasserts_encountered = 0, nasserts_failed = 0; + uint32_t nsuites_failed = 0; + + for (struct CU_Suite *suite = suites; suite; suite = suite->next) + { + ntests_defined += suite->ntests; + if (!suite->active) + continue; + cur_suite = suite; + if (suite->init) + { + if (suite->init () != 0) + { + fprintf (stderr, "failed to initialize suite %s\n", suite->name); + suite->initfailed = true; + nsuites_failed++; + continue; + } + } + for (struct CU_Test *test = suite->tests; test; test = test->next) + { + if (!test->active) + continue; + cur_test = test; + if (runtest (test)) + suite->ntests_pass++; + else + { + suite->ntests_failed++; + if (test->nasserts == 0) + { + fprintf (stderr, "no asserts in suite %s test %s, considering it a failed test\n", suite->name, test->name); + failure_count++; + } + nasserts_failed += test->nfailures; + } + nasserts_encountered += test->nasserts; + } + if (suite->cleanup) + (void) suite->cleanup (); + + ntests_failed += suite->ntests_failed; + ntests_pass += suite->ntests_pass; + } + + fprintf (stderr, "tests: pass %"PRIu32" fail %"PRIu32" (total defined %"PRIu32"); asserts: pass %"PRIu32" fail %"PRIu32"\n", + ntests_pass, ntests_failed, ntests_defined, nasserts_encountered - nasserts_failed, nasserts_failed); + if (ntests_failed) + { + fprintf (stderr, "failed tests\n"); + for (const struct CU_Suite *suite = suites; suite; suite = suite->next) + { + for (const struct CU_Test *test = suite->tests; test; test = test->next) + { + if (test->nfailures) + { + fprintf (stderr, "- %s %s\n", suite->name, test->name); + for (const struct CU_FailureRecord *fr = test->failures; fr; fr = fr->next) + fprintf (stderr, " assertion failure: %s:%d: %s\n", fr->file, fr->line, fr->expr); + } + } + } + } + if (nsuites_failed) + { + fprintf (stderr, "suite initialization failures: %"PRIu32":\n", nsuites_failed); + for (const struct CU_Suite *suite = suites; suite; suite = suite->next) + if (suite->initfailed) + fprintf (stderr, "- %s\n", suite->name); + failure_count++; + } + // no tests at all: failure + if (ntests_pass + ntests_failed == 0) + failure_count++; + return CUE_SUCCESS; +} + +uint32_t CU_get_number_of_failures (void) +{ + return failure_count; +} + +void CU_cleanup_registry (void) +{ + struct CU_Suite *suite; + while ((suite = suites) != NULL) + { + struct CU_Test *test; + suites = suite->next; + while ((test = suite->tests) != NULL) + { + suite->tests = test->next; + struct CU_FailureRecord *fr; + while ((fr = test->failures) != NULL) + { + test->failures = fr->next; + free (fr); + } + free (test->name); + free (test); + } + free (suite->name); + free (suite); + } +} diff --git a/src/ucunit/tests/test_ucunit.c b/src/ucunit/tests/test_ucunit.c new file mode 100644 index 0000000000..49e042ffaa --- /dev/null +++ b/src/ucunit/tests/test_ucunit.c @@ -0,0 +1,300 @@ +#include +#include "ucunit/ucunit.h" + +static int initflag, testflag; + +static int fail_suite_init (void) +{ + return -1; +} + +static int success_suite_init (void) +{ + initflag++; + return 0; +} + +static void f_no_assert (void) +{ + testflag++; +} + +static void f_pass (void) +{ + testflag++; + CU_PASS ("this passes"); +} + +static void f_fail (void) +{ + testflag++; + CU_ASSERT (0); +} + +static void f_fatal (void) +{ + testflag++; + CU_ASSERT_FATAL (0); + testflag++; // should not get here +} + +static bool test_fail_no_tests_at_all (void) +{ + CU_initialize_registry (); + CU_basic_run_tests (); + const bool ok = CU_get_number_of_failures () > 0; + CU_cleanup_registry (); + return ok; +} + +static bool test_fail_no_suite_no_test (void) +{ + initflag = testflag = 0; + CU_initialize_registry (); + CU_basic_run_tests (); + const bool ok = CU_get_number_of_failures () > 0; + CU_cleanup_registry (); + return ok; +} + +static bool test_fail_suite_no_test (void) +{ + initflag = testflag = 0; + CU_initialize_registry (); + CU_pSuite suite = CU_add_suite ("suite", NULL, NULL); + CU_set_suite_active (suite, false); + CU_basic_run_tests (); + const bool ok = CU_get_number_of_failures () > 0; + CU_cleanup_registry (); + return ok; +} + +static bool test_fail_active_suite_no_test (void) +{ + initflag = testflag = 0; + CU_initialize_registry (); + CU_pSuite suite = CU_add_suite ("suite", NULL, NULL); + CU_set_suite_active (suite, true); + CU_basic_run_tests (); + const bool ok = CU_get_number_of_failures () > 0; + CU_cleanup_registry (); + return ok; +} + +static bool test_fail_inactive_suite_test (void) +{ + initflag = testflag = 0; + CU_initialize_registry (); + CU_pSuite suite = CU_add_suite ("suite", NULL, NULL); + CU_set_suite_active (suite, false); + CU_pTest test = CU_add_test (suite, "test", f_pass); + CU_set_test_active (test, true); + CU_basic_run_tests (); + const bool ok = testflag == 0 && CU_get_number_of_failures () > 0; + CU_cleanup_registry (); + return ok; +} + +static bool test_fail_active_suite_inactive_test (void) +{ + initflag = testflag = 0; + CU_initialize_registry (); + CU_pSuite suite = CU_add_suite ("suite", NULL, NULL); + CU_set_suite_active (suite, true); + CU_pTest test = CU_add_test (suite, "test", f_pass); + CU_set_test_active (test, false); + CU_basic_run_tests (); + const bool ok = testflag == 0 && CU_get_number_of_failures () > 0; + CU_cleanup_registry (); + return ok; +} + +static bool test_pass (void) +{ + initflag = testflag = 0; + CU_initialize_registry (); + CU_pSuite suite = CU_add_suite ("suite", NULL, NULL); + CU_set_suite_active (suite, true); + CU_pTest test = CU_add_test (suite, "test", f_pass); + CU_set_test_active (test, true); + CU_basic_run_tests (); + const bool ok = testflag == 1 && CU_get_number_of_failures () == 0; + CU_cleanup_registry (); + return ok; +} + +static bool test_fail_suite_init (void) +{ + initflag = testflag = 0; + CU_initialize_registry (); + CU_pSuite suite = CU_add_suite ("suite", fail_suite_init, NULL); + CU_set_suite_active (suite, true); + CU_pTest test = CU_add_test (suite, "test", f_pass); + CU_set_test_active (test, true); + CU_basic_run_tests (); + const bool ok = testflag == 0 && CU_get_number_of_failures () > 0; + CU_cleanup_registry (); + return ok; +} + +static bool test_fail_suite_init2 (void) +{ + initflag = testflag = 0; + CU_initialize_registry (); + CU_pSuite suite = CU_add_suite ("suite", fail_suite_init, NULL); + CU_set_suite_active (suite, true); + CU_pTest test = CU_add_test (suite, "test", f_pass); + CU_set_test_active (test, true); + CU_pSuite suite2 = CU_add_suite ("suite2", NULL, NULL); + CU_set_suite_active (suite2, true); + CU_pTest test2 = CU_add_test (suite, "test2", f_pass); + CU_set_test_active (test2, true); + CU_basic_run_tests (); + const bool ok = testflag == 0 && CU_get_number_of_failures () > 0; + CU_cleanup_registry (); + return ok; +} + +static bool test_fail_no_assert (void) +{ + initflag = testflag = 0; + CU_initialize_registry (); + CU_pSuite suite = CU_add_suite ("suite", NULL, NULL); + CU_set_suite_active (suite, true); + CU_pTest test = CU_add_test (suite, "test", f_no_assert); + CU_set_test_active (test, true); + CU_basic_run_tests (); + const bool ok = testflag == 1 && CU_get_number_of_failures () > 0; + CU_cleanup_registry (); + return ok; +} + +static bool test_pass_suite_init (void) +{ + initflag = testflag = 0; + CU_initialize_registry (); + CU_pSuite suite = CU_add_suite ("suite", success_suite_init, NULL); + CU_set_suite_active (suite, true); + CU_pTest test = CU_add_test (suite, "test", f_pass); + CU_set_test_active (test, true); + CU_basic_run_tests (); + const bool ok = initflag == 1 && testflag == 1 && CU_get_number_of_failures () == 0; + CU_cleanup_registry (); + return ok; +} + +static bool test_pass_suite_init2 (void) +{ + initflag = testflag = 0; + CU_initialize_registry (); + CU_pSuite suite = CU_add_suite ("suite", success_suite_init, NULL); + CU_set_suite_active (suite, true); + CU_pTest test = CU_add_test (suite, "test", f_pass); + CU_set_test_active (test, true); + CU_pTest test2 = CU_add_test (suite, "test2", f_pass); + CU_set_test_active (test2, true); + CU_basic_run_tests (); + const bool ok = initflag == 1 && testflag == 2 && CU_get_number_of_failures () == 0; + CU_cleanup_registry (); + return ok; +} + +static bool test_pass_test_fail (void) +{ + initflag = testflag = 0; + CU_initialize_registry (); + CU_pSuite suite = CU_add_suite ("suite", NULL, NULL); + CU_set_suite_active (suite, true); + CU_pTest test = CU_add_test (suite, "test", f_fail); + CU_set_test_active (test, true); + CU_basic_run_tests (); + const bool ok = testflag == 1 && CU_get_number_of_failures () == 1; + CU_cleanup_registry (); + return ok; +} + +static bool test_pass_test_fatal (void) +{ + initflag = testflag = 0; + CU_initialize_registry (); + CU_pSuite suite = CU_add_suite ("suite", NULL, NULL); + CU_set_suite_active (suite, true); + CU_pTest test = CU_add_test (suite, "test", f_fatal); + CU_set_test_active (test, true); + CU_basic_run_tests (); + const bool ok = testflag == 1 && CU_get_number_of_failures () == 1; + CU_cleanup_registry (); + return ok; +} + +static bool test_fail_pass_after_fail (void) +{ + initflag = testflag = 0; + CU_initialize_registry (); + CU_pSuite suite = CU_add_suite ("suite", NULL, NULL); + CU_set_suite_active (suite, true); + CU_pTest test = CU_add_test (suite, "test", f_fail); + CU_set_test_active (test, true); + CU_pTest test2 = CU_add_test (suite, "test2", f_pass); + CU_set_test_active (test2, true); + CU_basic_run_tests (); + const bool ok = testflag == 2 && CU_get_number_of_failures () == 1; + CU_cleanup_registry (); + return ok; +} + +static bool test_fail_pass_after_fatal (void) +{ + initflag = testflag = 0; + CU_initialize_registry (); + CU_pSuite suite = CU_add_suite ("suite", NULL, NULL); + CU_set_suite_active (suite, true); + CU_pTest test = CU_add_test (suite, "test", f_fatal); + CU_set_test_active (test, true); + CU_pTest test2 = CU_add_test (suite, "test2", f_pass); + CU_set_test_active (test2, true); + CU_basic_run_tests (); + const bool ok = testflag == 2 && CU_get_number_of_failures () == 1; + CU_cleanup_registry (); + return ok; +} + +#define TEST(n) { #n, n } +static const struct { const char *name; bool (*f) (void); } tests[] = { + TEST (test_fail_no_tests_at_all), + TEST (test_fail_no_suite_no_test), + TEST (test_fail_suite_no_test), + TEST (test_fail_active_suite_no_test), + TEST (test_fail_inactive_suite_test), + TEST (test_fail_active_suite_inactive_test), + TEST (test_pass), + TEST (test_fail_suite_init), + TEST (test_fail_suite_init2), + TEST (test_fail_no_assert), + TEST (test_pass_suite_init), + TEST (test_pass_suite_init2), + TEST (test_pass_test_fail), + TEST (test_pass_test_fatal), + TEST (test_fail_pass_after_fail), + TEST (test_fail_pass_after_fatal) +}; + +int main (int argc, char **argv) +{ + (void) argc; (void) argv; + bool ok = true; + for (size_t i = 0; i < sizeof (tests) / sizeof (tests[0]); i++) + { + printf ("%s:\n", tests[i].name); + fflush (stdout); + if (tests[i].f ()) + printf ("%s: pass\n", tests[i].name); + else + { + printf ("%s: failed\n", tests[i].name); + ok = false; + } + fflush (stdout); + } + return ok ? EXIT_SUCCESS : EXIT_FAILURE; +}