forked from irungentoo/toxcore
-
Notifications
You must be signed in to change notification settings - Fork 292
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Add fuzz tests to the coverage run.
So we don't need to write so many edge case tests ourselves for things like parsers, which really don't need those manual tests, as long as we can check for some properties like "can output the parsed data and it'll be the same as the input".
- Loading branch information
Showing
9 changed files
with
69 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,33 @@ | ||
# For coverage tests | ||
target_compile_definitions(toxcore_static PUBLIC "FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION") | ||
|
||
# Override network and random functions | ||
add_library(fuzz_support func_conversion.h fuzz_support.cc fuzz_support.h) | ||
|
||
set(LIBFUZZER_LINKER_FLAGS) | ||
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") | ||
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") | ||
set(LIBFUZZER_LINKER_FLAGS "-fsanitize=fuzzer") | ||
else() | ||
message(SEND_ERROR "Compiler must be Clang to build fuzz targets") | ||
endif() | ||
|
||
function(fuzz_test target source_dir) | ||
set(${target}_CORPUS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/toktok-fuzzer/corpus/${target}_fuzz_test) | ||
file(GLOB ${target}_fuzz_CORPUS "${${target}_CORPUS_DIR}/*") | ||
add_executable(${target}_fuzz_test ${source_dir}/${target}_fuzz_test.cc) | ||
target_link_libraries(${target}_fuzz_test PRIVATE toxcore_fuzz fuzz_support ${LIBFUZZER_LINKER_FLAGS}) | ||
if(${target}_fuzz_CORPUS) | ||
add_test(NAME ${target}_fuzz COMMAND ${CROSSCOMPILING_EMULATOR} ${target}_fuzz_test -max_total_time=10 ${${target}_fuzz_CORPUS}) | ||
endif() | ||
endfunction() | ||
|
||
# Fuzzes the toxsave API | ||
add_executable(toxsave_fuzzer toxsave_harness.cc) | ||
target_link_libraries(toxsave_fuzzer PRIVATE toxcore_static fuzz_support ${LIBFUZZER_LINKER_FLAGS}) | ||
target_link_libraries(toxsave_fuzzer PRIVATE toxcore_fuzz fuzz_support ${LIBFUZZER_LINKER_FLAGS}) | ||
|
||
# Fuzzes the bootstrap process | ||
add_executable(bootstrap_fuzzer bootstrap_harness.cc) | ||
target_link_libraries(bootstrap_fuzzer PRIVATE toxcore_static fuzz_support ${LIBFUZZER_LINKER_FLAGS}) | ||
|
||
add_executable(DHT_fuzz_test ../../toxcore/DHT_fuzz_test.cc) | ||
target_link_libraries(DHT_fuzz_test PRIVATE toxcore_static fuzz_support ${LIBFUZZER_LINKER_FLAGS}) | ||
target_link_libraries(bootstrap_fuzzer PRIVATE toxcore_fuzz fuzz_support ${LIBFUZZER_LINKER_FLAGS}) | ||
|
||
add_executable(tox_events_fuzz_test ../../toxcore/tox_events_fuzz_test.cc) | ||
target_link_libraries(tox_events_fuzz_test PRIVATE toxcore_static fuzz_support ${LIBFUZZER_LINKER_FLAGS}) | ||
fuzz_test(DHT ../../toxcore) | ||
fuzz_test(forwarding ../../toxcore) | ||
fuzz_test(group_announce ../../toxcore) | ||
fuzz_test(group_moderation ../../toxcore) | ||
fuzz_test(tox_events ../../toxcore) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters