Writing Gazebo/ROS unit tests
Hello,
I've been trying to use the Gazebo ServerFixture to set up very basic unit tests for a ROS enabled Gazebo plugin. I'm using the velodyne lidar tutorial as a simple example that I know will compile and work as expected to help me understand the process of setting up the testing environment. I'm using ROS Kinetic on Ubuntu 16.04 with gazebo 7.14.0. I also have Gtest 1.7.0 installed from the Debian package.
I'd like to be able to use the catkinaddgtest macro in my CMakeList to add tests and then be able to build and run them with catkin runtests, but I don't know if this is possible. I have the plugin set up in a catkin package and it properly build and run. But when I run catkin runtests, there seems to be an issue linking with Gazebo. The output from the terminal is below:
[100%] Linking CXX executable /home/robert/gazebo_sandbox_ws/devel/.private/velodyne_hld32_plugin/lib/velodyne_hld32_plugin/velodyne_hld32_plugin-test
/usr/bin/cmake -E cmake_link_script CMakeFiles/velodyne_hld32_plugin-test.dir/link.txt --verbose=1
/usr/bin/c++ -std=c++11 CMakeFiles/velodyne_hld32_plugin-test.dir/test/test_velodyne_hld32_plugin.cpp.o -o /home/robert/gazebo_sandbox_ws/devel/.private/velodyne_hld32_plugin/lib/velodyne_hld32_plugin/velodyne_hld32_plugin-test -L/usr/lib/x86_64-linux-gnu/gazebo-7/plugins -L/home/robert/gazebo_sandbox_ws/build/velodyne_hld32_plugin/gtest -rdynamic gtest/gtest/libgtest.so /home/robert/gazebo_sandbox_ws/devel/.private/velodyne_hld32_plugin/lib/libvelodyne_hld32_plugin.so -lpthread /opt/ros/kinetic/lib/libgazebo_ros_api_plugin.so /opt/ros/kinetic/lib/libgazebo_ros_paths_plugin.so /opt/ros/kinetic/lib/libroslib.so /opt/ros/kinetic/lib/librospack.so -lpython2.7 -lboost_program_options -ltinyxml /opt/ros/kinetic/lib/libtf.so /opt/ros/kinetic/lib/libtf2_ros.so /opt/ros/kinetic/lib/libactionlib.so /opt/ros/kinetic/lib/libmessage_filters.so /opt/ros/kinetic/lib/libtf2.so /opt/ros/kinetic/lib/libdynamic_reconfigure_config_init_mutex.so /opt/ros/kinetic/lib/libroscpp.so -lboost_filesystem -lboost_signals /opt/ros/kinetic/lib/librosconsole.so /opt/ros/kinetic/lib/librosconsole_log4cxx.so /opt/ros/kinetic/lib/librosconsole_backend_interface.so -llog4cxx -lboost_regex /opt/ros/kinetic/lib/libxmlrpcpp.so /opt/ros/kinetic/lib/libroscpp_serialization.so /opt/ros/kinetic/lib/librostime.so /opt/ros/kinetic/lib/libcpp_common.so -lboost_system -lboost_thread -lboost_chrono -lboost_date_time -lboost_atomic -lpthread -lconsole_bridge -Wl,-rpath,/usr/lib/x86_64-linux-gnu/gazebo-7/plugins:/home/robert/gazebo_sandbox_ws/build/velodyne_hld32_plugin/gtest:/home/robert/gazebo_sandbox_ws/build/velodyne_hld32_plugin/gtest/gtest:/home/robert/gazebo_sandbox_ws/devel/.private/velodyne_hld32_plugin/lib:/opt/ros/kinetic/lib
CMakeFiles/velodyne_hld32_plugin-test.dir/test/test_velodyne_hld32_plugin.cpp.o: In function `VelodyneHLD32PluginTest_TestLoadingWorld_Test::TestBody()':
test_velodyne_hld32_plugin.cpp:(.text+0xaf): undefined reference to `gazebo::physics::get_world(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
CMakeFiles/velodyne_hld32_plugin-test.dir/test/test_velodyne_hld32_plugin.cpp.o: In function `VelodyneHLD32PluginTest::VelodyneHLD32PluginTest()':
test_velodyne_hld32_plugin.cpp:(.text._ZN23VelodyneHLD32PluginTestC2Ev[_ZN23VelodyneHLD32PluginTestC5Ev]+0x14): undefined reference to `gazebo::ServerFixture::ServerFixture()'
CMakeFiles/velodyne_hld32_plugin-test.dir/test/test_velodyne_hld32_plugin.cpp.o: In function `VelodyneHLD32PluginTest::~VelodyneHLD32PluginTest()':
test_velodyne_hld32_plugin.cpp:(.text._ZN23VelodyneHLD32PluginTestD2Ev[_ZN23VelodyneHLD32PluginTestD5Ev]+0x20): undefined reference to `gazebo::ServerFixture::~ServerFixture()'
CMakeFiles/velodyne_hld32_plugin-test.dir/test/test_velodyne_hld32_plugin.cpp.o:(.rodata._ZTV45VelodyneHLD32PluginTest_TestLoadingWorld_Test[_ZTV45VelodyneHLD32PluginTest_TestLoadingWorld_Test]+0x28): undefined reference to `gazebo::ServerFixture::TearDown()'
CMakeFiles/velodyne_hld32_plugin-test.dir/test/test_velodyne_hld32_plugin.cpp.o:(.rodata._ZTV45VelodyneHLD32PluginTest_TestLoadingWorld_Test[_ZTV45VelodyneHLD32PluginTest_TestLoadingWorld_Test]+0x40): undefined reference to `gazebo::ServerFixture::Unload()'
CMakeFiles/velodyne_hld32_plugin-test.dir/test/test_velodyne_hld32_plugin.cpp.o:(.rodata._ZTV45VelodyneHLD32PluginTest_TestLoadingWorld_Test[_ZTV45VelodyneHLD32PluginTest_TestLoadingWorld_Test]+0x48): undefined reference to `gazebo::ServerFixture::Load(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
CMakeFiles/velodyne_hld32_plugin-test.dir/test/test_velodyne_hld32_plugin.cpp.o:(.rodata._ZTV45VelodyneHLD32PluginTest_TestLoadingWorld_Test[_ZTV45VelodyneHLD32PluginTest_TestLoadingWorld_Test]+0x50): undefined reference to `gazebo::ServerFixture::Load(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, bool)'
CMakeFiles/velodyne_hld32_plugin-test.dir/test/test_velodyne_hld32_plugin.cpp.o:(.rodata._ZTV45VelodyneHLD32PluginTest_TestLoadingWorld_Test[_ZTV45VelodyneHLD32PluginTest_TestLoadingWorld_Test]+0x58): undefined reference to `gazebo::ServerFixture::Load(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, bool, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&)'
CMakeFiles/velodyne_hld32_plugin-test.dir/test/test_velodyne_hld32_plugin.cpp.o:(.rodata._ZTV45VelodyneHLD32PluginTest_TestLoadingWorld_Test[_ZTV45VelodyneHLD32PluginTest_TestLoadingWorld_Test]+0x60): undefined reference to `gazebo::ServerFixture::LoadArgs(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
CMakeFiles/velodyne_hld32_plugin-test.dir/test/test_velodyne_hld32_plugin.cpp.o:(.rodata._ZTV23VelodyneHLD32PluginTest[_ZTV23VelodyneHLD32PluginTest]+0x28): undefined reference to `gazebo::ServerFixture::TearDown()'
CMakeFiles/velodyne_hld32_plugin-test.dir/test/test_velodyne_hld32_plugin.cpp.o:(.rodata._ZTV23VelodyneHLD32PluginTest[_ZTV23VelodyneHLD32PluginTest]+0x40): undefined reference to `gazebo::ServerFixture::Unload()'
CMakeFiles/velodyne_hld32_plugin-test.dir/test/test_velodyne_hld32_plugin.cpp.o:(.rodata._ZTV23VelodyneHLD32PluginTest[_ZTV23VelodyneHLD32PluginTest]+0x48): undefined reference to `gazebo::ServerFixture::Load(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
CMakeFiles/velodyne_hld32_plugin-test.dir/test/test_velodyne_hld32_plugin.cpp.o:(.rodata._ZTV23VelodyneHLD32PluginTest[_ZTV23VelodyneHLD32PluginTest]+0x50): undefined reference to `gazebo::ServerFixture::Load(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, bool)'
CMakeFiles/velodyne_hld32_plugin-test.dir/test/test_velodyne_hld32_plugin.cpp.o:(.rodata._ZTV23VelodyneHLD32PluginTest[_ZTV23VelodyneHLD32PluginTest]+0x58): undefined reference to `gazebo::ServerFixture::Load(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, bool, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&)'
CMakeFiles/velodyne_hld32_plugin-test.dir/test/test_velodyne_hld32_plugin.cpp.o:(.rodata._ZTV23VelodyneHLD32PluginTest[_ZTV23VelodyneHLD32PluginTest]+0x60): undefined reference to `gazebo::ServerFixture::LoadArgs(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
CMakeFiles/velodyne_hld32_plugin-test.dir/test/test_velodyne_hld32_plugin.cpp.o:(.rodata._ZTI23VelodyneHLD32PluginTest[_ZTI23VelodyneHLD32PluginTest]+0x10): undefined reference to `typeinfo for gazebo::ServerFixture'
collect2: error: ld returned 1 exit status
CMakeFiles/velodyne_hld32_plugin-test.dir/build.make:128: recipe for target '/home/robert/gazebo_sandbox_ws/devel/.private/velodyne_hld32_plugin/lib/velodyne_hld32_plugin/velodyne_hld32_plugin-test' failed
make[3]: Leaving directory '/home/robert/gazebo_sandbox_ws/build/velodyne_hld32_plugin'
make[3]: *** [/home/robert/gazebo_sandbox_ws/devel/.private/velodyne_hld32_plugin/lib/velodyne_hld32_plugin/velodyne_hld32_plugin-test] Error 1
CMakeFiles/Makefile2:134: recipe for target 'CMakeFiles/velodyne_hld32_plugin-test.dir/all' failed
make[2]: Leaving directory '/home/robert/gazebo_sandbox_ws/build/velodyne_hld32_plugin'
make[2]: *** [CMakeFiles/velodyne_hld32_plugin-test.dir/all] Error 2
CMakeFiles/Makefile2:1298: recipe for target 'CMakeFiles/run_tests.dir/rule' failed
make[1]: Leaving directory '/home/robert/gazebo_sandbox_ws/build/velodyne_hld32_plugin'
make[1]: *** [CMakeFiles/run_tests.dir/rule] Error 2
Makefile:667: recipe for target 'run_tests' failed
make: *** [run_tests] Error 2
My CMakeList.txt:
``` cmakeminimumrequired(VERSION 2.8.3) project(velodynehld32plugin)
findpackage(catkin REQUIRED COMPONENTS gazeboros roscpp std_msgs )
findpackage(gazebo REQUIRED) includedirectories(${GAZEBOINCLUDEDIRS}
linkdirectories(${GAZEBOLIBRARYDIRS}) set(CMAKECXXFLAGS "${CMAKECXXFLAGS} ${GAZEBOCXX_FLAGS}")
catkinpackage( LIBRARIES velodynehld32plugin CATKINDEPENDS roscpp DEPENDS systemlib gazebo gazeboros )
includedirectories( ${catkinINCLUDE_DIRS})
addlibrary(${PROJECTNAME} src/velodynehld32plugin.cpp) targetlinklibraries(${PROJECTNAME} ${GAZEBOlibraries} ${catkin_LIBRARIES})
catkinaddgtest(${PROJECTNAME}-test test/testvelodynehld32plugin.cpp) if(TARGET ${PROJECTNAME}-test) targetlinklibraries(${PROJECTNAME}-test ${PROJECTNAME} ${GAZEBOlibraries}) endif() ```
I could be making some really dumb mistake, but I feel like I'm just trying random things and I'm spinning my wheels. If anyone has any corrections/suggestions they would be greatly appreciated.
Thanks,
Robert
Asked by Robert Brothers on 2018-10-29 12:14:23 UTC
Answers
ServerFixture
is build as a static library and is not part of GAZEBO_LIBRARIES
.
Add it like this:
target_link_libraries(myTarget "libgazebo_test_fixture.a")
Asked by LukasWoodtli on 2018-11-14 14:54:41 UTC
Comments