Juraj Vijtiuk | f3939c9 | 2019-05-14 13:07:38 +0200 | [diff] [blame] | 1 | cmake_minimum_required(VERSION 2.8.12) |
| 2 | |
Juraj Vijtiuk | d798942 | 2020-09-15 13:54:00 +0200 | [diff] [blame] | 3 | if (ENABLE_FUZZ_TARGETS) |
| 4 | set(fuzz_targets lys_parse_mem lyd_parse_mem buf_add_char yang_parse_module) |
Juraj Vijtiuk | f3939c9 | 2019-05-14 13:07:38 +0200 | [diff] [blame] | 5 | |
Juraj Vijtiuk | d798942 | 2020-09-15 13:54:00 +0200 | [diff] [blame] | 6 | if(FUZZER STREQUAL "AFL") |
| 7 | foreach(target_name IN LISTS fuzz_targets) |
| 8 | add_executable(${target_name} ${target_name}.c main.c $<TARGET_OBJECTS:yangobj>) |
| 9 | target_link_libraries(${target_name} yang) |
| 10 | target_link_libraries(${target_name} ${CMAKE_THREADS_LIB_INIT}) |
| 11 | endforeach(target_name) |
| 12 | elseif(FUZZER STREQUAL "LibFuzzer") |
| 13 | foreach(target_name IN LISTS fuzz_targets) |
| 14 | add_executable(${target_name} ${target_name}.c $<TARGET_OBJECTS:yangobj>) |
| 15 | set_source_files_properties(${target_name}.c PROPERTIES COMPILE_FLAGS "-fsanitize=fuzzer") |
| 16 | target_link_libraries(${target_name} yang "-fsanitize=fuzzer") |
| 17 | endforeach(target_name) |
| 18 | endif() |
| 19 | endif() |
| 20 | |
| 21 | if (ENABLE_TESTING) |
| 22 | add_executable(fuzz_regression_test fuzz_regression_test.c) |
| 23 | set(fuzz_regression_tests lys_parse_mem lyd_parse_mem) |
| 24 | foreach(target_name IN LISTS fuzz_regression_tests) |
| 25 | file(COPY ${CMAKE_SOURCE_DIR}/tests/fuzz/corpus/${target_name} DESTINATION ${CMAKE_BINARY_DIR}/tests/fuzz/) |
| 26 | add_executable(${target_name}_test ${target_name}.c main.c $<TARGET_OBJECTS:yangobj>) |
| 27 | set_target_properties(${target_name}_test PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/tests/fuzz/${target_name}") |
| 28 | target_link_libraries(${target_name}_test yang) |
| 29 | target_link_libraries(${target_name}_test ${CMAKE_THREADS_LIB_INIT}) |
| 30 | add_test(NAME ${target_name}_test COMMAND fuzz_regression_test ${target_name}_test . WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/tests/fuzz/${target_name}) |
Juraj Vijtiuk | 260407e | 2020-03-18 10:32:13 +0100 | [diff] [blame] | 31 | endforeach(target_name) |
| 32 | endif() |