Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ option(BUILD_WITH_PROTO_REFLECTION "Build mavsdk_server with proto reflection" O
option(BUILD_SHARED_LIBS "Build core as shared libraries instead of static ones" ON)
option(MAVLINK_DIALECT "MAVLink dialect. Default: common" "common")
option(BUILD_TESTING "Build tests" ON)
option(BUILD_FUZZ_TESTS "Build fuzz tests with libfuzzer" OFF)
option(BUILD_WITHOUT_CURL "Build without CURL" OFF)

message("Using cmake version: ${CMAKE_VERSION}")
Expand Down
4 changes: 4 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ if(BUILD_TESTING)
add_subdirectory(system_tests)
endif()

if(BUILD_FUZZ_TESTS)
add_subdirectory(fuzz_tests)
endif()

if (BUILD_MAVSDK_SERVER)
message(STATUS "Building mavsdk server")
add_subdirectory(mavsdk_server)
Expand Down
50 changes: 50 additions & 0 deletions src/fuzz_tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Check if fuzzing is enabled and compiler supports libfuzzer
if(NOT BUILD_FUZZ_TESTS)
return()
endif()

# Check if we're using Clang (required for libfuzzer)
if(NOT CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
message(WARNING "Fuzz tests require Clang compiler. Skipping fuzz tests.")
return()
endif()

# Create the UDP fuzzer executable
add_executable(udp_fuzzer
udp_fuzzer.cpp
)

# Set fuzzer-specific compiler and linker flags
target_compile_options(udp_fuzzer PRIVATE
-fsanitize=fuzzer,address
-g
-O1
)

target_link_options(udp_fuzzer PRIVATE
-fsanitize=fuzzer,address
)

# Link against MAVSDK
target_link_libraries(udp_fuzzer
mavsdk
)

# Include MAVSDK headers
target_include_directories(udp_fuzzer PRIVATE
${PROJECT_SOURCE_DIR}/mavsdk/core/include
${PROJECT_SOURCE_DIR}/mavsdk/core
)

# Add custom target for running the fuzzer
add_custom_target(run_udp_fuzzer
COMMAND ${CMAKE_CURRENT_BINARY_DIR}/udp_fuzzer -max_total_time=60 -print_final_stats=1
DEPENDS udp_fuzzer
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Running UDP fuzzer for 60 seconds"
)

# Print instructions
message(STATUS "Fuzz tests enabled. Build target 'udp_fuzzer' to create fuzzer executable.")
message(STATUS "Run 'make run_udp_fuzzer' to execute fuzzing for 60 seconds.")
message(STATUS "Or run manually: ./udp_fuzzer -help for options")
Loading