Skip to content

Commit

Permalink
updates to use new memory_tools from osrf_testing_tools_cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
wjwwood committed May 22, 2018
1 parent c052e6b commit f36aa7d
Show file tree
Hide file tree
Showing 19 changed files with 496 additions and 677 deletions.
1 change: 1 addition & 0 deletions rcl/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
<test_depend>rmw_implementation_cmake</test_depend>
<test_depend>launch</test_depend>
<test_depend>example_interfaces</test_depend>
<test_depend>osrf_testing_tools_cpp</test_depend>
<test_depend>std_msgs</test_depend>

<export>
Expand Down
108 changes: 61 additions & 47 deletions rcl/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,64 +6,65 @@ find_package(std_msgs REQUIRED)

find_package(rmw_implementation_cmake REQUIRED)

find_package(osrf_testing_tools_cpp REQUIRED)

get_target_property(memory_tools_ld_preload_env_var
osrf_testing_tools_cpp::memory_tools LIBRARY_PRELOAD_ENVIRONMENT_VARIABLE)

include(cmake/rcl_add_custom_executable.cmake)
include(cmake/rcl_add_custom_gtest.cmake)
include(cmake/rcl_add_custom_launch_test.cmake)

set(extra_test_libraries)
set(extra_test_env)
set(extra_lib_dirs "${rcl_lib_dir}")

# finding gtest once in the highest scope
# prevents finding it repeatedly in each local scope
ament_find_gtest()

# This subdirectory extends both extra_test_libraries, extra_test_env, and extra_lib_dirs.
add_subdirectory(memory_tools)

macro(test_target)
find_package(${rmw_implementation} REQUIRED)
test_target_function()
endmacro()

function(test_target_function)
message(STATUS "Creating tests for '${rmw_implementation}'")
list(APPEND extra_test_env RMW_IMPLEMENTATION=${rmw_implementation})
set(rmw_implementation_env_var RMW_IMPLEMENTATION=${rmw_implementation})

# Gtests

rcl_add_custom_gtest(test_client${target_suffix}
SRCS rcl/test_client.cpp
ENV ${extra_test_env}
INCLUDE_DIRS ${osrf_testing_tools_cpp_INCLUDE_DIRS}
ENV ${rmw_implementation_env_var}
APPEND_LIBRARY_DIRS ${extra_lib_dirs}
LIBRARIES ${PROJECT_NAME} ${extra_test_libraries}
LIBRARIES ${PROJECT_NAME}
AMENT_DEPENDENCIES ${rmw_implementation} "example_interfaces"
)

rcl_add_custom_gtest(test_time${target_suffix}
SRCS rcl/test_time.cpp
ENV ${extra_test_env}
ENV ${rmw_implementation_env_var} ${memory_tools_ld_preload_env_var}
APPEND_LIBRARY_DIRS ${extra_lib_dirs}
LIBRARIES ${PROJECT_NAME} ${extra_test_libraries}
LIBRARIES ${PROJECT_NAME} osrf_testing_tools_cpp::memory_tools
AMENT_DEPENDENCIES ${rmw_implementation}
)

rcl_add_custom_gtest(test_common${target_suffix}
SRCS rcl/test_common.cpp
ENV
${extra_test_env}
${rmw_implementation_env_var}
EMPTY_TEST=
NORMAL_TEST=foo
APPEND_LIBRARY_DIRS ${extra_lib_dirs}
LIBRARIES ${PROJECT_NAME} ${extra_test_libraries}
LIBRARIES ${PROJECT_NAME}
AMENT_DEPENDENCIES ${rmw_implementation}
)

rcl_add_custom_gtest(test_get_node_names${target_suffix}
SRCS rcl/test_get_node_names.cpp
ENV ${extra_test_env}
ENV ${rmw_implementation_env_var}
APPEND_LIBRARY_DIRS ${extra_lib_dirs}
LIBRARIES ${PROJECT_NAME} ${extra_test_libraries}
LIBRARIES ${PROJECT_NAME}
AMENT_DEPENDENCIES ${rmw_implementation}
)

Expand All @@ -77,118 +78,130 @@ function(test_target_function)
endif()
rcl_add_custom_gtest(test_graph${target_suffix}
SRCS rcl/test_graph.cpp
ENV ${extra_test_env}
INCLUDE_DIRS ${osrf_testing_tools_cpp_INCLUDE_DIRS}
ENV ${rmw_implementation_env_var}
APPEND_LIBRARY_DIRS ${extra_lib_dirs}
LIBRARIES ${PROJECT_NAME} ${extra_test_libraries}
LIBRARIES ${PROJECT_NAME}
AMENT_DEPENDENCIES ${rmw_implementation} "example_interfaces" "std_msgs"
${SKIP_TEST}
)

rcl_add_custom_gtest(test_rcl${target_suffix}
SRCS rcl/test_rcl.cpp
ENV ${extra_test_env}
ENV ${rmw_implementation_env_var} ${memory_tools_ld_preload_env_var}
APPEND_LIBRARY_DIRS ${extra_lib_dirs}
LIBRARIES ${PROJECT_NAME} ${extra_test_libraries}
LIBRARIES ${PROJECT_NAME} osrf_testing_tools_cpp::memory_tools
AMENT_DEPENDENCIES ${rmw_implementation}
)

rcl_add_custom_gtest(test_node${target_suffix}
SRCS rcl/test_node.cpp
ENV ${extra_test_env}
INCLUDE_DIRS ${osrf_testing_tools_cpp_INCLUDE_DIRS}
ENV ${rmw_implementation_env_var} ${memory_tools_ld_preload_env_var}
APPEND_LIBRARY_DIRS ${extra_lib_dirs}
LIBRARIES ${PROJECT_NAME} ${extra_test_libraries}
LIBRARIES ${PROJECT_NAME} osrf_testing_tools_cpp::memory_tools
AMENT_DEPENDENCIES ${rmw_implementation}
)

rcl_add_custom_gtest(test_arguments${target_suffix}
SRCS rcl/test_arguments.cpp
ENV ${extra_test_env}
ENV ${rmw_implementation_env_var}
APPEND_LIBRARY_DIRS ${extra_lib_dirs}
LIBRARIES ${PROJECT_NAME} ${extra_test_libraries}
LIBRARIES ${PROJECT_NAME}
)

rcl_add_custom_gtest(test_remap${target_suffix}
SRCS rcl/test_remap.cpp
ENV ${extra_test_env}
INCLUDE_DIRS ${osrf_testing_tools_cpp_INCLUDE_DIRS}
ENV ${rmw_implementation_env_var}
APPEND_LIBRARY_DIRS ${extra_lib_dirs}
LIBRARIES ${PROJECT_NAME} ${extra_test_libraries}
LIBRARIES ${PROJECT_NAME}
)

rcl_add_custom_gtest(test_remap_integration${target_suffix}
SRCS rcl/test_remap_integration.cpp
INCLUDE_DIRS ${osrf_testing_tools_cpp_INCLUDE_DIRS}
TIMEOUT 200
ENV ${extra_test_env}
ENV ${rmw_implementation_env_var}
APPEND_LIBRARY_DIRS ${extra_lib_dirs}
LIBRARIES ${PROJECT_NAME} ${extra_test_libraries}
LIBRARIES ${PROJECT_NAME}
AMENT_DEPENDENCIES "std_msgs" "example_interfaces"
)

rcl_add_custom_gtest(test_guard_condition${target_suffix}
SRCS rcl/test_guard_condition.cpp
ENV ${extra_test_env}
INCLUDE_DIRS ${osrf_testing_tools_cpp_INCLUDE_DIRS}
ENV ${rmw_implementation_env_var} ${memory_tools_ld_preload_env_var}
APPEND_LIBRARY_DIRS ${extra_lib_dirs}
LIBRARIES ${PROJECT_NAME} ${extra_test_libraries}
LIBRARIES ${PROJECT_NAME} osrf_testing_tools_cpp::memory_tools
AMENT_DEPENDENCIES ${rmw_implementation}
)

rcl_add_custom_gtest(test_publisher${target_suffix}
SRCS rcl/test_publisher.cpp
ENV ${extra_test_env}
INCLUDE_DIRS ${osrf_testing_tools_cpp_INCLUDE_DIRS}
ENV ${rmw_implementation_env_var}
APPEND_LIBRARY_DIRS ${extra_lib_dirs}
LIBRARIES ${PROJECT_NAME} ${extra_test_libraries}
LIBRARIES ${PROJECT_NAME}
AMENT_DEPENDENCIES ${rmw_implementation} "std_msgs"
)

rcl_add_custom_gtest(test_service${target_suffix}
SRCS rcl/test_service.cpp
ENV ${extra_test_env}
INCLUDE_DIRS ${osrf_testing_tools_cpp_INCLUDE_DIRS}
ENV ${rmw_implementation_env_var}
APPEND_LIBRARY_DIRS ${extra_lib_dirs}
LIBRARIES ${PROJECT_NAME} ${extra_test_libraries}
LIBRARIES ${PROJECT_NAME}
AMENT_DEPENDENCIES ${rmw_implementation} "example_interfaces"
)

