GTest functional tests that include parameters and uORB messaging (#12521)

* Add kdevelop to gitignore

* Add test stubs

* Rename px4_add_gtest to px4_add_unit_gtest

* Add infrastructure to run functional tests

* Add example tests with parameters and uorb messages

* Fix memory issues in destructors in uORB manager and CDev

* Add a more real-world test of the collision prevention
This commit is contained in:
Julian Kent
2019-08-09 15:10:09 +02:00
committed by GitHub
parent 4eb9c7d812
commit d70b024ec7
28 changed files with 535 additions and 16 deletions
+53 -3
View File
@@ -39,12 +39,12 @@ include(px4_base)
#
# Adds a googletest unit test to the test_results target.
#
function(px4_add_gtest)
function(px4_add_unit_gtest)
# skip if unit testing is not configured
if(BUILD_TESTING)
# parse source file and library dependencies from arguments
px4_parse_function_args(
NAME px4_add_gtest
NAME px4_add_unit_gtest
ONE_VALUE SRC
MULTI_VALUE LINKLIBS
REQUIRED SRC
@@ -62,7 +62,57 @@ function(px4_add_gtest)
target_link_libraries(${TESTNAME} ${LINKLIBS} gtest_main)
# add the test to the ctest plan
add_test(NAME ${TESTNAME} COMMAND ${TESTNAME})
add_test(NAME ${TESTNAME}
COMMAND ${TESTNAME}
WORKING_DIRECTORY ${PX4_BINARY_DIR})
# attach it to the unit test target
add_dependencies(test_results ${TESTNAME})
endif()
endfunction()
function(px4_add_functional_gtest)
# skip if unit testing is not configured
if(BUILD_TESTING)
# parse source file and library dependencies from arguments
px4_parse_function_args(
NAME px4_add_functional_gtest
ONE_VALUE SRC
MULTI_VALUE LINKLIBS
REQUIRED SRC
ARGN ${ARGN})
# infer test name from source filname
get_filename_component(TESTNAME ${SRC} NAME_WE)
string(REPLACE Test "" TESTNAME ${TESTNAME})
set(TESTNAME functional-${TESTNAME})
# build a binary for the unit test
add_executable(${TESTNAME} EXCLUDE_FROM_ALL ${SRC})
# link the libary to test and gtest
target_link_libraries(${TESTNAME} ${LINKLIBS} gtest_main
px4_daemon
px4_platform
modules__uORB
px4_layer
systemlib
cdev
px4_work_queue
px4_daemon
work_queue
parameters
perf
tinybson
uorb_msgs
test_stubs) #put test_stubs last
# add the test to the ctest plan
add_test(NAME ${TESTNAME}
# functional tests need to run in a new process for each test,
# since they set up and tear down system components
COMMAND ${PX4_SOURCE_DIR}/Tools/run-gtest-isolated.py ${TESTNAME}
WORKING_DIRECTORY ${PX4_BINARY_DIR})
# attach it to the unit test target
add_dependencies(test_results ${TESTNAME})