Debian Codegraph @

c/tests/fuzz/CMakeLists.txt

raw
1 #
2 # Licensed to the Apache Software Foundation (ASF) under one
3 # or more contributor license agreements. See the NOTICE file
4 # distributed with this work for additional information
5 # regarding copyright ownership. The ASF licenses this file
6 # to you under the Apache License, Version 2.0 (the
7 # "License"); you may not use this file except in compliance
8 # with the License. You may obtain a copy of the License at
9 #
10 # http://www.apache.org/licenses/LICENSE-2.0
11 #
12 # Unless required by applicable law or agreed to in writing,
13 # software distributed under the License is distributed on an
14 # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 # KIND, either express or implied. See the License for the
16 # specific language governing permissions and limitations
17 # under the License.
18 #
19
20 add_definitions(${C_STANDARD_FLAGS} ${COMPILE_WARNING_FLAGS})
21
22 option(FUZZ_REGRESSION_TESTS "Run fuzz tests with regression test driver" ON)
23 option(FUZZ_LONG_TESTS "Run fuzz tests that take a long time" OFF)
24
25 # prefer static lib for the fuzzer, if available
26 if (BUILD_STATIC_LIBS)
27 set(FUZZING_QPID_PROTON_CORE_LIBRARY qpid-proton-core-static)
28 set(FUZZING_QPID_PROTON_PROACTOR_LIBRARY qpid-proton-proactor-static)
29 else()
30 set(FUZZING_QPID_PROTON_CORE_LIBRARY qpid-proton-core)
31 set(FUZZING_QPID_PROTON_PROACTOR_LIBRARY qpid-proton-proactor)
32 endif()
33
34 if (FUZZ_REGRESSION_TESTS)
35 set(FUZZING_LIBRARY StandaloneFuzzTargetMain)
36 else ()
37 set(FUZZING_LIBRARY FuzzingEngine)
38 endif ()
39
40 add_library (StandaloneFuzzTargetMain STATIC StandaloneFuzzTargetMain.c StandaloneFuzzTargetInit.c)
41
42 macro (pn_add_fuzz_test test)
43 add_executable (${test} ${ARGN})
44 target_link_libraries (${test} ${FUZZING_LIBRARY})
45 # -lFuzzingEngine is a C++ library, which needs c++ std lib
46 set_target_properties(${test} PROPERTIES LINKER_LANGUAGE CXX)
47
48 list(APPEND fuzz_test_src ${ARGN})
49
50 if (FUZZ_REGRESSION_TESTS)
51 # StandaloneFuzzTargetMain cannot walk directory trees
52 file(GLOB_RECURSE files ${CMAKE_CURRENT_SOURCE_DIR}/${test}/*)
53 unset(file_lines)
54 foreach(f IN LISTS files)
55 set(file_lines "${file_lines}${f}\n")
56 endforeach()
57 file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/${test}-files" "${file_lines}")
58 pn_add_test(
59 EXECUTABLE
60 NAME ${test}
61 PREPEND_ENVIRONMENT ${test_env}
62 COMMAND $<TARGET_FILE:${test}> "@${CMAKE_CURRENT_BINARY_DIR}/${test}-files")
63 else ()
64 pn_add_test(
65 EXECUTABLE
66 NAME ${test}
67 COMMAND $<TARGET_FILE:${test}> -runs=1 ${CMAKE_CURRENT_SOURCE_DIR}/${test}>)
68 endif ()
69 endmacro(pn_add_fuzz_test)
70
71 unset(fuzz_test_src)
72
73 # Fuzz tests at the User API level
74 pn_add_fuzz_test (fuzz-connection-driver fuzz-connection-driver.c)
75 target_link_libraries (fuzz-connection-driver ${FUZZING_QPID_PROTON_CORE_LIBRARY})
76 pn_add_fuzz_test (fuzz-message-decode fuzz-message-decode.c)
77 target_link_libraries (fuzz-message-decode ${FUZZING_QPID_PROTON_CORE_LIBRARY})
78
79 # pn_url_parse is not in proton core and is only used by messenger so compile specially
80 pn_add_fuzz_test (fuzz-url
81 fuzz-url.c
82 ${PN_C_SOURCE_DIR}/extra/url.c
83 ${PN_C_SOURCE_DIR}/core/object/object.c
84 ${PN_C_SOURCE_DIR}/core/object/string.c
85 ${PN_C_SOURCE_DIR}/core/util.c
86 ${PN_C_SOURCE_DIR}/core/memory.c)
87 target_compile_definitions(fuzz-url PRIVATE PROTON_DECLARE_STATIC)
88
89 # This regression test can take a very long time so don't run by default
90 if(HAS_PROACTOR AND FUZZ_LONG_TESTS)
91 pn_add_fuzz_test (fuzz-proactor-receive fuzz-proactor-receive.c)
92 target_link_libraries(fuzz-proactor-receive ${FUZZING_QPID_PROTON_CORE_LIBRARY} ${FUZZING_QPID_PROTON_PROACTOR_LIBRARY})
93 endif()
94
95 # Fuzz tests of internals
96
97 # pni_sniff_header is internal so it has to be compiled specially
98 pn_add_fuzz_test (fuzz-sniff-header fuzz-sniff-header.c ${PN_C_SOURCE_DIR}/core/autodetect.c)