ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Do rostest test nodes publish to rosout?

asked 2020-04-22 04:53:45 -0500

swaroophs gravatar image

Hello all,

Some background. I am new to writing unit tests in gtests/rostest. So a lot of this might be just me unable to find that awesome link which will clear everything up. Anyway, here it goes:

My node under test: This node is only subscribing to /rosout_agg. Think of this as some sort of diagnostics node.

My test scenario: I want to publish several series of messages to /rosout from my test cases and see how my diagnostics node responds to this. So I was thinking I will just use the log statements such as ROS_INFO, ROS_WARN and ROS_ERROR to publish my test case messages onto /rosout. I am not directly publishing to this topic. Rather just using the log statements.

My rostest file looks like follows:

<?xml version="1.0"?>
    <node pkg="diagnostics" type="diagnostics" name="diagnostics_node"  output="screen"/>
    <test test-name="diagnostics_test_node" pkg="diagnostics" type="diagnostics_test_node"/>
  • When I run this file using rostest, my diagnostics node is not picking up any messages from /rosout_agg. The subscriber callback in my node under test never gets called.
  • Note that, when I run my diagnostics_test_node as just a gtest and my diagnostics node separately, everything is working as expected.

So the question I have is, do the test nodes that rostest starts automatically start a rosout as well (The XML file does not seem to have any mention of rosout)? What happens to the messages created by the log statements in the test node in this case? Should I be directly publishing to /rosout instead of using log statements? Any other ideas on how I should be testing a stream of messages from /rosout_agg?

Please let me know if I can expand on my question!

edit retag flag offensive close merge delete


IIRC the log level of a test is set to warn, so ros info and ros debug messages will not get written to rosout

Link gravatar image Link  ( 2020-04-22 08:58:38 -0500 )edit

Thanks for the comment! Yes info and debug wont be shown unless a test node logger level is set otherwise. But I’m not seeing warns and errors be caught even though I see all my test messages on screen. In other words warn and error are seen on screen but there is no way to check if rosout is picking them.

swaroophs gravatar image swaroophs  ( 2020-04-22 09:03:32 -0500 )edit

2 Answers

Sort by » oldest newest most voted

answered 2020-06-01 12:30:27 -0500

JohnStechschulte gravatar image

updated 2020-06-03 23:04:32 -0500

Update: I found a workaround. Simply launch your own rosout node in your .test file, with a different name, and it works just like roslaunch:

<node name="my_rosout" pkg="rosout" type="rosout" />

This is only a half-answer, which I've figured out while debugging a similar problem.

Yes, test nodes do publish to rosout, however, the rosout node that subscribes to these messages and publishes rosout_agg is not started by rostest.

Running my test via rostest creates a ~/.ros/log/rostest-computer-PID.log file that does say, [roslaunch][INFO] 2020-06-01 10:51:35,758: Added core node of type [rosout/rosout] in namespace [/], but has no other mention of a rosout node. By comparison, when running roslaunch the resulting log in ~/.ros/log/latest/roslaunch-computer-PID.log has this line, but also has a lot more about actually starting the node and publishing rosout_agg.

To verify my theory, I also just had my node subscribe directly to rosout instead of rosout_agg, and it did get messages and work properly.

edit flag offensive delete link more

answered 2020-05-05 03:44:08 -0500

swaroophs gravatar image

updated 2020-05-05 03:44:40 -0500

After further research it DOES look like rostest nodes DO NOT automatically publish to /rosout and hence /rosout_agg. So if you are working with these topics, have your test nodes manually create a publisher to these topics and publish periodically so that your nodes under test can read from that.

P.S: Since I did not get an "official" answer, I'll post this one as an answer until someone else decides to enlighten us!

edit flag offensive delete link more

Question Tools



Asked: 2020-04-22 04:53:45 -0500

Seen: 767 times

Last updated: Jun 03 '20