refactoring test layout and cmake logic
This commit is contained in:
parent
aaa773eb8b
commit
226c39a8af
13 changed files with 281 additions and 175 deletions
|
@ -12,8 +12,8 @@ find_package(rosidl_generator_c REQUIRED)
|
||||||
include_directories(include)
|
include_directories(include)
|
||||||
|
|
||||||
if(NOT WIN32)
|
if(NOT WIN32)
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra")
|
|
||||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra")
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra")
|
||||||
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wextra")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
set(${PROJECT_NAME}_sources
|
set(${PROJECT_NAME}_sources
|
||||||
|
@ -47,6 +47,12 @@ macro(target)
|
||||||
ARCHIVE DESTINATION lib
|
ARCHIVE DESTINATION lib
|
||||||
LIBRARY DESTINATION lib
|
LIBRARY DESTINATION lib
|
||||||
RUNTIME DESTINATION bin)
|
RUNTIME DESTINATION bin)
|
||||||
|
|
||||||
|
# rcl_lib_dir is passed as APPEND_LIBRARY_DIRS for each ament_add_gtest call so
|
||||||
|
# the librcl that they link against is on the library path.
|
||||||
|
# This is especially important on Windows.
|
||||||
|
# This is overwritten each loop, but which one it points to doesn't really matter.
|
||||||
|
set(rcl_lib_dir "$<TARGET_FILE_DIR:${PROJECT_NAME}${target_suffix}>")
|
||||||
endmacro()
|
endmacro()
|
||||||
|
|
||||||
call_for_each_rmw_implementation(target GENERATE_DEFAULT)
|
call_for_each_rmw_implementation(target GENERATE_DEFAULT)
|
||||||
|
|
|
@ -1,117 +1,91 @@
|
||||||
find_package(ament_cmake_gtest REQUIRED)
|
find_package(ament_cmake_gtest REQUIRED)
|
||||||
|
find_package(std_msgs REQUIRED)
|
||||||
|
|
||||||
|
include(rcl_add_custom_gtest.cmake)
|
||||||
|
|
||||||
set(extra_test_libraries)
|
set(extra_test_libraries)
|
||||||
set(extra_memory_tools_env PHONY=) # Use a phony env var so there is always at least one.
|
set(extra_test_env)
|
||||||
# rcl_lib_dir is passed as APPEND_LIBRARY_DIRS for each ament_add_gtest call so
|
|
||||||
# the librcl that they link against is on the library path.
|
|
||||||
# This is especially improtant on Windows.
|
|
||||||
set(rcl_lib_dir $<TARGET_FILE_DIR:${PROJECT_NAME}>)
|
|
||||||
ament_find_gtest() # For GTEST_LIBRARIES
|
|
||||||
if(APPLE)
|
|
||||||
add_library(${PROJECT_NAME}_memory_tools_interpose SHARED memory_tools_osx_interpose.cpp)
|
|
||||||
target_link_libraries(${PROJECT_NAME}_memory_tools_interpose ${GTEST_LIBRARIES})
|
|
||||||
set_target_properties(${PROJECT_NAME}_memory_tools_interpose
|
|
||||||
PROPERTIES COMPILE_FLAGS "-std=c++11")
|
|
||||||
list(APPEND extra_test_libraries ${PROJECT_NAME}_memory_tools_interpose)
|
|
||||||
list(APPEND extra_memory_tools_env
|
|
||||||
DYLD_INSERT_LIBRARIES=$<TARGET_FILE:${PROJECT_NAME}_memory_tools_interpose>)
|
|
||||||
endif()
|
|
||||||
add_library(${PROJECT_NAME}_memory_tools SHARED memory_tools.cpp)
|
|
||||||
if(NOT WIN32)
|
|
||||||
set_target_properties(${PROJECT_NAME}_memory_tools PROPERTIES COMPILE_FLAGS "-std=c++11")
|
|
||||||
endif()
|
|
||||||
if(UNIX AND NOT APPLE)
|
|
||||||
list(APPEND extra_test_libraries dl)
|
|
||||||
list(APPEND extra_memory_tools_env DL_PRELOAD=$<TARGET_FILE:${PROJECT_NAME}_memory_tools>)
|
|
||||||
endif()
|
|
||||||
target_link_libraries(${PROJECT_NAME}_memory_tools ${extra_test_libraries})
|
|
||||||
target_compile_definitions(${PROJECT_NAME}_memory_tools
|
|
||||||
PRIVATE "RCL_MEMORY_TOOLS_BUILDING_DLL")
|
|
||||||
list(APPEND extra_test_libraries ${PROJECT_NAME}_memory_tools)
|
|
||||||
|
|
||||||
if(NOT WIN32)
|
# This subdirectory extends both extra_test_libraries and extra_test_env.
|
||||||
ament_add_gtest(test_memory_tools test_memory_tools.cpp
|
add_subdirectory(memory_tools)
|
||||||
ENV ${extra_memory_tools_env} APPEND_LIBRARY_DIRS ${rcl_lib_dir})
|
|
||||||
if(TARGET test_memory_tools)
|
macro(test_target)
|
||||||
target_include_directories(test_memory_tools PUBLIC
|
find_package(${rmw_implementation} REQUIRED)
|
||||||
${rcl_interfaces_INCLUDE_DIRS}
|
test_target_function()
|
||||||
${rmw_INCLUDE_DIRS}
|
endmacro()
|
||||||
)
|
|
||||||
if(NOT WIN32)
|
function(test_target_function)
|
||||||
set_target_properties(test_memory_tools PROPERTIES COMPILE_FLAGS "-std=c++11")
|
# TODO(wjwwood): remove these when C type support is supported by typesupport_introspection.
|
||||||
endif()
|
# after removing, we can also recombine the function and macro
|
||||||
target_link_libraries(test_memory_tools ${PROJECT_NAME} ${extra_test_libraries})
|
if("${rmw_implementation} " STREQUAL "rmw_connext_dynamic_cpp ")
|
||||||
|
message(STATUS "Skipping tests for '${rmw_implementation}'")
|
||||||
|
return()
|
||||||
|
endif()
|
||||||
|
if("${rmw_implementation} " STREQUAL "rmw_fastrtps_cpp ")
|
||||||
|
message(STATUS "Skipping tests for '${rmw_implementation}'")
|
||||||
|
return()
|
||||||
endif()
|
endif()
|
||||||
endif()
|
|
||||||
|
|
||||||
ament_add_gtest(test_allocator rcl/test_allocator.cpp
|
message(STATUS "Creating tests for '${rmw_implementation}'")
|
||||||
ENV ${extra_memory_tools_env} APPEND_LIBRARY_DIRS ${rcl_lib_dir})
|
|
||||||
if(TARGET test_allocator)
|
rcl_add_custom_gtest(test_allocator${target_suffix}
|
||||||
target_include_directories(test_allocator PUBLIC
|
SRCS rcl/test_allocator.cpp
|
||||||
${rcl_interfaces_INCLUDE_DIRS}
|
ENV ${extra_test_env}
|
||||||
${rmw_INCLUDE_DIRS}
|
APPEND_LIBRARY_DIRS "${rcl_lib_dir}"
|
||||||
|
LIBRARIES ${PROJECT_NAME}${target_suffix} ${extra_test_libraries}
|
||||||
|
AMENT_DEPENDENCIES ${rmw_implementation}
|
||||||
)
|
)
|
||||||
if(NOT WIN32)
|
|
||||||
set_target_properties(test_allocator PROPERTIES COMPILE_FLAGS "-std=c++11")
|
|
||||||
endif()
|
|
||||||
target_link_libraries(test_allocator ${PROJECT_NAME} ${extra_test_libraries})
|
|
||||||
endif()
|
|
||||||
|
|
||||||
ament_add_gtest(test_time rcl/test_time.cpp
|
rcl_add_custom_gtest(test_time${target_suffix}
|
||||||
ENV ${extra_memory_tools_env} APPEND_LIBRARY_DIRS ${rcl_lib_dir})
|
SRCS rcl/test_time.cpp
|
||||||
if(TARGET test_time)
|
ENV ${extra_test_env}
|
||||||
target_include_directories(test_time PUBLIC
|
APPEND_LIBRARY_DIRS "${rcl_lib_dir}"
|
||||||
${rcl_interfaces_INCLUDE_DIRS}
|
LIBRARIES ${PROJECT_NAME}${target_suffix} ${extra_test_libraries}
|
||||||
${rmw_INCLUDE_DIRS}
|
AMENT_DEPENDENCIES ${rmw_implementation}
|
||||||
)
|
)
|
||||||
if(NOT WIN32)
|
|
||||||
set_target_properties(test_time PROPERTIES COMPILE_FLAGS "-std=c++11")
|
|
||||||
endif()
|
|
||||||
target_link_libraries(test_time ${PROJECT_NAME} ${extra_test_libraries})
|
|
||||||
endif()
|
|
||||||
|
|
||||||
ament_add_gtest(test_common
|
rcl_add_custom_gtest(test_common${target_suffix}
|
||||||
rcl/test_common.cpp
|
SRCS rcl/test_common.cpp
|
||||||
ENV
|
ENV
|
||||||
${extra_memory_tools_env}
|
${extra_test_env}
|
||||||
EMPTY_TEST=
|
EMPTY_TEST=
|
||||||
NORMAL_TEST=foo
|
NORMAL_TEST=foo
|
||||||
APPEND_LIBRARY_DIRS
|
APPEND_LIBRARY_DIRS "${rcl_lib_dir}"
|
||||||
${rcl_lib_dir}
|
LIBRARIES ${PROJECT_NAME}${target_suffix} ${extra_test_libraries}
|
||||||
)
|
AMENT_DEPENDENCIES ${rmw_implementation}
|
||||||
if(TARGET test_common)
|
|
||||||
target_include_directories(test_common PUBLIC
|
|
||||||
${rcl_interfaces_INCLUDE_DIRS}
|
|
||||||
${rmw_INCLUDE_DIRS}
|
|
||||||
)
|
)
|
||||||
if(NOT WIN32)
|
|
||||||
set_target_properties(test_common PROPERTIES COMPILE_FLAGS "-std=c++11")
|
|
||||||
endif()
|
|
||||||
target_link_libraries(test_common ${PROJECT_NAME} ${extra_test_libraries})
|
|
||||||
endif()
|
|
||||||
|
|
||||||
ament_add_gtest(test_rcl rcl/test_rcl.cpp
|
rcl_add_custom_gtest(test_rcl${target_suffix}
|
||||||
ENV ${extra_memory_tools_env} APPEND_LIBRARY_DIRS ${rcl_lib_dir})
|
SRCS rcl/test_rcl.cpp
|
||||||
if(TARGET test_rcl)
|
ENV ${extra_test_env}
|
||||||
target_include_directories(test_rcl PUBLIC
|
APPEND_LIBRARY_DIRS "${rcl_lib_dir}"
|
||||||
${rcl_interfaces_INCLUDE_DIRS}
|
LIBRARIES ${PROJECT_NAME}${target_suffix} ${extra_test_libraries}
|
||||||
${rmw_INCLUDE_DIRS}
|
AMENT_DEPENDENCIES ${rmw_implementation}
|
||||||
)
|
)
|
||||||
if(NOT WIN32)
|
|
||||||
set_target_properties(test_rcl PROPERTIES COMPILE_FLAGS "-std=c++11")
|
|
||||||
endif()
|
|
||||||
target_link_libraries(test_rcl ${PROJECT_NAME} ${extra_test_libraries})
|
|
||||||
endif()
|
|
||||||
|
|
||||||
ament_add_gtest(test_node rcl/test_node.cpp
|
rcl_add_custom_gtest(test_node${target_suffix}
|
||||||
ENV ${extra_memory_tools_env} APPEND_LIBRARY_DIRS ${rcl_lib_dir})
|
SRCS rcl/test_node.cpp
|
||||||
if(TARGET test_node)
|
ENV ${extra_test_env}
|
||||||
target_include_directories(test_node PUBLIC
|
APPEND_LIBRARY_DIRS "${rcl_lib_dir}"
|
||||||
${rcl_interfaces_INCLUDE_DIRS}
|
LIBRARIES ${PROJECT_NAME}${target_suffix} ${extra_test_libraries}
|
||||||
${rmw_INCLUDE_DIRS}
|
AMENT_DEPENDENCIES ${rmw_implementation}
|
||||||
)
|
)
|
||||||
if(NOT WIN32)
|
|
||||||
set_target_properties(test_node PROPERTIES COMPILE_FLAGS "-std=c++11")
|
rcl_add_custom_gtest(test_publisher${target_suffix}
|
||||||
endif()
|
SRCS rcl/test_publisher.cpp
|
||||||
target_link_libraries(test_node ${PROJECT_NAME} ${extra_test_libraries})
|
ENV ${extra_test_env}
|
||||||
endif()
|
APPEND_LIBRARY_DIRS "${rcl_lib_dir}"
|
||||||
|
LIBRARIES ${PROJECT_NAME}${target_suffix} ${extra_test_libraries}
|
||||||
|
AMENT_DEPENDENCIES ${rmw_implementation} "std_msgs"
|
||||||
|
)
|
||||||
|
|
||||||
|
rcl_add_custom_gtest(test_subscription${target_suffix}
|
||||||
|
SRCS rcl/test_subscription.cpp
|
||||||
|
ENV ${extra_test_env}
|
||||||
|
APPEND_LIBRARY_DIRS "${rcl_lib_dir}"
|
||||||
|
LIBRARIES ${PROJECT_NAME}${target_suffix} ${extra_test_libraries}
|
||||||
|
AMENT_DEPENDENCIES ${rmw_implementation} "std_msgs"
|
||||||
|
)
|
||||||
|
endfunction()
|
||||||
|
|
||||||
|
call_for_each_rmw_implementation(test_target)
|
||||||
|
|
36
rcl/test/memory_tools/CMakeLists.txt
Normal file
36
rcl/test/memory_tools/CMakeLists.txt
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
ament_find_gtest() # For GTEST_LIBRARIES
|
||||||
|
|
||||||
|
# Create the memory_tools library which is used by the tests. (rmw implementation agnostic)
|
||||||
|
add_library(${PROJECT_NAME}_memory_tools SHARED memory_tools.cpp)
|
||||||
|
if(APPLE)
|
||||||
|
# Create an OS X specific version of the memory tools that does interposing.
|
||||||
|
# See: http://toves.freeshell.org/interpose/
|
||||||
|
add_library(${PROJECT_NAME}_memory_tools_interpose SHARED memory_tools_osx_interpose.cpp)
|
||||||
|
target_link_libraries(${PROJECT_NAME}_memory_tools_interpose ${GTEST_LIBRARIES})
|
||||||
|
list(APPEND extra_test_libraries ${PROJECT_NAME}_memory_tools_interpose)
|
||||||
|
list(APPEND extra_test_env
|
||||||
|
DYLD_INSERT_LIBRARIES=$<TARGET_FILE:${PROJECT_NAME}_memory_tools_interpose>)
|
||||||
|
endif()
|
||||||
|
if(UNIX AND NOT APPLE)
|
||||||
|
# On Linux like systems, add dl and use the normal library and DL_PRELOAD.
|
||||||
|
list(APPEND extra_test_libraries dl)
|
||||||
|
list(APPEND extra_test_env DL_PRELOAD=$<TARGET_FILE:${PROJECT_NAME}_memory_tools>)
|
||||||
|
endif()
|
||||||
|
target_link_libraries(${PROJECT_NAME}_memory_tools ${extra_test_libraries})
|
||||||
|
target_compile_definitions(${PROJECT_NAME}_memory_tools
|
||||||
|
PRIVATE "RCL_MEMORY_TOOLS_BUILDING_DLL")
|
||||||
|
list(APPEND extra_test_libraries ${PROJECT_NAME}_memory_tools)
|
||||||
|
|
||||||
|
# Create tests for the memory tools library.
|
||||||
|
if(NOT WIN32) # (memory tools doesn't do anything on Windows)
|
||||||
|
include(../rcl_add_custom_gtest.cmake)
|
||||||
|
|
||||||
|
rcl_add_custom_gtest(test_memory_tools
|
||||||
|
SRCS test_memory_tools.cpp
|
||||||
|
ENV ${extra_test_env}
|
||||||
|
LIBRARIES ${extra_test_libraries}
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
set(extra_test_libraries ${extra_test_libraries} PARENT_SCOPE)
|
||||||
|
set(extra_test_env ${extra_test_env} PARENT_SCOPE)
|
|
@ -55,14 +55,16 @@ free(void * pointer)
|
||||||
|
|
||||||
void start_memory_checking()
|
void start_memory_checking()
|
||||||
{
|
{
|
||||||
printf("starting memory checking...\n");
|
if (!enabled.exchange(true)) {
|
||||||
enabled.store(true);
|
printf("starting memory checking...\n");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void stop_memory_checking()
|
void stop_memory_checking()
|
||||||
{
|
{
|
||||||
printf("stopping memory checking...\n");
|
if (enabled.exchange(false)) {
|
||||||
enabled.store(false);
|
printf("stopping memory checking...\n");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/******************************************************************************
|
/******************************************************************************
|
|
@ -16,8 +16,8 @@
|
||||||
// https://dxr.mozilla.org/mozilla-central/rev/
|
// https://dxr.mozilla.org/mozilla-central/rev/
|
||||||
// cc9c6cd756cb744596ba039dcc5ad3065a7cc3ea/memory/build/replace_malloc.c
|
// cc9c6cd756cb744596ba039dcc5ad3065a7cc3ea/memory/build/replace_malloc.c
|
||||||
|
|
||||||
#ifndef MEMORY_TOOLS_HPP_
|
#ifndef RCL__TEST__MEMORY_TOOLS__MEMORY_TOOLS_HPP_
|
||||||
#define MEMORY_TOOLS_HPP_
|
#define RCL__TEST__MEMORY_TOOLS__MEMORY_TOOLS_HPP_
|
||||||
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
|
@ -104,4 +104,29 @@ RCL_MEMORY_TOOLS_PUBLIC
|
||||||
void
|
void
|
||||||
memory_checking_thread_init();
|
memory_checking_thread_init();
|
||||||
|
|
||||||
#endif // MEMORY_TOOLS_HPP_
|
// What follows is a set of failing allocator functions, used for testing.
|
||||||
|
void *
|
||||||
|
failing_malloc(size_t size, void * state)
|
||||||
|
{
|
||||||
|
(void)size;
|
||||||
|
(void)state;
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
void *
|
||||||
|
failing_realloc(void * pointer, size_t size, void * state)
|
||||||
|
{
|
||||||
|
(void)pointer;
|
||||||
|
(void)size;
|
||||||
|
(void)state;
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
failing_free(void * pointer, void * state)
|
||||||
|
{
|
||||||
|
(void)pointer;
|
||||||
|
(void)state;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // RCL__TEST__MEMORY_TOOLS__MEMORY_TOOLS_HPP_
|
|
@ -25,7 +25,7 @@
|
||||||
#endif // defined(__APPLE__)
|
#endif // defined(__APPLE__)
|
||||||
|
|
||||||
#include "./memory_tools.hpp"
|
#include "./memory_tools.hpp"
|
||||||
#include "./scope_exit.hpp"
|
#include "../scope_exit.hpp"
|
||||||
|
|
||||||
static std::atomic<bool> enabled(false);
|
static std::atomic<bool> enabled(false);
|
||||||
|
|
||||||
|
@ -65,9 +65,11 @@ custom_malloc(size_t size)
|
||||||
}
|
}
|
||||||
void * memory = malloc(size);
|
void * memory = malloc(size);
|
||||||
uint64_t fw_size = size;
|
uint64_t fw_size = size;
|
||||||
MALLOC_PRINTF(
|
if (!malloc_expected) {
|
||||||
" malloc (%s) %p %" PRIu64 "\n",
|
MALLOC_PRINTF(
|
||||||
malloc_expected ? " expected" : "not expected", memory, fw_size);
|
" malloc (%s) %p %" PRIu64 "\n",
|
||||||
|
malloc_expected ? " expected" : "not expected", memory, fw_size);
|
||||||
|
}
|
||||||
return memory;
|
return memory;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -107,9 +109,11 @@ custom_realloc(void * memory_in, size_t size)
|
||||||
}
|
}
|
||||||
void * memory = realloc(memory_in, size);
|
void * memory = realloc(memory_in, size);
|
||||||
uint64_t fw_size = size;
|
uint64_t fw_size = size;
|
||||||
MALLOC_PRINTF(
|
if (!realloc_expected) {
|
||||||
"realloc (%s) %p %p %" PRIu64 "\n",
|
MALLOC_PRINTF(
|
||||||
malloc_expected ? " expected" : "not expected", memory_in, memory, fw_size);
|
"realloc (%s) %p %p %" PRIu64 "\n",
|
||||||
|
realloc_expected ? " expected" : "not expected", memory_in, memory, fw_size);
|
||||||
|
}
|
||||||
return memory;
|
return memory;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -147,8 +151,10 @@ custom_free(void * memory)
|
||||||
(*unexpected_free_callback)();
|
(*unexpected_free_callback)();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
MALLOC_PRINTF(
|
if (!free_expected) {
|
||||||
" free (%s) %p\n", malloc_expected ? " expected" : "not expected", memory);
|
MALLOC_PRINTF(
|
||||||
|
" free (%s) %p\n", free_expected ? " expected" : "not expected", memory);
|
||||||
|
}
|
||||||
free(memory);
|
free(memory);
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,14 +40,16 @@ typedef struct interpose_s
|
||||||
void osx_start_memory_checking()
|
void osx_start_memory_checking()
|
||||||
{
|
{
|
||||||
// No loading required, it is handled by DYLD_INSERT_LIBRARIES and dynamic library interposing.
|
// No loading required, it is handled by DYLD_INSERT_LIBRARIES and dynamic library interposing.
|
||||||
MALLOC_PRINTF("starting memory checking...\n");
|
if (!enabled.exchange(true)) {
|
||||||
enabled.store(true);
|
MALLOC_PRINTF("starting memory checking...\n");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void osx_stop_memory_checking()
|
void osx_stop_memory_checking()
|
||||||
{
|
{
|
||||||
MALLOC_PRINTF("stopping memory checking...\n");
|
if (enabled.exchange(false)) {
|
||||||
enabled.store(false);
|
MALLOC_PRINTF("stopping memory checking...\n");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
OSX_INTERPOSE(custom_malloc, malloc);
|
OSX_INTERPOSE(custom_malloc, malloc);
|
|
@ -16,7 +16,7 @@
|
||||||
|
|
||||||
#include "rcl/allocator.h"
|
#include "rcl/allocator.h"
|
||||||
|
|
||||||
#include "../memory_tools.hpp"
|
#include "../memory_tools/memory_tools.hpp"
|
||||||
|
|
||||||
class TestAllocatorFixture : public ::testing::Test
|
class TestAllocatorFixture : public ::testing::Test
|
||||||
{
|
{
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
#include "rcl/node.h"
|
#include "rcl/node.h"
|
||||||
#include "rmw/rmw.h" // For rmw_get_implementation_identifier.
|
#include "rmw/rmw.h" // For rmw_get_implementation_identifier.
|
||||||
|
|
||||||
#include "../memory_tools.hpp"
|
#include "../memory_tools/memory_tools.hpp"
|
||||||
#include "../scope_exit.hpp"
|
#include "../scope_exit.hpp"
|
||||||
#include "rcl/error_handling.h"
|
#include "rcl/error_handling.h"
|
||||||
|
|
||||||
|
@ -47,30 +47,6 @@ public:
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
void *
|
|
||||||
failing_malloc(size_t size, void * state)
|
|
||||||
{
|
|
||||||
(void)(size);
|
|
||||||
(void)(state);
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
void *
|
|
||||||
failing_realloc(void * pointer, size_t size, void * state)
|
|
||||||
{
|
|
||||||
(void)(pointer);
|
|
||||||
(void)(size);
|
|
||||||
(void)(state);
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
failing_free(void * pointer, void * state)
|
|
||||||
{
|
|
||||||
(void)pointer;
|
|
||||||
(void)state;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool is_opensplice =
|
bool is_opensplice =
|
||||||
std::string(rmw_get_implementation_identifier()).find("opensplice") != std::string::npos;
|
std::string(rmw_get_implementation_identifier()).find("opensplice") != std::string::npos;
|
||||||
#if defined(WIN32)
|
#if defined(WIN32)
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
|
|
||||||
#include "rcl/rcl.h"
|
#include "rcl/rcl.h"
|
||||||
|
|
||||||
#include "../memory_tools.hpp"
|
#include "../memory_tools/memory_tools.hpp"
|
||||||
#include "rcl/error_handling.h"
|
#include "rcl/error_handling.h"
|
||||||
|
|
||||||
class TestRCLFixture : public ::testing::Test
|
class TestRCLFixture : public ::testing::Test
|
||||||
|
@ -42,30 +42,6 @@ public:
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
void *
|
|
||||||
failing_malloc(size_t size, void * state)
|
|
||||||
{
|
|
||||||
(void)(size);
|
|
||||||
(void)(state);
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
void *
|
|
||||||
failing_realloc(void * pointer, size_t size, void * state)
|
|
||||||
{
|
|
||||||
(void)(pointer);
|
|
||||||
(void)(size);
|
|
||||||
(void)(state);
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
failing_free(void * pointer, void * state)
|
|
||||||
{
|
|
||||||
(void)pointer;
|
|
||||||
(void)state;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct FakeTestArgv
|
struct FakeTestArgv
|
||||||
{
|
{
|
||||||
FakeTestArgv()
|
FakeTestArgv()
|
||||||
|
@ -97,6 +73,9 @@ struct FakeTestArgv
|
||||||
|
|
||||||
int argc;
|
int argc;
|
||||||
char ** argv;
|
char ** argv;
|
||||||
|
|
||||||
|
private:
|
||||||
|
FakeTestArgv(const FakeTestArgv &) = delete;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Tests the rcl_init(), rcl_ok(), and rcl_shutdown() functions.
|
/* Tests the rcl_init(), rcl_ok(), and rcl_shutdown() functions.
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
#include "rcl/error_handling.h"
|
#include "rcl/error_handling.h"
|
||||||
#include "rcl/time.h"
|
#include "rcl/time.h"
|
||||||
|
|
||||||
#include "../memory_tools.hpp"
|
#include "../memory_tools/memory_tools.hpp"
|
||||||
|
|
||||||
class TestTimeFixture : public ::testing::Test
|
class TestTimeFixture : public ::testing::Test
|
||||||
{
|
{
|
||||||
|
|
100
rcl/test/rcl_add_custom_gtest.cmake
Normal file
100
rcl/test/rcl_add_custom_gtest.cmake
Normal file
|
@ -0,0 +1,100 @@
|
||||||
|
# Copyright 2016 Open Source Robotics Foundation, Inc.
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
# you may not use this file except in compliance with the License.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
||||||
|
|
||||||
|
if(rcl_add_custom_gtest_INCLUDED)
|
||||||
|
return()
|
||||||
|
endif()
|
||||||
|
set(rcl_add_custom_gtest_INCLUDED TRUE)
|
||||||
|
|
||||||
|
# include CMake functions
|
||||||
|
include(CMakeParseArguments)
|
||||||
|
|
||||||
|
#
|
||||||
|
# Custom macro for adding a gtest in rcl.
|
||||||
|
#
|
||||||
|
# It also takes some of the arguments of ament_add_gtest as well as
|
||||||
|
# INCLUDE_DIRS, LIBRARIES, and AMENT_DEPENDENCIES which are passed to
|
||||||
|
# target_include_directories(), target_link_libraries(), and
|
||||||
|
# ament_target_dependencies() respectively.
|
||||||
|
#
|
||||||
|
# :param target: the target name which will also be used as the test name
|
||||||
|
# :type target: string
|
||||||
|
# :param SRCS: list of source files used to create the gtest
|
||||||
|
# :type SRCS: list of strings
|
||||||
|
# :param ENV: list of env vars to set; listed as ``VAR=value``
|
||||||
|
# :type ENV: list of strings
|
||||||
|
# :param APPEND_ENV: list of env vars to append if already set, otherwise set;
|
||||||
|
# listed as ``VAR=value``
|
||||||
|
# :type APPEND_ENV: list of strings
|
||||||
|
# :param APPEND_LIBRARY_DIRS: list of library dirs to append to the appropriate
|
||||||
|
# OS specific env var, a la LD_LIBRARY_PATH
|
||||||
|
# :type APPEND_LIBRARY_DIRS: list of strings
|
||||||
|
# :param INCLUDE_DIRS: list of include directories to add to the target
|
||||||
|
# :type INCLUDE_DIRS: list of strings
|
||||||
|
# :param LIBRARIES: list of libraries to link to the target
|
||||||
|
# :type LIBRARIES: list of strings
|
||||||
|
# :param AMENT_DEPENDENCIES: list of depends to pass ament_target_dependencies
|
||||||
|
# :type AMENT_DEPENDENCIES: list of strings
|
||||||
|
#
|
||||||
|
# @public
|
||||||
|
#
|
||||||
|
macro(rcl_add_custom_gtest target)
|
||||||
|
cmake_parse_arguments(_ARG
|
||||||
|
"TRACE"
|
||||||
|
""
|
||||||
|
"SRCS;ENV;APPEND_ENV;APPEND_LIBRARY_DIRS;INCLUDE_DIRS;LIBRARIES;AMENT_DEPENDENCIES"
|
||||||
|
${ARGN})
|
||||||
|
if(_ARG_UNPARSED_ARGUMENTS)
|
||||||
|
message(FATAL_ERROR "rcl_add_custom_gtest() called with unused arguments: ${_ARG_UNPARSED_ARGUMENTS}")
|
||||||
|
endif()
|
||||||
|
if(_ARG_ENV)
|
||||||
|
set(_ARG_ENV "ENV" ${_ARG_ENV})
|
||||||
|
endif()
|
||||||
|
if(_ARG_APPEND_ENV)
|
||||||
|
set(_ARG_APPEND_ENV "APPEND_ENV" ${_ARG_APPEND_ENV})
|
||||||
|
endif()
|
||||||
|
if(_ARG_APPEND_LIBRARY_DIRS)
|
||||||
|
set(_ARG_APPEND_LIBRARY_DIRS "APPEND_LIBRARY_DIRS" ${_ARG_APPEND_LIBRARY_DIRS})
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Pass args along to ament_add_gtest().
|
||||||
|
ament_add_gtest(${target} ${_ARG_SRCS} ${_ARG_ENV} ${_ARG_APPEND_ENV} ${_ARG_APPEND_LIBRARY_DIRS})
|
||||||
|
# Check if the target was actually created.
|
||||||
|
if(TARGET ${target})
|
||||||
|
if(_ARG_TRACE)
|
||||||
|
message(STATUS "rcl_add_custom_gtest() Target '${target}':")
|
||||||
|
endif()
|
||||||
|
# Add extra include directories, if any.
|
||||||
|
if(_ARG_INCLUDE_DIRS)
|
||||||
|
if(_ARG_TRACE)
|
||||||
|
message(STATUS " rcl_add_custom_gtest() INCLUDE_DIRS: ${_ARG_INCLUDE_DIRS}")
|
||||||
|
endif()
|
||||||
|
target_include_directories(${target} PUBLIC ${_ARG_INCLUDE_DIRS})
|
||||||
|
endif()
|
||||||
|
# Add extra link libraries, if any.
|
||||||
|
if(_ARG_LIBRARIES)
|
||||||
|
if(_ARG_TRACE)
|
||||||
|
message(STATUS " rcl_add_custom_gtest() LIBRARIES: ${_ARG_LIBRARIES}")
|
||||||
|
endif()
|
||||||
|
target_link_libraries(${target} ${_ARG_LIBRARIES})
|
||||||
|
endif()
|
||||||
|
# Add extra ament dependencies, if any.
|
||||||
|
if(_ARG_AMENT_DEPENDENCIES)
|
||||||
|
if(_ARG_TRACE)
|
||||||
|
message(STATUS " rcl_add_custom_gtest() AMENT_DEPENDENCIES: ${_ARG_AMENT_DEPENDENCIES}")
|
||||||
|
endif()
|
||||||
|
ament_target_dependencies(${target} ${_ARG_AMENT_DEPENDENCIES})
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
endmacro()
|
Loading…
Add table
Add a link
Reference in a new issue