Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 24 additions & 25 deletions tf2/test/simple_tf2_core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,31 +34,22 @@
#include "tf2/exceptions.h"
#include "tf2/time.h"

typedef std::chrono::system_clock::time_point TimePoint;

void seed_rand()
{
//Seed random number generator with current microseond count
srand((unsigned int)std::chrono::system_clock::now().time_since_epoch().count());
};

void generate_rand_vectors(double scale, uint64_t runs, std::vector<double>& xvalues, std::vector<double>& yvalues, std::vector<double>&zvalues)
{
seed_rand();
for ( uint64_t i = 0; i < runs ; i++ )
{
xvalues[i] = 1.0 * ((double) rand() - (double)RAND_MAX /2.0) /(double)RAND_MAX;
yvalues[i] = 1.0 * ((double) rand() - (double)RAND_MAX /2.0) /(double)RAND_MAX;
zvalues[i] = 1.0 * ((double) rand() - (double)RAND_MAX /2.0) /(double)RAND_MAX;
}
}



Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that related to uninitialized messages?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, not directly. It just wasn't used. This is a piece that can go upstream as well.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in that case can you make this in separate commits in the future. This way you can submit the same commit upstream.

TEST(tf2, setTransformFail)
{
tf2::BufferCore tfc;
geometry_msgs::msg::TransformStamped st;
st.header.frame_id = "foo";

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this test was relying on 'bad' values.

Here's the output of an upstream job (http://build.ros.org/job/Ipr__geometry2__ubuntu_trusty_amd64/83/consoleFull search for setTransformFail):

16:02:56 [----------] 3 tests from tf2
16:02:56 [ RUN      ] tf2.setTransformFail
16:02:56 Error:   TF_SELF_TRANSFORM: Ignoring transform from authority "authority1" with frame_id and child_frame_id  "" because they are the same
16:02:56          at line 220 in /tmp/catkin_workspace/src/geometry2/tf2/src/buffer_core.cpp
16:02:56 Error:   TF_NO_CHILD_FRAME_ID: Ignoring transform from authority "authority1" because child_frame_id not set 
16:02:56          at line 226 in /tmp/catkin_workspace/src/geometry2/tf2/src/buffer_core.cpp
16:02:56 Error:   TF_NO_FRAME_ID: Ignoring transform with child_frame_id ""  from authority "authority1" because frame_id not set
16:02:56          at line 232 in /tmp/catkin_workspace/src/geometry2/tf2/src/buffer_core.cpp
16:02:56 Error:   TF_DENORMALIZED_QUATERNION: Ignoring transform for child_frame_id "" from authority "authority1" because of an invalid quaternion in the transform (0.000000 0.000000 0.000000 0.000000)
16:02:56          at line 256 in /tmp/catkin_workspace/src/geometry2/tf2/src/buffer_core.cpp

But the output of the CI for this job:

16:26:36 3: [ RUN      ] tf2.setTransformFail
16:26:36 3: Error:   TF_SELF_TRANSFORM: Ignoring transform from authority "authority1" with frame_id and child_frame_id  "foo" because they are the same
16:26:36 3:          at line 235 in /Users/osrf/jenkins/workspace/ci_osx/ws/src/ros2/geometry2/tf2/src/buffer_core.cpp
16:26:36 3: [       OK ] tf2.setTransformFail (0 ms)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, will fix.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, I'll use the 'request changes' button from now on so comments don't get buried accidentally

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#19

st.header.stamp = builtin_interfaces::msg::Time();
st.header.stamp.sec = 1;
st.header.stamp.nanosec = 1;
st.child_frame_id = "foo";
st.transform.translation.x = 0;
st.transform.translation.y = 0;
st.transform.translation.z = 0;
st.transform.rotation.x = 0;
st.transform.rotation.y = 0;
st.transform.rotation.z = 0;
st.transform.rotation.w = 1;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you provide an example / test showing that they're not initialized? If they're not initialized it should be fixed in the message generation and not in the test of a leaf package.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, we should probably have a conversation about this. This is the second time I've had to do something like this in a test (I can't remember where the other one was, but I can dig it up). What's going on here is that a declaration like:

