Skip to content

Commit

Permalink
Fb fuzz corpus (#293)
Browse files Browse the repository at this point in the history
* Add corpus directory to fuzz test registration function
* Add directory test before using corpus
  • Loading branch information
bretambrose authored Apr 2, 2019
1 parent fbe9359 commit a4f2f60
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
13 changes: 11 additions & 2 deletions cmake/AwsLibFuzzer.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ set(FUZZ_TESTS_MAX_TIME 60 CACHE STRING "Max time to run each fuzz test")
# Options:
# fuzz_files: The list of fuzz test files
# other_files: Other files to link into each fuzz test
function(aws_add_fuzz_tests fuzz_files other_files)
# corpus_dir: directory where corpus files can be found
function(aws_add_fuzz_tests fuzz_files other_files corpus_dir)
if(ENABLE_FUZZ_TESTS)
if(NOT ENABLE_SANITIZERS)
message(FATAL_ERROR "ENABLE_FUZZ_TESTS is set but ENABLE_SANITIZERS is set to OFF")
Expand All @@ -43,7 +44,15 @@ function(aws_add_fuzz_tests fuzz_files other_files)
target_compile_definitions(${FUZZ_BINARY_NAME} PRIVATE AWS_UNSTABLE_TESTING_API=1)
target_include_directories(${FUZZ_BINARY_NAME} PRIVATE ${CMAKE_CURRENT_LIST_DIR})

add_test(NAME fuzz_${TEST_FILE_NAME} COMMAND ${FUZZ_BINARY_NAME} -timeout=1 -max_total_time=${FUZZ_TESTS_MAX_TIME})
if (corpus_dir)
file(TO_NATIVE_PATH "${corpus_dir}/${TEST_FILE_NAME}" TEST_CORPUS_DIR)
endif()

if (TEST_CORPUS_DIR AND (EXISTS "${TEST_CORPUS_DIR}"))
add_test(NAME fuzz_${TEST_FILE_NAME} COMMAND ${FUZZ_BINARY_NAME} -timeout=1 -max_total_time=${FUZZ_TESTS_MAX_TIME} "${TEST_CORPUS_DIR}")
else()
add_test(NAME fuzz_${TEST_FILE_NAME} COMMAND ${FUZZ_BINARY_NAME} -timeout=1 -max_total_time=${FUZZ_TESTS_MAX_TIME})
endif()
endforeach()
endif()
endfunction()
2 changes: 1 addition & 1 deletion tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -290,4 +290,4 @@ if (NOT MSVC)
endif()

file(GLOB FUZZ_TESTS "fuzz/*.c")
aws_add_fuzz_tests("${FUZZ_TESTS}" "")
aws_add_fuzz_tests("${FUZZ_TESTS}" "" "")

0 comments on commit a4f2f60

Please sign in to comment.