Skip to content

Commit

Permalink
Drafting record param test
Browse files Browse the repository at this point in the history
  • Loading branch information
roncapat committed Nov 12, 2023
1 parent 358016d commit 47b6b29
Show file tree
Hide file tree
Showing 7 changed files with 128 additions and 2 deletions.
6 changes: 6 additions & 0 deletions rosbag2_transport/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,12 @@ function(create_tests_for_rmw_implementation)
LINK_LIBS rosbag2_transport
AMENT_DEPS test_msgs rosbag2_test_common)

rosbag2_transport_add_gmock(test_record_params
test/rosbag2_transport/test_record_params.cpp
LINK_LIBS rosbag2_transport
AMENT_DEPS test_msgs rosbag2_test_common
${SKIP_TEST})

rosbag2_transport_add_gmock(test_record_all_ignore_leaf_topics
test/rosbag2_transport/test_record_all_ignore_leaf_topics.cpp
LINK_LIBS rosbag2_transport
Expand Down
31 changes: 31 additions & 0 deletions rosbag2_transport/test/resources/params_recorder.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
recorder_params_node:
ros__parameters:
all: true
is_discovery_disabled: true
topics: {"topic", "other_topic"}
rmw_serialization_format: "cdr"
topic_polling_interval:
sec: 0
nsec: 10000000
regex: "[xyz]/topic"
exclude: "*"
node_prefix: "prefix"
compression_mode: "stream"
compression_format: "h264"
compression_queue_size: 10
compression_threads: 2
qos_profile_overrides_path: ""
include_hidden_topics: true
include_unpublished_topics: true
ignore_leaf_topics: false
start_paused: false
use_sim_time: false

storage_id: sqlite3
config_uri: ""
max_bagfile_size: 12345
max_bagfile_duration: 54321
max_cache_size: 9898
preset_profile: "none"
snapshot_mode: false
custom_data: ["test=true"]
16 changes: 16 additions & 0 deletions rosbag2_transport/test/rosbag2_transport/mock_recorder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ class MockRecorder : public rosbag2_transport::Recorder
: Recorder(writer, storage_options, record_options)
{}

explicit MockRecorder(
const std::string & node_name = "rosbag2_mock_composable_recorder",
const rclcpp::NodeOptions & node_options = rclcpp::NodeOptions())
: Recorder(node_name, node_options)
{}

template<typename DurationRepT = int64_t, typename DurationT = std::milli>
bool wait_for_topic_to_be_discovered(
const std::string & topic_name_to_wait_for,
Expand Down Expand Up @@ -65,6 +71,16 @@ class MockRecorder : public rosbag2_transport::Recorder
}
return available_for_recording;
}

rosbag2_storage::StorageOptions retrieve_storage_options()
{
return get_storage_options();
}

rosbag2_transport::RecordOptions retrieve_record_options()
{
return get_record_options();
}
};

#endif // ROSBAG2_TRANSPORT__MOCK_RECORDER_HPP_
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ TEST_F(RosBag2PlayTestFixture, parse_parameter_from_file) {
opts.arguments(
{
"--ros-args",
"--params-file", _SRC_RESOURCES_DIR_PATH "/params.yaml"
"--params-file", _SRC_RESOURCES_DIR_PATH "/params_player.yaml"
});
opts.append_parameter_override(
"qos_profile_overrides_path",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,5 @@ TEST(record_options, test_yaml_serialization)
CHECK(is_discovery_disabled);
CHECK(topics);
CHECK(rmw_serialization_format);
#undef CMP
#undef CHECK
}
73 changes: 73 additions & 0 deletions rosbag2_transport/test/rosbag2_transport/test_record_params.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// Copyright 2023, Patrick Roncagliolo.
//
// 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 <gmock/gmock.h>

#include <chrono>
#include <future>
#include <memory>
#include <string>
#include <thread>
#include <vector>
#include <utility>

#include "rclcpp/rclcpp.hpp"
#include "mock_recorder.hpp"
#include "rosbag2_transport_test_fixture.hpp"
#include "rosbag2_storage/storage_options.hpp"
#include "rosbag2_transport/record_options.hpp"

TEST_F(Rosbag2TransportTestFixture, parse_parameter_from_file) {
// _SRC_RESOURCES_DIR_PATH defined in CMakeLists.txt
rclcpp::NodeOptions opts;
opts.arguments(
{
"--ros-args",
"--params-file", _SRC_RESOURCES_DIR_PATH "/params_recorder.yaml"
});
opts.append_parameter_override(
"qos_profile_overrides_path",
_SRC_RESOURCES_DIR_PATH "/overrides.yaml");
opts.append_parameter_override(
"uri",
_SRC_RESOURCES_DIR_PATH "/sqlite3/test_bag_for_seek");

auto node = std::make_shared<MockRecorder>("recorder_params_node", opts);
auto record_options = node->retrieve_record_options();
auto storage_options = node->retrieve_storage_options();
YAML::Node yaml_record_opt = YAML::convert<rosbag2_transport::RecordOptions>().encode(record_options);
YAML::Node yaml_storage_opt = YAML::convert<rosbag2_storage::StorageOptions>().encode(
storage_options);

auto param_node = YAML::LoadFile(_SRC_RESOURCES_DIR_PATH "/params.yaml");

YAML::Emitter emitter;
emitter
<< YAML::Newline << YAML::Comment("params.yaml")
<< param_node << YAML::Newline
<< YAML::Newline << YAML::Comment("node record parameters")
<< yaml_record_opt << YAML::Newline
<< YAML::Newline << YAML::Comment("node storage parameters")
<< yaml_storage_opt << YAML::Newline;

std::cout << emitter.c_str() << std::endl;

// TODO(roncapat): compare YAML trees (from file vs from struct)
}

/*
TEST_F(RosBag2PlayTestFixture, test_negative_durations) {
// TODO(roncapat): implement
}
*/

0 comments on commit 47b6b29

Please sign in to comment.