posix: add fuzz testing using MAVLink messages

This adds the env option PX4_FUZZ which runs the LLVM libFuzzer which
throws random bytes at mavlink_receiver using MAVLink messages over UDP.

The MAVLink messages that are being sent are valid, so the CRC is
calculated but the payload and msgid, etc. are generally garbage, unless
the fuzzing gets a msgid right by chance.

As I understand it, libFuzzer watches the test coverage and will try to
execute as much of the code as possible.
This commit is contained in:
Julian Oes
2019-09-04 16:30:20 +02:00
committed by Daniel Agar
parent c17a9e8003
commit 9eda5b373c
5 changed files with 200 additions and 4 deletions

View File

@@ -130,6 +130,23 @@ elseif (CMAKE_BUILD_TYPE STREQUAL UndefinedBehaviorSanitizer)
function(sanitizer_fail_test_on_error test_name)
set_tests_properties(${test_name} PROPERTIES FAIL_REGULAR_EXPRESSION "runtime error:")
endfunction(sanitizer_fail_test_on_error)
elseif (CMAKE_BUILD_TYPE STREQUAL FuzzTesting)
message(STATUS "FuzzTesting enabled")
add_compile_options(
-g3
-fsanitize=fuzzer,address,undefined
-DFUZZTESTING
)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=fuzzer,address,undefined" CACHE INTERNAL "" FORCE)
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fsanitize=fuzzer,address,undefined" CACHE INTERNAL "" FORCE)
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -fsanitize=fuzzer,address,undefined" CACHE INTERNAL "" FORCE)
function(sanitizer_fail_test_on_error test_name)
# Not sure what to do here
endfunction(sanitizer_fail_test_on_error)
else()
function(sanitizer_fail_test_on_error test_name)