Skip to content

Commit

Permalink
Add multithread ping test
Browse files Browse the repository at this point in the history
Add multithread test support

Fix typo

Test CI

Set library full path and dependencies

Modify client link method

Add link_directories

Trigger CI

Fix include paths

Trigger CI

Update CMakeLists.txt
Fix create bin field

Revert cmake change

Update participant name
  • Loading branch information
Acuadros95 committed May 31, 2021
1 parent 19537f8 commit f9396ee
Show file tree
Hide file tree
Showing 11 changed files with 203 additions and 32 deletions.
41 changes: 41 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,46 @@ if(UXRCE_ENABLE_CLIENT)
list(APPEND _deps client)
endif()

if(UXRCE_TEST_THREAD)
ExternalProject_Add(client_thread
GIT_REPOSITORY
https://github.com/eProsima/Micro-XRCE-DDS-Client.git
GIT_TAG
${_client_tag}
PREFIX
${PROJECT_BINARY_DIR}/client_thread
INSTALL_DIR
${PROJECT_BINARY_DIR}/temp_install
TEST_AFTER_INSTALL
${_run_tests}
TEST_COMMAND
${_test_command}
CMAKE_CACHE_ARGS
-DLIB_PREFIX:STRING=libthread_
-DUCLIENT_PROFILE_MULTITHREAD:BOOL=ON
-DCMAKE_CXX_COMPILER:FILEPATH=${CMAKE_CXX_COMPILER}
-DCMAKE_C_COMPILER:FILEPATH=${CMAKE_C_COMPILER}
-DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE}
-DCMAKE_C_FLAGS:STRING=${CMAKE_C_FLAGS}
-DCMAKE_CXX_FLAGS:STRING=${CMAKE_CXX_FLAGS}
-DCMAKE_EXE_LINKER_FLAGS:STRING=${CMAKE_EXE_LINKER_FLAGS}
-DCMAKE_SHARED_LINKER_FLAGS:STRING=${CMAKE_SHARED_LINKER_FLAGS}
-DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR>
-DCMAKE_PREFIX_PATH:PATH=<INSTALL_DIR>
-DBIN_INSTALL_DIR:PATH=${BIN_INSTALL_DIR}
-DINCLUDE_INSTALL_DIR:PATH=${INCLUDE_INSTALL_DIR}_thread
-DLIB_INSTALL_DIR:PATH=${LIB_INSTALL_DIR}
-DDATA_INSTALL_DIR:PATH=${DATA_INSTALL_DIR}
-DUCLIENT_BUILD_EXAMPLES:BOOL=${UXRCE_BUILD_EXAMPLES}
-DUCLIENT_INSTALL_EXAMPLES:BOOL=${UXRCE_BUILD_EXAMPLES}
-DUCLIENT_PIC:BOOL=ON
-DUCLIENT_BUILD_TESTS:BOOL=${UXRCE_BUILD_TESTS}
-DUCLIENT_ISOLATED_INSTALL:BOOL=OFF
-DGTEST_INDIVIDUAL:BOOL=ON
)
list(APPEND _deps client_thread)
endif()

if(UXRCE_ENABLE_AGENT)
ExternalProject_Add(agent
GIT_REPOSITORY
Expand Down Expand Up @@ -223,6 +263,7 @@ if(UXRCE_BUILD_TESTS)
TEST_COMMAND
${_test_command}
CMAKE_CACHE_ARGS
-DUXRCE_TEST_THREAD:BOOL=${UXRCE_TEST_THREAD}
-DCMAKE_CXX_COMPILER:FILEPATH=${CMAKE_CXX_COMPILER}
-DCMAKE_C_COMPILER:FILEPATH=${CMAKE_C_COMPILER}
-DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE}
Expand Down
1 change: 1 addition & 0 deletions ci/linux/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ ExternalProject_Add(microxrcedds
BUILD_COMMAND
""
CMAKE_CACHE_ARGS
-DUXRCE_TEST_THREAD:BOOL=ON
-DCMAKE_CXX_COMPILER:STRING=${CMAKE_CXX_COMPILER}
-DCMAKE_C_COMPILER:STRING=${CMAKE_C_COMPILER}
-DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE}
Expand Down
5 changes: 5 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,8 @@ add_subdirectory(test/publisher_subscriber)
add_subdirectory(test/discovery)
add_subdirectory(test/custom_transports)
#add_subdirectory(test/shapes_demo) TODO (julibert): fix client and agent paths.

