blob: 66c035381c5d373e2fba2354a89a37c39e47e495 [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)
Juraj Vijtiuka1c0c702020-10-02 09:55:48 +02004 set(fuzz_targets lys_parse_mem lyd_parse_mem_xml lyd_parse_mem_json 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)
Juraj Vijtiuk2bab6f22020-09-24 13:55:53 +02008 add_executable(${target_name}_fuzz_harness ${target_name}.c main.c $<TARGET_OBJECTS:yangobj>)
9 target_link_libraries(${target_name}_fuzz_harness yang)
10 target_link_libraries(${target_name}_fuzz_harness ${CMAKE_THREADS_LIB_INIT})
Juraj Vijtiukd7989422020-09-15 13:54:00 +020011 endforeach(target_name)
12 elseif(FUZZER STREQUAL "LibFuzzer")
13 foreach(target_name IN LISTS fuzz_targets)
Juraj Vijtiuk2bab6f22020-09-24 13:55:53 +020014 add_executable(${target_name}_fuzz_harness ${target_name}.c $<TARGET_OBJECTS:yangobj>)
Juraj Vijtiukd7989422020-09-15 13:54:00 +020015 set_source_files_properties(${target_name}.c PROPERTIES COMPILE_FLAGS "-fsanitize=fuzzer")
Juraj Vijtiuk2bab6f22020-09-24 13:55:53 +020016 target_link_libraries(${target_name}_fuzz_harness yang "-fsanitize=fuzzer")
Juraj Vijtiukd7989422020-09-15 13:54:00 +020017 endforeach(target_name)
18 endif()
19endif()
20
Michal Vaskocdffdab2021-06-23 14:00:10 +020021if (ENABLE_TESTS)
Juraj Vijtiukd7989422020-09-15 13:54:00 +020022 add_executable(fuzz_regression_test fuzz_regression_test.c)
Juraj Vijtiuka1c0c702020-10-02 09:55:48 +020023 set(fuzz_regression_tests lys_parse_mem lyd_parse_mem_xml lyd_parse_mem_json)
Juraj Vijtiukd7989422020-09-15 13:54:00 +020024 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/)
Juraj Vijtiuk419cdc62020-09-28 12:43:20 +020026 add_executable(regress_fuzz_${target_name} ${target_name}.c main.c $<TARGET_OBJECTS:yangobj>)
27 set_target_properties(regress_fuzz_${target_name} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/tests/fuzz/${target_name}")
28 target_link_libraries(regress_fuzz_${target_name} yang)
29 target_link_libraries(regress_fuzz_${target_name} ${CMAKE_THREADS_LIB_INIT})
30 add_test(NAME regress_fuzz_${target_name} COMMAND fuzz_regression_test regress_fuzz_${target_name} . WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/tests/fuzz/${target_name})
Juraj Vijtiuk260407e2020-03-18 10:32:13 +010031 endforeach(target_name)
32endif()