Run unit-test with custom interfaces
Hi, I have a package with the following characteristics: it creates custom interfaces, it creates a library and it contains unit-tests for that library. The library provides a node that uses the generated interfaces and the unit-tests need to instantiate that node.
I can run the unit-tests using the colcon test
command, which produces the following log
test 1
Start 1: test_fancy_stuff
1: Test command: /usr/bin/python3 "-u" "/opt/ros/foxy/share/ament_cmake_test/cmake/run_test.py" "/root/ws/build/fancy_pkg/test_results/fancy_pkg/test_fancy_stuff.gtest.xml" "--package-name" "fancy_pkg" "--output-file" "/root/ws/build/fancy_pkg/ament_cmake_gtest/test_fancy_stuff.txt" "--command" "/root/ws/build/fancy_pkg/test_fancy_stuff" "--gtest_output=xml:/root/ws/build/fancy_pkg/test_results/fancy_pkg/test_fancy_stuff.gtest.xml"
1: Test timeout computed to be: 60
1: -- run_test.py: invoking following command in '/root/ws/build/fancy_pkg':
1: - /root/ws/build/fancy_pkg/test_fancy_stuff --gtest_output=xml:/root/ws/build/fancy_pkg/test_results/fancy_pkg/test_fancy_stuff.gtest.xml
1: Running main() from /opt/ros/foxy/src/gtest_vendor/src/gtest_main.cc
1: [==========] Running 1 test from 1 test case.
1: [----------] Global test environment set-up.
1: [----------] 1 test from FancyTest
1: [ RUN ] FancyTest.stuff
1: [INFO] [1602082277.983172124] [fancy_node]: Node created!!
1: [ OK ] FancyTest.stuff (17 ms)
1: [----------] 1 test from FancyTest (17 ms total)
1:
1: [----------] Global test environment tear-down
1: [==========] 1 test from 1 test case ran. (17 ms total)
1: [ PASSED ] 1 test.
1: -- run_test.py: return code 0
1: -- run_test.py: inject classname prefix into gtest result file '/root/ws/build/fancy_pkg/test_results/fancy_pkg/test_fancy_stuff.gtest.xml'
1: -- run_test.py: verify result file '/root/ws/build/fancy_pkg/test_results/fancy_pkg/test_fancy_stuff.gtest.xml'
1/1 Test #1: test_fancy_stuff ................. Passed 0.11 sec
However, I would like to be able to run the test also without using the colcon
utility.
For example using standard ctest.
However this fails with the following exception
Failed to find library 'fancy_pkg__rosidl_typesupport_fastrtps_cpp'
unknown file: Failure
C++ exception with description "could not create publisher: type support not from this implementation, at /tmp/binarydeb/ros-foxy-rmw-fastrtps-cpp-1.2.0/src/publisher.cpp:75, at /tmp/binarydeb/ros-foxy-rcl-1.1.7/src/rcl/publisher.c:172" thrown in the test body.
This looks like it's coming from the find_library
utility (see here) which search for the message library in the LD_LIBRARY_PATH
.
How can I tell the unit-test that the interfaces are generated from the same package that I'm testing, so that it should be able to find them in the same place where it finds the library?
Is there something special that colcon test
is doing under the hood? I really would prefer not have to use the source scripts for this use-case.
Thank you
For completeness, this is my CMakeLists.txt
file
cmake_minimum_required(VERSION 3.5)
project(fancy_pkg)
# Default to C++14
if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 14)
endif()
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wall -Wextra -Wpedantic)
endif()
find_package(ament_cmake REQUIRED)
find_package(builtin_interfaces REQUIRED)
find_package(rosidl_default_generators REQUIRED)
find_package(rclcpp REQUIRED)
rosidl_generate_interfaces(${PROJECT_NAME}
"msg/Fancy.msg"
DEPENDENCIES builtin_interfaces
)
add_library(fancy_lib SHARED src/fancy_node.cpp)
target_include_directories(fancy_lib PUBLIC ...
After enabling debug logs, I see that the full
ctest
command used bycolcon test
includes the changes to LD_LIBRARY_PATH. My question remains as I feel that this is unnecessary for this case.