if(UXRCE_TEST_THREAD)
add_subdirectory(test/multithread)
endif()

2 changes: 1 addition & 1 deletion test/profiling/publisher/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ int main(int args, char** argv)
ucdrBuffer ub;
uxr_prepare_output_stream(&session, besteffort_out, datawriter_id, &ub, 4 + strlen(topic));
ucdr_serialize_string(&ub, topic);

UXR_UNLOCK_STREAM_ID(&session, besteffort_out);
printf("Send topic %s, by %d\n", topic, client_key);
connected = uxr_run_session_time(&session, 50);
++count;
Expand Down
1 change: 1 addition & 0 deletions test/test/client_agent/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ target_include_directories(client-agent-test
${GTEST_INCLUDE_DIR}
)

link_directories(${PROJECT_BINARY_DIR}/test/interaction_client)
target_link_libraries(client-agent-test
PRIVATE
interaction_client
Expand Down
2 changes: 1 addition & 1 deletion test/test/client_agent/ClientAgentInteraction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ TEST_P(ClientAgentInteraction, ExistantEntitiesCreationReplaceReuseBINBINReliabl
TEST_P(ClientAgentInteraction, PingFromClientToAgent)
{
const Transport transport_kind(std::get<0>(GetParam()));
ASSERT_NO_FATAL_FAILURE(client_.ping_agent(transport_kind));
ASSERT_NO_FATAL_FAILURE(client_.ping_agent(transport_kind, 1, 1));
}

INSTANTIATE_TEST_CASE_P(
Expand Down
87 changes: 59 additions & 28 deletions test/test/interaction_client/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,38 +28,69 @@ set(SRCS
Discovery.cpp
)

add_library(interaction_client STATIC ${SRCS})
list(APPEND libs interaction_client)
find_library(CLIENT microxrcedds_client REQUIRED
HINTS ${PROJECT_BINARY_DIR}/../../../temp_install/lib/libmicroxrcedds_client.a)

set_common_compile_options(interaction_client)
if(UXRCE_TEST_THREAD)
list(APPEND libs interaction_thread_client)
find_library(CLIENT_MULTITHREAD thread_microxrcedds_client REQUIRED
HINTS ${PROJECT_BINARY_DIR}/../../../temp_install/lib/libthread_microxrcedds_client.a)
endif()

if(MSVC OR MSVC_IDE)
target_compile_options(interaction_client
PRIVATE
/wd4996
foreach(lib ${libs})
add_library(${lib} STATIC ${SRCS})
set_common_compile_options(${lib})

if(MSVC OR MSVC_IDE)
target_compile_options(${lib}
PRIVATE
/wd4996
PUBLIC
-D_CRT_SECURE_NO_WARNINGS
)
endif()

if(${lib} STREQUAL interaction_client)
target_include_directories(${lib}
PUBLIC
-D_CRT_SECURE_NO_WARNINGS
${PROJECT_BINARY_DIR}/../../../temp_install/include
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_BINARY_DIR}
PRIVATE
${GTEST_INCLUDE_DIRS}
)
endif()

target_include_directories(interaction_client
PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_BINARY_DIR}
PRIVATE
${GTEST_INCLUDE_DIRS}
)
target_link_libraries(${lib}
PUBLIC
${CLIENT}
custom_transports
PRIVATE
${GTEST_BOTH_LIBRARIES}
)
elseif(${lib} STREQUAL interaction_thread_client)
target_include_directories(${lib}
PUBLIC
${PROJECT_BINARY_DIR}/../../../temp_install/include_thread
${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_CURRENT_SOURCE_DIR}
PRIVATE
${GTEST_INCLUDE_DIRS}
)

target_link_libraries(interaction_client
PUBLIC
microxrcedds_client
custom_transports
PRIVATE
${GTEST_BOTH_LIBRARIES}
)
target_link_libraries(${lib}
PUBLIC
${CLIENT_MULTITHREAD}
custom_transports
PRIVATE
${GTEST_BOTH_LIBRARIES}
)
endif()

set_target_properties(interaction_client PROPERTIES
CXX_STANDARD
11
CXX_STANDARD_REQUIRED
YES
)
set_target_properties(${lib} PROPERTIES
CXX_STANDARD
11
CXX_STANDARD_REQUIRED
YES
)
endforeach()
15 changes: 13 additions & 2 deletions test/test/interaction_client/Client.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,11 @@ class Client
std::this_thread::sleep_for(std::chrono::milliseconds(2000));
(void) uxr_run_session_time(&session_, 500);

publish_run(id, stream_id_raw, number, message);
}

void publish_run(uint8_t id, uint8_t stream_id_raw, size_t number, const std::string& message)
{
uxrStreamId output_stream_id = uxr_stream_id_from_raw(stream_id_raw, UXR_OUTPUT_STREAM);
uxrObjectId datawriter_id = uxr_object_id(id, UXR_DATAWRITER_ID);

Expand All @@ -297,6 +302,7 @@ class Client
ASSERT_TRUE(written);
ASSERT_FALSE(ub.error);
bool sent = uxr_run_session_until_confirm_delivery(&session_, timeout);
UXR_UNLOCK_STREAM_ID(&session_, output_stream_id);
ASSERT_TRUE(sent);
}
}
Expand Down Expand Up @@ -436,7 +442,7 @@ class Client
}