geometry_msgs::msg::TransformStamped foo;

has a constructor that looks like this:

TransformStamped_()
{
}
explicit TransformStamped_(const ContainerAllocator & _alloc)
// INDENT-OFF (prevent uncrustify from making unnecessary indents here)
// INDENT-ON
{
(void)_alloc;
}

(from transform_stamped__struct.hpp). As far as I understand, what that means is that that constructor doesn't initialize any member variables. Thus, when you use the object later on, everything is uninitialized. When you run this under valgrind, it throws a slew of errors saying you are making decisions using uninitialized variables, etc.

I think you are right, by the way; for the long-term maintenance of this stuff, we should probably do a real constructor for these messages by changing the message generation.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So let's see. I'm discussing this with @dirk-thomas on ros2/rosidl#77 . If we decide to do a default initialization of all fields, then that will take time to implement. If we decide not to do it, then we have to fill in all of the fields. Thus, my feeling is that for the short-term, we should take this code (after review, of course), no matter which way we decide to go. Thoughts?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 sounds good to me

EXPECT_FALSE(tfc.setTransform(st, "authority1"));

}
Expand Down Expand Up @@ -89,7 +80,15 @@ TEST(tf2, setTransformInvalidQuaternion)
geometry_msgs::msg::TransformStamped st;
st.header.frame_id = "foo";
st.header.stamp = builtin_interfaces::msg::Time();
st.header.stamp.sec = 1;
st.header.stamp.nanosec = 1;
st.child_frame_id = "child";
st.transform.translation.x = 0;
st.transform.translation.y = 0;
st.transform.translation.z = 0;
st.transform.rotation.x = 0;
st.transform.rotation.y = 0;
st.transform.rotation.z = 0;
st.transform.rotation.w = 0;
EXPECT_FALSE(tfc.setTransform(st, "authority1"));

Expand All @@ -98,14 +97,14 @@ TEST(tf2, setTransformInvalidQuaternion)
TEST(tf2_lookupTransform, LookupException_Nothing_Exists)
{
tf2::BufferCore tfc;
EXPECT_THROW(tfc.lookupTransform("a", "b", TimePoint(std::chrono::seconds(1))), tf2::LookupException);
EXPECT_THROW(tfc.lookupTransform("a", "b", tf2::TimePoint(std::chrono::seconds(1))), tf2::LookupException);

}

TEST(tf2_canTransform, Nothing_Exists)
{
tf2::BufferCore tfc;
EXPECT_FALSE(tfc.canTransform("a", "b", TimePoint(std::chrono::seconds(1))));
EXPECT_FALSE(tfc.canTransform("a", "b", tf2::TimePoint(std::chrono::seconds(1))));

}

Expand All @@ -126,7 +125,7 @@ TEST(tf2_lookupTransform, LookupException_One_Exists)
st.transform.rotation.z = 0;
st.transform.rotation.w = 1;
EXPECT_TRUE(tfc.setTransform(st, "authority1"));
EXPECT_THROW(tfc.lookupTransform("foo", "bar", TimePoint(std::chrono::seconds(1))), tf2::LookupException);
EXPECT_THROW(tfc.lookupTransform("foo", "bar", tf2::TimePoint(std::chrono::seconds(1))), tf2::LookupException);

}

Expand All @@ -147,7 +146,7 @@ TEST(tf2_canTransform, One_Exists)
st.transform.rotation.z = 0;
st.transform.rotation.w = 1;
EXPECT_TRUE(tfc.setTransform(st, "authority1"));
EXPECT_FALSE(tfc.canTransform("foo", "bar", TimePoint(std::chrono::seconds(1))));
EXPECT_FALSE(tfc.canTransform("foo", "bar", tf2::TimePoint(std::chrono::seconds(1))));
}

TEST(tf2_time, Display_Time_Point)
Expand Down