forked from ros-simulation/gazebo_ros_pkgs
-
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.
ros-simulation#408 Making very simple tests to show that running two …
…gazebo tests in sequence doesn't work.
- Loading branch information
Showing
4 changed files
with
89 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?xml version="1.0"?> | ||
<launch> | ||
<param name="/use_sim_time" value="true" /> | ||
|
||
<node name="gazebo" pkg="gazebo_ros" type="gzserver" | ||
respawn="false" output="screen" | ||
args="-r $(find gazebo_plugins)/test/camera/empty.world" /> | ||
|
||
<test test-name="gazebo_ros" pkg="gazebo_ros" type="gazebo_ros-test" | ||
clear_params="true" time-limit="30.0" /> | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?xml version="1.0"?> | ||
<launch> | ||
<param name="/use_sim_time" value="true" /> | ||
|
||
<node name="gazebo" pkg="gazebo_ros" type="gzserver" | ||
respawn="false" output="screen" | ||
args="-r $(find gazebo_plugins)/test/camera/empty.world" /> | ||
|
||
<test test-name="gazebo_ros2" pkg="gazebo_ros" type="gazebo_ros-test" | ||
clear_params="true" time-limit="30.0" /> | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#include <gazebo_msgs/ModelStates.h> | ||
#include <gtest/gtest.h> | ||
#include <ros/ros.h> | ||
#include <rosgraph_msgs/Clock.h> | ||
|
||
class GazeboRosTest : public testing::Test | ||
{ | ||
protected: | ||
virtual void SetUp() | ||
{ | ||
has_new_stamp_ = false; | ||
} | ||
|
||
ros::NodeHandle nh_; | ||
ros::Subscriber model_states_sub_; | ||
bool has_new_stamp_; | ||
ros::Time stamp_; | ||
public: | ||
void clockCallback(const rosgraph_msgs::ClockConstPtr& msg) | ||
{ | ||
stamp_ = msg->clock; | ||
has_new_stamp_ = true; | ||
} | ||
}; | ||
|
||
// Test if the camera image is published at all, and that the timestamp | ||
// is not too long in the past. | ||
TEST_F(GazeboRosTest, cameraSubscribeTest) | ||
{ | ||
model_states_sub_ = nh_.subscribe("clock", 1, | ||
&GazeboRosTest::clockCallback, | ||
dynamic_cast<GazeboRosTest*>(this)); | ||
|
||
while (!has_new_stamp_) | ||
{ | ||
ros::spinOnce(); | ||
ros::Duration(0.1).sleep(); | ||
} | ||
|
||
// This check depends on the update period being much longer | ||
// than the expected difference between now and the received image time | ||
// TODO(lucasw) | ||
// this likely isn't that robust - what if the testing system is really slow? | ||
double time_diff = (ros::Time::now() - stamp_).toSec(); | ||
ROS_INFO_STREAM(time_diff); | ||
EXPECT_LT(time_diff, 0.5); | ||
model_states_sub_.shutdown(); | ||
} | ||
|
||
int main(int argc, char** argv) | ||
{ | ||
ros::init(argc, argv, "gazebo_ros_test"); | ||
testing::InitGoogleTest(&argc, argv); | ||
return RUN_ALL_TESTS(); | ||
} |