-
Notifications
You must be signed in to change notification settings - Fork 913
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Add failing tests for topic statistics frequency for rospy and roscpp * Fix TopicStatistics dynamic windowing to adjust evaluation frequency in the right direction * test_roscpp: fixed topic_statistic_frequency * test_roscpp/topic_statistic_frequency: cleanup
- Loading branch information
1 parent
ab67be5
commit 8d9af41
Showing
12 changed files
with
367 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
test/test_roscpp/test/launch/topic_statistic_frequency.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<!-- basic smoke test for TopicStatistics --> | ||
<launch> | ||
<param name="/enable_statistics" value="true" /> | ||
<!-- default 10 would take 5s to warm up for very slow talker --> | ||
<param name="/statistics_window_min_elements" value="4" /> | ||
|
||
<!-- under 1Hz important, since checking window starts there --> | ||
<node name="very_slow_talker" pkg="test_roscpp" type="test_roscpp-publisher_rate" required="true" args="0.8"> | ||
<remap from="data" to="very_slow_chatter" /> | ||
</node> | ||
<node name="very_slow_listener" pkg="test_roscpp" type="test_roscpp-subscriber" required="true"> | ||
<remap from="data" to="very_slow_chatter" /> | ||
</node> | ||
|
||
<!-- publishing within fairly normal range of frequencies --> | ||
<node name="slow_talker" pkg="test_roscpp" type="test_roscpp-publisher_rate" required="true" args="18"> | ||
<remap from="data" to="slow_chatter" /> | ||
</node> | ||
<node name="slow_listener" pkg="test_roscpp" type="test_roscpp-subscriber" required="true"> | ||
<remap from="data" to="slow_chatter" /> | ||
</node> | ||
|
||
<node name="fast_talker" pkg="test_roscpp" type="test_roscpp-publisher_rate" required="true" args="53"> | ||
<remap from="data" to="fast_chatter" /> | ||
</node> | ||
<node name="fast_listener" pkg="test_roscpp" type="test_roscpp-subscriber" required="true"> | ||
<remap from="data" to="fast_chatter" /> | ||
</node> | ||
|
||
<!-- fast outlier (for most ros systems) --> | ||
<node name="very_fast_talker" pkg="test_roscpp" type="test_roscpp-publisher_rate" required="true" args="171"> | ||
<remap from="data" to="/very_fast_chatter" /> | ||
</node> | ||
<node name="very_fast_listener" pkg="test_roscpp" type="test_roscpp-subscriber" required="true"> | ||
<remap from="data" to="/very_fast_chatter" /> | ||
</node> | ||
|
||
<test test-name="roscpp_topic_statistics" pkg="test_roscpp" type="test_roscpp-topic_statistic_frequency" /> | ||
</launch> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Publish big data chunks | ||
// Author: Max Schwarz <[email protected]> | ||
|
||
#include <ros/publisher.h> | ||
#include <ros/init.h> | ||
#include <ros/node_handle.h> | ||
|
||
#include <std_msgs/Int8MultiArray.h> | ||
|
||
int main(int argc, char** argv) | ||
{ | ||
ros::init(argc, argv, "publisher"); | ||
ros::NodeHandle n; | ||
|
||
const size_t NUM_BYTES = 8; | ||
std_msgs::Int8MultiArray data; | ||
data.data.reserve(NUM_BYTES); | ||
|
||
assert(argc > 1); | ||
float frequency = atof(argv[1]); | ||
|
||
ros::Publisher pub = n.advertise<std_msgs::Int8MultiArray>("data", 1); | ||
ros::Rate rate(frequency); | ||
|
||
size_t start = 0; | ||
while(ros::ok()) | ||
{ | ||
data.data.clear(); | ||
for(size_t i = 0; i < NUM_BYTES; ++i) | ||
{ | ||
data.data.push_back(start + i); | ||
} | ||
pub.publish(data); | ||
rate.sleep(); | ||
start++; | ||
} | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
#include <map> | ||
#include <string> | ||
|
||
#include <ros/ros.h> | ||
#include <gtest/gtest.h> | ||
#include <rosgraph_msgs/TopicStatistics.h> | ||
#include <boost/thread.hpp> | ||
#include <std_msgs/Int8MultiArray.h> | ||
|
||
class Aggregator { | ||
public: | ||
std::map<std::string, ros::Duration> topic_period_mean_map_; | ||
|
||
void cb(const rosgraph_msgs::TopicStatistics& msg) { | ||
topic_period_mean_map_[msg.topic] = msg.period_mean; | ||
} | ||
|
||
bool frequencyAcceptable(const std::string& topic, float expected) { | ||
float errorMargin = 0.1; | ||
float foundFreq = 1.f / topic_period_mean_map_[topic].toSec(); | ||
return std::fabs(foundFreq - expected) / expected <= errorMargin; | ||
} | ||
}; | ||
|
||
void assertEventuallyHasTopic(const Aggregator& agg, const std::string& topic) { | ||
ros::Duration timeout(5.0); | ||
auto start = ros::Time::now(); | ||
while (ros::Time::now() - start < timeout && !agg.topic_period_mean_map_.count(topic)) { | ||
ros::Duration(0.5).sleep(); | ||
} | ||
ASSERT_EQ(agg.topic_period_mean_map_.count(topic), 1u); | ||
} | ||
|
||
TEST(TopicStatisticFrequency, statisticFrequency) | ||
{ | ||
ros::NodeHandle nh; | ||
Aggregator agg; | ||
ros::Subscriber stat_sub = nh.subscribe("/statistics", 1, &Aggregator::cb, &agg); | ||
|
||
ros::AsyncSpinner spinner(4); | ||
spinner.start(); | ||
|
||
ros::Duration(5.0).sleep(); | ||
|
||
assertEventuallyHasTopic(agg, "/very_fast_chatter"); | ||
assertEventuallyHasTopic(agg, "/fast_chatter"); | ||
assertEventuallyHasTopic(agg, "/slow_chatter"); | ||
assertEventuallyHasTopic(agg, "/very_slow_chatter"); | ||
|
||
ros::shutdown(); | ||
|
||
ASSERT_TRUE(agg.frequencyAcceptable("/very_fast_chatter", 171)); | ||
ASSERT_TRUE(agg.frequencyAcceptable("/fast_chatter", 53)); | ||
ASSERT_TRUE(agg.frequencyAcceptable("/slow_chatter", 18)); | ||
ASSERT_TRUE(agg.frequencyAcceptable("/very_slow_chatter", 0.8)); | ||
} | ||
|
||
|
||
int main(int argc, char** argv) | ||
{ | ||
testing::InitGoogleTest(&argc, argv); | ||
ros::init(argc, argv, "topic_statistic_frequency"); | ||
ros::NodeHandle nh; | ||
return RUN_ALL_TESTS(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#!/usr/bin/env python | ||
# Software License Agreement (BSD License) | ||
# | ||
# Copyright (c) 2008, Willow Garage, Inc. | ||
# All rights reserved. | ||
# | ||
# Redistribution and use in source and binary forms, with or without | ||
# modification, are permitted provided that the following conditions | ||
# are met: | ||
# | ||
# * Redistributions of source code must retain the above copyright | ||
# notice, this list of conditions and the following disclaimer. | ||
# * Redistributions in binary form must reproduce the above | ||
# copyright notice, this list of conditions and the following | ||
# disclaimer in the documentation and/or other materials provided | ||
# with the distribution. | ||
# * Neither the name of Willow Garage, Inc. nor the names of its | ||
# contributors may be used to endorse or promote products derived | ||
# from this software without specific prior written permission. | ||
# | ||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | ||
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | ||
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | ||
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN | ||
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
# POSSIBILITY OF SUCH DAMAGE. | ||
|
||
''' | ||
Copy of talker demo for stats testing purposes. Publishes String to 'chatter' | ||
''' | ||
|
||
import rospy | ||
from std_msgs.msg import String | ||
|
||
NAME = 'talker' | ||
|
||
|
||
def talker(): | ||
pub = rospy.Publisher("chatter", String, queue_size=1) | ||
rospy.init_node(NAME, anonymous=True) | ||
freq = rospy.get_param("~frequency", 10) | ||
rate = rospy.Rate(freq) | ||
|
||
count = 0 | ||
while not rospy.is_shutdown(): | ||
pub.publish(String("hello world {}".format(count))) | ||
count += 1 | ||
rate.sleep() | ||
|
||
|
||
if __name__ == '__main__': | ||
talker() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<!-- basic smoke test for TopicStatistics --> | ||
<launch> | ||
<param name="/enable_statistics" value="true" /> | ||
<!-- default 10 would take 5s to warm up for very slow talker --> | ||
<param name="/statistics_window_min_elements" value="5" /> | ||
|
||
<!-- under 1Hz important, since checking window starts there --> | ||
<node name="very_slow_talker" pkg="test_rospy" type="freq_talker" required="true"> | ||
<param name="frequency" value="0.5" /> | ||
<remap from="chatter" to="very_slow_chatter" /> | ||
</node> | ||
<node name="very_slow_listener" pkg="test_rospy" type="listener.py" required="true"> | ||
<remap from="chatter" to="very_slow_chatter" /> | ||
</node> | ||
<!-- publishing within fairly normal range of frequencies --> | ||
<node name="slow_talker" pkg="test_rospy" type="freq_talker" required="true"> | ||
<param name="frequency" value="8" /> | ||
<remap from="chatter" to="slow_chatter" /> | ||
</node> | ||
<node name="slow_listener" pkg="test_rospy" type="listener.py" required="true"> | ||
<remap from="chatter" to="slow_chatter" /> | ||
</node> | ||
|
||
<node name="fast_talker" pkg="test_rospy" type="freq_talker" required="true"> | ||
<param name="frequency" value="53" /> | ||
<remap from="chatter" to="fast_chatter" /> | ||
</node> | ||
<node name="fast_listener" pkg="test_rospy" type="listener.py" required="true"> | ||
<remap from="chatter" to="fast_chatter" /> | ||
</node> | ||
|
||
<!-- fast outlier (for most ros systems) --> | ||
<node name="very_fast_talker" pkg="test_rospy" type="freq_talker" required="true"> | ||
<param name="frequency" value="150" /> | ||
<remap from="chatter" to="very_fast_chatter" /> | ||
</node> | ||
<node name="very_fast_listener" pkg="test_rospy" type="listener.py" required="true"> | ||
<remap from="chatter" to="very_fast_chatter" /> | ||
</node> | ||
|
||
<test test-name="rospy_topic_statistics" pkg="test_rospy" type="test_topic_statistics.py" /> | ||
</launch> |
Oops, something went wrong.