mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-23 05:43:34 +08:00
build: disable fuzztest when building with TSAN
fuzztest's coverage instrumentation is incompatible with Thread Sanitizer. Add px4_setup_gtest_without_fuzztest() macro to cmake/px4_add_gtest.cmake that fetches GTest standalone and stubs out fuzztest cmake functions. Guard all fuzztest-specific code on TARGET fuzztest::fuzztest so it compiles cleanly without fuzztest.
This commit is contained in:
+46
-17
@@ -31,6 +31,30 @@
|
|||||||
#
|
#
|
||||||
############################################################################
|
############################################################################
|
||||||
|
|
||||||
|
#=============================================================================
|
||||||
|
#
|
||||||
|
# px4_setup_gtest_without_fuzztest
|
||||||
|
#
|
||||||
|
# Fetches GTest standalone and stubs out fuzztest cmake functions.
|
||||||
|
# Used when fuzztest is not available (e.g. TSAN builds where fuzztest's
|
||||||
|
# coverage instrumentation is incompatible).
|
||||||
|
#
|
||||||
|
macro(px4_setup_gtest_without_fuzztest)
|
||||||
|
include(FetchContent)
|
||||||
|
FetchContent_Declare(
|
||||||
|
googletest
|
||||||
|
GIT_REPOSITORY https://github.com/google/googletest.git
|
||||||
|
GIT_TAG v1.16.0
|
||||||
|
)
|
||||||
|
FetchContent_MakeAvailable(googletest)
|
||||||
|
|
||||||
|
function(link_fuzztest name)
|
||||||
|
target_link_libraries(${name} PRIVATE gtest gtest_main)
|
||||||
|
endfunction()
|
||||||
|
macro(fuzztest_setup_fuzzing_flags)
|
||||||
|
endmacro()
|
||||||
|
endmacro()
|
||||||
|
|
||||||
#=============================================================================
|
#=============================================================================
|
||||||
#
|
#
|
||||||
# px4_add_unit_gtest
|
# px4_add_unit_gtest
|
||||||
@@ -98,23 +122,28 @@ function(px4_add_functional_gtest)
|
|||||||
add_executable(${TESTNAME} EXCLUDE_FROM_ALL ${SRC} ${EXTRA_SRCS})
|
add_executable(${TESTNAME} EXCLUDE_FROM_ALL ${SRC} ${EXTRA_SRCS})
|
||||||
|
|
||||||
# link the libary to test and gtest
|
# link the libary to test and gtest
|
||||||
target_link_libraries(${TESTNAME} PRIVATE ${LINKLIBS} gtest_functional_main
|
set(_FUNCTIONAL_GTEST_LIBS ${LINKLIBS} gtest_functional_main
|
||||||
px4_layer
|
px4_layer
|
||||||
px4_platform
|
px4_platform
|
||||||
uORB
|
uORB
|
||||||
systemlib
|
systemlib
|
||||||
cdev
|
cdev
|
||||||
px4_work_queue
|
px4_work_queue
|
||||||
px4_daemon
|
px4_daemon
|
||||||
work_queue
|
work_queue
|
||||||
parameters
|
parameters
|
||||||
events
|
events
|
||||||
perf
|
perf
|
||||||
tinybson
|
tinybson
|
||||||
uorb_msgs
|
uorb_msgs)
|
||||||
fuzztest::fuzztest # Do not use link_fuzztest() here because that
|
if(TARGET fuzztest::fuzztest)
|
||||||
# also links to fuzztest_gtest_main
|
list(APPEND _FUNCTIONAL_GTEST_LIBS fuzztest::fuzztest) # Do not use link_fuzztest() here because that
|
||||||
test_stubs) # put test_stubs last
|
# also links to fuzztest_gtest_main
|
||||||
|
else()
|
||||||
|
list(APPEND _FUNCTIONAL_GTEST_LIBS gtest)
|
||||||
|
endif()
|
||||||
|
list(APPEND _FUNCTIONAL_GTEST_LIBS test_stubs) # put test_stubs last
|
||||||
|
target_link_libraries(${TESTNAME} PRIVATE ${_FUNCTIONAL_GTEST_LIBS})
|
||||||
|
|
||||||
target_compile_definitions(${TESTNAME} PRIVATE MODULE_NAME="${TESTNAME}")
|
target_compile_definitions(${TESTNAME} PRIVATE MODULE_NAME="${TESTNAME}")
|
||||||
|
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ add_executable(px4
|
|||||||
apps.cpp
|
apps.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
if (BUILD_TESTING)
|
if (BUILD_TESTING AND TARGET fuzztest::fuzztest)
|
||||||
# Build mavlink fuzz tests. These run other modules and thus cannot be a functional/unit test
|
# Build mavlink fuzz tests. These run other modules and thus cannot be a functional/unit test
|
||||||
add_executable(mavlink_fuzz_tests EXCLUDE_FROM_ALL
|
add_executable(mavlink_fuzz_tests EXCLUDE_FROM_ALL
|
||||||
src/px4/common/mavlink_fuzz_tests.cpp
|
src/px4/common/mavlink_fuzz_tests.cpp
|
||||||
|
|||||||
@@ -36,4 +36,9 @@ set(SRCS
|
|||||||
)
|
)
|
||||||
|
|
||||||
px4_add_library(gtest_functional_main ${SRCS})
|
px4_add_library(gtest_functional_main ${SRCS})
|
||||||
target_link_libraries(gtest_functional_main PUBLIC gtest fuzztest::init_fuzztest)
|
if(TARGET fuzztest::init_fuzztest)
|
||||||
|
target_link_libraries(gtest_functional_main PUBLIC gtest fuzztest::init_fuzztest)
|
||||||
|
target_compile_definitions(gtest_functional_main PRIVATE HAVE_FUZZTEST)
|
||||||
|
else()
|
||||||
|
target_link_libraries(gtest_functional_main PUBLIC gtest)
|
||||||
|
endif()
|
||||||
|
|||||||
@@ -32,7 +32,9 @@
|
|||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
|
#ifdef HAVE_FUZZTEST
|
||||||
#include <fuzztest/init_fuzztest.h>
|
#include <fuzztest/init_fuzztest.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <uORB/Subscription.hpp>
|
#include <uORB/Subscription.hpp>
|
||||||
|
|
||||||
@@ -42,8 +44,10 @@ int main(int argc, char **argv)
|
|||||||
{
|
{
|
||||||
testing::InitGoogleTest(&argc, argv);
|
testing::InitGoogleTest(&argc, argv);
|
||||||
|
|
||||||
|
#ifdef HAVE_FUZZTEST
|
||||||
fuzztest::ParseAbslFlags(argc, argv);
|
fuzztest::ParseAbslFlags(argc, argv);
|
||||||
fuzztest::InitFuzzTest(&argc, &argv);
|
fuzztest::InitFuzzTest(&argc, &argv);
|
||||||
|
#endif
|
||||||
|
|
||||||
uORB::Manager::initialize();
|
uORB::Manager::initialize();
|
||||||
param_init();
|
param_init();
|
||||||
|
|||||||
@@ -49,14 +49,16 @@ px4_add_module(
|
|||||||
module.yaml
|
module.yaml
|
||||||
)
|
)
|
||||||
|
|
||||||
px4_add_functional_gtest(SRC septentrio_fuzz_tests.cpp
|
if(TARGET fuzztest::fuzztest)
|
||||||
LINKLIBS
|
px4_add_functional_gtest(SRC septentrio_fuzz_tests.cpp
|
||||||
driver__septentrio
|
LINKLIBS
|
||||||
COMPILE_FLAGS
|
driver__septentrio
|
||||||
# There warnings come from within fuzztest
|
COMPILE_FLAGS
|
||||||
-Wno-float-equal
|
# There warnings come from within fuzztest
|
||||||
-Wno-sign-compare
|
-Wno-float-equal
|
||||||
-Wno-shadow
|
-Wno-sign-compare
|
||||||
-Wno-extra
|
-Wno-shadow
|
||||||
-Wno-non-template-friend
|
-Wno-extra
|
||||||
)
|
-Wno-non-template-friend
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|||||||
+9
-5
@@ -1,8 +1,12 @@
|
|||||||
px4_add_git_submodule(TARGET git_fuzztest PATH "fuzztest")
|
if(CMAKE_BUILD_TYPE STREQUAL "ThreadSanitizer")
|
||||||
|
message(STATUS "TSAN build: skipping fuzztest, fetching GTest only")
|
||||||
message(STATUS "Adding fuzztest")
|
px4_setup_gtest_without_fuzztest()
|
||||||
# This will also add GTest
|
else()
|
||||||
add_subdirectory(fuzztest EXCLUDE_FROM_ALL)
|
px4_add_git_submodule(TARGET git_fuzztest PATH "fuzztest")
|
||||||
|
message(STATUS "Adding fuzztest")
|
||||||
|
# This will also add GTest
|
||||||
|
add_subdirectory(fuzztest EXCLUDE_FROM_ALL)
|
||||||
|
endif()
|
||||||
|
|
||||||
# Ensure there's no -R without any filter expression since that trips newer ctest versions
|
# Ensure there's no -R without any filter expression since that trips newer ctest versions
|
||||||
if(TESTFILTER)
|
if(TESTFILTER)
|
||||||
|
|||||||
Reference in New Issue
Block a user