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:
Julian Oes
2026-02-19 05:43:44 +13:00
parent 64ddfebfc6
commit 5dbf62cd11
6 changed files with 79 additions and 35 deletions
+1 -1
View File
@@ -28,7 +28,7 @@ add_executable(px4
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
add_executable(mavlink_fuzz_tests EXCLUDE_FROM_ALL
src/px4/common/mavlink_fuzz_tests.cpp
@@ -36,4 +36,9 @@ set(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>
#ifdef HAVE_FUZZTEST
#include <fuzztest/init_fuzztest.h>
#endif
#include <uORB/Subscription.hpp>
@@ -42,8 +44,10 @@ int main(int argc, char **argv)
{
testing::InitGoogleTest(&argc, argv);
#ifdef HAVE_FUZZTEST
fuzztest::ParseAbslFlags(argc, argv);
fuzztest::InitFuzzTest(&argc, &argv);
#endif
uORB::Manager::initialize();
param_init();