rcl_add_custom_gtest(test_subscription${target_suffix}
SRCS rcl/test_subscription.cpp
ENV ${extra_test_env}
INCLUDE_DIRS ${osrf_testing_tools_cpp_INCLUDE_DIRS}
ENV ${rmw_implementation_env_var}
APPEND_LIBRARY_DIRS ${extra_lib_dirs}
LIBRARIES ${PROJECT_NAME} ${extra_test_libraries}
LIBRARIES ${PROJECT_NAME}
AMENT_DEPENDENCIES ${rmw_implementation} "std_msgs"
)

rcl_add_custom_gtest(test_wait${target_suffix}
SRCS rcl/test_wait.cpp
ENV ${extra_test_env}
INCLUDE_DIRS ${osrf_testing_tools_cpp_INCLUDE_DIRS}
ENV ${rmw_implementation_env_var}
APPEND_LIBRARY_DIRS ${extra_lib_dirs}
LIBRARIES ${PROJECT_NAME} ${extra_test_libraries}
LIBRARIES ${PROJECT_NAME}
AMENT_DEPENDENCIES ${rmw_implementation}
)

rcl_add_custom_gtest(test_namespace${target_suffix}
SRCS test_namespace.cpp
ENV ${extra_test_env}
INCLUDE_DIRS ${osrf_testing_tools_cpp_INCLUDE_DIRS}
ENV ${rmw_implementation_env_var}
APPEND_LIBRARY_DIRS ${extra_lib_dirs}
LIBRARIES ${PROJECT_NAME} ${extra_test_libraries}
LIBRARIES ${PROJECT_NAME}
AMENT_DEPENDENCIES ${rmw_implementation} "example_interfaces"
)

# Launch tests

rcl_add_custom_executable(service_fixture${target_suffix}
SRCS rcl/service_fixture.cpp
LIBRARIES ${PROJECT_NAME} ${extra_test_libraries}
INCLUDE_DIRS ${osrf_testing_tools_cpp_INCLUDE_DIRS}
LIBRARIES ${PROJECT_NAME}
AMENT_DEPENDENCIES ${rmw_implementation} "example_interfaces"
)

rcl_add_custom_executable(client_fixture${target_suffix}
SRCS rcl/client_fixture.cpp
LIBRARIES ${PROJECT_NAME} ${extra_test_libraries}
INCLUDE_DIRS ${osrf_testing_tools_cpp_INCLUDE_DIRS}
LIBRARIES ${PROJECT_NAME}
AMENT_DEPENDENCIES ${rmw_implementation} "example_interfaces"
)

rcl_add_custom_launch_test(test_services
service_fixture
client_fixture
ENV ${extra_test_env}
ENV ${rmw_implementation_env_var}
APPEND_LIBRARY_DIRS ${extra_lib_dirs}
TIMEOUT 15
)
Expand Down Expand Up @@ -233,21 +246,22 @@ call_for_each_rmw_implementation(test_target)

rcl_add_custom_gtest(test_validate_topic_name
SRCS rcl/test_validate_topic_name.cpp
ENV ${extra_test_env}
ENV ${rmw_implementation_env_var}
APPEND_LIBRARY_DIRS ${extra_lib_dirs}
LIBRARIES ${PROJECT_NAME} ${extra_test_libraries}
LIBRARIES ${PROJECT_NAME}
)

rcl_add_custom_gtest(test_expand_topic_name
SRCS rcl/test_expand_topic_name.cpp
ENV ${extra_test_env}
ENV ${rmw_implementation_env_var}
APPEND_LIBRARY_DIRS ${extra_lib_dirs}
LIBRARIES ${PROJECT_NAME} ${extra_test_libraries}
LIBRARIES ${PROJECT_NAME}
)

rcl_add_custom_gtest(test_timer${target_suffix}
SRCS rcl/test_timer.cpp
ENV ${extra_test_env}
INCLUDE_DIRS ${osrf_testing_tools_cpp_INCLUDE_DIRS}
ENV ${rmw_implementation_env_var}
APPEND_LIBRARY_DIRS ${extra_lib_dirs}
LIBRARIES ${PROJECT_NAME} ${extra_test_libraries}
LIBRARIES ${PROJECT_NAME}
)
20 changes: 9 additions & 11 deletions rcl/test/rcl/arg_macros.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include "rcl/rcl.h"
#include "rcutils/strdup.h"

#include "../scope_exit.hpp"
#include "osrf_testing_tools_cpp/scope_exit.hpp"

