mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-20 01:53:34 +08:00
Issue #132 Proper googletest dependency and fixes for unitests on OSX.
Problem: It's really hard to get Libuavcan tests building on a mac or other platform if googletest isn't installed. Solution: add "if linux" guards to problem areas. Also include googletest as recommended in the googletest project's README. Testing: Successfully built on OSX sierra using gcc6
This commit is contained in:
@@ -89,7 +89,6 @@ install(CODE "execute_process(COMMAND ${PYTHON} setup.py install --record instal
|
||||
#
|
||||
function(add_libuavcan_test name library flags) # Adds GTest executable and creates target to execute it every build
|
||||
find_package(Threads REQUIRED)
|
||||
include_directories(${GTEST_INCLUDE_DIRS})
|
||||
|
||||
file(GLOB_RECURSE TEST_CXX_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "test/*.cpp")
|
||||
add_executable(${name} ${TEST_CXX_FILES})
|
||||
@@ -99,9 +98,11 @@ function(add_libuavcan_test name library flags) # Adds GTest executable and crea
|
||||
set_target_properties(${name} PROPERTIES COMPILE_FLAGS ${flags})
|
||||
endif ()
|
||||
|
||||
target_link_libraries(${name} ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries(${name} gmock_main)
|
||||
target_link_libraries(${name} ${library})
|
||||
target_link_libraries(${name} rt)
|
||||
if (${UAVCAN_PLATFORM} STREQUAL "linux")
|
||||
target_link_libraries(${name} rt)
|
||||
endif()
|
||||
|
||||
# Tests run automatically upon successful build
|
||||
# If failing tests need to be investigated with debugger, use 'make --ignore-errors'
|
||||
@@ -145,10 +146,8 @@ if (DEBUG_BUILD)
|
||||
set_target_properties(uavcan_optim PROPERTIES COMPILE_FLAGS ${optim_flags})
|
||||
add_dependencies(uavcan_optim libuavcan_dsdlc)
|
||||
|
||||
# GTest executables
|
||||
find_package(GTest)
|
||||
if (GTEST_FOUND)
|
||||
message(STATUS "GTest found, tests will be built and run [${GTEST_INCLUDE_DIRS}] [${GTEST_BOTH_LIBRARIES}]")
|
||||
message(STATUS "GTest found, tests will be built and run.")
|
||||
add_libuavcan_test(libuavcan_test uavcan "") # Default
|
||||
add_libuavcan_test(libuavcan_test_cpp03 uavcan_cpp03 "${cpp03_flags}") # C++03
|
||||
add_libuavcan_test(libuavcan_test_optim uavcan_optim "${optim_flags}") # Max optimization
|
||||
|
||||
@@ -4,13 +4,19 @@
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <uavcan/helpers/heap_based_pool_allocator.hpp>
|
||||
#ifdef __linux__
|
||||
#include <malloc.h>
|
||||
|
||||
#else
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
|
||||
TEST(HeapBasedPoolAllocator, Basic)
|
||||
{
|
||||
#ifdef __linux__
|
||||
std::cout << ">>> HEAP BEFORE:" << std::endl;
|
||||
malloc_stats();
|
||||
#endif
|
||||
|
||||
uavcan::HeapBasedPoolAllocator<uavcan::MemPoolBlockSize> al(0xEEEE);
|
||||
|
||||
@@ -61,8 +67,10 @@ TEST(HeapBasedPoolAllocator, Basic)
|
||||
ASSERT_EQ(0, al.getNumReservedBlocks());
|
||||
ASSERT_EQ(0, al.getNumAllocatedBlocks());
|
||||
|
||||
#ifdef __linux__
|
||||
std::cout << ">>> HEAP AFTER:" << std::endl;
|
||||
malloc_stats();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -115,9 +123,11 @@ std::mutex RaiiSynchronizer::mutex;
|
||||
|
||||
TEST(HeapBasedPoolAllocator, Concurrency)
|
||||
{
|
||||
#ifdef __linux__
|
||||
std::cout << ">>> HEAP BEFORE:" << std::endl;
|
||||
malloc_stats();
|
||||
|
||||
#endif
|
||||
uavcan::HeapBasedPoolAllocator<uavcan::MemPoolBlockSize, RaiiSynchronizer> al(1000);
|
||||
|
||||
ASSERT_EQ(1000, al.getBlockCapacity());
|
||||
@@ -167,13 +177,17 @@ TEST(HeapBasedPoolAllocator, Concurrency)
|
||||
std::cout << "Allocated: " << al.getNumAllocatedBlocks() << std::endl;
|
||||
std::cout << "Reserved: " << al.getNumReservedBlocks() << std::endl;
|
||||
|
||||
#ifdef __linux__
|
||||
std::cout << ">>> HEAP BEFORE SHRINK:" << std::endl;
|
||||
malloc_stats();
|
||||
|
||||
#endif
|
||||
al.shrink();
|
||||
|
||||
#ifdef __linux__
|
||||
std::cout << ">>> HEAP AFTER SHRINK:" << std::endl;
|
||||
malloc_stats();
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user