Why are my rostests giving me a std::bad_alloc error?
I'm porting my ROS code from Indigo on Ubuntu 14.04 to using the newer ROS Kinetic on Ubuntu 16.04. What I've noticed is that, in one particular test, I will occasionally get a std::bad_alloc
exception thrown:
C++ exception with description "std::bad_alloc" thrown in the test fixture's constructor
Behaviour
Error only occurs when there are more than one
TEST_F()
functions.Console output stops displaying after first
TEST_F()
is run.
Code
class TransitionClientTest : public ::testing::Test
{
public:
void SetUp()
{
query_client_.Initialize(node_handle_);
}
private:
ros::NodeHandle node_handle_
QueryClientType query_client_;
};
TEST_F(TransitionClientTest, TestQuery)
{
ROS_INFO("TestQuery running");
EXPECT_EQ(query_client_.Query(), 1);
}
TEST_F(TransitionClientTest, TestPort)
{
ROS_INFO("TestPort running"); // Won't get displayed
EXPECT_EQ(query_client_.Port(), 99);
}
int main(int argc, char** argv)
{
ros::init(argc, argv, "TransitionClientTest");
testing::InitGoogleTest(&argc, argv);
int result = RUN_ALL_TESTS();
return result;
}
The TestPort test will often cause a std::bad_alloc
error. If it doesn't, then it will not display the ROS_INFO
statement.
The test is defined in my CMakeLists in a add_rostest_gtest()
call.