blob: add72834193a9ab29aaf5f45e56fc06a4d615b1d [file] [log] [blame]
Juraj Vijtiukf3939c92019-05-14 13:07:38 +02001cmake_minimum_required(VERSION 2.8.12)
2
Juraj Vijtiukd7989422020-09-15 13:54:00 +02003if (ENABLE_FUZZ_TARGETS)
4 set(fuzz_targets lys_parse_mem lyd_parse_mem buf_add_char yang_parse_module)
Juraj Vijtiukf3939c92019-05-14 13:07:38 +02005
Juraj Vijtiukd7989422020-09-15 13:54:00 +02006 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()
19endif()
20
21if (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 Vijtiuk260407e2020-03-18 10:32:13 +010031 endforeach(target_name)
32endif()