void ping_agent(
const Transport transport_kind)
const Transport transport_kind, size_t number, uint8_t attempts)
{
uxrCommunication* comm(nullptr);

Expand Down Expand Up @@ -464,7 +470,12 @@ class Client
FAIL() << "Transport type not supported";
break;
}
ASSERT_TRUE(uxr_ping_agent_attempts(comm, 1000, 1));

for(size_t i = 0; i < number; ++i)
{
ASSERT_TRUE(uxr_ping_agent_attempts(comm, 1000, attempts));
std::cout << "Ping sent: " << i << std::endl;
}
}

protected:
Expand Down
47 changes: 47 additions & 0 deletions test/test/multithread/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# 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_host_system_information(RESULT HOSTNAME_SUFFIX QUERY HOSTNAME)

add_executable(client-thread-test ClientAgentInteractionThread.cpp)

add_gtest(client-thread-test
SOURCES
ClientAgentInteractionThread.cpp
ENVIRONMENTS
$<$<PLATFORM_ID:Linux>:LD_LIBRARY_PATH=${CMAKE_PREFIX_PATH}/lib>
$<$<PLATFORM_ID:Windows>:PATH=${CMAKE_PREFIX_PATH}/bin>
)

target_include_directories(client-thread-test
PRIVATE
${PROJECT_BINARY_DIR}/microxrcedds-build/itests
${GTEST_INCLUDE_DIR}
)

target_link_libraries(client-thread-test
PRIVATE
interaction_thread_client
microxrcedds_agent
${GTEST_BOTH_LIBRARIES}
${CMAKE_THREAD_LIBS_INIT}
)

set_target_properties(client-thread-test PROPERTIES
CXX_STANDARD
11
CXX_STANDARD_REQUIRED
YES
)

33 changes: 33 additions & 0 deletions test/test/multithread/ClientAgentInteractionThread.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include <gtest/gtest.h>
#include <thread>

#include <Client.hpp>
#include "../client_agent/ClientAgentInteraction.hpp"

class ClientAgentInteractionThread : public ClientAgentInteraction
{
};

TEST_P(ClientAgentInteractionThread, PingFromClientToAgentThread)
{
const Transport transport_kind(std::get<0>(GetParam()));

std::string message("Hello DDS world!");
std::thread ping_thread(&Client::ping_agent, client_, transport_kind, 10, 1);
std::thread publisher_thread(&Client::publish_run, client_, 1, 1, 10, message);
publisher_thread.join();
ping_thread.join();
}

INSTANTIATE_TEST_CASE_P(
Transports,
ClientAgentInteractionThread,
::testing::Combine(
::testing::Values(Transport::UDP_IPV4_TRANSPORT, Transport::TCP_IPV4_TRANSPORT, Transport::UDP_IPV6_TRANSPORT, Transport::TCP_IPV6_TRANSPORT),
::testing::Values(MiddlewareKind::FASTDDS, MiddlewareKind::FASTRTPS, MiddlewareKind::CED)));

int main(int args, char** argv)
{
::testing::InitGoogleTest(&args, argv);
return RUN_ALL_TESTS();
}
1 change: 1 addition & 0 deletions test/test/publisher_subscriber/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ target_include_directories(publisher-subscriber-interaction-test
${GTEST_INCLUDE_DIR}
)

link_directories(${PROJECT_BINARY_DIR}/test/interaction_client)
target_link_libraries(publisher-subscriber-interaction-test
PRIVATE
interaction_client
Expand Down

0 comments on commit f9396ee

Please sign in to comment.