Skip to content

Commit

Permalink
Strip replaying methods from McapFileReadTest & McapFileReadWithTypeTest
Browse files Browse the repository at this point in the history
Signed-off-by: tempate <[email protected]>
  • Loading branch information
Tempate committed Jun 11, 2024
1 parent 140efb7 commit aca9425
Show file tree
Hide file tree
Showing 35 changed files with 538 additions and 323 deletions.
2 changes: 1 addition & 1 deletion ddsreplayer/src/cpp/tool/DdsReplayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ namespace replayer {

DdsReplayer::DdsReplayer(
yaml::ReplayerConfiguration& configuration,
std::string& input_file)
const std::string& input_file)
: configuration_(configuration)
{
// Create Payload Pool
Expand Down
2 changes: 1 addition & 1 deletion ddsreplayer/src/cpp/tool/DdsReplayer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class DdsReplayer
*/
DdsReplayer(
yaml::ReplayerConfiguration& configuration,
std::string& input_file);
const std::string& input_file);

/**
* @brief DdsReplayer destructor.
Expand Down
102 changes: 102 additions & 0 deletions ddsreplayer/test/blackbox/FileReadTest.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
// Copyright 2024 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 <chrono>
#include <memory>
#include <string>
#include <thread>

#include <gtest/gtest.h>

#include <fastdds/dds/domain/DomainParticipantListener.hpp>

#include <cpp_utils/testing/gtest_aux.hpp>

#include <ddsrecorder_yaml/recorder/YamlReaderConfiguration.hpp>

#include <tool/DdsReplayer.hpp>

#include "../resources/constants.hpp"
#include "../resources/dds/DataToCheck.hpp"
#include "../resources/dds/HelloWorldDynTypesSubscriber.h"
#include "../resources/dds/HelloWorldSubscriber.h"

using namespace eprosima;


class FileReadTest : public testing::Test
{

protected:

/**
* The order in which objects are created is relevant;
* if the replayer was created before the subscriber,
* a segmentation fault may occur as the dynamic type
* could be received by the subscriber's participant
* before the DDS subscriber is created (which is required
* for creating a DataReader with the received type).
*/
DataToCheck replay_(
const std::string& configuration_path,
const std::string& input_file,
bool publish_types = false,
bool is_ros2_topic = false)
{
DataToCheck data;

// Create Subscriber
std::unique_ptr<fastdds::dds::DomainParticipantListener> subscriber;

const auto topic_name = is_ros2_topic ? test::ROS2_TOPIC_NAME : test::DDS_TOPIC_NAME;

if (publish_types)
{
subscriber = std::make_unique<HelloWorldDynTypesSubscriber>(topic_name, test::DOMAIN, data);
}
else
{
subscriber = std::make_unique<HelloWorldSubscriber>(topic_name, test::DOMAIN, data);
}

// Configuration
ddsrecorder::yaml::ReplayerConfiguration configuration(configuration_path);
configuration.replayer_configuration->domain.domain_id = test::DOMAIN;

// Create replayer instance
auto replayer = std::make_unique<ddsrecorder::replayer::DdsReplayer>(configuration, input_file);

// Give time for replayer and subscriber to match.
// Waiting for the subscriber to match the replayer
// before starting to replay messages does not ensure
// that no samples will be lost (even if using reliable QoS).
// This is because endpoint matching does not occur
// at the same exact moment in both ends of communication,
// so the replayer's writer might have not yet matched the
// subscriber even if the latter already has (matched the writer).
// Transient local QoS would be a solution for this,
// but it is not used as it might pollute frequency arrival
// measurements.
std::this_thread::sleep_for(std::chrono::seconds(1));

// Start replaying data
replayer->process_file();

replayer->stop();

// Replayer waits on destruction a maximum of wait-all-acked-timeout
// ms until all sent msgs are acknowledged
return data;
}
};
70 changes: 49 additions & 21 deletions ddsreplayer/test/blackbox/mcap/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,22 @@ else()
set(DDS_TYPES_VERSION "v2")
endif()