/// Helper to get around non-const args passed to rcl_init().
char **
Expand Down Expand Up @@ -52,12 +52,11 @@ destroy_args(int argc, char ** args)
rcl_ret_t ret = rcl_init(argc, argv, rcl_get_default_allocator()); \
ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string_safe(); \
} \
auto __scope_global_args_exit = make_scope_exit( \
[argc, argv] { \
destroy_args(argc, argv); \
rcl_ret_t ret = rcl_shutdown(); \
ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string_safe(); \
})
OSRF_TESTING_TOOLS_CPP_SCOPE_EXIT({ \
destroy_args(argc, argv); \
rcl_ret_t ret = rcl_shutdown(); \
ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string_safe(); \
})

#define SCOPE_ARGS(local_arguments, ...) \
{ \
Expand All @@ -67,9 +66,8 @@ destroy_args(int argc, char ** args)
local_argc, local_argv, rcl_get_default_allocator(), &local_arguments); \
ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string_safe(); \
} \
auto __scope_ ## local_arguments ## _exit = make_scope_exit( \
[&local_arguments] { \
ASSERT_EQ(RCL_RET_OK, rcl_arguments_fini(&local_arguments)); \
})
OSRF_TESTING_TOOLS_CPP_SCOPE_EXIT({ \
ASSERT_EQ(RCL_RET_OK, rcl_arguments_fini(&local_arguments)); \
})

#endif // RCL__ARG_MACROS_HPP_
48 changes: 22 additions & 26 deletions rcl/test/rcl/client_fixture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@

#include "example_interfaces/srv/add_two_ints.h"

#include "../memory_tools/memory_tools.hpp"
#include "../scope_exit.hpp"
#include "osrf_testing_tools_cpp/scope_exit.hpp"
#include "rcl/error_handling.h"
#include "rcl/graph.h"

Expand Down Expand Up @@ -68,14 +67,13 @@ wait_for_client_to_be_ready(
ROS_PACKAGE_NAME, "Error in wait set init: %s", rcl_get_error_string_safe())
return false;
}
auto wait_set_exit = make_scope_exit(
[&wait_set]() {
if (rcl_wait_set_fini(&wait_set) != RCL_RET_OK) {
RCUTILS_LOG_ERROR_NAMED(
ROS_PACKAGE_NAME, "Error in wait set fini: %s", rcl_get_error_string_safe())
throw std::runtime_error("error while waiting for client");
}
});
OSRF_TESTING_TOOLS_CPP_SCOPE_EXIT({
if (rcl_wait_set_fini(&wait_set) != RCL_RET_OK) {
RCUTILS_LOG_ERROR_NAMED(
ROS_PACKAGE_NAME, "Error in wait set fini: %s", rcl_get_error_string_safe())
throw std::runtime_error("error while waiting for client");
}
});
size_t iteration = 0;
do {
++iteration;
Expand Down Expand Up @@ -123,14 +121,13 @@ int main(int argc, char ** argv)
ROS_PACKAGE_NAME, "Error in node init: %s", rcl_get_error_string_safe())
return -1;
}
auto node_exit = make_scope_exit(
[&main_ret, &node]() {
if (rcl_node_fini(&node) != RCL_RET_OK) {
RCUTILS_LOG_ERROR_NAMED(
ROS_PACKAGE_NAME, "Error in node fini: %s", rcl_get_error_string_safe())
main_ret = -1;
}
});
OSRF_TESTING_TOOLS_CPP_SCOPE_EXIT({
if (rcl_node_fini(&node) != RCL_RET_OK) {
RCUTILS_LOG_ERROR_NAMED(
ROS_PACKAGE_NAME, "Error in node fini: %s", rcl_get_error_string_safe())
main_ret = -1;
}
});

const rosidl_service_type_support_t * ts = ROSIDL_GET_SRV_TYPE_SUPPORT(
example_interfaces, AddTwoInts);
Expand All @@ -145,14 +142,13 @@ int main(int argc, char ** argv)
return -1;
}

auto client_exit = make_scope_exit(
[&client, &main_ret, &node]() {
if (rcl_client_fini(&client, &node)) {
RCUTILS_LOG_ERROR_NAMED(
ROS_PACKAGE_NAME, "Error in client fini: %s", rcl_get_error_string_safe())
main_ret = -1;
}
});
OSRF_TESTING_TOOLS_CPP_SCOPE_EXIT({
if (rcl_client_fini(&client, &node)) {
RCUTILS_LOG_ERROR_NAMED(
ROS_PACKAGE_NAME, "Error in client fini: %s", rcl_get_error_string_safe())
main_ret = -1;
}
});

// Wait until server is available
if (!wait_for_server_to_be_available(&node, &client, 1000, 100)) {
Expand Down
Loading

0 comments on commit f36aa7d

Please sign in to comment.