Skip to content

Commit

Permalink
Do not compile SHM transport if thirdparty/boost test fail (eProsima#…
Browse files Browse the repository at this point in the history
…1105)

* Refs #8063. Do not compile SHM transport if thirdparty/boost test failed.

* Refs #8063. Remove a warning in clang.
  • Loading branch information
adolfomarver authored Mar 27, 2020
1 parent 8ad968d commit eaddd8e
Show file tree
Hide file tree
Showing 10 changed files with 151 additions and 76 deletions.
7 changes: 5 additions & 2 deletions cmake/modules/FindThirdpartyBoost.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,12 @@ try_compile(IS_THIRDPARTY_BOOST_OK
OUTPUT_VARIABLE OUT
)

set(IS_THIRDPARTY_BOOST_SUPPORTED ${IS_THIRDPARTY_BOOST_OK})

if(NOT IS_THIRDPARTY_BOOST_OK)
message(FATAL_ERROR "Couldn't compile thirdparty/boost with current configuration!!!\n" ${OUT})
message(STATUS ${OUT} "\nCouldn't compile thirdparty/boost. SHM Transport feature will be disabled!!!\n")
else()
message(STATUS "Thirdparty/boost compiled OK")
mark_as_advanced(THIRDPARTY_BOOST_INCLUDE_DIR)
endif()