set(TEST_SOURCES
file(
GLOB_RECURSE TEST_SOURCES
McapFileReadTest.cpp
${PROJECT_SOURCE_DIR}/test/blackbox/mcap/dds/types/${DDS_TYPES_VERSION}/hello_world/HelloWorld.cxx
$<$<STREQUAL:${DDS_TYPES_VERSION},v2>:${PROJECT_SOURCE_DIR}/test/blackbox/mcap/dds/types/v2/hello_world/HelloWorldv1.cxx>
${PROJECT_SOURCE_DIR}/test/blackbox/mcap/dds/types/${DDS_TYPES_VERSION}/hello_world/HelloWorldPubSubTypes.cxx
${PROJECT_SOURCE_DIR}/test/blackbox/mcap/dds/HelloWorldSubscriber.cpp
)
${PROJECT_SOURCE_DIR}/test/resources/dds/HelloWorldSubscriber.cpp
${PROJECT_SOURCE_DIR}/test/resources/dds/HelloWorldDynTypesSubscriber.cpp
"${PROJECT_SOURCE_DIR}/test/resources/types/*.c*"
)

list(FILTER TEST_LIBRARY_SOURCES EXCLUDE REGEX "/main.cpp")

# Exclude types' files depending on the Fast DDS version
if ("${fastrtps_VERSION}" VERSION_LESS 2.13)
list(FILTER TEST_SOURCES EXCLUDE REGEX "v2/")
else()
list(FILTER TEST_SOURCES EXCLUDE REGEX "v1/")
endif()

set(TEST_LIST
trivial
Expand All @@ -45,12 +54,12 @@ set(TEST_LIST

set(TEST_NEEDED_SOURCES
resources/helloworld_file.mcap
resources/config_file.yaml
resources/config_file_less_hz.yaml
resources/config_file_more_hz.yaml
resources/config_file_begin_time.yaml
resources/config_file_end_time.yaml
resources/config_file_start_replay_time_earlier.yaml
../../resources/config/config_file.yaml
../../resources/config/config_file_less_hz.yaml
../../resources/config/config_file_more_hz.yaml
../../resources/config/config_file_begin_time.yaml
../../resources/config/config_file_end_time.yaml
../../resources/config/config_file_start_replay_time_earlier.yaml
)

set(TEST_EXTRA_HEADERS
Expand All @@ -70,11 +79,30 @@ add_blackbox_executable(

set(TEST_NAME McapFileReadWithTypeTest)

set(TEST_SOURCES
McapFileReadWithTypeTest.cpp
${PROJECT_SOURCE_DIR}/test/blackbox/mcap/dds/HelloWorldDynTypesSubscriber.cpp
# Determine Fast DDS version
if ("${fastrtps_VERSION}" VERSION_LESS 2.13)
set(DDS_TYPES_VERSION "v1")
else()
set(DDS_TYPES_VERSION "v2")
endif()

file(
GLOB_RECURSE TEST_SOURCES
McapFileReadWithTypeTest.cpp
${PROJECT_SOURCE_DIR}/test/resources/dds/HelloWorldSubscriber.cpp
${PROJECT_SOURCE_DIR}/test/resources/dds/HelloWorldDynTypesSubscriber.cpp
"${PROJECT_SOURCE_DIR}/test/resources/types/*.c*"
)

list(FILTER TEST_LIBRARY_SOURCES EXCLUDE REGEX "/main.cpp")

# Exclude types' files depending on the Fast DDS version
if ("${fastrtps_VERSION}" VERSION_LESS 2.13)
list(FILTER TEST_SOURCES EXCLUDE REGEX "v2/")
else()
list(FILTER TEST_SOURCES EXCLUDE REGEX "v1/")
endif()

set(TEST_LIST
trivial
dds_data_to_check
Expand All @@ -91,12 +119,12 @@ set(TEST_LIST
set(TEST_NEEDED_SOURCES
resources/helloworld_withtype_file.mcap
resources/ros2_file.mcap
resources/config_file.yaml
resources/config_file_less_hz.yaml
resources/config_file_more_hz.yaml
resources/config_file_begin_time_with_types.yaml
resources/config_file_end_time_with_types.yaml
resources/config_file_start_replay_time_earlier_with_types.yaml
../../resources/config/config_file.yaml
../../resources/config/config_file_less_hz.yaml
../../resources/config/config_file_more_hz.yaml
../../resources/config/config_file_begin_time_with_types.yaml
../../resources/config/config_file_end_time_with_types.yaml
../../resources/config/config_file_start_replay_time_earlier_with_types.yaml
)

set(TEST_EXTRA_HEADERS
Expand Down
Loading

0 comments on commit aca9425

Please sign in to comment.