From 139a6bb9a1f0669b71e322805926ceb3830ca8f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juli=C3=A1n=20Berm=C3=BAdez=20Ortega?= Date: Tue, 3 Dec 2019 15:39:38 +0100 Subject: [PATCH] PIC dependecies (#110) * Add PIC selection on Micro-CDR. * Update Micro-CDR version to 1.1.1. * Change version temporarily to 1.1.3. * Modify connection attempts and interval default configuration. * Change Micro-CDR dependency from submodule to git external project. * Remove submodules. * Change Micro-CDR tag. * Test cases (#111) * Refs #6972. Move Jenkins file from root to ci folder. * Refs #6972. Add Linux and Windows CI projects. * Refs #6972. Add CTestConfig.cmake file. * Refs #6972. Add UCLIENT_BUILD_CI_TESTS flag. * Refs #6972. Add test cases. * Refs #6972. Add dependencies to Config.cmake file. --- .gitmodules | 3 -- CMakeLists.txt | 35 ++++++++++++-- CTestConfig.cmake | 22 +++++++++ CTestJenkins.cmake => ci/CTestJenkins.cmake | 0 ci/linux/CMakeLists.txt | 48 +++++++++++++++++++ valgrind.supp => ci/valgrind.supp | 0 ci/windows/CMakeLists.txt | 39 +++++++++++++++ client.config | 4 +- cmake/SuperBuild.cmake | 11 +++-- cmake/packaging/Config.cmake.in | 6 +++ test/case/CMakeLists.txt | 36 ++++++++++++++ test/case/installation/InstallationTest.cmake | 26 ++++++++++ test/case/packaging/CMakeLists.txt | 23 +++++++++ test/case/packaging/Packaging.cmake | 37 ++++++++++++++ test/case/packaging/main.c | 6 +++ thirdparty/microcdr | 1 - 16 files changed, 283 insertions(+), 14 deletions(-) delete mode 100644 .gitmodules create mode 100644 CTestConfig.cmake rename CTestJenkins.cmake => ci/CTestJenkins.cmake (100%) create mode 100644 ci/linux/CMakeLists.txt rename valgrind.supp => ci/valgrind.supp (100%) create mode 100644 ci/windows/CMakeLists.txt create mode 100644 test/case/CMakeLists.txt create mode 100644 test/case/installation/InstallationTest.cmake create mode 100644 test/case/packaging/CMakeLists.txt create mode 100644 test/case/packaging/Packaging.cmake create mode 100644 test/case/packaging/main.c delete mode 160000 thirdparty/microcdr diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index 30e9cb53..00000000 --- a/.gitmodules +++ /dev/null @@ -1,3 +0,0 @@ -[submodule "thirdparty/microcdr"] - path = thirdparty/microcdr - url = https://github.com/eProsima/micro-CDR.git diff --git a/CMakeLists.txt b/CMakeLists.txt index cc44c627..070d010e 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,11 +27,20 @@ option(UCLIENT_VERBOSE_SERIALIZATION "Build with serialization verbosity." OFF) option(UCLIENT_VERBOSE_MESSAGE "Build with message verbosity." OFF) option(UCLIENT_PIC "Control Position Independent Code." ON) option(BUILD_SHARED_LIBS "Control shared/static library building." OFF) + +option(UCLIENT_BUILD_CI_TESTS "Build CI test cases." OFF) +if(UCLIENT_BUILD_CI_TESTS) + set(UCLIENT_BUILD_TESTS ON) + set(UCLIENT_BUILD_EXAMPLES ON) +endif() + if((CMAKE_SYSTEM_NAME STREQUAL "") AND (CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux")) option(UCLIENT_MEMORY_TESTS "Build memory tests." OFF) option(UCLIENT_PERFORMANCE_TESTS "Build performance tests." OFF) endif() + option(UCLIENT_BIG_ENDIANNESS "Set the machine endianness to big endianness (by default is little endianness)." OFF) + set(UCLIENT_CONFIG "${CMAKE_CURRENT_SOURCE_DIR}/client.config" CACHE PATH "Configuration client file.") include(GNUInstallDirs) @@ -45,12 +54,21 @@ else() set(LICENSE_INSTALL_DIR ${DATA_INSTALL_DIR}/${PROJECT_NAME} CACHE PATH "Installation directory for licenses") endif() +############################################################################### +# Dependencies +############################################################################### +set(_microcdr_version 1.1.1) +set(_microcdr_tag v1.1.1) + +set(_deps "") +list(APPEND _deps "microcdr\;${_microcdr_version}") + ############################################################################### # Project ############################################################################### set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules) if(NOT UCLIENT_SUPERBUILD) - project(microxrcedds_client VERSION "1.1.3" LANGUAGES C) + project(microxrcedds_client VERSION "1.1.4" LANGUAGES C) else() project(uclient_superbuild NONE) include(${PROJECT_SOURCE_DIR}/cmake/SuperBuild.cmake) @@ -89,7 +107,13 @@ endif() ############################################################################### # Load external eProsima projects. ############################################################################### -find_package(microcdr 1.1.0 EXACT REQUIRED PATHS ${PROJECT_BINARY_DIR}/temp_install) +set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} ${PROJECT_BINARY_DIR}/temp_install) + +foreach(d ${_deps}) + list(GET d 0 _name) + list(GET d 1 _version) + find_package(${_name} ${_version} EXACT REQUIRED) +endforeach() ############################################################################### # Sources @@ -193,7 +217,7 @@ set_target_properties(${PROJECT_NAME} PROPERTIES C_STANDARD_REQUIRED YES POSITION_INDEPENDENT_CODE - ${UCLIENT_PIC} + ${UCLIENT_PIC} ) target_compile_options(${PROJECT_NAME} @@ -274,6 +298,11 @@ endif() ############################################################################### # Tests ############################################################################### +if(UCLIENT_BUILD_CI_TESTS) + include(CTest) + add_subdirectory(test/case) +endif() + if(UCLIENT_BUILD_TESTS) include(${PROJECT_SOURCE_DIR}/cmake/common/gtest.cmake) find_package(GTest REQUIRED) diff --git a/CTestConfig.cmake b/CTestConfig.cmake new file mode 100644 index 00000000..f10eab53 --- /dev/null +++ b/CTestConfig.cmake @@ -0,0 +1,22 @@ +# Copyright 2019 Proyectos y Sistemas de Mantenimiento SL (eProsima). +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +if(CMAKE_SYSTEM_NAME STREQUAL "Linux") + # MemoryCheck configuration. + find_program(MEMORYCHECK_COMMAND NAMES valgrind) + set(MEMORYCHECK_COMMAND_OPTIONS "${MEMORYCHECK_COMMAND_OPTIONS} --quiet --tool=memcheck --leak-check=yes --show-reachable=yes --num-callers=50 --xml=yes --xml-file=test_%p_memcheck.xml \"--suppressions=${CMAKE_CURRENT_SOURCE_DIR}/ci/valgrind.supp\"") + + # Coverage configuration. + find_program(COVERAGE_COMMAND NAMES gcov) +endif() \ No newline at end of file diff --git a/CTestJenkins.cmake b/ci/CTestJenkins.cmake similarity index 100% rename from CTestJenkins.cmake rename to ci/CTestJenkins.cmake diff --git a/ci/linux/CMakeLists.txt b/ci/linux/CMakeLists.txt new file mode 100644 index 00000000..261a72be --- /dev/null +++ b/ci/linux/CMakeLists.txt @@ -0,0 +1,48 @@ +# Copyright 2019 Proyectos y Sistemas de Mantenimiento SL (eProsima). +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +cmake_minimum_required(VERSION 3.5.0 FATAL_ERROR) + +project(microxrcedds_client_ci LANGUAGES C CXX) + +include(ExternalProject) + +set(_c_flags "-fwrapv -fprofile-arcs -ftest-coverage") +set(_cxx_flags "-fwrapv -fprofile-arcs -ftest-coverage") +set(_exe_linker_flags "-fprofile-arcs -ftest-coverage") +set(_shared_linker_flags "-fprofile-arcs -ftest-coverage") + +ExternalProject_Add(microxrcedds_client + SOURCE_DIR + ${CMAKE_CURRENT_SOURCE_DIR}/../../ + BINARY_DIR + ${PROJECT_BINARY_DIR}/microxrcedds_client-build + INSTALL_DIR + ${PROJECT_BINARY_DIR}/temp_install + TEST_AFTER_INSTALL + TRUE + TEST_COMMAND + COMMAND ${CMAKE_CTEST_COMMAND} -VV -T Test + COMMAND ${CMAKE_CTEST_COMMAND} -VV -T MemCheck -E "test-case*" + COMMAND ${CMAKE_CTEST_COMMAND} -VV -T Coverage -E "test-case*" + CMAKE_CACHE_ARGS + -DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE} + -DCMAKE_C_FLAGS:STRING=${_c_flags} + -DCMAKE_CXX_FLAGS:STRING=${_cxx_flags} + -DCMAKE_EXE_LINKER_FLAGS:STRING=${_exe_linker_flags} + -DCMAKE_SHARED_LINKER_FLAGS:STRING=${_shared_linker_flags} + -DCMAKE_INSTALL_PREFIX:PATH= + -DUCLIENT_BUILD_CI_TESTS:BOOL=ON + -DGTEST_INDIVIDUAL:BOOL=ON + ) \ No newline at end of file diff --git a/valgrind.supp b/ci/valgrind.supp similarity index 100% rename from valgrind.supp rename to ci/valgrind.supp diff --git a/ci/windows/CMakeLists.txt b/ci/windows/CMakeLists.txt new file mode 100644 index 00000000..0d58bf48 --- /dev/null +++ b/ci/windows/CMakeLists.txt @@ -0,0 +1,39 @@ +# Copyright 2019 Proyectos y Sistemas de Mantenimiento SL (eProsima). +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +cmake_minimum_required(VERSION 3.5.0 FATAL_ERROR) + +project(microxrcedds_client_ci LANGUAGES C CXX) + +include(ExternalProject) + +ExternalProject_Add(microxrcedds_client + SOURCE_DIR + ${CMAKE_CURRENT_SOURCE_DIR}/../../ + BINARY_DIR + ${PROJECT_BINARY_DIR}/microxrcedds_client-build + INSTALL_DIR + ${PROJECT_BINARY_DIR}/temp_install + TEST_AFTER_INSTALL + TRUE + TEST_COMMAND + COMMAND ${CMAKE_CTEST_COMMAND} -VV -C ${CMAKE_BUILD_TYPE} -T Test + CMAKE_CACHE_ARGS + -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} + -DCMAKE_GENERATOR_TOOLSET:STRING=${CMAKE_GENERATOR_TOOLSET} + -DCMAKE_GENERATOR_PLATFORM:STRING=${CMAKE_GENERATOR_PLATFORM} + -DCMAKE_INSTALL_PREFIX:PATH= + -DUCLIENT_BUILD_CI_TESTS:BOOL=ON + -DGTEST_INDIVIDUAL:BOOL=ON + ) \ No newline at end of file diff --git a/client.config b/client.config index 08ce23a8..5f03cf16 100644 --- a/client.config +++ b/client.config @@ -8,8 +8,8 @@ CONFIG_MAX_OUTPUT_RELIABLE_STREAMS=1 CONFIG_MAX_INPUT_BEST_EFFORT_STREAMS=1 CONFIG_MAX_INPUT_RELIABLE_STREAMS=1 -CONFIG_MAX_SESSION_CONNECTION_ATTEMPTS=12 -CONFIG_MIN_SESSION_CONNECTION_INTERVAL=1 +CONFIG_MAX_SESSION_CONNECTION_ATTEMPTS=5 +CONFIG_MIN_SESSION_CONNECTION_INTERVAL=500 CONFIG_MIN_HEARTBEAT_TIME_INTERVAL=1 CONFIG_BIG_ENDIANNESS=FALSE diff --git a/cmake/SuperBuild.cmake b/cmake/SuperBuild.cmake index 8534168e..46e81b30 100644 --- a/cmake/SuperBuild.cmake +++ b/cmake/SuperBuild.cmake @@ -18,15 +18,15 @@ unset(_deps) # Micro CDR. unset(microcdr_DIR CACHE) -find_package(microcdr "1.1.0" EXACT QUIET) +find_package(microcdr ${_microcdr_version} EXACT QUIET) if(NOT microcdr_FOUND) ExternalProject_Add(ucdr - DOWNLOAD_COMMAND - cd ${PROJECT_SOURCE_DIR} && git submodule update --init thirdparty/microcdr/ + GIT_REPOSITORY + https://github.com/eProsima/Micro-CDR.git + GIT_TAG + ${_microcdr_tag} PREFIX ${PROJECT_BINARY_DIR}/ucdr - SOURCE_DIR - ${PROJECT_SOURCE_DIR}/thirdparty/microcdr INSTALL_DIR ${PROJECT_BINARY_DIR}/temp_install CMAKE_ARGS @@ -36,6 +36,7 @@ if(NOT microcdr_FOUND) -DCMAKE_SYSROOT:PATH=${CMAKE_SYSROOT} -DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE} -DCONFIG_BIG_ENDIANNESS=${UCLIENT_BIG_ENDIANNESS} + -DUCDR_PIC=${UCLIENT_PIC} ) list(APPEND _deps ucdr) endif() diff --git a/cmake/packaging/Config.cmake.in b/cmake/packaging/Config.cmake.in index 3e00a3df..74962f0f 100644 --- a/cmake/packaging/Config.cmake.in +++ b/cmake/packaging/Config.cmake.in @@ -23,4 +23,10 @@ set_and_check(@PROJECT_NAME@_INCLUDE_DIR "@PACKAGE_INCLUDE_INSTALL_DIR@") set_and_check(@PROJECT_NAME@_LIB_DIR "@PACKAGE_LIB_INSTALL_DIR@") set_and_check(@PROJECT_NAME@_DATA_DIR "@PACKAGE_DATA_INSTALL_DIR@") +foreach(d @_deps@) + list(GET d 0 _name) + list(GET d 1 _version) + find_package(${_name} ${_version} EXACT REQUIRED) +endforeach() + include(${@PROJECT_NAME@_DATA_DIR}/@PROJECT_NAME@/cmake/@PROJECT_NAME@Targets.cmake) diff --git a/test/case/CMakeLists.txt b/test/case/CMakeLists.txt new file mode 100644 index 00000000..0ce49839 --- /dev/null +++ b/test/case/CMakeLists.txt @@ -0,0 +1,36 @@ +# Copyright 2019 Proyectos y Sistemas de Mantenimiento SL (eProsima). +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +add_test( + NAME + test-case-installation + COMMAND + ${CMAKE_COMMAND} + -DINSTALL_PATH=${CMAKE_INSTALL_PREFIX} + -DLIBRARY_NAME=$ + -P ${CMAKE_CURRENT_SOURCE_DIR}/installation/InstallationTest.cmake + ) + +add_test( + NAME + test-case-packaging + COMMAND + ${CMAKE_COMMAND} + -DORIGINAL_DIR=${CMAKE_CURRENT_SOURCE_DIR}/packaging + -DCMAKE_PREFIX_PATH=${CMAKE_INSTALL_PREFIX} + -DREQUIRED_VERSION=${PROJECT_VERSION} + -DCMAKE_GENERATOR_TOOLSET=${CMAKE_GENERATOR_TOOLSET} + -DCMAKE_GENERATOR_PLATFORM=${CMAKE_GENERATOR_PLATFORM} + -P ${CMAKE_CURRENT_SOURCE_DIR}/packaging/Packaging.cmake + ) \ No newline at end of file diff --git a/test/case/installation/InstallationTest.cmake b/test/case/installation/InstallationTest.cmake new file mode 100644 index 00000000..8b12087f --- /dev/null +++ b/test/case/installation/InstallationTest.cmake @@ -0,0 +1,26 @@ +# Copyright 2019 Proyectos y Sistemas de Mantenimiento SL (eProsima). +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Check directories. +set(_directories "lib" "include" "share") +foreach(_dir ${_directories}) + if(NOT EXISTS ${INSTALL_PATH}/${_dir}) + message(FATAL_ERROR "Directory ${_dir} not found.") + endif() +endforeach() + +# Check library. +if(NOT EXISTS ${INSTALL_PATH}/lib/${LIBRARY_NAME}) + message(FATAL_ERROR "Library lib/${LIBRARY_NAME} not found.") +endif() \ No newline at end of file diff --git a/test/case/packaging/CMakeLists.txt b/test/case/packaging/CMakeLists.txt new file mode 100644 index 00000000..b06079b1 --- /dev/null +++ b/test/case/packaging/CMakeLists.txt @@ -0,0 +1,23 @@ +# Copyright 2019 Proyectos y Sistemas de Mantenimiento SL (eProsima). +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +cmake_minimum_required(VERSION 3.5.0 FATAL_ERROR) + +project(packaging LANGUAGES C) + +find_package(microxrcedds_client EXACT ${REQUIRED_VERSION} REQUIRED) + +add_executable(${PROJECT_NAME} main.c) + +target_link_libraries(${PROJECT_NAME} microxrcedds_client) \ No newline at end of file diff --git a/test/case/packaging/Packaging.cmake b/test/case/packaging/Packaging.cmake new file mode 100644 index 00000000..72dea830 --- /dev/null +++ b/test/case/packaging/Packaging.cmake @@ -0,0 +1,37 @@ +# Copyright 2019 Proyectos y Sistemas de Mantenimiento SL (eProsima). +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +execute_process( + COMMAND + ${CMAKE_COMMAND} ${ORIGINAL_DIR} + -DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH} + -DREQUIRED_VERSION=${REQUIRED_VERSION} + -DCMAKE_GENERATOR_TOOLSET=${CMAKE_GENERATOR_TOOLSET} + -DCMAKE_GENERATOR_PLATFORM=${CMAKE_GENERATOR_PLATFORM} + RESULT_VARIABLE _result + ) + +if(_result) + message(FATAL_ERROR "Error in find_package.") +endif() + +execute_process( + COMMAND + ${CMAKE_COMMAND} --build . + RESULT_VARIABLE _result + ) + +if(_result) + message(FATAL_ERROR "Error compiling example.") +endif() \ No newline at end of file diff --git a/test/case/packaging/main.c b/test/case/packaging/main.c new file mode 100644 index 00000000..1ecb4a3f --- /dev/null +++ b/test/case/packaging/main.c @@ -0,0 +1,6 @@ +#include + +int main() +{ + return 0; +} \ No newline at end of file diff --git a/thirdparty/microcdr b/thirdparty/microcdr deleted file mode 160000 index ef671568..00000000 --- a/thirdparty/microcdr +++ /dev/null @@ -1 +0,0 @@ -Subproject commit ef671568fba72cc2dbf146ab6b6c9ffdc09dd0a8