forked from ros/nodelet_core
-
Notifications
You must be signed in to change notification settings - Fork 0
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
… the test should fail)
- Loading branch information
Showing
5 changed files
with
141 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/********************************************************************* | ||
* Software License Agreement (BSD License) | ||
* | ||
* Copyright (c) 2016, JSK Lab, University of Tokyo. | ||
* 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/o2r other materials provided | ||
* with the distribution. | ||
* * Neither the name of the JSK Lab 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. | ||
*********************************************************************/ | ||
|
||
/* Author: Kentaro Wada <[email protected]> | ||
*/ | ||
|
||
#include <nodelet_topic_tools/nodelet_demux.h> | ||
#include <pluginlib/class_list_macros.h> | ||
#include <std_msgs/String.h> | ||
|
||
typedef nodelet::NodeletDEMUX<std_msgs::String> NodeletDemuxString; | ||
PLUGINLIB_EXPORT_CLASS(NodeletDemuxString, nodelet::Nodelet); |
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 | ||
|
||
import rospy | ||
import threading | ||
import unittest | ||
|
||
from std_msgs.msg import String | ||
|
||
|
||
class TestNodeletDemux(unittest.TestCase): | ||
def __init__(self, *args): | ||
super(TestNodeletDemux, self).__init__(*args) | ||
|
||
self._lock = threading.RLock() | ||
|
||
self._msgs_rec = {} | ||
|
||
self._pub = rospy.Publisher('input', String, queue_size=4) | ||
self.output_topics = rospy.get_param('~output_topics', []) | ||
rospy.loginfo(self.output_topics) | ||
self._sub = {} | ||
for key in self.output_topics: | ||
self._sub[key] = rospy.Subscriber(key, String, self._cb, (key)) | ||
|
||
def _cb(self, msg, key): | ||
with self._lock: | ||
if key not in self._msgs_rec.keys(): | ||
self._msgs_rec[key] = 0 | ||
self._msgs_rec[key] += 1 | ||
|
||
def test_nodelet_demux(self): | ||
self._msgs_rec = {} | ||
num_each_to_receive = 4 | ||
num_to_send = len(self.output_topics) * num_each_to_receive | ||
self.assert_(num_to_send > 0, "No output topics to test with") | ||
|
||
# TODO(lucasw) is this a really brittle test, maybe a few messags will be missed | ||
# and the assert below should be within 10-20% of expected? | ||
rospy.sleep(1.0) | ||
for i in range(num_to_send): | ||
self._pub.publish(String('hello, world')) | ||
rospy.sleep(0.2) | ||
rospy.sleep(1.0) | ||
|
||
rospy.loginfo(self._msgs_rec) | ||
for key in self.output_topics: | ||
self.assert_(key in self._msgs_rec.keys(), "No messages received on " + | ||
key + "\" " + str(num_each_to_receive)) | ||
if key in self._msgs_rec.keys(): | ||
self.assert_(self._msgs_rec[key] == num_each_to_receive, | ||
"Wrong messages received from nodelet demux on topic \"" + | ||
key + "\" " + str(self._msgs_rec[key]) + " != " + str(num_each_to_receive)) | ||
|
||
if __name__ == '__main__': | ||
rospy.init_node('test_nodelet_demux') | ||
|
||
import rostest | ||
rostest.rosrun('test_nodelet_topic_tools', 'test_nodelet_demux', TestNodeletDemux) |
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,28 @@ | ||
<?xml version="1.0"?> | ||
<launch> | ||
|
||
<node pkg="nodelet" name="nodelet_manager" type="nodelet" args="manager"/> | ||
|
||
<param name="verbose_connection" value="true" /> | ||
|
||
<node name="string_nodelet_demux" | ||
pkg="nodelet" type="nodelet" | ||
args="load NodeletDemuxString nodelet_manager" | ||
output="screen"> | ||
<remap from="~input" to="input"/> | ||
<param name="auto_index" value="true" /> | ||
<rosparam> | ||
output_topics: [/input1, /input2] | ||
</rosparam> | ||
</node> | ||
|
||
<test test-name="test_demux" | ||
name="test_demux" | ||
pkg="test_nodelet_topic_tools" type="test_demux.py" | ||
retry="3"> | ||
<rosparam> | ||
output_topics: [/input1, /input2] | ||
</rosparam> | ||
</test> | ||
|
||
</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