| 1 |
# Override network and random functions |
| 2 |
|
| 3 |
set(LIBFUZZER_LINKER_FLAGS) |
| 4 |
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") |
| 5 |
set(LIBFUZZER_LINKER_FLAGS "-fsanitize=fuzzer") |
| 6 |
else() |
| 7 |
message(SEND_ERROR "Compiler must be Clang to build fuzz targets") |
| 8 |
endif() |
| 9 |
|
| 10 |
function(fuzz_test target source_dir) |
| 11 |
set(CORPUS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/toktok-fuzzer/corpus/${target}_fuzz_test) |
| 12 |
file(GLOB CORPUS "${CORPUS_DIR}/*") |
| 13 |
add_executable(${target}_fuzz_test ${source_dir}/${target}_fuzz_test.cc) |
| 14 |
target_link_libraries(${target}_fuzz_test PRIVATE support test_util toxcore_fuzz ${LIBFUZZER_LINKER_FLAGS}) |
| 15 |
if(CORPUS) |
| 16 |
add_test(NAME ${target}_fuzz COMMAND ${target}_fuzz_test -max_total_time=10 ${CORPUS}) |
| 17 |
set_property(TEST ${target}_fuzz PROPERTY ENVIRONMENT "LLVM_PROFILE_FILE=${target}.profraw;srcdir=${CMAKE_CURRENT_SOURCE_DIR}") |
| 18 |
endif() |
| 19 |
endfunction() |
| 20 |
|
| 21 |
fuzz_test(bootstrap .) # Fuzzes the bootstrap process |
| 22 |
# TODO(iphydf): Fix this in the cmake build. |
| 23 |
# fuzz_test(e2e .) # Fuzzes an end-to-end connection |
| 24 |
fuzz_test(toxsave .) # Fuzzes tox_new and tox_get_savedata |
| 25 |
|
| 26 |
fuzz_test(DHT ../../toxcore) |
| 27 |
fuzz_test(forwarding ../../toxcore) |
| 28 |
fuzz_test(group_announce ../../toxcore) |
| 29 |
fuzz_test(group_moderation ../../toxcore) |
| 30 |
fuzz_test(net_crypto ../../toxcore) |
| 31 |
fuzz_test(tox_events ../../toxcore) |