Skip to content
This repository has been archived by the owner on Jun 10, 2021. It is now read-only.

Commit

Permalink
Add SubscriberTopicStatisticsNode and tests (#112)
Browse files Browse the repository at this point in the history
* Add subscriber_topic_statistics class and tests

Signed-off-by: Prajakta Gokhale <prajaktg@amazon.com>

* Rebase on changes in interfaces, address feedback

Signed-off-by: Prajakta Gokhale <prajaktg@amazon.com>

* Fix unit test and try to increase coverage

Signed-off-by: Prajakta Gokhale <prajaktg@amazon.com>

* Address review feedback

Signed-off-by: Prajakta Gokhale <prajaktg@amazon.com>

* Fix incorrect handling of publish timer and review comments

Signed-off-by: Prajakta Gokhale <prajaktg@amazon.com>

* Resolve conflicts

Signed-off-by: Prajakta Gokhale <prajaktg@amazon.com>

* New utility header and more review comments

Signed-off-by: Prajakta Gokhale <prajaktg@amazon.com>
  • Loading branch information
Prajakta Gokhale committed Apr 1, 2020
1 parent 22f8de5 commit aae3cb5
Show file tree
Hide file tree
Showing 6 changed files with 818 additions and 0 deletions.
Expand Up @@ -27,6 +27,9 @@ namespace topic_statistics_constants
constexpr const char kMsgAgeStatName[] = "message_age";
constexpr const char kMsgPeriodStatName[] = "message_period";
constexpr const char kMillisecondUnitName[] = "ms";

constexpr const char kCollectStatsTopicNameParam[] = "collect_topic_name";
constexpr const char kPublishStatsTopicNameParam[] = "publish_topic_name";
} // namespace topic_statistics_constants

} // namespace topic_statistics_collector
Expand Down
5 changes: 5 additions & 0 deletions system_metrics_collector/CMakeLists.txt
Expand Up @@ -127,6 +127,11 @@ if(BUILD_TESTING)
test/system_metrics_collector/test_utilities.cpp)
target_link_libraries(test_utilities system_metrics_collector)
ament_target_dependencies(test_utilities rclcpp)

ament_add_gtest(test_subscriber_topic_statistics
test/topic_statistics_collector/test_subscriber_topic_statistics.cpp)
target_link_libraries(test_subscriber_topic_statistics system_metrics_collector)
ament_target_dependencies(test_subscriber_topic_statistics rcl rclcpp sensor_msgs)
endif()

# Install launch files
Expand Down
1 change: 1 addition & 0 deletions system_metrics_collector/package.xml
Expand Up @@ -27,6 +27,7 @@
<test_depend>ament_lint_common</test_depend>
<test_depend>class_loader</test_depend>
<test_depend>lifecycle_msgs</test_depend>
<test_depend>sensor_msgs</test_depend>

<!--Required for e2e test file-->
<test_depend>python3-retrying</test_depend>
Expand Down
@@ -0,0 +1,90 @@
// Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
//
// 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.

#ifndef TOPIC_STATISTICS_COLLECTOR__PARAMETER_UTILS_HPP_
#define TOPIC_STATISTICS_COLLECTOR__PARAMETER_UTILS_HPP_

#include <limits>
#include <string>

#include "rcpputils/asserts.hpp"

namespace topic_statistics_collector
{
/**
* Build a positive integer range to use in parameter descriptors.
*
* @return a positive integer range with specififies start, end and step values
*/
static rcl_interfaces::msg::IntegerRange BuildIntegerRange(
int64_t from,
int64_t to,
uint64_t step)
{
rcl_interfaces::msg::IntegerRange range;
range.from_value = from;
range.to_value = to;
range.step = step;

return range;
}

/**
* Build a parameter description for period node parameters.
*
* @return a read-only integer range topic descriptor
*/
static rcl_interfaces::msg::ParameterDescriptor BuildPeriodParameterDescriptor(
const std::string & description)
{
const auto range = BuildIntegerRange(
1,
std::numeric_limits<decltype(rcl_interfaces::msg::IntegerRange::to_value)>::max(),
1
);

rcl_interfaces::msg::ParameterDescriptor period_descriptor;
period_descriptor.read_only = true;
period_descriptor.integer_range.push_back(range);
period_descriptor.description = description;

return period_descriptor;
}

/**
* Build a parameter description for string node parameters.
*
* @return a read-only topic descriptor
*/
static rcl_interfaces::msg::ParameterDescriptor BuildTopicParameterDescriptor(
const std::string & description)
{
rcl_interfaces::msg::ParameterDescriptor topic_descriptor;
topic_descriptor.description = description;
topic_descriptor.read_only = true;

return topic_descriptor;
}

/**
* Validate the values assigned to string node parameters.
*
* @throws std::invalid_argument if the parameter value is empty
*/
static void ValidateStringParam(const std::string & name, const std::string & value)
{
rcpputils::require_true(!value.empty(), name + " node parameter cannot be empty");
}
} // namespace topic_statistics_collector
#endif // TOPIC_STATISTICS_COLLECTOR__PARAMETER_UTILS_HPP_

0 comments on commit aae3cb5

Please sign in to comment.