mark_as_advanced(THIRDPARTY_BOOST_INCLUDE_DIR)
14 changes: 11 additions & 3 deletions src/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,11 @@ set(${PROJECT_NAME}_source_files
rtps/transport/UDPv4Transport.cpp
rtps/transport/TCPTransportInterface.cpp
rtps/transport/UDPTransportInterface.cpp
rtps/transport/shared_mem/SharedMemTransport.cpp
rtps/transport/shared_mem/SharedMemTransportDescriptor.cpp
rtps/transport/TCPv4Transport.cpp
rtps/transport/UDPv6Transport.cpp
rtps/transport/TCPv6Transport.cpp
rtps/transport/test_UDPv4Transport.cpp
rtps/transport/shared_mem/test_SharedMemTransport.cpp
rtps/transport/tcp/TCPControlMessage.cpp
rtps/transport/tcp/RTCPMessageManager.cpp

Expand Down Expand Up @@ -198,6 +197,14 @@ set(${PROJECT_NAME}_source_files
fastrtps_deprecated/utils/TimedConditionVariable.cpp
)

# SHM Transport
if(IS_THIRDPARTY_BOOST_OK)
list(APPEND ${PROJECT_NAME}_source_files
rtps/transport/shared_mem/test_SharedMemTransport.cpp
rtps/transport/shared_mem/SharedMemTransport.cpp
)
endif()

# TLS Support
if(TLS_FOUND)
list(APPEND ${PROJECT_NAME}_source_files
Expand Down Expand Up @@ -342,7 +349,8 @@ elseif(NOT EPROSIMA_INSTALLER)
$<$<AND:$<BOOL:${WIN32}>,$<NOT:$<STREQUAL:"${CMAKE_SYSTEM_NAME}","WindowsStore">>>:_WIN32_WINNT=0x0601>
$<$<AND:$<BOOL:${WIN32}>,$<STREQUAL:"${CMAKE_SYSTEM_NAME}","WindowsStore">>:SQLITE_OS_WINRT>
$<$<AND:$<BOOL:${ANDROID}>,$<NOT:$<BOOL:${HAVE_CXX14}>>,$<NOT:$<BOOL:${HAVE_CXX1Y}>>>:ASIO_DISABLE_STD_STRING_VIEW>
$<$<BOOL:${WIN32}>:_ENABLE_ATOMIC_ALIGNMENT_FIX>
$<$<BOOL:${WIN32}>:_ENABLE_ATOMIC_ALIGNMENT_FIX>
$<$<NOT:$<BOOL:${IS_THIRDPARTY_BOOST_SUPPORTED}>>:FASTDDS_SHM_TRANSPORT_DISABLED> # Do not compile SHM Transport
)

# Define public headers
Expand Down
27 changes: 16 additions & 11 deletions src/cpp/rtps/network/NetworkFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,21 +86,26 @@ bool NetworkFactory::RegisterTransport(const TransportDescriptorInterface* descr
uint32_t minSendBufferSize = std::numeric_limits<uint32_t>::max();

std::unique_ptr<TransportInterface> transport(descriptor->create_transport());
if(transport->init())
{
minSendBufferSize = transport->get_configuration()->min_send_buffer_size();
mRegisteredTransports.emplace_back(std::move(transport));
wasRegistered = true;
}

if(wasRegistered)
if(transport)
{
if(descriptor->max_message_size() < maxMessageSizeBetweenTransports_)
maxMessageSizeBetweenTransports_ = descriptor->max_message_size();
if(transport->init())
{
minSendBufferSize = transport->get_configuration()->min_send_buffer_size();
mRegisteredTransports.emplace_back(std::move(transport));
wasRegistered = true;
}

if(minSendBufferSize < minSendBufferSize_)
minSendBufferSize_ = minSendBufferSize;
if(wasRegistered)
{
if(descriptor->max_message_size() < maxMessageSizeBetweenTransports_)
maxMessageSizeBetweenTransports_ = descriptor->max_message_size();

if(minSendBufferSize < minSendBufferSize_)
minSendBufferSize_ = minSendBufferSize;
}
}

return wasRegistered;
}

Expand Down
24 changes: 21 additions & 3 deletions src/cpp/rtps/participant/RTPSParticipantImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,27 @@ RTPSParticipantImpl::RTPSParticipantImpl(
// User defined transports
for (const auto& transportDescriptor : PParam.userTransports)
{
m_network_Factory.RegisterTransport(transportDescriptor.get());

has_shm_transport_ |= (dynamic_cast<fastdds::rtps::SharedMemTransportDescriptor*>(transportDescriptor.get()) != nullptr);
if(m_network_Factory.RegisterTransport(transportDescriptor.get()))
{
has_shm_transport_ |=
(dynamic_cast<fastdds::rtps::SharedMemTransportDescriptor*>(transportDescriptor.get()) != nullptr);
}
else
{
// SHM transport could be disabled
if((dynamic_cast<fastdds::rtps::SharedMemTransportDescriptor*>(transportDescriptor.get()) != nullptr))
{
logError(RTPS_PARTICIPANT,
"Unable to Register SHM Transport. SHM Transport is not supported in"
" the current platform.");
}
else
{
logError(RTPS_PARTICIPANT,
"User transport failed to register.");
}

}
}

mp_userParticipant->mp_impl = this;
Expand Down
29 changes: 0 additions & 29 deletions src/cpp/rtps/transport/shared_mem/SharedMemTransport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,35 +47,6 @@ using LocatorSelectorEntry = fastrtps::rtps::LocatorSelectorEntry;
using LocatorSelector = fastrtps::rtps::LocatorSelector;
using PortParameters = fastrtps::rtps::PortParameters;

//*********************************************************
// SharedMemTransportDescriptor
//*********************************************************

SharedMemTransportDescriptor::SharedMemTransportDescriptor()
: TransportDescriptorInterface(SharedMemTransport::default_segment_size, s_maximumInitialPeersRange)
, segment_size_(SharedMemTransport::default_segment_size)
, port_queue_capacity_(SharedMemTransport::default_port_queue_capacity)
, port_overflow_policy_(SharedMemTransport::default_overflow_policy)
, segment_overflow_policy_(SharedMemTransport::default_overflow_policy)
, healthy_check_timeout_ms_(SharedMemTransport::default_healthy_check_timeout_ms)
, rtps_dump_file_("")
{
maxMessageSize = segment_size_;
}

SharedMemTransportDescriptor::SharedMemTransportDescriptor(
const SharedMemTransportDescriptor& t)
: TransportDescriptorInterface(t.segment_size_, s_maximumInitialPeersRange)
, segment_size_(t.segment_size_)
, port_queue_capacity_(t.port_queue_capacity_)
, port_overflow_policy_(t.port_overflow_policy_)
, segment_overflow_policy_(t.segment_overflow_policy_)
, healthy_check_timeout_ms_(t.healthy_check_timeout_ms_)
, rtps_dump_file_(t.rtps_dump_file_)
{
maxMessageSize = t.segment_size_;
}

TransportInterface* SharedMemTransportDescriptor::create_transport() const
{
return new SharedMemTransport(*this);
Expand Down
7 changes: 0 additions & 7 deletions src/cpp/rtps/transport/shared_mem/SharedMemTransport.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,6 @@ class SharedMemTransport : public TransportInterface
{
public:

static const uint32_t maximum_message_size = (std::numeric_limits<uint32_t>::max)();
static const uint32_t default_segment_size = 262144;
static const uint32_t default_port_queue_capacity = 512;
static const SharedMemTransportDescriptor::OverflowPolicy default_overflow_policy =
SharedMemTransportDescriptor::OverflowPolicy::DISCARD;
static const uint32_t default_healthy_check_timeout_ms = 1000;

RTPS_DllAPI SharedMemTransport(
const SharedMemTransportDescriptor&);
void clean();
Expand Down
67 changes: 67 additions & 0 deletions src/cpp/rtps/transport/shared_mem/SharedMemTransportDescriptor.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// Copyright 2020 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.

#include <fastdds/rtps/transport/TransportInterface.h>
#include <fastdds/rtps/transport/shared_mem/SharedMemTransportDescriptor.h>

using namespace eprosima::fastdds::rtps;

namespace eprosima {
namespace fastdds {
namespace rtps {

static constexpr uint32_t shm_default_segment_size = 262144;
static constexpr uint32_t shm_default_port_queue_capacity = 512;
static constexpr SharedMemTransportDescriptor::OverflowPolicy shm_default_overflow_policy =
SharedMemTransportDescriptor::OverflowPolicy::DISCARD;
static constexpr uint32_t shm_default_healthy_check_timeout_ms = 1000;

} // rtps
} // fastdds
} // eprosima

//*********************************************************
// SharedMemTransportDescriptor
//*********************************************************
SharedMemTransportDescriptor::SharedMemTransportDescriptor()
: TransportDescriptorInterface(shm_default_segment_size, s_maximumInitialPeersRange)
, segment_size_(shm_default_segment_size)
, port_queue_capacity_(shm_default_port_queue_capacity)
, port_overflow_policy_(shm_default_overflow_policy)
, segment_overflow_policy_(shm_default_overflow_policy)
, healthy_check_timeout_ms_(shm_default_healthy_check_timeout_ms)
, rtps_dump_file_("")
{
maxMessageSize = segment_size_;
}

SharedMemTransportDescriptor::SharedMemTransportDescriptor(
const SharedMemTransportDescriptor& t)
: TransportDescriptorInterface(t.segment_size_, s_maximumInitialPeersRange)
, segment_size_(t.segment_size_)
, port_queue_capacity_(t.port_queue_capacity_)
, port_overflow_policy_(t.port_overflow_policy_)
, segment_overflow_policy_(t.segment_overflow_policy_)
, healthy_check_timeout_ms_(t.healthy_check_timeout_ms_)
, rtps_dump_file_(t.rtps_dump_file_)
{
maxMessageSize = t.segment_size_;
}

#ifdef FASTDDS_SHM_TRANSPORT_DISABLED
TransportInterface* SharedMemTransportDescriptor::create_transport() const
{
return nullptr;
}
#endif
4 changes: 4 additions & 0 deletions test/blackbox/BlackboxTestsTransportSHM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef FASTDDS_SHM_TRANSPORT_DISABLED

#include "BlackboxTests.hpp"

#include "PubSubReader.hpp"
Expand Down Expand Up @@ -346,4 +348,6 @@ TEST(SHM, SHM_UDPvsUDP)
reader.wait_participant_undiscovery();
}

#endif // EPROSIMA_SHM_TRANSPORT_DISABLED


4 changes: 3 additions & 1 deletion test/blackbox/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,9 @@ if(NOT ((MSVC OR MSVC_IDE) AND EPROSIMA_INSTALLER) AND fastcdr_FOUND)
${CMAKE_CURRENT_BINARY_DIR}/PubSubReader.xml)

add_executable(BlackboxTests ${BLACKBOXTESTS_SOURCE})
target_compile_definitions(BlackboxTests PRIVATE)
target_compile_definitions(BlackboxTests PRIVATE
$<$<NOT:$<BOOL:${IS_THIRDPARTY_BOOST_SUPPORTED}>>:FASTDDS_SHM_TRANSPORT_DISABLED> # Do not compile SHM Transport
)
target_include_directories(BlackboxTests PRIVATE ${GTEST_INCLUDE_DIRS})
target_link_libraries(BlackboxTests fastrtps fastcdr foonathan_memory ${GTEST_LIBRARIES})
add_blackbox_gtest(BlackboxTests SOURCES ${BLACKBOXTESTS_TEST_SOURCE}
Expand Down
44 changes: 24 additions & 20 deletions test/unittest/transport/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ if(NOT ((MSVC OR MSVC_IDE) AND EPROSIMA_INSTALLER))
${PROJECT_SOURCE_DIR}/src/cpp/fastdds/log/Log.cpp
${PROJECT_SOURCE_DIR}/src/cpp/fastdds/log/StdoutConsumer.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/shared_mem/SharedMemTransport.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/shared_mem/SharedMemTransportDescriptor.cpp
${PROJECT_SOURCE_DIR}/src/cpp/rtps/transport/ChannelResource.cpp
${PROJECT_SOURCE_DIR}/src/cpp/fastrtps_deprecated/utils/IPFinder.cpp
${PROJECT_SOURCE_DIR}/src/cpp/fastrtps_deprecated/utils/IPLocator.cpp
Expand Down Expand Up @@ -285,27 +286,30 @@ if(NOT ((MSVC OR MSVC_IDE) AND EPROSIMA_INSTALLER))
endif()
add_gtest(TCPv4Tests SOURCES ${TCPV4TESTS_SOURCE})

add_executable(SharedMemTests ${SHAREDMEMTESTS_SOURCE})

target_compile_definitions(SharedMemTests PRIVATE FASTRTPS_NO_LIB
$<$<BOOL:${WIN32}>:_ENABLE_ATOMIC_ALIGNMENT_FIX>)

target_include_directories(SharedMemTests PRIVATE
${GTEST_INCLUDE_DIRS} ${GMOCK_INCLUDE_DIRS}
${PROJECT_SOURCE_DIR}/test/mock/rtps/MessageReceiver
${PROJECT_SOURCE_DIR}/test/mock/rtps/ReceiverResource
${PROJECT_SOURCE_DIR}/include ${PROJECT_BINARY_DIR}/include
${PROJECT_SOURCE_DIR}/src/cpp
${THIRDPARTY_BOOST_INCLUDE_DIR}
)
target_link_libraries(SharedMemTests ${GTEST_LIBRARIES} ${MOCKS}
$<$<BOOL:${TLS_FOUND}>:OpenSSL::SSL$<SEMICOLON>OpenSSL::Crypto>
${THIRDPARTY_BOOST_LINK_LIBS})
if(MSVC OR MSVC_IDE)
target_link_libraries(SharedMemTests ${PRIVACY} iphlpapi Shlwapi )
else()
target_link_libraries(SharedMemTests ${PRIVACY} )
if(IS_THIRDPARTY_BOOST_OK)
add_executable(SharedMemTests ${SHAREDMEMTESTS_SOURCE})

target_compile_definitions(SharedMemTests PRIVATE FASTRTPS_NO_LIB
$<$<BOOL:${WIN32}>:_ENABLE_ATOMIC_ALIGNMENT_FIX>)

target_include_directories(SharedMemTests PRIVATE
${GTEST_INCLUDE_DIRS} ${GMOCK_INCLUDE_DIRS}
${PROJECT_SOURCE_DIR}/test/mock/rtps/MessageReceiver
${PROJECT_SOURCE_DIR}/test/mock/rtps/ReceiverResource
${PROJECT_SOURCE_DIR}/include ${PROJECT_BINARY_DIR}/include
${PROJECT_SOURCE_DIR}/src/cpp
${THIRDPARTY_BOOST_INCLUDE_DIR}
)
target_link_libraries(SharedMemTests ${GTEST_LIBRARIES} ${MOCKS}
$<$<BOOL:${TLS_FOUND}>:OpenSSL::SSL$<SEMICOLON>OpenSSL::Crypto>
${THIRDPARTY_BOOST_LINK_LIBS})
if(MSVC OR MSVC_IDE)
target_link_libraries(SharedMemTests ${PRIVACY} iphlpapi Shlwapi )
else()
target_link_libraries(SharedMemTests ${PRIVACY} )
endif()
add_gtest(SharedMemTests SOURCES ${SHAREDMEMTESTS_SOURCE})
endif()
add_gtest(SharedMemTests SOURCES ${SHAREDMEMTESTS_SOURCE})
endif()
endif()

0 comments on commit eaddd8e

Please sign in to comment.